-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Fix exempt URI method views (#28)
* Fix tests assertEquals calls When running tests in Python 3.12.0, an error indicating `assertEquals` is not available. * Modify tests for exempted URI with explicit override in view The tests were previously testing against the following configuration: ```python {'GET': ['director', 'judge', 'employee'], 'POST': ['director', 'judge'], 'UPDATE': ['director', 'judge'], 'DELETE': ['director', 'judge'], 'PATCH': ['director', 'judge', 'employee']} ``` It was not possible to override the test cases. The `'POST'` method was removed from keycloak_roles in order to be able to appropriately test the intended behavior, as described in the test case, `test_when_some_EXEMPT_URI_is_permitted_on_authentication_with_keycloak_roles_on_view`. * Add explicit override logic for exempted URIs in middleware This will close and fix #27. Using a simple `if` statement, adding one more check to see if the processing of a given view should occur makes it simple to allow for more complex behaviors on a `ModelViewSet` than either fully exempted or exempted, yet able to be overriden in a View. * Update version number * Fix AttributeError for is_api_view check When attempting to access the `/admin` interface in Django, an `AttributeError` gets `raise`d: ``` Traceback (most recent call last): File "/Users/thomasfex/development/github/ItkBackend/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/Users/thomasfex/development/github/ItkBackend/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 171, in _get_response response = middleware_method(request, callback, callback_args, callback_kwargs) File "/Users/thomasfex/development/github/ItkBackend/env/lib/python3.8/site-packages/django_keycloak_auth/middleware.py", line 91, in process_view is_api_view = True if str(view_func.cls.__qualname__) == "WrappedAPIView" else False AttributeError: 'function' object has no attribute 'cls' [03-11-23 13:38:09] django.server 500 "GET /admin/ HTTP/1.1" 500 95736 ``` A `try`/`except` block successfully allows the access of `/admin` pages. Co-authored-by: Thomas Cross <[email protected]> --------- Co-authored-by: Marcelo Vinicius de Sousa Campos <[email protected]> Co-authored-by: Thomas Cross <[email protected]>
- Loading branch information
1 parent
976708d
commit f360b5d
Showing
5 changed files
with
34 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,18 @@ | ||
version: "3" | ||
|
||
volumes: | ||
my_data: | ||
|
||
networks: | ||
my_network: | ||
driver: bridge | ||
|
||
services: | ||
db: | ||
image: postgres:12.0-alpine | ||
volumes: | ||
- my_data:/var/lib/postgresql/data | ||
keycloak: | ||
image: jboss/keycloak | ||
restart: "no" | ||
environment: | ||
POSTGRES_DB: deposito | ||
POSTGRES_USER: admin | ||
POSTGRES_PASSWORD: 123 | ||
- DB_VENDOR=H2 | ||
- KEYCLOAK_USER=admin | ||
- KEYCLOAK_PASSWORD=123 | ||
ports: | ||
- "8080:8080" | ||
networks: | ||
- my_network | ||
|
||
keycloak: | ||
image: jboss/keycloak | ||
environment: | ||
DB_VENDOR: POSTGRES | ||
DB_ADDR: db | ||
DB_DATABASE: deposito | ||
DB_USER: admin | ||
DB_SCHEMA: public | ||
DB_PASSWORD: 123 | ||
KEYCLOAK_USER: admin | ||
KEYCLOAK_PASSWORD: 123 | ||
ports: | ||
- 8080:8080 | ||
depends_on: | ||
- db | ||
networks: | ||
- my_network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters