From ab820994950f8f43214bccd8dc4adf2cea40621c Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 27 Feb 2014 17:49:44 +0100 Subject: nagios test for logging into webapp --- test/nagios/webapp_login.py | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 test/nagios/webapp_login.py (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py new file mode 100755 index 0000000..c046750 --- /dev/null +++ b/test/nagios/webapp_login.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python + +# Test Authentication with the webapp API works. + +import requests +import json +import string +import random +import srp._pysrp as srp +import binascii +import yaml + + +safe_unhexlify = lambda x: binascii.unhexlify(x) if (len(x) % 2 == 0) else binascii.unhexlify('0'+x) + +def read_config(): + stream = open("/etc/leap/hiera.yaml", 'r') + config = yaml.load(stream) + stream.close + 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://' + api['domain'] + ':' + str(api['port']) + '/' + str(api['version']) + 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) + +run_tests(read_config()) -- cgit v1.2.3 From e4b42733d61887e2e7f01e9f159e963d50044465 Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 2 Mar 2014 08:25:24 +0100 Subject: autopep8 nagios webapp login test --- test/nagios/webapp_login.py | 109 ++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 50 deletions(-) mode change 100755 => 100644 test/nagios/webapp_login.py (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py old mode 100755 new mode 100644 index c046750..1239769 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -11,66 +11,75 @@ import binascii import yaml -safe_unhexlify = lambda x: binascii.unhexlify(x) if (len(x) % 2 == 0) else binascii.unhexlify('0'+x) +safe_unhexlify = lambda x: binascii.unhexlify(x) if ( + len(x) % 2 == 0) else binascii.unhexlify('0' + x) + def read_config(): - stream = open("/etc/leap/hiera.yaml", 'r') - config = yaml.load(stream) - stream.close - 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} + 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)) + 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 + request = response.request + try: + return json.loads(response.text) + except ValueError: + return None + def authenticate(api, usr): - api_url = 'https://' + api['domain'] + ':' + str(api['port']) + '/' + str(api['version']) - 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 + api_url = 'https://' + api['domain'] + ':' + \ + str(api['port']) + '/' + str(api['version']) + 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) + print '2 webapp_login - CRITICAL - ' + reason + exit(2) run_tests(read_config()) -- cgit v1.2.3 From 35b3387b99024a69402cc0d7b5d0dc7fed37a0fa Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 2 Mar 2014 08:38:10 +0100 Subject: including chiiphs comments --- test/nagios/webapp_login.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) mode change 100644 => 100755 test/nagios/webapp_login.py (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py old mode 100644 new mode 100755 index 1239769..afa3edf --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -16,12 +16,12 @@ safe_unhexlify = lambda x: binascii.unhexlify(x) if ( def read_config(): - open("/etc/leap/hiera.yaml", 'r') as stream - config = yaml.load(stream) + with open("/etc/leap/hiera.yaml", 'r') as stream: + config = yaml.load(stream) user = config['webapp']['nagios_test_user'] - if ('username' not in user): + if 'username' not in user: fail('nagios test user lacks username') - if ('password' not in user): + if 'password' not in user: fail('nagios test user lacks password') api = config['api'] api['version'] = config['webapp']['api_version'] @@ -50,8 +50,7 @@ def parse(response): def authenticate(api, usr): - api_url = 'https://' + api['domain'] + ':' + \ - str(api['port']) + '/' + str(api['version']) + api_url = "https://{domain}:{port}/{version}".format(**api) session = requests.session() uname, A = usr.start_authentication() params = { @@ -67,9 +66,10 @@ def authenticate(api, usr): 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') + +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' -- cgit v1.2.3 From 453f5e91593c8fcef4a330016bfb0128ca37c204 Mon Sep 17 00:00:00 2001 From: db Date: Thu, 6 Mar 2014 10:53:54 -0300 Subject: Add script to check if soledad is working (#5239). --- test/nagios/webapp_login.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py index afa3edf..1711238 100755 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -82,4 +82,5 @@ def fail(reason): print '2 webapp_login - CRITICAL - ' + reason exit(2) -run_tests(read_config()) +if __name__ == '__main__': + run_tests(read_config()) -- cgit v1.2.3 From a14f66c2642ff43c2cc497b0597bfb17d19a7139 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 15 Apr 2014 09:47:07 +0200 Subject: refactor nagios tests, remove parse --- test/nagios/webapp_login.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py index 1711238..86a4045 100755 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -33,21 +33,11 @@ def run_tests(config): api = config['api'] usr = srp.User(user['username'], user['password'], srp.SHA256, srp.NG_1024) try: - auth = parse(authenticate(api, usr)) + auth = 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) @@ -57,14 +47,15 @@ def authenticate(api, usr): 'login': uname, 'A': binascii.hexlify(A) } - init = parse( - session.post(api_url + '/sessions', data=params, verify=False)) + response = session.post(api_url + '/sessions', data=params, verify=False) + init = response.json() 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, + response = session.put(api_url + '/sessions/' + uname, verify=False, data={'client_auth': binascii.hexlify(M)}) + return response.json() def report(auth, usr): -- cgit v1.2.3 From 44d2d031555c889b94e9738cb45740b16a4071ce Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 15 Apr 2014 12:51:06 +0200 Subject: refactor reporting in webapp login nagios test --- test/nagios/webapp_login.py | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'test/nagios/webapp_login.py') 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()) -- cgit v1.2.3 From be2971c2e615cc8a808822317d049e99f5183bdc Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 15 Apr 2014 17:17:36 +0200 Subject: refactor: move nagios specifs to nagios_test nagios_test.run takes a function and executes it. If it returns nothing or 0 and OK nagios message is printed. If it returns sth. else this will be printed a a warning If it raises an exception that will result in a CRITICAL report. This way we can keep the nagios things outside the test cases and just write simple functions that either return 0, a warnign or raise a meaningful exception --- test/nagios/webapp_login.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py index a7e3473..6d06438 100755 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -9,40 +9,34 @@ 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: - report.fail('nagios test user lacks username') + raise Exception('nagios test user lacks username') if 'password' not in user: - report.fail('nagios test user lacks password') + raise Exception('nagios test user lacks password') api = config['api'] api['version'] = config['webapp']['api_version'] return {'api': api, 'user': user} -def run_tests(config): +def login_successfully(config=None): + config = config or read_config() user = config['user'] api = config['api'] usr = srp.User(user['username'], user['password'], srp.SHA256, srp.NG_1024) - try: - auth = authenticate(api, usr) - except requests.exceptions.ConnectionError: - report.fail('no connection to server') + auth = authenticate(api, usr) if ('errors' in auth): - report.fail('srp password auth failed') + raise Exception('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') + if not usr.authenticated(): + return 'failed to verify webapp server' def authenticate(api, usr): api_url = "https://{domain}:{port}/{version}".format(**api) @@ -55,7 +49,7 @@ def authenticate(api, usr): response = session.post(api_url + '/sessions', data=params, verify=False) init = response.json() if ('errors' in init): - report.fail('test user not found') + raise Exception('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, @@ -63,4 +57,6 @@ def authenticate(api, usr): return response.json() if __name__ == '__main__': - run_tests(read_config()) + import nagios_test + exit_code = nagios_test.run(login_successfully) + exit(exit_code) -- cgit v1.2.3 From 73bdb9a9ea8932e9a14f996391d348690da1a63c Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 16 Apr 2014 10:13:28 +0200 Subject: nagios test: refactor webapp_login with classes --- test/nagios/webapp_login.py | 127 +++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 42 deletions(-) (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py index 6d06438..7e2efd7 100755 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -13,48 +13,91 @@ import yaml 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: - raise Exception('nagios test user lacks username') - if 'password' not in user: - raise Exception('nagios test user lacks password') - api = config['api'] - api['version'] = config['webapp']['api_version'] - return {'api': api, 'user': user} - - -def login_successfully(config=None): - config = config or read_config() - user = config['user'] - api = config['api'] - usr = srp.User(user['username'], user['password'], srp.SHA256, srp.NG_1024) - auth = authenticate(api, usr) - if ('errors' in auth): - raise Exception('srp password auth failed') - usr.verify_session(safe_unhexlify(auth["M2"])) - if not usr.authenticated(): - return 'failed to verify webapp server' - -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) - } - response = session.post(api_url + '/sessions', data=params, verify=False) - init = response.json() - if ('errors' in init): - raise Exception('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() +class Config(): + def __init__(self, filename="/etc/leap/hiera.yaml"): + with open("/etc/leap/hiera.yaml", 'r') as stream: + config = yaml.load(stream) + self.user = config['webapp']['nagios_test_user'] + if 'username' not in self.user: + raise Exception('nagios test user lacks username') + if 'password' not in self.user: + raise Exception('nagios test user lacks password') + self.api = config['api'] + self.api['version'] = config['webapp']['api_version'] + +class Api(): + def __init__(self, config, verify=True): + self.config = config.api + self.session = requests.session() + self.verify = verify + + def api_url(self, path): + return self.api_root() + path + + def api_root(self): + return "https://{domain}:{port}/{version}/".format(**self.config) + + def get(self, path, **args): + response = self.session.get(self.api_url(path), + verify=self.verify, + **args) + return response.json() + + def post(self, path, **args): + response = self.session.post(self.api_url(path), + verify=self.verify, + **args) + return response.json() + + def put(self, path, **args): + response = self.session.put(self.api_url(path), + verify=self.verify, + **args) + return response.json() + +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 login(self, api): + init=self.init_authentication(api) + if ('errors' in init): + raise Exception('test user not found') + auth=self.authenticate(api, init) + if ('errors' in auth): + raise Exception('srp password auth failed') + self.verify_server(auth) + if not self.is_authenticated(): + raise Exception('user is not authenticated') + + def init_authentication(self, api): + uname, A = self.srp_user.start_authentication() + params = { + 'login': uname, + 'A': binascii.hexlify(A) + } + return api.post('sessions', data=params) + + 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"], + data={'client_auth': binascii.hexlify(M)}) + return auth + + def verify_server(self, auth): + self.srp_user.verify_session(safe_unhexlify(auth["M2"])) + + def is_authenticated(self): + return self.srp_user.authenticated() + + +def login_successfully(): + config = Config() + user = User(config) + api = Api(config, verify=False) + user.login(api) if __name__ == '__main__': import nagios_test -- cgit v1.2.3 From 0f0057e65c6bfcb98ce53e1a48aa1460d3a6716a Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 16 Apr 2014 11:14:55 +0200 Subject: move support classes into their own package now the webapp_login test looks nice and clean. soledad next. --- test/nagios/webapp_login.py | 93 ++------------------------------------------- 1 file changed, 4 insertions(+), 89 deletions(-) (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py index 7e2efd7..4e78836 100755 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -2,96 +2,11 @@ # Test Authentication with the webapp API works. -import requests -import json import string import random -import srp._pysrp as srp -import binascii -import yaml - -safe_unhexlify = lambda x: binascii.unhexlify(x) if ( - len(x) % 2 == 0) else binascii.unhexlify('0' + x) - -class Config(): - def __init__(self, filename="/etc/leap/hiera.yaml"): - with open("/etc/leap/hiera.yaml", 'r') as stream: - config = yaml.load(stream) - self.user = config['webapp']['nagios_test_user'] - if 'username' not in self.user: - raise Exception('nagios test user lacks username') - if 'password' not in self.user: - raise Exception('nagios test user lacks password') - self.api = config['api'] - self.api['version'] = config['webapp']['api_version'] - -class Api(): - def __init__(self, config, verify=True): - self.config = config.api - self.session = requests.session() - self.verify = verify - - def api_url(self, path): - return self.api_root() + path - - def api_root(self): - return "https://{domain}:{port}/{version}/".format(**self.config) - - def get(self, path, **args): - response = self.session.get(self.api_url(path), - verify=self.verify, - **args) - return response.json() - - def post(self, path, **args): - response = self.session.post(self.api_url(path), - verify=self.verify, - **args) - return response.json() - - def put(self, path, **args): - response = self.session.put(self.api_url(path), - verify=self.verify, - **args) - return response.json() - -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 login(self, api): - init=self.init_authentication(api) - if ('errors' in init): - raise Exception('test user not found') - auth=self.authenticate(api, init) - if ('errors' in auth): - raise Exception('srp password auth failed') - self.verify_server(auth) - if not self.is_authenticated(): - raise Exception('user is not authenticated') - - def init_authentication(self, api): - uname, A = self.srp_user.start_authentication() - params = { - 'login': uname, - 'A': binascii.hexlify(A) - } - return api.post('sessions', data=params) - - 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"], - data={'client_auth': binascii.hexlify(M)}) - return auth - - def verify_server(self, auth): - self.srp_user.verify_session(safe_unhexlify(auth["M2"])) - - def is_authenticated(self): - return self.srp_user.authenticated() - +from support.api import Api +from support.config import Config +from support.user import User def login_successfully(): config = Config() @@ -100,6 +15,6 @@ def login_successfully(): user.login(api) if __name__ == '__main__': - import nagios_test + from support import nagios_test exit_code = nagios_test.run(login_successfully) exit(exit_code) -- cgit v1.2.3 From bfda2c55bd4824d94d384a39960c91b6e1f8d14b Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 16 Apr 2014 11:16:00 +0200 Subject: remove unneeded imports --- test/nagios/webapp_login.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/nagios/webapp_login.py') diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py index 4e78836..7741325 100755 --- a/test/nagios/webapp_login.py +++ b/test/nagios/webapp_login.py @@ -2,8 +2,6 @@ # Test Authentication with the webapp API works. -import string -import random from support.api import Api from support.config import Config from support.user import User -- cgit v1.2.3