From acd6dd2848f38ba1b728f263f297bc6d2ad9e4bb Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 2 Dec 2014 23:47:35 -0800 Subject: add soledad sync test to `leap test`. closes #6431 --- tests/helpers/bonafide_helper.rb | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/helpers/bonafide_helper.rb (limited to 'tests/helpers/bonafide_helper.rb') diff --git a/tests/helpers/bonafide_helper.rb b/tests/helpers/bonafide_helper.rb new file mode 100644 index 00000000..c84ea142 --- /dev/null +++ b/tests/helpers/bonafide_helper.rb @@ -0,0 +1,87 @@ +# +# helper for the communication with the provider API for creating, authenticating, and deleting accounts. +# + +class LeapTest + + def assert_tmp_user + user = assert_create_user + assert_authenticate_user(user) + yield user if block_given? + rescue + # ^^ ensure here would eat any failed assertions + assert_delete_user(user) + raise + end + + def api_url(path) + api = property('api') + "https://%{domain}:%{port}#{path}" % { + :domain => api['domain'], + :port => api['port'] + } + end + + # + # attempts to create a user account via the API, + # returning the user object if successful. + # + def assert_create_user + user = SRP::User.new + url = api_url("/1/users.json") + assert_post(url, user.to_params) do |body| + assert response = JSON.parse(body), 'response should be JSON' + assert response['ok'], 'creating a user should be successful' + end + user.ok = true + return user + end + + # + # attempts to authenticate user. if successful, + # user object is updated with id and session token. + # + def assert_authenticate_user(user) + url = api_url("/1/sessions.json") + session = SRP::Session.new(user) + params = {'login' => user.username, 'A' => session.aa} + assert_post(url, params) do |response, body| + cookie = response['Set-Cookie'].split(';').first + assert(response = JSON.parse(body), 'response should be JSON') + assert(session.bb = response["B"], 'response should include "B"') + url = api_url("/1/sessions/login.json") + params = {'client_auth' => session.m, 'A' => session.aa} + options = {:headers => {'Cookie' => cookie}} + assert_put(url, params, options) do |body| + assert(response = JSON.parse(body), 'response should be JSON') + assert(response['M2'], 'response should include M2') + user.session_token = response['token'] + user.id = response['id'] + assert(user.session_token, 'response should include token') + assert(user.id, 'response should include user id') + end + end + end + + # + # attempts to destroy a user account via the API. + # + def assert_delete_user(user) + if user && user.ok && user.id && user.session_token + url = api_url("/1/users/#{user.id}.json") + options = {:headers => { + "Authorization" => "Token token=\"#{user.session_token}\"" + }} + delete(url, {}, options) do |body, response, error| + if response.code.to_i != 200 + skip "It appears the web api is too old to support deleting users" + else + assert(response = JSON.parse(body), 'response should be JSON') + assert(response["success"], 'delete should be a success') + pass + end + end + end + end + +end -- cgit v1.2.3 From 7ca1a6feb2f881f2a99b624c266f0779d2402ff9 Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 4 Dec 2014 15:16:25 -0800 Subject: tests - better errors, ensure tmp users are deleted, remove bad 'pass()' call that made tmp_user tests always succeed. --- tests/helpers/bonafide_helper.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/helpers/bonafide_helper.rb') diff --git a/tests/helpers/bonafide_helper.rb b/tests/helpers/bonafide_helper.rb index c84ea142..d96b3977 100644 --- a/tests/helpers/bonafide_helper.rb +++ b/tests/helpers/bonafide_helper.rb @@ -8,10 +8,13 @@ class LeapTest user = assert_create_user assert_authenticate_user(user) yield user if block_given? - rescue - # ^^ ensure here would eat any failed assertions assert_delete_user(user) - raise + rescue StandardError, MiniTest::Assertion => exc + begin + assert_delete_user(user) + rescue + end + raise exc end def api_url(path) @@ -67,19 +70,16 @@ class LeapTest # attempts to destroy a user account via the API. # def assert_delete_user(user) - if user && user.ok && user.id && user.session_token + if user && user.ok && user.id && user.session_token && !user.deleted url = api_url("/1/users/#{user.id}.json") options = {:headers => { "Authorization" => "Token token=\"#{user.session_token}\"" }} + user.deleted = true delete(url, {}, options) do |body, response, error| - if response.code.to_i != 200 - skip "It appears the web api is too old to support deleting users" - else - assert(response = JSON.parse(body), 'response should be JSON') - assert(response["success"], 'delete should be a success') - pass - end + assert response.code.to_i == 200, "Unable to delete user: HTTP response from API should have code 200, was #{response.code} #{error} #{body}" + assert(response = JSON.parse(body), 'Delete response should be JSON') + assert(response["success"], 'Deleting user should be a success') end end end -- cgit v1.2.3 From aedd6a57b5bf2a5d53cb19d181f90d78918ddf75 Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 15 Dec 2014 16:06:27 -0800 Subject: bugfix: identities of test users must be also destroyed. closes #6550. --- tests/helpers/bonafide_helper.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'tests/helpers/bonafide_helper.rb') diff --git a/tests/helpers/bonafide_helper.rb b/tests/helpers/bonafide_helper.rb index d96b3977..faf8c1f4 100644 --- a/tests/helpers/bonafide_helper.rb +++ b/tests/helpers/bonafide_helper.rb @@ -75,12 +75,24 @@ class LeapTest options = {:headers => { "Authorization" => "Token token=\"#{user.session_token}\"" }} + params = { + :identities => 'destroy' + } user.deleted = true - delete(url, {}, options) do |body, response, error| + delete(url, params, options) do |body, response, error| + assert error.nil?, "Error deleting user: #{error}" assert response.code.to_i == 200, "Unable to delete user: HTTP response from API should have code 200, was #{response.code} #{error} #{body}" assert(response = JSON.parse(body), 'Delete response should be JSON') assert(response["success"], 'Deleting user should be a success') end + domain = property('domain.full_suffix') + identities_url = couchdb_url("/identities/_design/Identity/_view/by_address?key=%22#{user.username}@#{domain}%22") + get(identities_url) do |body, response, error| + assert error.nil?, "Error checking identities db: #{error}" + assert response.code.to_i == 200, "Unable to check that user identity was deleted: HTTP response from API should have code 200, was #{response.code} #{error} #{body}" + assert(response = JSON.parse(body), 'Couch response should be JSON') + assert response['rows'].empty?, "Identity should have been deleted for test user #{user.username} (id #{user.id}), but was not! Response was: #{body}." + end end end -- cgit v1.2.3 From b49fc6c4a864c6e42a4fd4deae25c0ab2eb564ea Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 17 Dec 2014 16:22:29 -0800 Subject: tests: don't run soledad test if there are no soledad nodes --- tests/helpers/bonafide_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/helpers/bonafide_helper.rb') diff --git a/tests/helpers/bonafide_helper.rb b/tests/helpers/bonafide_helper.rb index faf8c1f4..9b26eaaf 100644 --- a/tests/helpers/bonafide_helper.rb +++ b/tests/helpers/bonafide_helper.rb @@ -34,7 +34,7 @@ class LeapTest url = api_url("/1/users.json") assert_post(url, user.to_params) do |body| assert response = JSON.parse(body), 'response should be JSON' - assert response['ok'], 'creating a user should be successful' + assert response['ok'], "Creating a user should be successful, got #{response.inspect} instead." end user.ok = true return user -- cgit v1.2.3