mirror of
https://github.com/neocities/neocities.git
synced 2025-08-06 09:34:57 +02:00
separate site and account settings context
This commit is contained in:
parent
7e36dc83f8
commit
d0970cdf9e
16 changed files with 515 additions and 443 deletions
86
tests/acceptance/settings/account_tests.rb
Normal file
86
tests/acceptance/settings/account_tests.rb
Normal file
|
@ -0,0 +1,86 @@
|
|||
require_relative '../environment.rb'
|
||||
|
||||
describe 'site/settings' do
|
||||
describe 'email' do
|
||||
include Capybara::DSL
|
||||
|
||||
before do
|
||||
EmailWorker.jobs.clear
|
||||
@email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||
@site = Fabricate :site, email: @email
|
||||
page.set_rack_session id: @site.id
|
||||
visit '/settings'
|
||||
end
|
||||
|
||||
it 'should change email' do
|
||||
@new_email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||
fill_in 'email', with: @new_email
|
||||
click_button 'Change Email'
|
||||
page.must_have_content /successfully changed email/i
|
||||
@site.reload
|
||||
@site.email.must_equal @new_email
|
||||
EmailWorker.jobs.length.must_equal 1
|
||||
args = EmailWorker.jobs.first['args'].first
|
||||
args['to'].must_equal @new_email
|
||||
args['subject'].must_match /confirm your email address/i
|
||||
args['body'].must_match /hello #{@site.username}/i
|
||||
args['body'].must_match /#{@site.email_confirmation_token}/
|
||||
end
|
||||
|
||||
it 'should fail for invalid email address' do
|
||||
@new_email = SecureRandom.uuid.gsub '-', ''
|
||||
fill_in 'email', with: @new_email
|
||||
click_button 'Change Email'
|
||||
page.must_have_content /a valid email address is required/i
|
||||
@site.reload
|
||||
@site.email.wont_equal @new_email
|
||||
EmailWorker.jobs.empty?.must_equal true
|
||||
end
|
||||
|
||||
it 'should fail for existing email' do
|
||||
@existing_email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||
@existing_site = Fabricate :site, email: @existing_email
|
||||
|
||||
fill_in 'email', with: @existing_email
|
||||
click_button 'Change Email'
|
||||
page.must_have_content /this email address already exists on neocities/i
|
||||
@site.reload
|
||||
@site.email.wont_equal @new_email
|
||||
EmailWorker.jobs.empty?.must_equal true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'change password' do
|
||||
include Capybara::DSL
|
||||
|
||||
before do
|
||||
@site = Fabricate :site, password: 'derpie'
|
||||
page.set_rack_session id: @site.id
|
||||
visit '/settings'
|
||||
end
|
||||
|
||||
it 'should change correctly' do
|
||||
fill_in 'current_password', with: 'derpie'
|
||||
fill_in 'new_password', with: 'derpie2'
|
||||
fill_in 'new_password_confirm', with: 'derpie2'
|
||||
click_button 'Change Password'
|
||||
|
||||
page.must_have_content /successfully changed password/i
|
||||
@site.reload
|
||||
@site.valid_password?('derpie').must_equal false
|
||||
@site.valid_password?('derpie2').must_equal true
|
||||
end
|
||||
|
||||
it 'should not change for invalid current password' do
|
||||
fill_in 'current_password', with: 'dademurphy'
|
||||
fill_in 'new_password', with: 'derpie2'
|
||||
fill_in 'new_password_confirm', with: 'derpie2'
|
||||
click_button 'Change Password'
|
||||
|
||||
page.must_have_content /provided password does not match the current one/i
|
||||
@site.reload
|
||||
@site.valid_password?('derpie').must_equal true
|
||||
@site.valid_password?('derpie2').must_equal false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
require_relative './environment.rb'
|
||||
require_relative '../environment.rb'
|
||||
|
||||
def generate_ssl_certs(opts={})
|
||||
# https://github.com/kyledrake/ruby-openssl-cheat-sheet/blob/master/certificate_authority.rb
|
||||
|
@ -92,13 +92,13 @@ describe 'site/settings' do
|
|||
it 'fails without domain set' do
|
||||
@site = Fabricate :site
|
||||
page.set_rack_session id: @site.id
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
page.must_have_content /Cannot upload SSL certificate until domain is added/i
|
||||
end
|
||||
|
||||
it 'fails with expired key' do
|
||||
@ssl = generate_ssl_certs domain: @domain, expired: true
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
attach_file 'key', @ssl[:key_path]
|
||||
attach_file 'cert', @ssl[:combined_cert_path]
|
||||
click_button 'Upload SSL Key and Certificate'
|
||||
|
@ -107,14 +107,14 @@ describe 'site/settings' do
|
|||
|
||||
it 'works with valid key and unified cert' do
|
||||
@ssl = generate_ssl_certs domain: @domain
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
key = File.read @ssl[:key_path]
|
||||
combined_cert = File.read @ssl[:combined_cert_path]
|
||||
page.must_have_content /status: inactive/i
|
||||
attach_file 'key', @ssl[:key_path]
|
||||
attach_file 'cert', @ssl[:combined_cert_path]
|
||||
click_button 'Upload SSL Key and Certificate'
|
||||
page.current_path.must_equal '/custom_domain'
|
||||
page.current_path.must_equal "/settings/#{@site.username}"
|
||||
page.must_have_content /Updated SSL/
|
||||
page.must_have_content /status: installed/i
|
||||
@site.reload
|
||||
|
@ -123,9 +123,9 @@ describe 'site/settings' do
|
|||
end
|
||||
|
||||
it 'fails with no uploads' do
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
click_button 'Upload SSL Key and Certificate'
|
||||
page.current_path.must_equal '/custom_domain'
|
||||
page.current_path.must_equal "/settings/#{@site.username}"
|
||||
page.must_have_content /ssl key.+certificate.+required/i
|
||||
@site.reload
|
||||
@site.ssl_key.must_equal nil
|
||||
|
@ -134,42 +134,42 @@ describe 'site/settings' do
|
|||
|
||||
it 'fails gracefully with encrypted key' do
|
||||
@ssl = generate_ssl_certs domain: @domain
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
attach_file 'key', './tests/files/ssl/derpie.com-encrypted.key'
|
||||
attach_file 'cert', @ssl[:cert_path]
|
||||
click_button 'Upload SSL Key and Certificate'
|
||||
page.current_path.must_equal '/custom_domain'
|
||||
page.current_path.must_equal "/settings/#{@site.username}"
|
||||
page.must_have_content /could not process ssl key/i
|
||||
end
|
||||
|
||||
it 'fails with junk key' do
|
||||
@ssl = generate_ssl_certs domain: @domain
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
attach_file 'key', './tests/files/index.html'
|
||||
attach_file 'cert', @ssl[:cert_path]
|
||||
click_button 'Upload SSL Key and Certificate'
|
||||
page.current_path.must_equal '/custom_domain'
|
||||
page.current_path.must_equal "/settings/#{@site.username}"
|
||||
page.must_have_content /could not process ssl key/i
|
||||
end
|
||||
|
||||
it 'fails with junk cert' do
|
||||
@ssl = generate_ssl_certs domain: @domain
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
attach_file 'key', @ssl[:key_path]
|
||||
attach_file 'cert', './tests/files/index.html'
|
||||
click_button 'Upload SSL Key and Certificate'
|
||||
page.current_path.must_equal '/custom_domain'
|
||||
page.current_path.must_equal "/settings/#{@site.username}"
|
||||
page.must_have_content /could not process ssl certificate/i
|
||||
end
|
||||
|
||||
if ENV['TRAVIS'] != 'true'
|
||||
it 'fails with bad cert chain' do
|
||||
@ssl = generate_ssl_certs domain: @domain
|
||||
visit '/custom_domain'
|
||||
visit "/settings/#{@site.username}#custom_domain"
|
||||
attach_file 'key', @ssl[:key_path]
|
||||
attach_file 'cert', @ssl[:bad_combined_cert_path]
|
||||
click_button 'Upload SSL Key and Certificate'
|
||||
page.current_path.must_equal '/custom_domain'
|
||||
page.current_path.must_equal "/settings/#{@site.username}"
|
||||
page.must_have_content /there is something wrong with your certificate/i
|
||||
end
|
||||
end
|
||||
|
@ -200,7 +200,7 @@ describe 'site/settings' do
|
|||
click_button 'Create My Website'
|
||||
fill_in_valid
|
||||
click_button 'Create Home Page'
|
||||
visit '/settings'
|
||||
visit "/settings/#{@site[:username]}#username"
|
||||
fill_in 'name', with: ''
|
||||
click_button 'Change Name'
|
||||
fill_in 'name', with: '../hack'
|
||||
|
@ -215,87 +215,4 @@ describe 'site/settings' do
|
|||
Site[username: ''].must_equal nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'email' do
|
||||
include Capybara::DSL
|
||||
|
||||
before do
|
||||
EmailWorker.jobs.clear
|
||||
@email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||
@site = Fabricate :site, email: @email
|
||||
page.set_rack_session id: @site.id
|
||||
visit '/settings'
|
||||
end
|
||||
|
||||
it 'should change email' do
|
||||
@new_email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||
fill_in 'email', with: @new_email
|
||||
click_button 'Change Email'
|
||||
page.must_have_content /successfully changed email/i
|
||||
@site.reload
|
||||
@site.email.must_equal @new_email
|
||||
EmailWorker.jobs.length.must_equal 1
|
||||
args = EmailWorker.jobs.first['args'].first
|
||||
args['to'].must_equal @new_email
|
||||
args['subject'].must_match /confirm your email address/i
|
||||
args['body'].must_match /hello #{@site.username}/i
|
||||
args['body'].must_match /#{@site.email_confirmation_token}/
|
||||
end
|
||||
|
||||
it 'should fail for invalid email address' do
|
||||
@new_email = SecureRandom.uuid.gsub '-', ''
|
||||
fill_in 'email', with: @new_email
|
||||
click_button 'Change Email'
|
||||
page.must_have_content /a valid email address is required/i
|
||||
@site.reload
|
||||
@site.email.wont_equal @new_email
|
||||
EmailWorker.jobs.empty?.must_equal true
|
||||
end
|
||||
|
||||
it 'should fail for existing email' do
|
||||
@existing_email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||
@existing_site = Fabricate :site, email: @existing_email
|
||||
|
||||
fill_in 'email', with: @existing_email
|
||||
click_button 'Change Email'
|
||||
page.must_have_content /this email address already exists on neocities/i
|
||||
@site.reload
|
||||
@site.email.wont_equal @new_email
|
||||
EmailWorker.jobs.empty?.must_equal true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'change password' do
|
||||
include Capybara::DSL
|
||||
|
||||
before do
|
||||
@site = Fabricate :site, password: 'derpie'
|
||||
page.set_rack_session id: @site.id
|
||||
visit '/settings'
|
||||
end
|
||||
|
||||
it 'should change correctly' do
|
||||
fill_in 'current_password', with: 'derpie'
|
||||
fill_in 'new_password', with: 'derpie2'
|
||||
fill_in 'new_password_confirm', with: 'derpie2'
|
||||
click_button 'Change Password'
|
||||
|
||||
page.must_have_content /successfully changed password/i
|
||||
@site.reload
|
||||
@site.valid_password?('derpie').must_equal false
|
||||
@site.valid_password?('derpie2').must_equal true
|
||||
end
|
||||
|
||||
it 'should not change for invalid current password' do
|
||||
fill_in 'current_password', with: 'dademurphy'
|
||||
fill_in 'new_password', with: 'derpie2'
|
||||
fill_in 'new_password_confirm', with: 'derpie2'
|
||||
click_button 'Change Password'
|
||||
|
||||
page.must_have_content /provided password does not match the current one/i
|
||||
@site.reload
|
||||
@site.valid_password?('derpie').must_equal true
|
||||
@site.valid_password?('derpie2').must_equal false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue