-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- updates backend so it considers minimal authentication parameters - updates unittests to consider more authentication flows Ref: #71
- Loading branch information
1 parent
4066b1c
commit b6f7d29
Showing
4 changed files
with
77 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 3.2.16 on 2022-11-17 17:41 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import ldapdb.models.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0002_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='KeycloakUser', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('sub', models.CharField(max_length=255, unique=True)), | ||
('realm', models.CharField(max_length=255)), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='keycloak_user', to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.AddConstraint( | ||
model_name='keycloakuser', | ||
constraint=models.UniqueConstraint(fields=('sub', 'realm'), name='unique_sub_realm'), | ||
), | ||
] |
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,16 +1,17 @@ | ||
from django.contrib.auth import authenticate, login | ||
from tapir.utils.tests_utils import TapirFactoryTestBase | ||
from tapir.accounts.tests.factories.factories import TapirUserFactory | ||
from django.test import RequestFactory | ||
|
||
class KeyCloakAuthentication(TapirFactoryTestBase): | ||
|
||
def setUp(self): | ||
# Every test needs access to the request factory. | ||
self.factory = RequestFactory() | ||
class KeycloakAuthentication(TapirFactoryTestBase): | ||
|
||
def test_backend_authenticates_user_against_keycloak_server(self): | ||
request = RequestFactory().get('/') | ||
auth_user = authenticate(request, username='demo@demo.com', password='demo') | ||
self.assertIsNotNone(auth_user) | ||
|
||
def test_backend_sets_active_status(self): | ||
self.fail('check for the is_active key value and update') | ||
|
||
def test_bla(self): | ||
from django.contrib.auth import authenticate, login | ||
request = self.factory.get('/') | ||
user = TapirUserFactory() | ||
auth_user = authenticate(request, username='asd', password='asd') | ||
login(request, auth_user) | ||
def test_backend_differentiates_between_diferent_realms(self): | ||
self.fail("user from another realm cannot login") |