Skip to content

Commit

Permalink
Update response code in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsoulas committed Dec 27, 2023
1 parent 444314d commit 0bf743b
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, hmac
from josepy.b64 import b64encode

from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import SuspiciousOperation
from django.test import RequestFactory, TestCase, override_settings
from django.utils.encoding import force_bytes, smart_str
from josepy.b64 import b64encode

from mozilla_django_oidc.auth import (
default_username_algo,
OIDCAuthenticationBackend,
)

from mozilla_django_oidc.auth import OIDCAuthenticationBackend, default_username_algo

User = get_user_model()

Expand Down Expand Up @@ -61,7 +56,7 @@ def test_invalid_token(self, request_mock, token_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"accesss_token": "access_token",
Expand Down Expand Up @@ -239,7 +234,7 @@ def test_successful_authentication_existing_user_namespaced(
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -288,7 +283,7 @@ def test_successful_authentication_existing_user(self, token_mock, request_mock)
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -341,7 +336,7 @@ def test_successful_authentication_existing_user_upper_case(
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -394,7 +389,7 @@ def test_failed_authentication_verify_claims(
claims_response = {"nickname": "a_username", "email": "[email protected]"}
get_json_mock.json.return_value = claims_response
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -445,7 +440,7 @@ def test_successful_authentication_new_user(
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -505,7 +500,7 @@ def test_successful_authentication_basic_auth_token(self, token_mock, request_mo
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -576,7 +571,7 @@ def test_jwt_decode_params(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "token",
"access_token": "access_token",
Expand All @@ -602,7 +597,7 @@ def test_jwt_decode_params_verify_false(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "token",
"access_token": "access_token",
Expand Down Expand Up @@ -642,7 +637,7 @@ def test_create_user_disabled(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand All @@ -666,7 +661,7 @@ def test_create_user_enabled(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -695,7 +690,7 @@ def test_custom_username_algo(self, request_mock, jws_mock, algo_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -725,7 +720,7 @@ def test_custom_username_algo_dotted_path(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -753,7 +748,7 @@ def test_duplicate_emails_exact(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand All @@ -778,7 +773,7 @@ def test_duplicate_emails_case_mismatch(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -812,7 +807,7 @@ def update_user(user, claims):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "id_token",
"access_token": "access_granted",
Expand Down Expand Up @@ -850,7 +845,7 @@ def test_jwt_verify_sign_key(self, request_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "token",
"access_token": "access_token",
Expand Down Expand Up @@ -899,7 +894,7 @@ def test_jwt_verify_sign_key_calls(self, request_mock, jwk_mock, jws_mock):
"email": "[email protected]",
}
request_mock.get.return_value = get_json_mock
post_json_mock = Mock()
post_json_mock = Mock(status_code=200)
post_json_mock.json.return_value = {
"id_token": "token",
"access_token": "access_token",
Expand Down

0 comments on commit 0bf743b

Please sign in to comment.