mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
change name downcases username check
This commit is contained in:
parent
9170f9f99c
commit
aeb5fe4e34
2 changed files with 26 additions and 11 deletions
|
@ -179,7 +179,7 @@ post '/settings/:username/change_name' do
|
|||
redirect "/settings/#{@site.username}#username"
|
||||
end
|
||||
|
||||
if old_username == params[:name]
|
||||
if old_username.downcase == params[:name].downcase
|
||||
flash[:error] = 'You already have this name.'
|
||||
redirect "/settings/#{@site.username}#username"
|
||||
end
|
||||
|
|
|
@ -200,29 +200,44 @@ describe 'site/settings' do
|
|||
end
|
||||
=end
|
||||
|
||||
describe 'change username' do
|
||||
describe 'changing username' do
|
||||
include Capybara::DSL
|
||||
|
||||
before do
|
||||
Capybara.reset_sessions!
|
||||
@site = Fabricate :site
|
||||
page.set_rack_session id: @site.id
|
||||
visit "/settings/#{@site[:username]}#username"
|
||||
end
|
||||
|
||||
it 'does not allow bad usernames' do
|
||||
visit "/settings/#{@site[:username]}#username"
|
||||
after do
|
||||
Site[username: @site[:username]].wont_equal nil
|
||||
end
|
||||
|
||||
it 'fails for blank username' do
|
||||
fill_in 'name', with: ''
|
||||
click_button 'Change Name'
|
||||
page.must_have_content /cannot be blank/i
|
||||
Site[username: ''].must_equal nil
|
||||
end
|
||||
|
||||
it 'fails for subdir periods' do
|
||||
fill_in 'name', with: '../hack'
|
||||
click_button 'Change Name'
|
||||
fill_in 'name', with: 'derp../hack'
|
||||
click_button 'Change Name'
|
||||
## TODO fix this without screwing up legacy sites
|
||||
#fill_in 'name', with: '-'
|
||||
#click_button 'Change Name'
|
||||
page.must_have_content /Usernames can only contain/i
|
||||
Site[username: @site[:username]].wont_equal nil
|
||||
Site[username: ''].must_equal nil
|
||||
Site[username: '../hack'].must_equal nil
|
||||
end
|
||||
|
||||
it 'fails for same username' do
|
||||
fill_in 'name', with: @site.username
|
||||
click_button 'Change Name'
|
||||
page.must_have_content /You already have this name/
|
||||
end
|
||||
|
||||
it 'fails for same username with DiFfErEnT CaSiNg' do
|
||||
fill_in 'name', with: @site.username.upcase
|
||||
click_button 'Change Name'
|
||||
page.must_have_content /You already have this name/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue