Skip to content

Commit

Permalink
fail in the extra function
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaran committed Dec 5, 2023
1 parent 49c15b0 commit 6af2426
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/fakeapi/hello/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,22 @@ def name_check(*args, **kwargs):
return True


def fail_this():
raise Exception("Custom auth fail!")


def get_user_authz_extra_func():
request.firetail_authz = {"user_id": 7}
request.name_check = name_check
return {"user_id": 7, "name": "max"}


def get_user_authz_extra_func_fails():
request.firetail_authz = {"user_id": 7}
request.name_check = fail_this
return {"user_id": 7, "name": "max"}


def get_user_authz_fails():
request.firetail_authz = {"user_id": 8}
return {"user_id": 7, "name": "max"}
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/json_validation/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/User'
/authzEndExtraFuncFail:
get:
operationId: fakeapi.hello.get_user_authz_extra_func_fails
responses:
200:
description: Success
x-ft-security:
authenticated-principal-path: "user_id"
resource-authorized-principal-path: "user_id"
access-resolver: "name_check"
content:
application/json:
schema:
$ref: '#/components/schemas/User'
/authzEndFails:
get:
operationId: fakeapi.hello.get_user_authz_fails
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/json_validation/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ paths:
access-resolver: "name_check"
schema:
$ref: '#/definitions/User'
/authzEndExtraFuncFail:
get:
operationId: fakeapi.hello.get_user_authz_extra_func_fails
responses:
200:
description: User object
x-ft-security:
authenticated-principal-path: "user_id"
resource-authorized-principal-path: "user_id"
access-resolver: "name_check"
schema:
$ref: '#/definitions/User'
/authzEndFails:
get:
operationId: fakeapi.hello.get_user_authz_fails
Expand Down
10 changes: 10 additions & 0 deletions tests/test_json_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def test_validator_map_ft_authz_success_extra_auth(json_validation_spec_dir, spe
assert res.status_code == 200


@pytest.mark.parametrize("spec", SPECS)
def test_validator_map_ft_authz_extra_auth_fails(json_validation_spec_dir, spec):
app = App(__name__, specification_dir=json_validation_spec_dir)
app.add_api(spec, validate_responses=True)
app_client = app.app.test_client()

res = app_client.get("/v1.0/authzEndExtraFuncFail") # type: flask.Response
assert res.status_code == 401


@pytest.mark.parametrize("spec", SPECS)
def x_test_validator_map_ft_authz_fails_extra_auth(json_validation_spec_dir, spec):
app = App(__name__, specification_dir=json_validation_spec_dir)
Expand Down

0 comments on commit 6af2426

Please sign in to comment.