def test_tenant_id_criteria_works_on_all_auth_methods_with_tenant(self): """ Failure injection based on the username criteria will work on username/password, username/api-key, and token. But not impersonation. """ core, root = core_and_root([]) fail_params = {"message": "Invalid creds", "code": 403} # make sure a user exists in mimic with the given username tenant # associated response, body = authenticate_with_username_password( self, root, username="******", tenant_id="123456") self.assertEqual(response.code, 200) # tenant auths fail register_behavior(self, root, auth_behavior_endpoint, behavior_name="fail", criteria=[{"tenant_id": "123456"}], parameters=fail_params) for auth_func in (authenticate_with_username_password, authenticate_with_api_key, authenticate_with_token): response, body = auth_func(self, root, tenant_id="123456") self.assertEqual(response.code, 403) self.assertEqual(body, {"unauthorized": fail_params}) # impersonation with that username succeeds response, body = impersonate_user(self, root, username="******") self.assertEqual(response.code, 200)
def test_string_errors_as_well_as_json_errors(self): """ Failure injection will return a string error response as well as a json response. """ core, root = core_and_root([]) fail_params = {"message": "Failure of JSON", "code": 500, "type": "string"} register_behavior(self, root, auth_behavior_endpoint, behavior_name="fail", criteria=[{"username": "******"}], parameters=fail_params) response, body = authenticate_with_username_password( self, root, username="******", request_func=request_with_content) self.assertEqual(response.code, 500) self.assertEqual(body, "Failure of JSON")