Skip to content

Commit 7ca1a6f

Browse files
committed
tests - better errors, ensure tmp users are deleted, remove bad 'pass()' call that made tmp_user tests always succeed.
1 parent 60bd765 commit 7ca1a6f

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

bin/run_tests

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ end
4949

5050
# this class is raised if a test file wants to be skipped entirely.
5151
# (to skip an individual test, MiniTest::Skip is used instead)
52-
class SkipTest < Exception
52+
class SkipTest < StandardError
5353
end
5454

5555
# raised if --no-continue and there is an error
56-
class TestError < Exception
56+
class TestError < StandardError
5757
end
5858

5959
# raised if --no-continue and there is a failure
60-
class TestFailure < Exception
60+
class TestFailure < StandardError
6161
end
6262

6363
##

tests/helpers/bonafide_helper.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ def assert_tmp_user
88
user = assert_create_user
99
assert_authenticate_user(user)
1010
yield user if block_given?
11-
rescue
12-
# ^^ ensure here would eat any failed assertions
1311
assert_delete_user(user)
14-
raise
12+
rescue StandardError, MiniTest::Assertion => exc
13+
begin
14+
assert_delete_user(user)
15+
rescue
16+
end
17+
raise exc
1518
end
1619

1720
def api_url(path)
@@ -67,19 +70,16 @@ def assert_authenticate_user(user)
6770
# attempts to destroy a user account via the API.
6871
#
6972
def assert_delete_user(user)
70-
if user && user.ok && user.id && user.session_token
73+
if user && user.ok && user.id && user.session_token && !user.deleted
7174
url = api_url("/1/users/#{user.id}.json")
7275
options = {:headers => {
7376
"Authorization" => "Token token=\"#{user.session_token}\""
7477
}}
78+
user.deleted = true
7579
delete(url, {}, options) do |body, response, error|
76-
if response.code.to_i != 200
77-
skip "It appears the web api is too old to support deleting users"
78-
else
79-
assert(response = JSON.parse(body), 'response should be JSON')
80-
assert(response["success"], 'delete should be a success')
81-
pass
82-
end
80+
assert response.code.to_i == 200, "Unable to delete user: HTTP response from API should have code 200, was #{response.code} #{error} #{body}"
81+
assert(response = JSON.parse(body), 'Delete response should be JSON')
82+
assert(response["success"], 'Deleting user should be a success')
8383
end
8484
end
8585
end

tests/helpers/soledad_sync.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import os
2121
import sys
22+
import traceback
2223
import tempfile
2324
import shutil
2425
import u1db
@@ -73,4 +74,5 @@ def soledad_sync(uuid, token, server):
7374
exit(1)
7475
except Exception as exc:
7576
print(exc.message or str(exc))
77+
traceback.print_exc(file=sys.stdout)
7678
exit(2)

tests/helpers/srp_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'digest'
77
require 'openssl'
88
require 'securerandom'
9+
require 'base64'
910

1011
module SRP
1112

@@ -135,14 +136,15 @@ def u
135136
class User
136137
include SRP::Util
137138

138-
attr_accessor :username, :password, :salt, :verifier, :id, :session_token, :ok
139+
attr_accessor :username, :password, :salt, :verifier, :id, :session_token, :ok, :deleted
139140

140141
def initialize
141142
@username = "test_user_" + SecureRandom.urlsafe_base64(10).downcase.gsub(/[_-]/, '')
142143
@password = "password_" + SecureRandom.urlsafe_base64(10)
143144
@salt = bigrand(4).hex
144145
@verifier = modpow(GENERATOR, private_key)
145146
@ok = false
147+
@deleted = false
146148
end
147149

148150
def private_key

tests/white-box/webapp.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_06_Can_sync_Soledad?
5151
if soledad_config && !soledad_config.empty?
5252
soledad_server = pick_soledad_server(soledad_config)
5353
assert_tmp_user do |user|
54-
assert user_db_exists?(user), "Could not find user db for test user #{user.username}"
54+
assert_user_db_exists(user)
5555
command = File.expand_path "../../helpers/soledad_sync.py", __FILE__
5656
soledad_url = "https://#{soledad_server}/user-#{user.id}"
5757
assert_run "#{command} #{user.id} #{user.session_token} #{soledad_url}"
@@ -87,17 +87,19 @@ def pick_soledad_server(soledad_config_json_str)
8787
# returns true if the per-user db created by tapicero exists.
8888
# we try three times, and give up after that.
8989
#
90-
def user_db_exists?(user)
90+
def assert_user_db_exists(user)
91+
last_body, last_response, last_error = nil
9192
3.times do
9293
sleep 0.1
9394
get(couchdb_url("/user-#{user.id}/_design/docs")) do |body, response, error|
95+
last_body, last_response, last_error = body, response, error
9496
if response.code.to_i == 200
95-
return true
97+
return
9698
end
9799
end
98100
sleep 0.2
99101
end
100-
return false
102+
assert false, "Could not find user db for test user #{user.username}\nuuid=#{user.id}\nHTTP #{last_response.code} #{last_error} #{last_body}"
101103
end
102104

103105
#

0 commit comments

Comments
 (0)