🧑‍💻(demo) configure people as an IdP

This configures local environment to test login through people:
- Keycloak configuration of the IdP (people)
- Add Keycloak Application in people

The only user who can login for now is "admin".
This commit is contained in:
Quentin BEY
2025-01-14 11:48:55 +01:00
committed by BEY Quentin
parent db6cdadd72
commit 68550f6f7e
5 changed files with 187 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ from django.core.management.base import BaseCommand, CommandError
from django.utils.text import slugify
from faker import Faker
from oauth2_provider.models import Application
from treebeard.mp_tree import MP_Node
from core import models
@@ -133,6 +134,25 @@ class Timeit:
return elapsed_time
def create_oidc_people_idp_client():
"""Configure the OIDC client for the People Identity Provider if missing."""
try:
Application.objects.get(client_id="people-idp")
except Application.DoesNotExist:
application = Application(
client_id="people-idp",
client_secret="local-tests-only",
client_type=Application.CLIENT_CONFIDENTIAL,
authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
name="People Identity Provider",
algorithm=Application.RS256_ALGORITHM,
redirect_uris="http://localhost:8083/realms/people/broker/oidc-people-local/endpoint",
skip_authorization=True,
)
application.clean()
application.save()
def create_demo(stdout): # pylint: disable=too-many-locals
"""
Create a database with demo data for developers to work in a realistic environment.
@@ -315,6 +335,10 @@ def create_demo(stdout): # pylint: disable=too-many-locals
queue.flush()
# OIDC configuration
if settings.OAUTH2_PROVIDER.get("OIDC_ENABLED", False):
create_oidc_people_idp_client()
class Command(BaseCommand):
"""A management command to create a demo database."""

View File

@@ -3,7 +3,6 @@
from unittest import mock
from django.core.management import call_command
from django.test import override_settings
import pytest
@@ -11,6 +10,7 @@ from core import models
from demo import defaults
from mailbox_manager import models as mailbox_models
from people.settings import Base
pytestmark = pytest.mark.django_db
@@ -23,10 +23,13 @@ TEST_NB_OBJECTS = {
}
@override_settings(DEBUG=True)
@mock.patch.dict(defaults.NB_OBJECTS, TEST_NB_OBJECTS)
def test_commands_create_demo():
def test_commands_create_demo(settings):
"""The create_demo management command should create objects as expected."""
settings.DEBUG = True
settings.OAUTH2_PROVIDER["OIDC_ENABLED"] = True
settings.OAUTH2_PROVIDER["OIDC_RSA_PRIVATE_KEY"] = Base.generate_temporary_rsa_key()
call_command("create_demo")
# Monique Test, Jeanne Test and Jean Something (quick fix for e2e)
@@ -37,7 +40,7 @@ def test_commands_create_demo():
assert models.Team.objects.count() == TEST_NB_OBJECTS["teams"]
assert models.TeamAccess.objects.count() >= TEST_NB_OBJECTS["teams"]
assert mailbox_models.MailDomain.objects.count() == TEST_NB_OBJECTS["domains"]
assert mailbox_models.MailDomain.objects.count() == TEST_NB_OBJECTS["domains"] + 1
# 3 domain access for each user with domain rights
# 3 x 3 domain access for each user with both rights