summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-16 12:37:03 +0200
committerAzul <azul@leap.se>2014-04-17 10:39:59 +0200
commit36e99d8b23263cffcd58988c40ca3217349a94f2 (patch)
tree08766f68bd91a397bd86cd7468957d48d10c73b8
parent8907100f3ffe99a2a9110c90418c9e5844b4ab03 (diff)
nagios test: also test registering new users
-rw-r--r--test/nagios/support/user.py28
-rwxr-xr-xtest/nagios/webapp_signup.py19
2 files changed, 43 insertions, 4 deletions
diff --git a/test/nagios/support/user.py b/test/nagios/support/user.py
index 912de89..9bf1d0a 100644
--- a/test/nagios/support/user.py
+++ b/test/nagios/support/user.py
@@ -1,13 +1,33 @@
import srp._pysrp as srp
import binascii
+import string
+import random
safe_unhexlify = lambda x: binascii.unhexlify(x) if (
len(x) % 2 == 0) else binascii.unhexlify('0' + x)
+# let's have some random name and password
+def id_generator(size=6, chars=string.ascii_lowercase + string.digits):
+ return ''.join(random.choice(chars) for x in range(size))
+
class User():
- def __init__(self, config):
- self.config = config.user
- self.srp_user = srp.User(self.config['username'], self.config['password'], srp.SHA256, srp.NG_1024)
+ def __init__(self, config = None):
+ if config and config.user:
+ self.username = config.user["username"]
+ self.password = config.user["password"]
+ else:
+ self.username = 'test_' + id_generator()
+ self.password = id_generator() + id_generator()
+ self.srp_user = srp.User(self.username, self.password, srp.SHA256, srp.NG_1024)
+
+ def signup(self, api):
+ salt, vkey = srp.create_salted_verification_key( self.username, self.password, srp.SHA256, srp.NG_1024 )
+ user_params = {
+ 'user[login]': self.username,
+ 'user[password_verifier]': binascii.hexlify(vkey),
+ 'user[password_salt]': binascii.hexlify(salt)
+ }
+ return api.post('users.json', data = user_params)
def login(self, api):
init=self.init_authentication(api)
@@ -32,7 +52,7 @@ class User():
def authenticate(self, api, init):
M = self.srp_user.process_challenge(
safe_unhexlify(init['salt']), safe_unhexlify(init['B']))
- auth = api.put('sessions/' + self.config["username"],
+ auth = api.put('sessions/' + self.username,
data={'client_auth': binascii.hexlify(M)})
return auth
diff --git a/test/nagios/webapp_signup.py b/test/nagios/webapp_signup.py
new file mode 100755
index 0000000..3e7283e
--- /dev/null
+++ b/test/nagios/webapp_signup.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+# Test Signup and Login with the webapp API works.
+
+from support.api import Api
+from support.config import Config
+from support.user import User
+
+def signup_successfully():
+ config = Config()
+ user = User()
+ api = Api(config, verify=False)
+ user.signup(api)
+ user.login(api)
+
+if __name__ == '__main__':
+ from support import nagios_test
+ exit_code = nagios_test.run(signup_successfully)
+ exit(exit_code)