Skip to content

Commit 009754e

Browse files
pedro-cfjonhealy1
andauthored
Basic Auth bug fix & test fixes. (#266)
**Description:** Basic Auth bug fix & test fix. `request.url.path` would return the absolute path f.e.: `/collections/test-collection` `request.scope.get("route").path` returns `/collections/{collection_id}` which is correct for matching permissions **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [x] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog --------- Co-authored-by: Jonathan Healy <jonathan.d.healy@gmail.com>
1 parent 3d85ba6 commit 009754e

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
### Fixed
1515

1616
- API sort extension tests [#264](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/264)
17+
- Basic auth permission fix for checking route path instead of absolute path [#266](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/266)
1718

1819
## [v3.0.0a1]
1920

stac_fastapi/core/stac_fastapi/core/basic_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def has_access(
6161
)
6262

6363
permissions = user.get("permissions", [])
64-
path = request.url.path
64+
path = request.scope.get("route").path
6565
method = request.method
6666

6767
if permissions == "*":

stac_fastapi/tests/basic_auth/test_basic_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def test_delete_resource_insufficient_permissions(app_client_basic_auth, c
7474

7575
assert response.status_code == 403
7676
assert response.json() == {
77-
"detail": "Insufficient permissions for [DELETE /collections/test-collection]"
77+
"detail": "Insufficient permissions for [DELETE /collections/{collection_id}]"
7878
}
7979

8080

0 commit comments

Comments
 (0)