Skip to content

Commit

Permalink
Merge pull request #107 from bento-platform/fix/handle-method-not-all…
Browse files Browse the repository at this point in the history
…owed

fix: handle MethodNotAllowed errors
  • Loading branch information
davidlougheed authored Apr 15, 2024
2 parents 99a00eb + 37870da commit 54c75a9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
18 changes: 7 additions & 11 deletions chord_drs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask import Flask
from flask_cors import CORS
from flask_migrate import Migrate
from werkzeug.exceptions import BadRequest, Forbidden, NotFound, RequestedRangeNotSatisfiable
from werkzeug.exceptions import BadRequest, Forbidden, NotFound, MethodNotAllowed, RequestedRangeNotSatisfiable

from .authz import authz_middleware
from .backend import close_backend
Expand Down Expand Up @@ -47,19 +47,11 @@
)
application.register_error_handler(
BadRequest,
flask_errors.flask_error_wrap(
flask_errors.flask_bad_request_error,
drs_compat=True,
authz=authz_middleware,
),
flask_errors.flask_error_wrap(flask_errors.flask_bad_request_error, drs_compat=True, authz=authz_middleware),
)
application.register_error_handler(
Forbidden,
flask_errors.flask_error_wrap(
flask_errors.flask_forbidden_error,
drs_compat=True,
authz=authz_middleware,
),
flask_errors.flask_error_wrap(flask_errors.flask_forbidden_error, drs_compat=True, authz=authz_middleware),
)
application.register_error_handler(
NotFound,
Expand All @@ -70,6 +62,10 @@
authz=authz_middleware,
)(e),
)
application.register_error_handler(
MethodNotAllowed,
flask_errors.flask_error_wrap(flask_errors.flask_method_not_allowed_error, drs_compat=True, authz=authz_middleware),
)
application.register_error_handler(
RequestedRangeNotSatisfiable,
flask_errors.flask_error_wrap(
Expand Down
24 changes: 12 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include = [
[tool.poetry.dependencies]
python = "^3.10"
boto3 = ">=1.34.81,<1.35"
bento-lib = {version = "^11.5.2", extras = ["flask"]}
bento-lib = {version = "^11.6.0", extras = ["flask"]}
flask = ">=2.2.5,<2.3"
flask-sqlalchemy = ">=3.1.1,<3.2"
flask-migrate = ">=4.0.5,<4.1"
Expand Down
5 changes: 5 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def test_service_info(client):
validate(data, bento_lib.schemas.ga4gh.SERVICE_INFO_SCHEMA)


def test_method_not_allowed(client):
res = client.post("/service-info")
assert res.status_code == 405


def authz_everything_true(count=1):
responses.post(f"{AUTHZ_URL}/policy/evaluate", json={"result": [[True] for _ in range(count)]})

Expand Down

0 comments on commit 54c75a9

Please sign in to comment.