generated from ocadotechnology/codeforlife-template-backend
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial * initial code * quick save * install portal instead * auth backends * tidy up auth backends * update auth backends * quick save * deploy to gcloud * fix pipeline * don't check migrations * use correct service name * no pytest * use latest cfl packages * quick save * include a base url for service routing * set base route * use cfl package * tests and remove user import * session config * quick save * remove logout endpoint * login working * set session cookie domain * return invalid form errors * login middleware * simplify code * remove login middleware * remove extra white spacing * update launch * use new cfl package * fix pipeline * raise validation errors * remove todos * use latest package version * use latest cfl package * set secret key * new cfl package * fix: set env vars * use new cfl package * user new cfl-common package * house keeping [skip ci] * use latest cfl package * feedback * remove unnecessary return types * return remaining session auth factors * codeforlife.user * save session data before response * return auth factors * update readme * merge from development * update lock * support backup token authentication * test otp * remove users expired sessions * update lock * fix mock * use new cfl package * remove todo
- Loading branch information
Showing
9 changed files
with
118 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# codeforlife-service-template | ||
# codeforlife-sso | ||
|
||
[Frontend Docs](docs/frontend) | ||
This repo contains CFL's Single Sign-On (SSO) service. This will be responsible for authenticating users. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,55 @@ | ||
from unittest.mock import Mock, patch | ||
from unittest.mock import patch | ||
|
||
import pyotp | ||
from codeforlife.tests import CronTestCase | ||
from codeforlife.user.models import AuthFactor, User | ||
from django.core import management | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
|
||
|
||
class TestClearExpiredView(CronTestCase): | ||
@patch("django.core.management.call_command") | ||
def test_clear_expired_view(self, call_command: Mock): | ||
self.client.get(reverse("clear-expired-sessions")) | ||
class TestLoginView(TestCase): | ||
def setUp(self): | ||
self.user = User.objects.get(id=2) | ||
|
||
def test_post__otp(self): | ||
AuthFactor.objects.create( | ||
user=self.user, | ||
type=AuthFactor.Type.OTP, | ||
) | ||
|
||
response = self.client.post( | ||
reverse("login", kwargs={"form": "email"}), | ||
data={ | ||
"email": self.user.email, | ||
"password": "Password1", | ||
}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
self.assertDictEqual( | ||
response.json(), {"auth_factors": [AuthFactor.Type.OTP]} | ||
) | ||
|
||
self.user.userprofile.otp_secret = pyotp.random_base32() | ||
self.user.userprofile.save() | ||
|
||
call_command.assert_called_once_with("clearsessions") | ||
totp = pyotp.TOTP(self.user.userprofile.otp_secret) | ||
|
||
now = timezone.now() | ||
with patch.object(timezone, "now", return_value=now): | ||
response = self.client.post( | ||
reverse("login", kwargs={"form": "otp"}), | ||
data={"otp": totp.at(now)}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
self.assertDictEqual(response.json(), {"auth_factors": []}) | ||
|
||
|
||
class TestClearExpiredView(CronTestCase): | ||
def test_clear_expired_view(self): | ||
with patch.object(management, "call_command") as call_command: | ||
self.client.get(reverse("clear-expired-sessions")) | ||
call_command.assert_called_once_with("clearsessions") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters