Skip to content

Commit

Permalink
refactor oxauth, no longer using for login
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Dec 20, 2023
1 parent 4a54261 commit 5d7cdd5
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 121 deletions.
1 change: 0 additions & 1 deletion openstax/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
admin.site.site_header = 'OpenStax'

urlpatterns = [
path('oxauth/', include('oxauth.urls')), # new auth package
path('admin/', include(wagtailadmin_urls)),

path('django-admin/error/', throw_error, name='throw_error'),
Expand Down
15 changes: 15 additions & 0 deletions oxauth/migrations/0004_delete_openstaxuserprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 4.2.8 on 2023-12-20 21:02

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("oxauth", "0003_alter_openstaxuserprofile_options"),
]

operations = [
migrations.DeleteModel(
name="OpenStaxUserProfile",
),
]
12 changes: 0 additions & 12 deletions oxauth/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
from django.contrib.auth.models import User
from django.db import models

class OpenStaxUserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
openstax_accounts_id = models.IntegerField()
openstax_accounts_uuid = models.UUIDField()

def __str__(self):
return self.user.username

class Meta:
verbose_name = 'OpenStax User Profile'
11 changes: 1 addition & 10 deletions oxauth/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.test import TestCase, Client

from shared.test_utilities import RequestMock
from oxauth.models import OpenStaxUserProfile
from oxauth.functions import decrypt_cookie, get_logged_in_user_id, get_logged_in_user_uuid
from http import cookies

Expand All @@ -27,12 +26,4 @@ def test_can_get_logged_in_user_uuid(self):
response = self.client.get('/admin')
request = response.wsgi_request
uuid = get_logged_in_user_uuid(request, bypass_sso_cookie_check=False)
# self.assertEqual(uuid, '467cea6c-8159-40b1-90f1-e9b0dc26344c')

def creates_openstax_profile_on_login(self):
biscuits = cookies.SimpleCookie()
biscuits['oxa'] = self.sso_cookie
self.client.cookies = biscuits
response = self.client.get('/admin')
profile = OpenStaxUserProfile.objects.last('id')
self.assertEqual(profile.openstax_accounts_uuid, '467cea6c-8159-40b1-90f1-e9b0dc26344c')
self.assertEqual(uuid, '467cea6c-8159-40b1-90f1-e9b0dc26344c')
7 changes: 0 additions & 7 deletions oxauth/urls.py

This file was deleted.

81 changes: 0 additions & 81 deletions oxauth/views.py

This file was deleted.

16 changes: 16 additions & 0 deletions oxmenus/migrations/0003_alter_menus_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.8 on 2023-12-20 21:02

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("oxmenus", "0002_alter_menus_menu"),
]

operations = [
migrations.AlterModelOptions(
name="menus",
options={"verbose_name_plural": "Menus"},
),
]
1 change: 0 additions & 1 deletion salesforce/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.db.models import Avg
from django.core.validators import MaxValueValidator, MinValueValidator
from django.core.exceptions import ValidationError

Expand Down
21 changes: 12 additions & 9 deletions shared/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from django.core.handlers.base import BaseHandler
from django.test.client import RequestFactory
from django.http.response import HttpResponsePermanentRedirect
from django.contrib.auth import login as auth_login
from django.contrib.auth.models import User
from oxauth.functions import decrypt_cookie
from oxauth.views import create_sso_profile


def assertPathDoesNotRedirectToTrailingSlash(test, path):
try:
Expand All @@ -15,19 +13,24 @@ def assertPathDoesNotRedirectToTrailingSlash(test, path):

response = test.client.get(path)

if (isinstance(response, HttpResponsePermanentRedirect)):
test.assertNotEqual(response.url, path + "/")
if isinstance(response, HttpResponsePermanentRedirect):
test.assertNotEqual(response.url, path + "/")


def mock_user_login():
cookie = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..mktqRLloaCze0VeT.0WU9d20PI1Iu6zajuQMiIJ5GQJVy0D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64Z7AZDptM9oXK035cbvMMuzG9b1jH3XE2o3gO5ekixDpMwTKT8uI1wH9gOqbf9ehirExYgxEh-EVXTlT6t-kk4N-tu83zCLi8MZNTAVqlisakFlnkn4o53Bj5nn9bRQT61HJG_cLxs.Sz3rB-YyqatRUpekkxpyfw'
decrypted_cookie = decrypt_cookie(cookie).payload_dict['sub']
user, _ = User.objects.get_or_create(
username='test',
first_name='Test',
last_name='User',
email='[email protected]'
)

user = create_sso_profile(decrypted_cookie)
return user


class RequestMock(RequestFactory):
def request(self, **request):
"Construct a generic request object."
"""Construct a generic request object."""
request = RequestFactory.request(self, **request)
handler = BaseHandler()
handler.load_middleware()
Expand Down

0 comments on commit 5d7cdd5

Please sign in to comment.