summaryrefslogtreecommitdiff
path: root/test/nagios/support
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 /test/nagios/support
parent8907100f3ffe99a2a9110c90418c9e5844b4ab03 (diff)
nagios test: also test registering new users
Diffstat (limited to 'test/nagios/support')
-rw-r--r--test/nagios/support/user.py28
1 files changed, 24 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