Skip to content

deal with 404 or 405 validator error #1499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions tests/test_oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json

import pytest
import requests
from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import make_password
from django.utils import timezone
Expand Down Expand Up @@ -501,18 +502,26 @@ def setUpTestData(cls):
cls.introspection_token = "test_introspection_token"
cls.validator = OAuth2Validator()

def test_response_when_auth_server_response_return_404(self):
with self.assertLogs(logger="oauth2_provider") as mock_log:
self.validator._get_token_from_authentication_server(
self.token, self.introspection_url, self.introspection_token, None
)
self.assertIn(
"ERROR:oauth2_provider:Introspection: Failed to "
"get a valid response from authentication server. "
"Status code: 404, Reason: "
"Not Found.\nNoneType: None",
mock_log.output,
)
def test_response_when_auth_server_response_not_200(self):
"""
Ensure we log the error when the authentication server returns a non-200 response.
"""
mock_response = requests.Response()
mock_response.status_code = 404
mock_response.reason = "Not Found"
with mock.patch("requests.post") as mock_post:
mock_post.return_value = mock_response
with self.assertLogs(logger="oauth2_provider") as mock_log:
self.validator._get_token_from_authentication_server(
self.token, self.introspection_url, self.introspection_token, None
)
self.assertIn(
"ERROR:oauth2_provider:Introspection: Failed to "
"get a valid response from authentication server. "
"Status code: 404, Reason: "
"Not Found.\nNoneType: None",
mock_log.output,
)


@pytest.mark.oauth2_settings(presets.OIDC_SETTINGS_RW)
Expand Down
Loading