summaryrefslogtreecommitdiff
path: root/users/test
diff options
context:
space:
mode:
Diffstat (limited to 'users/test')
-rwxr-xr-xusers/test/integration/api/python/flow_with_srp.py18
-rw-r--r--users/test/test_helper.rb2
-rw-r--r--users/test/unit/user_test.rb41
3 files changed, 36 insertions, 25 deletions
diff --git a/users/test/integration/api/python/flow_with_srp.py b/users/test/integration/api/python/flow_with_srp.py
index 3bbbc71..0a11aec 100755
--- a/users/test/integration/api/python/flow_with_srp.py
+++ b/users/test/integration/api/python/flow_with_srp.py
@@ -16,24 +16,24 @@ def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
# using globals for a start
-server = 'http://localhost:3000'
+server = 'http://springbok/1/'
login = id_generator()
password = id_generator() + id_generator()
-print ' username = "' + login + '"'
-print ' password = "' + password + '"'
+# print ' username = "' + login + '"'
+# print ' password = "' + password + '"'
# log the server communication
def print_and_parse(response):
# print response.request.method + ': ' + response.url
# print " " + json.dumps(response.request.data)
- print " -> " + response.text
+ # print " -> " + response.text
return json.loads(response.text)
def signup(session):
salt, vkey = srp.create_salted_verification_key( login, password, srp.SHA256, srp.NG_1024 )
- print ' salt = "' + binascii.hexlify(salt) + '"'
- print ' v = "' + binascii.hexlify(vkey) + '"'
+ # print ' salt = "' + binascii.hexlify(salt) + '"'
+ # print ' v = "' + binascii.hexlify(vkey) + '"'
user_params = {
'user[login]': login,
'user[password_verifier]': binascii.hexlify(vkey),
@@ -45,16 +45,16 @@ usr = srp.User( login, password, srp.SHA256, srp.NG_1024 )
def authenticate(session, login):
uname, A = usr.start_authentication()
- print ' aa = "' + binascii.hexlify(A) + '"'
+ # print ' aa = "' + binascii.hexlify(A) + '"'
params = {
'login': uname,
'A': binascii.hexlify(A)
}
init = print_and_parse(session.post(server + '/sessions', data = params))
# print ' b = "' + init['b'] + '"'
- print ' bb = "' + init['B'] + '"'
+ # print ' bb = "' + init['B'] + '"'
M = usr.process_challenge( safe_unhexlify(init['salt']), safe_unhexlify(init['B']) )
- print ' m = "' + binascii.hexlify(M) + '"'
+ # print ' m = "' + binascii.hexlify(M) + '"'
return session.put(server + '/sessions/' + login,
data = {'client_auth': binascii.hexlify(M)})
diff --git a/users/test/test_helper.rb b/users/test/test_helper.rb
index b268c51..08d4d41 100644
--- a/users/test/test_helper.rb
+++ b/users/test/test_helper.rb
@@ -1,5 +1,5 @@
ENV["RAILS_ENV"] = "test"
-require File.expand_path('../dummy/config/environment', __FILE__)
+require File.expand_path('../../../test/dummy/config/environment', __FILE__)
require 'rails/test_help'
require 'mocha'
diff --git a/users/test/unit/user_test.rb b/users/test/unit/user_test.rb
index 870d422..822ef33 100644
--- a/users/test/unit/user_test.rb
+++ b/users/test/unit/user_test.rb
@@ -3,37 +3,48 @@ require 'test_helper'
class UserTest < ActiveSupport::TestCase
include SRP::Util
+ setup do
+ @attribs = User.valid_attributes_hash
+ @user = User.new(@attribs)
+ end
+
test "test set of attributes should be valid" do
- user = User.new(User.valid_attributes_hash)
- assert user.valid?
+ @user.valid?
+ assert_equal Hash.new, @user.errors.messages
+ end
+
+ test "test require hex for password_verifier" do
+ @user.password_verifier = "QWER"
+ assert !@user.valid?
+ end
+
+ test "test require alphanumerical for login" do
+ @user.login = "qwär"
+ assert !@user.valid?
end
test "find_by_param gets User by login" do
- user = User.create!(User.valid_attributes_hash)
- assert_equal user, User.find_by_param(user.login)
- user.destroy
+ @user.save
+ assert_equal @user, User.find_by_param(@user.login)
+ @user.destroy
end
test "to_param gives user login" do
- user = User.new(User.valid_attributes_hash)
- assert_equal user.login, user.to_param
+ assert_equal @user.login, @user.to_param
end
test "verifier returns number for the hex in password_verifier" do
- user = User.new(User.valid_attributes_hash)
- assert_equal user.password_verifier.hex, user.verifier
+ assert_equal @user.password_verifier.hex, @user.verifier
end
test "salt returns number for the hex in password_salt" do
- user = User.new(User.valid_attributes_hash)
- assert_equal user.password_salt.hex, user.salt
+ assert_equal @user.password_salt.hex, @user.salt
end
- test "should include SRP::Authentication" do
+ test "should include SRP" do
client_rnd = bigrand(32).hex
- user = User.new(User.valid_attributes_hash)
- srp_session = user.initialize_auth(client_rnd)
- assert srp_session.is_a? SRP::Authentication::Session
+ srp_session = @user.initialize_auth(client_rnd)
+ assert srp_session.is_a? SRP::Session
assert_equal client_rnd, srp_session.aa
end