Skip to content

Commit

Permalink
clean up unused oxauth functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Jan 3, 2024
1 parent 1928100 commit 245a2a3
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 157 deletions.
1 change: 0 additions & 1 deletion openstax/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'oxauth.backend.OpenStaxAccountsBackend',
)

TEMPLATES = [
Expand Down
12 changes: 0 additions & 12 deletions oxauth/admin.py

This file was deleted.

18 changes: 0 additions & 18 deletions oxauth/backend.py

This file was deleted.

15 changes: 15 additions & 0 deletions oxauth/migrations/0003_delete_openstaxuserprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 4.2.8 on 2024-01-03 22:26

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("oxauth", "0002_create_user_profile"),
]

operations = [
migrations.DeleteModel(
name="OpenStaxUserProfile",
),
]
13 changes: 0 additions & 13 deletions oxauth/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
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'
17 changes: 1 addition & 16 deletions oxauth/tests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import json
from urllib.parse import urlencode
from urllib.request import urlopen

from django.test import TestCase, Client
from django.conf import settings
from django.urls import reverse

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


Expand All @@ -36,10 +28,3 @@ def test_can_get_logged_in_user_uuid(self):
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')
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.

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.0WU9d20PI1Iu6zajuQMiIJ5GQJVy0DQ1H3BINxkYIS56f1X6p_mesuujHphLcukQny6q0_rmvZUkKLEyojpo14p3czXXu0GF2EWtxprPmfOnPdAig0GXCBJxYVbxKIuZdR4FYodIZaDuDUjXC_hJohHuVoiTQW7jJEGIFj8m9dgAqP-3hOnqaO0C0OvKWoXi0sLb3CvTraT2AGRgj69jkg4B-2y1sUZn_yZO6o2HekGlxzhnKT7ILEAl7cd68W6LmmN0vk4V4nNFkcg0XQ3i1MzWLZroGSjD_9HrhALdHcofBC39UClOzxnbpynFlZk0gr7m0_MmCUFqWKSL8G0eRT9sgOIW6THsl0jpT4KyUFREVdGkTWxaS2qYRqZEQBk9wZlAHuHkE8s6UNZNYhvU5RJkGC1m4faHnM_umTEFQq5aBvRe7gq_8OtOGASXtmFggapuUSfxWX8Bxh8IgA4BT_DuxQbC4biO7FauOT0glZ0Dk4ZXIjbhxBnedtjmeH02xa4RpcKOSOv4UMy1ajCc4KLp9K5drQTKs1PeShAUg1aN58ZwgQq1w4MdjXHkMqnJFiFWt9abF3WYG2EywhTogxIcgq6IrrAIzW4NSptnQVAcxTPxp7hb3OT1mY9dcK138h0GtBR6Z562VbDRaSwplXCLvwcqKoGJyhotcl2m78ESmu1kIO_AJVstlaZprEA0Ji0A7uJlL03JAeTvlJptcouFGax8LGlxq9Ekpz_zifUxLR52MJ8otKcapsZvmtOpc8A70p7V-ceinzKdL5Jq_zA0teJ1Qk2gjMJ7IdeyG3VZ0QIFOQ_FffGkbdW1Ow-nHFHLVfHbkyEF65HIGHEN_RqL0OKUa1HcPlmL5c1S4w5zgdA-2ZAda6ASnY1clwGufFek5AwMp5SAUmdNUBYIDdQm6hbzn0Xe2VB5Y-jqKBOq4yk-M4rmwAf-tD5NJiKaYLZwT-Zst2eG8InRUOmQt6lBJtGNIYnk_a__rX8rfJpvKIJ-Ws8b9fHvSjzSQOroqM3KmfLrevucaJA7jM7CydgOOnt3VQGXKnYqgnhD6jii0zjR3sGAJHF24tQIVtoFCQGBJZly_MQL2Y-EeLqz64Z7AZDptM9oXK035cbvMMuzG9b1jH3XE2o3gO5ekixDpMwTKT8uI1wH9gOqbf9ehirExYgxEh-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 245a2a3

Please sign in to comment.