def test_check_auth_admin(self): self.request['login'] = '******' self.request['token'] = hashlib.sha512( bytes(datetime.datetime.now().strftime("%Y%m%d%H") + api.ADMIN_SALT, encoding='utf-8')).hexdigest() self.assertEqual(api.check_auth(self.method(self.request)), True)
def test_check_invalid_auth_fail(self, val): value_set = deepcopy(val) value_set['method'] = '--' value_set['token'] = 'invalid_token' bad_request_object = api.MethodRequest(**value_set) self.assertFalse(api.check_auth(bad_request_object))
def test_invalid_auth(arguments): request_dict = { "account": "horns&hoofs", "login": "******", "method": "online_score", "arguments": arguments } request_dict['token'] = get_invalid_auth(request_dict) request = api.MethodRequest().from_dict(request_dict) assert not api.check_auth(request)
def test_check_valid_auth_pass(self, val): value_set = deepcopy(val) value_set['method'] = '--' if value_set['login'] == api.ADMIN_LOGIN: value_set['token'] = make_token(admin=True, salt=api.ADMIN_SALT) good_request_object = api.MethodRequest(**value_set) self.assertTrue(api.check_auth(good_request_object))
def test_check_auth_valid(self, request): # Generating request token if request.get("login") == api.ADMIN_LOGIN: request["token"] = hashlib.sha512( datetime.datetime.now().strftime("%Y%m%d%H") + api.ADMIN_SALT).hexdigest() else: msg = request.get("account", "") + request.get("login", "") + api.SALT request["token"] = hashlib.sha512(msg).hexdigest() # testing check_auth request = api.MethodBaseRequest(request) request.is_valid() res = api.check_auth(request) self.assertEqual(res, True)
def test_bad_authorization(self, storage): auth_request = create_request(storage)["body"] self.assertFalse(check_auth(auth_request))
def test_right_authorization(self, storage): auth_request = create_request(storage)["body"] self.assertTrue(check_auth(auth_request))
def test_auth_admin_valid(self, args): set_valid_auth(args) request = api.MethodRequest(args) self.assertTrue(api.check_auth(request))
def test_auth_admin_not_valid(self, args): request = api.MethodRequest(args) self.assertFalse(api.check_auth(request))
def test_check_auth_user(self): self.assertEqual(api.check_auth(self.method(self.request)), True)
def test_bad_auth(self, request): request = api.set_attributes(api.MethodRequest, request) self.assertFalse(api.check_auth(request))
def test_check_auth_invalid(self, request): # testing with no token request = api.MethodBaseRequest(request) request.is_valid() res = api.check_auth(request) self.assertEqual(res, False)