From 374eb7bd3f369cba946d4b8002cd51a499aef32a Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 14 Jul 2013 14:28:35 +0200 Subject: js integration test for signup, login, logout --- users/test/integration/browser/account_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 users/test/integration/browser/account_test.rb (limited to 'users/test/integration') diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb new file mode 100644 index 0000000..a112430 --- /dev/null +++ b/users/test/integration/browser/account_test.rb @@ -0,0 +1,21 @@ +class AccountTest < BrowserIntegrationTest + + setup do + Capybara.current_driver = Capybara.javascript_driver # :selenium by default + end + + test "normal account workflow" do + username = "test_#{SecureRandom.urlsafe_base64}".downcase + password = SecureRandom.base64 + visit '/users/new' + fill_in 'Username', with: username + fill_in 'Password', with: password + fill_in 'Password confirmation', with: password + click_on 'Sign Up' + assert page.has_content?("Welcome #{username}"), + "failed to verify server. expected M2: #{page.evaluate_script("srp.session.getM2();")}" + click_on 'Logout' + assert_equal '/', current_path + end + +end -- cgit v1.2.3 From 740813d8350290c176c1b0d0cfe3ac80aee1b420 Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 14 Jul 2013 16:19:32 +0200 Subject: we do not expose M2 in srp.js anymore. So there is no way to print it. This message used to be correct but there are also other things that can cause this to fail now. So let's just remove it. --- users/test/integration/browser/account_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'users/test/integration') diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb index a112430..4fff637 100644 --- a/users/test/integration/browser/account_test.rb +++ b/users/test/integration/browser/account_test.rb @@ -12,8 +12,7 @@ class AccountTest < BrowserIntegrationTest fill_in 'Password', with: password fill_in 'Password confirmation', with: password click_on 'Sign Up' - assert page.has_content?("Welcome #{username}"), - "failed to verify server. expected M2: #{page.evaluate_script("srp.session.getM2();")}" + assert page.has_content?("Welcome #{username}") click_on 'Logout' assert_equal '/', current_path end -- cgit v1.2.3 From 8b79988c4c6cedd77664e14f16b149a669965eff Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 14 Jul 2013 19:52:54 +0200 Subject: make sure capybara runs the whole rack app We use port 3003 for the integration test server. This test takes a few seconds (~8) now. Most of this is startup time of the server. A second run still takes 2 seconds like before. --- users/test/integration/api/rack_test.rb | 3 --- users/test/integration/browser/account_test.rb | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'users/test/integration') diff --git a/users/test/integration/api/rack_test.rb b/users/test/integration/api/rack_test.rb index da960f2..9a69f52 100644 --- a/users/test/integration/api/rack_test.rb +++ b/users/test/integration/api/rack_test.rb @@ -1,6 +1,3 @@ -CONFIG_RU = (Rails.root + 'config.ru').to_s -OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first - class RackTest < ActiveSupport::TestCase include Rack::Test::Methods include Warden::Test::Helpers diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb index 4fff637..5483c89 100644 --- a/users/test/integration/browser/account_test.rb +++ b/users/test/integration/browser/account_test.rb @@ -1,7 +1,7 @@ class AccountTest < BrowserIntegrationTest setup do - Capybara.current_driver = Capybara.javascript_driver # :selenium by default + Capybara.current_driver = Capybara.javascript_driver end test "normal account workflow" do -- cgit v1.2.3 From 48db4caa2fff451ce9cbb1b52c895ea7136736a4 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 15 Jul 2013 12:26:07 +0200 Subject: require test_helper from account test so it can be run in isolation --- users/test/integration/browser/account_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'users/test/integration') diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb index 5483c89..9f6d067 100644 --- a/users/test/integration/browser/account_test.rb +++ b/users/test/integration/browser/account_test.rb @@ -1,3 +1,5 @@ +require 'test_helper' + class AccountTest < BrowserIntegrationTest setup do -- cgit v1.2.3 From f40c09a8b750d5d317a22af7186bde5c940b6924 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 16 Jul 2013 13:06:48 +0200 Subject: ensure the page has been reloaded before testing current_path This test would fail sometimes on assert_equal '/', current_path I believe it was a timing issue. page.has_content? will wait for the content to show up. So afterwards the current_path should always be correct. --- users/test/integration/browser/account_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'users/test/integration') diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb index 9f6d067..ce63baf 100644 --- a/users/test/integration/browser/account_test.rb +++ b/users/test/integration/browser/account_test.rb @@ -16,6 +16,7 @@ class AccountTest < BrowserIntegrationTest click_on 'Sign Up' assert page.has_content?("Welcome #{username}") click_on 'Logout' + assert page.has_content?("Sign Up") assert_equal '/', current_path end -- cgit v1.2.3 From 8486248a7a960bc75f25f2c5a00791416f124ac4 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 16 Jul 2013 13:14:01 +0200 Subject: adapt srp account_flow test for the api to new ruby_srp API --- users/test/integration/api/account_flow_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'users/test/integration') diff --git a/users/test/integration/api/account_flow_test.rb b/users/test/integration/api/account_flow_test.rb index f5cb0b1..4c94389 100644 --- a/users/test/integration/api/account_flow_test.rb +++ b/users/test/integration/api/account_flow_test.rb @@ -26,19 +26,19 @@ class AccountFlowTest < RackTest def handshake(login, aa) post "http://api.lvh.me:3000/1/sessions.json", :login => login, - 'A' => aa.to_s(16), + 'A' => aa, :format => :json response = JSON.parse(last_response.body) if response['errors'] raise RECORD_NOT_FOUND.new(response['errors']) else - return response['B'].hex + return response['B'] end end def validate(m) put "http://api.lvh.me:3000/1/sessions/" + @login + '.json', - :client_auth => m.to_s(16), + :client_auth => m, :format => :json return JSON.parse(last_response.body) end -- cgit v1.2.3