summaryrefslogtreecommitdiff
path: root/test/nagios/webapp_login.py
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2014-04-18 14:34:32 +0200
committerazul <azul@riseup.net>2014-04-18 14:34:32 +0200
commit8078cf0f853310cfb0d0681db45effb96850efc9 (patch)
tree86fb496091a772cefd0e07d1558f6b7fe0636963 /test/nagios/webapp_login.py
parent3513ad74f950b113af1ba1e3d06bc6a55c48fde5 (diff)
parentd639e0a48599b30777b80c2809ded1efb3a6d926 (diff)
Merge pull request #147 from azul/test/nagios-test-signup0.5.1-rc
Test/nagios test signup
Diffstat (limited to 'test/nagios/webapp_login.py')
-rwxr-xr-xtest/nagios/webapp_login.py90
1 files changed, 11 insertions, 79 deletions
diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py
index 1711238..7741325 100755
--- a/test/nagios/webapp_login.py
+++ b/test/nagios/webapp_login.py
@@ -2,85 +2,17 @@
# Test Authentication with the webapp API works.
-import requests
-import json
-import string
-import random
-import srp._pysrp as srp
-import binascii
-import yaml
+from support.api import Api
+from support.config import Config
+from support.user import User
-
-safe_unhexlify = lambda x: binascii.unhexlify(x) if (
- len(x) % 2 == 0) else binascii.unhexlify('0' + x)
-
-
-def read_config():
- with open("/etc/leap/hiera.yaml", 'r') as stream:
- config = yaml.load(stream)
- user = config['webapp']['nagios_test_user']
- if 'username' not in user:
- fail('nagios test user lacks username')
- if 'password' not in user:
- fail('nagios test user lacks password')
- api = config['api']
- api['version'] = config['webapp']['api_version']
- return {'api': api, 'user': user}
-
-
-def run_tests(config):
- user = config['user']
- api = config['api']
- usr = srp.User(user['username'], user['password'], srp.SHA256, srp.NG_1024)
- try:
- auth = parse(authenticate(api, usr))
- except requests.exceptions.ConnectionError:
- fail('no connection to server')
- exit(report(auth, usr))
-
-# parse the server responses
-
-
-def parse(response):
- request = response.request
- try:
- return json.loads(response.text)
- except ValueError:
- return None
-
-
-def authenticate(api, usr):
- api_url = "https://{domain}:{port}/{version}".format(**api)
- session = requests.session()
- uname, A = usr.start_authentication()
- params = {
- 'login': uname,
- 'A': binascii.hexlify(A)
- }
- init = parse(
- session.post(api_url + '/sessions', data=params, verify=False))
- if ('errors' in init):
- fail('test user not found')
- M = usr.process_challenge(
- safe_unhexlify(init['salt']), safe_unhexlify(init['B']))
- return session.put(api_url + '/sessions/' + uname, verify=False,
- data={'client_auth': binascii.hexlify(M)})
-
-
-def report(auth, usr):
- if ('errors' in auth):
- fail('srp password auth failed')
- usr.verify_session(safe_unhexlify(auth["M2"]))
- if usr.authenticated():
- print '0 webapp_login - OK - can login to webapp fine'
- return 0
- print '1 webapp_login - WARNING - failed to verify webapp server'
- return 1
-
-
-def fail(reason):
- print '2 webapp_login - CRITICAL - ' + reason
- exit(2)
+def login_successfully():
+ config = Config()
+ user = User(config)
+ api = Api(config, verify=False)
+ user.login(api)
if __name__ == '__main__':
- run_tests(read_config())
+ from support import nagios_test
+ exit_code = nagios_test.run(login_successfully)
+ exit(exit_code)