diff options
Diffstat (limited to 'test/nagios/webapp_login.py')
-rwxr-xr-x | test/nagios/webapp_login.py | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py index 86a4045..a7e3473 100755 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -9,20 +9,21 @@ import random import srp._pysrp as srp import binascii import yaml - +import report safe_unhexlify = lambda x: binascii.unhexlify(x) if ( len(x) % 2 == 0) else binascii.unhexlify('0' + x) +report.system = 'webapp login' 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') + report.fail('nagios test user lacks username') if 'password' not in user: - fail('nagios test user lacks password') + report.fail('nagios test user lacks password') api = config['api'] api['version'] = config['webapp']['api_version'] return {'api': api, 'user': user} @@ -35,9 +36,13 @@ def run_tests(config): try: auth = authenticate(api, usr) except requests.exceptions.ConnectionError: - fail('no connection to server') - exit(report(auth, usr)) - + report.fail('no connection to server') + if ('errors' in auth): + report.fail('srp password auth failed') + usr.verify_session(safe_unhexlify(auth["M2"])) + if usr.authenticated(): + report.ok('can login to webapp fine') + report.warn('failed to verify webapp server') def authenticate(api, usr): api_url = "https://{domain}:{port}/{version}".format(**api) @@ -50,28 +55,12 @@ def authenticate(api, usr): response = session.post(api_url + '/sessions', data=params, verify=False) init = response.json() if ('errors' in init): - fail('test user not found') + report.fail('test user not found') M = usr.process_challenge( safe_unhexlify(init['salt']), safe_unhexlify(init['B'])) response = session.put(api_url + '/sessions/' + uname, verify=False, data={'client_auth': binascii.hexlify(M)}) return response.json() - -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) - if __name__ == '__main__': run_tests(read_config()) |