summaryrefslogtreecommitdiff
path: root/users/test
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-08-22 11:44:47 -0700
committerjessib <jessib@riseup.net>2013-08-22 11:44:47 -0700
commit691dbff9dde60fb757810974ee4df2aa6fa48b58 (patch)
treeeeab4bbf69767b1aaa3ca7699fc23cf2aa7af971 /users/test
parent8c45a3c54f2b0b709ebf040de0db00b6913e709b (diff)
parent76bc9d708b119d8c5047b487ccedaa9c70fec78b (diff)
Merge pull request #69 from azul/bugfix/update_user_password_through_api
Test updating user password through api
Diffstat (limited to 'users/test')
-rw-r--r--users/test/integration/api/account_flow_test.rb22
-rwxr-xr-xusers/test/integration/api/python/flow_with_srp.py63
2 files changed, 60 insertions, 25 deletions
diff --git a/users/test/integration/api/account_flow_test.rb b/users/test/integration/api/account_flow_test.rb
index ec7753c..507f0b9 100644
--- a/users/test/integration/api/account_flow_test.rb
+++ b/users/test/integration/api/account_flow_test.rb
@@ -5,6 +5,7 @@ class AccountFlowTest < RackTest
setup do
@login = "integration_test_user"
+ Identity.find_by_address(@login + '@' + APP_CONFIG[:domain]).tap{|i| i.destroy if i}
User.find_by_login(@login).tap{|u| u.destroy if u}
@password = "srp, verify me!"
@srp = SRP::Client.new @login, :password => @password
@@ -18,7 +19,7 @@ class AccountFlowTest < RackTest
end
teardown do
- if @user
+ if @user.reload
@user.identity.destroy
@user.destroy
end
@@ -77,6 +78,25 @@ class AccountFlowTest < RackTest
assert_nil server_auth
end
+ test "update password via api" do
+ @srp.authenticate(self)
+ @password = "No! Verify me instead."
+ @srp = SRP::Client.new @login, :password => @password
+ @user_params = {
+ # :login => @login,
+ :password_verifier => @srp.verifier.to_s(16),
+ :password_salt => @srp.salt.to_s(16)
+ }
+ puts @user_params.inspect
+ put "http://api.lvh.me:3000/1/users/" + @user.id + '.json',
+ :user => @user_params,
+ :format => :json
+ server_auth = @srp.authenticate(self)
+ assert last_response.successful?
+ assert_nil server_auth["errors"]
+ assert server_auth["M2"]
+ end
+
test "update user" do
server_auth = @srp.authenticate(self)
test_public_key = 'asdlfkjslfdkjasd'
diff --git a/users/test/integration/api/python/flow_with_srp.py b/users/test/integration/api/python/flow_with_srp.py
index 7b741d6..d37c6af 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_lowercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
# using globals for a start
-server = 'https://api.bitmask.net:4430/1'
-login = id_generator()
+server = 'https://dev.bitmask.net/1'
+login = 'test_' + id_generator()
password = id_generator() + id_generator()
-# 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)
+ request = response.request
+ print request.method + ': ' + response.url
+ if hasattr(request, 'data'):
+ print " " + json.dumps(response.request.data)
print " -> " + response.text
- return json.loads(response.text)
+ try:
+ return json.loads(response.text)
+ except ValueError:
+ return None
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) + '"'
user_params = {
'user[login]': login,
'user[password_verifier]': binascii.hexlify(vkey),
@@ -41,38 +41,53 @@ def signup(session):
}
return session.post(server + '/users.json', data = user_params, verify = False)
-usr = srp.User( login, password, srp.SHA256, srp.NG_1024 )
+def change_password(session):
+ password = id_generator() + id_generator()
+ salt, vkey = srp.create_salted_verification_key( login, password, srp.SHA256, srp.NG_1024 )
+ user_params = {
+ 'user[password_verifier]': binascii.hexlify(vkey),
+ 'user[password_salt]': binascii.hexlify(salt)
+ }
+ print user_params
+ print_and_parse(session.put(server + '/users/' + auth['id'] + '.json', data = user_params, verify = False))
+ return srp.User( login, password, srp.SHA256, srp.NG_1024 )
+
def authenticate(session, login):
uname, A = usr.start_authentication()
- # print ' aa = "' + binascii.hexlify(A) + '"'
params = {
'login': uname,
'A': binascii.hexlify(A)
}
init = print_and_parse(session.post(server + '/sessions', data = params, verify=False))
- # print ' b = "' + init['b'] + '"'
- # print ' bb = "' + init['B'] + '"'
M = usr.process_challenge( safe_unhexlify(init['salt']), safe_unhexlify(init['B']) )
- # print ' m = "' + binascii.hexlify(M) + '"'
return session.put(server + '/sessions/' + login, verify = False,
data = {'client_auth': binascii.hexlify(M)})
+def verify_or_debug(auth):
+ if ( 'errors' in auth ):
+ print ' u = "%x"' % usr.u
+ print ' x = "%x"' % usr.x
+ print ' v = "%x"' % usr.v
+ print ' S = "%x"' % usr.S
+ print ' K = "' + binascii.hexlify(usr.K) + '"'
+ print ' M = "' + binascii.hexlify(usr.M) + '"'
+ else:
+ usr.verify_session( safe_unhexlify(auth["M2"]) )
+
+usr = srp.User( login, password, srp.SHA256, srp.NG_1024 )
session = requests.session()
user = print_and_parse(signup(session))
# SRP signup would happen here and calculate M hex
auth = print_and_parse(authenticate(session, user['login']))
-if ( 'errors' in auth ):
- print ' u = "%x"' % usr.u
- print ' x = "%x"' % usr.x
- print ' v = "%x"' % usr.v
- print ' S = "%x"' % usr.S
- print ' K = "' + binascii.hexlify(usr.K) + '"'
- print ' M = "%x"' % usr.M
-else:
- usr.verify_session( safe_unhexlify(auth["M2"]) )
+verify_or_debug(auth)
+assert usr.authenticated()
+
+usr = change_password(session)
+auth = print_and_parse(authenticate(session, user['login']))
+verify_or_debug(auth)
# At this point the authentication process is complete.
assert usr.authenticated()