wip: adds a walking skeleton test for SSO Authorize callback
This commit is contained in:
parent
5efb7d84a8
commit
86594973ff
|
|
@ -0,0 +1,37 @@
|
||||||
|
import uuid
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from vbv_lernwelt.core.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class TestSSO(TestCase):
|
||||||
|
def test_walking_skeleton(self):
|
||||||
|
self.assertTrue(True)
|
||||||
|
|
||||||
|
@patch("vbv_lernwelt.sso.views.oauth")
|
||||||
|
@patch("vbv_lernwelt.sso.views.decode_jwt")
|
||||||
|
def test_authorize_redirects_on_success(self, mock_decode_jwt, mock_oauth_service):
|
||||||
|
# GIVEN
|
||||||
|
email = "bobby@drop.table"
|
||||||
|
|
||||||
|
mock_oauth_service.authorize_access_token.return_value = {
|
||||||
|
"id_token": "test_token"
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_decode_jwt.return_value = {
|
||||||
|
"emails": [email],
|
||||||
|
"oid": uuid.uuid4(),
|
||||||
|
"given_name": "Bobby",
|
||||||
|
"family_name": "Drop-Table",
|
||||||
|
}
|
||||||
|
|
||||||
|
# WHEN
|
||||||
|
response = self.client.get(reverse("sso:authorize"))
|
||||||
|
|
||||||
|
# THEN
|
||||||
|
self.assertTrue(User.objects.filter(email=email).exists())
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
self.assertEqual(response.url, "/")
|
||||||
|
|
@ -22,6 +22,10 @@ def login(request):
|
||||||
|
|
||||||
|
|
||||||
def authorize(request):
|
def authorize(request):
|
||||||
|
print("authorize")
|
||||||
|
print(oauth)
|
||||||
|
print(decode_jwt)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.debug(request, label="sso")
|
logger.debug(request, label="sso")
|
||||||
token = getattr(oauth, settings.OAUTH["client_name"]).authorize_access_token(
|
token = getattr(oauth, settings.OAUTH["client_name"]).authorize_access_token(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue