diff options
author | elijah <elijah@riseup.net> | 2015-03-11 01:12:23 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2015-03-17 22:36:27 -0700 |
commit | 9266c3ac58404894539e25e514d8d8a6775c701f (patch) | |
tree | 3beaa846b37aecdf933763564710c2e1042c03a3 /test | |
parent | a777c4c677e8cbd4f91c66a29ee1ecb347c5b8ab (diff) |
add support for rotating tokens and sessions databases, and for a special tmp db for test users.
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/api/srp_test.rb | 10 | ||||
-rw-r--r-- | test/integration/api/tmp_user_test.rb | 19 | ||||
-rw-r--r-- | test/test_helper.rb | 9 | ||||
-rw-r--r-- | test/unit/tmp_user_test.rb | 29 | ||||
-rw-r--r-- | test/unit/token_test.rb | 2 |
5 files changed, 66 insertions, 3 deletions
diff --git a/test/integration/api/srp_test.rb b/test/integration/api/srp_test.rb index 946450e..fbef47e 100644 --- a/test/integration/api/srp_test.rb +++ b/test/integration/api/srp_test.rb @@ -32,11 +32,11 @@ class SrpTest < RackTest attr_reader :server_auth - def register_user(login = "integration_test_user", password = 'srp, verify me!') + def register_user(login = "integration_test", password = 'srp, verify me!') cleanup_user(login) post 'http://api.lvh.me:3000/1/users.json', user_params(login: login, password: password) - @user = User.find_by_login(login) + assert(@user = User.find_by_login(login), 'user should have been created: %s' % last_response_errors) @login = login @password = password end @@ -101,4 +101,10 @@ class SrpTest < RackTest SRP::Client.new(params.delete(:login) || @login, params) end end + + def last_response_errors + JSON.parse(last_response.body)['errors'] + rescue + "" + end end diff --git a/test/integration/api/tmp_user_test.rb b/test/integration/api/tmp_user_test.rb new file mode 100644 index 0000000..4c1e659 --- /dev/null +++ b/test/integration/api/tmp_user_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' +require_relative 'srp_test' + +class TmpUserTest < SrpTest + + setup do + register_user('test_user_'+SecureRandom.hex(5)) + end + + test "login with srp" do + authenticate + assert_nil server_auth["errors"] + assert_nil server_auth["error"] + assert_equal ["M2", "id", "token"], server_auth.keys + assert last_response.successful? + assert server_auth["M2"] + end + +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7959ddb..dfc6627 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -30,3 +30,12 @@ class ActiveSupport::TestCase require 'i18n/missing_translations' at_exit { I18n.missing_translations.dump } end + +# +# Create databases, since the temporary databases might not have been created +# when `rake couchrest:migrate` was run. +# + +Token.create_database! if Token.respond_to?(:create_database) +CouchRest::Session::Document.create_database! if CouchRest::Session::Document.respond_to?(:create_database) +User.create_tmp_database! if User.respond_to?(:create_tmp_database) diff --git a/test/unit/tmp_user_test.rb b/test/unit/tmp_user_test.rb new file mode 100644 index 0000000..55b117f --- /dev/null +++ b/test/unit/tmp_user_test.rb @@ -0,0 +1,29 @@ +require 'test_helper' + +class TmpUserTest < ActiveSupport::TestCase + + test "test_user saved to tmp_users" do + begin + assert User.ancestors.include?(TemporaryUser) + + assert_difference('User.database.info["doc_count"]') do + normal_user = User.create!(:login => 'a'+SecureRandom.hex(5).downcase, + :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF') + refute normal_user.database.to_s.include?('tmp') + end + + assert_difference('User.tmp_database.info["doc_count"]') do + tmp_user = User.create!(:login => 'test_user_'+SecureRandom.hex(5).downcase, + :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF') + assert tmp_user.database.to_s.include?('tmp') + end + ensure + begin + normal_user.destroy + tmp_user.destroy + rescue + end + end + end + +end diff --git a/test/unit/token_test.rb b/test/unit/token_test.rb index b143345..5468650 100644 --- a/test/unit/token_test.rb +++ b/test/unit/token_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ClientCertificateTest < ActiveSupport::TestCase +class TokenTest < ActiveSupport::TestCase include StubRecordHelper setup do |