summaryrefslogtreecommitdiff
path: root/test/nagios
diff options
context:
space:
mode:
Diffstat (limited to 'test/nagios')
-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)