From 5f6c8b57cf0dc11895d4cbe12e815ba6cb511904 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 25 Feb 2025 18:07:46 +0100 Subject: [PATCH] add some test Signed-off-by: Jens Langhammer --- authentik/lib/sync/outgoing/exceptions.py | 3 +++ authentik/providers/scim/tests/test_user.py | 26 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/authentik/lib/sync/outgoing/exceptions.py b/authentik/lib/sync/outgoing/exceptions.py index e83d96a3574d..0e87ae86fc13 100644 --- a/authentik/lib/sync/outgoing/exceptions.py +++ b/authentik/lib/sync/outgoing/exceptions.py @@ -30,6 +30,9 @@ def __init__(self, url: str, method: str, body: dict): self.method = method self.body = body + def __str__(self): + return f"{self.method} {self.url}" + class StopSync(BaseSyncException): """Exception raised when a configuration error should stop the sync process""" diff --git a/authentik/providers/scim/tests/test_user.py b/authentik/providers/scim/tests/test_user.py index a8ca5e813705..105927c062ba 100644 --- a/authentik/providers/scim/tests/test_user.py +++ b/authentik/providers/scim/tests/test_user.py @@ -330,3 +330,29 @@ def test_sync_task(self, mock: Mocker): "userName": uid, }, ) + + def test_user_create_dry_run(self): + """Test user creation (dry_run)""" + # Update the provider before we start mocking as saving the provider triggers a full sync + self.provider.dry_run = True + self.provider.save() + with Mocker() as mock: + scim_id = generate_id() + mock.get( + "https://localhost/ServiceProviderConfig", + json={}, + ) + mock.post( + "https://localhost/Users", + json={ + "id": scim_id, + }, + ) + uid = generate_id() + User.objects.create( + username=uid, + name=f"{uid} {uid}", + email=f"{uid}@goauthentik.io", + ) + self.assertEqual(mock.call_count, 1, mock.request_history) + self.assertEqual(mock.request_history[0].method, "GET")