-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
56 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
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,39 +1,40 @@ | ||
from django.test import RequestFactory,TransactionTestCase, Client | ||
from django.test import RequestFactory, TransactionTestCase, Client | ||
|
||
class test_passkeys(TransactionTestCase): | ||
|
||
class TestPasskeys(TransactionTestCase): | ||
def setUp(self) -> None: | ||
from django.contrib.auth import get_user_model | ||
self.user_model = get_user_model() | ||
self.user = self.user_model.objects.create_user(username="test",password="test") | ||
self.user = self.user_model.objects.create_user(username="test", password="test") | ||
self.client = Client() | ||
self.factory = RequestFactory() | ||
|
||
def test_raiseException(self): | ||
from django.contrib.auth import authenticate | ||
try: | ||
authenticate(request=None,username="test",password="test") | ||
authenticate(request=None, username="test", password="test") | ||
self.assertFalse(True) | ||
except Exception as e: | ||
self.assertEquals(str(e),"request is required for passkeys.backend.PasskeyModelBackend") | ||
self.assertEqual(str(e), "request is required for passkeys.backend.PasskeyModelBackend") | ||
|
||
def test_not_add_passkeys_field(self): | ||
request = self.factory.post("/auth/login",{"username":"","password":""}) | ||
request = self.factory.post("/auth/login", {"username": "", "password": ""}) | ||
from django.contrib.auth import authenticate | ||
try: | ||
user = authenticate(request=request,username="",password="") | ||
user = authenticate(request=request, username="", password="") | ||
self.assertFalse(True) | ||
except Exception as e: | ||
self.assertEquals(str(e),"Can't find 'passkeys' key in request.POST, did you add the hidden input?") | ||
self.assertEqual(str(e), "Can't find 'passkeys' key in request.POST, did you add the hidden input?") | ||
|
||
def test_username_password_failed_login(self): | ||
self.client.post("/auth/login",{"username":"test","password":"test123",'passkeys':''}) | ||
self.assertFalse(self.client.session.get('_auth_user_id',False)) | ||
self.client.post("/auth/login", {"username": "test", "password": "test123", "passkeys": ""}) | ||
self.assertFalse(self.client.session.get('_auth_user_id', False)) | ||
|
||
def test_username_password_login(self): | ||
self.client.post("/auth/login",{"username":"test","password":"test",'passkeys':''}) | ||
self.assertTrue(self.client.session.get('_auth_user_id',False)) | ||
self.client.post("/auth/login", {"username": "test", "password": "test", "passkeys": ""}) | ||
self.assertTrue(self.client.session.get('_auth_user_id', False)) | ||
self.assertFalse(self.client.session.get('passkey', {}).get('passkey', False)) | ||
|
||
def test_no_data(self): | ||
self.client.post("/auth/login",{"username":"","password":"",'passkeys':''}) | ||
self.assertFalse(self.client.session.get('_auth_user_id',False)) | ||
self.client.post("/auth/login", {"username": "", "password": "", "passkeys": ""}) | ||
self.assertFalse(self.client.session.get('_auth_user_id', False)) |
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