summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorvarac <varacanero@zeromail.org>2014-12-05 17:47:41 +0100
committervarac <varacanero@zeromail.org>2014-12-05 17:47:41 +0100
commit51a49227f83a615f9845461385beba5ef607967d (patch)
treea674f1a612d699255602898dbbcb8f6060d0d44b /tests
parent049b29370e406cb424254f3be9a283f83f9e92d8 (diff)
parent7ca1a6feb2f881f2a99b624c266f0779d2402ff9 (diff)
Merge branch 'develop' of ssh://code.leap.se/leap_platform into develop
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers/bonafide_helper.rb22
-rwxr-xr-xtests/helpers/soledad_sync.py2
-rw-r--r--tests/helpers/srp_helper.rb4
-rw-r--r--tests/white-box/webapp.rb10
4 files changed, 22 insertions, 16 deletions
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
diff --git a/tests/helpers/soledad_sync.py b/tests/helpers/soledad_sync.py
index 54b6f34b..2fb865fc 100755
--- a/tests/helpers/soledad_sync.py
+++ b/tests/helpers/soledad_sync.py
@@ -19,6 +19,7 @@
import os
import sys
+import traceback
import tempfile
import shutil
import u1db
@@ -73,4 +74,5 @@ if __name__ == '__main__':
exit(1)
except Exception as exc:
print(exc.message or str(exc))
+ traceback.print_exc(file=sys.stdout)
exit(2)
diff --git a/tests/helpers/srp_helper.rb b/tests/helpers/srp_helper.rb
index 0aa1b1fb..5d30b459 100644
--- a/tests/helpers/srp_helper.rb
+++ b/tests/helpers/srp_helper.rb
@@ -6,6 +6,7 @@
require 'digest'
require 'openssl'
require 'securerandom'
+require 'base64'
module SRP
@@ -135,7 +136,7 @@ d15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e5
class User
include SRP::Util
- attr_accessor :username, :password, :salt, :verifier, :id, :session_token, :ok
+ attr_accessor :username, :password, :salt, :verifier, :id, :session_token, :ok, :deleted
def initialize
@username = "test_user_" + SecureRandom.urlsafe_base64(10).downcase.gsub(/[_-]/, '')
@@ -143,6 +144,7 @@ d15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e5
@salt = bigrand(4).hex
@verifier = modpow(GENERATOR, private_key)
@ok = false
+ @deleted = false
end
def private_key
diff --git a/tests/white-box/webapp.rb b/tests/white-box/webapp.rb
index d2419ab4..d5d41833 100644
--- a/tests/white-box/webapp.rb
+++ b/tests/white-box/webapp.rb
@@ -51,7 +51,7 @@ class Webapp < LeapTest
if soledad_config && !soledad_config.empty?
soledad_server = pick_soledad_server(soledad_config)
assert_tmp_user do |user|
- assert user_db_exists?(user), "Could not find user db for test user #{user.username}"
+ assert_user_db_exists(user)
command = File.expand_path "../../helpers/soledad_sync.py", __FILE__
soledad_url = "https://#{soledad_server}/user-#{user.id}"
assert_run "#{command} #{user.id} #{user.session_token} #{soledad_url}"
@@ -87,17 +87,19 @@ class Webapp < LeapTest
# returns true if the per-user db created by tapicero exists.
# we try three times, and give up after that.
#
- def user_db_exists?(user)
+ def assert_user_db_exists(user)
+ last_body, last_response, last_error = nil
3.times do
sleep 0.1
get(couchdb_url("/user-#{user.id}/_design/docs")) do |body, response, error|
+ last_body, last_response, last_error = body, response, error
if response.code.to_i == 200
- return true
+ return
end
end
sleep 0.2
end
- return false
+ assert false, "Could not find user db for test user #{user.username}\nuuid=#{user.id}\nHTTP #{last_response.code} #{last_error} #{last_body}"
end
#