summaryrefslogtreecommitdiff
path: root/tests/white-box/webapp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tests/white-box/webapp.rb')
-rw-r--r--tests/white-box/webapp.rb103
1 files changed, 47 insertions, 56 deletions
diff --git a/tests/white-box/webapp.rb b/tests/white-box/webapp.rb
index 2aa87403..9f104899 100644
--- a/tests/white-box/webapp.rb
+++ b/tests/white-box/webapp.rb
@@ -41,63 +41,26 @@ class Webapp < LeapTest
pass
end
- def test_05_Can_create_user?
- @@user = nil
- 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 = user
+ def test_05_Can_create_and_authenticate_and_delete_user_via_API?
+ assert_tmp_user
pass
end
- def test_06_Can_authenticate?
- @@user_id = nil
- @@session_token = nil
- if @@user.nil?
- skip "Depends on user creation"
- else
- 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(bb = response["B"])
- session.bb = bb
- 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')
- assert(@@session_token = response['token'], 'response should include token')
- assert(@@user_id = response['id'], 'response should include user id')
- end
- end
- pass
- end
- end
-
- def test_07_Can_delete_user?
- if @@user_id.nil? || @@session_token.nil?
- skip "Depends on authentication"
- else
- url = api_url("/1/users/#{@@user_id}.json")
- options = {:headers => {
- "Authorization" => "Token token=\"#{@@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')
+ def test_06_Can_sync_Soledad?
+ soledad_config = property('definition_files.soledad_service')
+ if soledad_config && !soledad_config.empty?
+ soledad_server = pick_soledad_server(soledad_config)
+ if soledad_server
+ assert_tmp_user do |user|
+ 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}"
pass
end
end
+ else
+ skip 'No soledad service configuration'
end
end
@@ -110,11 +73,39 @@ class Webapp < LeapTest
}
end
- def api_url(path)
- "https://%{domain}:%{port}#{path}" % {
- :domain => property('api.domain'),
- :port => property('api.port')
- }
+ #
+ # pick a random soledad server.
+ # I am not sure why, but using IP address directly does not work.
+ #
+ def pick_soledad_server(soledad_config_json_str)
+ soledad_config = JSON.parse(soledad_config_json_str)
+ host_name = soledad_config['hosts'].keys.shuffle.first
+ if host_name
+ hostname = soledad_config['hosts'][host_name]['hostname']
+ port = soledad_config['hosts'][host_name]['port']
+ return "#{hostname}:#{port}"
+ else
+ return nil
+ end
+ end
+
+ #
+ # returns true if the per-user db created by tapicero exists.
+ # we try three times, and give up after that.
+ #
+ 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
+ end
+ end
+ sleep 0.2
+ end
+ assert false, "Could not find user db for test user #{user.username}\nuuid=#{user.id}\nHTTP #{last_response.code} #{last_error} #{last_body}"
end
#