Skip to content

providers/scim: fix scim user conflict resolution (cherry-pick #25998 to version-2026.5) - #26024

Open
authentik-cherry-pick[bot] wants to merge 1 commit into
version-2026.5from
cherry-pick/25998-to-version-2026.5
Open

authentik-cherry-pick[bot] wants to merge 1 commit into
version-2026.5from
cherry-pick/25998-to-version-2026.5

Conversation

@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

Cherry-pick of #25998 to version-2026.5 branch.

Original PR: #25998
Original Author: @ryanpesek
Cherry-picked commit: 82ca019

@netlify

netlify Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit f043413
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6b0b2e58b09ecdf1a1785152
😎 Deploy Preview https://deploy-preview-26024--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit f043413
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6b0b2e5887f90771d49de4a3
😎 Deploy Preview https://deploy-preview-26024--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit f043413
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6b0b2e58eec94a3988b516af
😎 Deploy Preview https://deploy-preview-26024--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
3846 2 3844 1
View the top 2 failed test(s) by shortest run time
authentik.providers.scim.tests.test_user.SCIMUserTests::test_user_create_conflict_lowercase_resources_key
Stack Traces | 0.544s run time
self = <unittest.case._Outcome object at 0x71ed5bb7ea50>
test_case = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>
subTest = False

    @contextlib.contextmanager
    def testPartExecutor(self, test_case, subTest=False):
        old_success = self.success
        self.success = True
        try:
>           yield

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/case.py:58: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>
result = <TestCaseFunction test_user_create_conflict_lowercase_resources_key>

    def run(self, result=None):
        if result is None:
            result = self.defaultTestResult()
            startTestRun = getattr(result, 'startTestRun', None)
            stopTestRun = getattr(result, 'stopTestRun', None)
            if startTestRun is not None:
                startTestRun()
        else:
            stopTestRun = None
    
        result.startTest(self)
        try:
            testMethod = getattr(self, self._testMethodName)
            if (getattr(self.__class__, "__unittest_skip__", False) or
                getattr(testMethod, "__unittest_skip__", False)):
                # If the class or method was skipped.
                skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
                            or getattr(testMethod, '__unittest_skip_why__', ''))
                _addSkip(result, self, skip_why)
                return result
    
            expecting_failure = (
                getattr(self, "__unittest_expecting_failure__", False) or
                getattr(testMethod, "__unittest_expecting_failure__", False)
            )
            outcome = _Outcome(result)
            start_time = time.perf_counter()
            try:
                self._outcome = outcome
    
                with outcome.testPartExecutor(self):
                    self._callSetUp()
                if outcome.success:
                    outcome.expecting_failure = expecting_failure
                    with outcome.testPartExecutor(self):
>                       self._callTestMethod(testMethod)

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/case.py:669: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>
method = <bound method SCIMUserTests.test_user_create_conflict_lowercase_resources_key of <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>>

    def _callTestMethod(self, method):
>       result = method()
                 ^^^^^^^^

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/case.py:615: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>,)
keywargs = {}
newargs = (<authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>,)
newkeywargs = {}

    @wraps(func)
    def patched(*args, **keywargs):
        with self.decoration_helper(patched,
                                    args,
                                    keywargs) as (newargs, newkeywargs):
>           return func(*newargs, **newkeywargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/mock.py:1439: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = [<authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>, <requests_mock.mocker.Mocker object at 0x71ed65c5a850>]
kwargs = {}, m = <requests_mock.mocker.Mocker object at 0x71ed65c5a850>

    @functools.wraps(func)
    def inner(*args, **kwargs):
        with self.copy() as m:
            if self._kw:
                kwargs[self._kw] = m
            else:
                args = list(args)
                args.append(m)
    
>           return func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^

.venv/lib/python3.14.../site-packages/requests_mock/mocker.py:317: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>
mock = <requests_mock.mocker.Mocker object at 0x71ed65c5a850>

    @Mocker()
    def test_user_create_conflict_lowercase_resources_key(self, mock: Mocker):
        """An existing user is adopted from a lowercase list response"""
>       self._test_user_create_conflict(mock, "resources")

.../scim/tests/test_user.py:137: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_lowercase_resources_key>
mock = <requests_mock.mocker.Mocker object at 0x71ed65c5a850>
resources_key = 'resources'

    def _test_user_create_conflict(self, mock: Mocker, resources_key: str):
        mock.get(
            "https:.../localhost/ServiceProviderConfig",
            json={
                "authenticationSchemes": [],
                "patch": {"supported": False},
                "bulk": {"supported": False},
                "filter": {"supported": True},
                "changePassword": {"supported": False},
                "sort": {"supported": False},
                "etag": {"supported": False},
            },
        )
        mock.post("https:.../localhost/Users", status_code=409)
        scim_id = generate_id()
        uid = generate_id()
        remote_user = {
            "id": scim_id,
            "userName": uid,
            "displayName": "Remote display name",
        }
        mock.get("https:.../localhost/Users", json={resources_key: [remote_user]})
    
        user = User.objects.create(username=uid, name=uid, email=f"{uid}@goauthentik.io")
    
>       connection = SCIMProviderUser.objects.get(provider=self.provider, user=user)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../scim/tests/test_user.py:122: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <django.db.models.manager.Manager object at 0x71ed713342d0>, args = ()
kwargs = {'provider': <SCIMProvider: SCIM Provider xPihg4jP2zzs7fvPcrXbxzeMd3HD1B8QUPMBpiHe>, 'user': <User: et1r29VjvjFy7LwO2s6JjmGVOfkTAnR8egIVvAvh>}

    @wraps(method)
    def manager_method(self, *args, **kwargs):
>       return getattr(self.get_queryset(), name)(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.venv/lib/python3.14.../db/models/manager.py:87: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <QuerySet []>, args = ()
kwargs = {'provider': <SCIMProvider: SCIM Provider xPihg4jP2zzs7fvPcrXbxzeMd3HD1B8QUPMBpiHe>, 'user': <User: et1r29VjvjFy7LwO2s6JjmGVOfkTAnR8egIVvAvh>}
clone = <QuerySet []>, limit = 21, num = 0

    def get(self, *args, **kwargs):
        """
        Perform the query and return a single object matching the given
        keyword arguments.
        """
        if self.query.combinator and (args or kwargs):
            raise NotSupportedError(
                "Calling QuerySet.get(...) with filters after %s() is not "
                "supported." % self.query.combinator
            )
        clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
        if self.query.can_filter() and not self.query.distinct_fields:
            clone = clone.order_by()
        limit = None
        if (
            not clone.query.select_for_update
            or connections[clone.db].features.supports_select_for_update_with_limit
        ):
            limit = MAX_GET_RESULTS
            clone.query.set_limits(high=limit)
        num = len(clone)
        if num == 1:
            return clone._result_cache[0]
        if not num:
>           raise self.model.DoesNotExist(
                "%s matching query does not exist." % self.model._meta.object_name
            )
E           authentik.providers.scim.models.SCIMProviderUser.DoesNotExist: SCIMProviderUser matching query does not exist.

.venv/lib/python3.14.../db/models/query.py:635: DoesNotExist
authentik.providers.scim.tests.test_user.SCIMUserTests::test_user_create_conflict_standard_resources_key
Stack Traces | 0.562s run time
self = <unittest.case._Outcome object at 0x71ed62140130>
test_case = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>
subTest = False

    @contextlib.contextmanager
    def testPartExecutor(self, test_case, subTest=False):
        old_success = self.success
        self.success = True
        try:
>           yield

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/case.py:58: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>
result = <TestCaseFunction test_user_create_conflict_standard_resources_key>

    def run(self, result=None):
        if result is None:
            result = self.defaultTestResult()
            startTestRun = getattr(result, 'startTestRun', None)
            stopTestRun = getattr(result, 'stopTestRun', None)
            if startTestRun is not None:
                startTestRun()
        else:
            stopTestRun = None
    
        result.startTest(self)
        try:
            testMethod = getattr(self, self._testMethodName)
            if (getattr(self.__class__, "__unittest_skip__", False) or
                getattr(testMethod, "__unittest_skip__", False)):
                # If the class or method was skipped.
                skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
                            or getattr(testMethod, '__unittest_skip_why__', ''))
                _addSkip(result, self, skip_why)
                return result
    
            expecting_failure = (
                getattr(self, "__unittest_expecting_failure__", False) or
                getattr(testMethod, "__unittest_expecting_failure__", False)
            )
            outcome = _Outcome(result)
            start_time = time.perf_counter()
            try:
                self._outcome = outcome
    
                with outcome.testPartExecutor(self):
                    self._callSetUp()
                if outcome.success:
                    outcome.expecting_failure = expecting_failure
                    with outcome.testPartExecutor(self):
>                       self._callTestMethod(testMethod)

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/case.py:669: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>
method = <bound method SCIMUserTests.test_user_create_conflict_standard_resources_key of <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>>

    def _callTestMethod(self, method):
>       result = method()
                 ^^^^^^^^

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/case.py:615: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>,)
keywargs = {}
newargs = (<authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>,)
newkeywargs = {}

    @wraps(func)
    def patched(*args, **keywargs):
        with self.decoration_helper(patched,
                                    args,
                                    keywargs) as (newargs, newkeywargs):
>           return func(*newargs, **newkeywargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../hostedtoolcache/Python/3.14.10............/x64/lib/python3.14/unittest/mock.py:1439: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = [<authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>, <requests_mock.mocker.Mocker object at 0x71ed5e1baf50>]
kwargs = {}, m = <requests_mock.mocker.Mocker object at 0x71ed5e1baf50>

    @functools.wraps(func)
    def inner(*args, **kwargs):
        with self.copy() as m:
            if self._kw:
                kwargs[self._kw] = m
            else:
                args = list(args)
                args.append(m)
    
>           return func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^

.venv/lib/python3.14.../site-packages/requests_mock/mocker.py:317: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>
mock = <requests_mock.mocker.Mocker object at 0x71ed5e1baf50>

    @Mocker()
    def test_user_create_conflict_standard_resources_key(self, mock: Mocker):
        """An existing user is adopted from a standard-cased list response"""
>       self._test_user_create_conflict(mock, "Resources")

.../scim/tests/test_user.py:132: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <authentik.providers.scim.tests.test_user.SCIMUserTests testMethod=test_user_create_conflict_standard_resources_key>
mock = <requests_mock.mocker.Mocker object at 0x71ed5e1baf50>
resources_key = 'Resources'

    def _test_user_create_conflict(self, mock: Mocker, resources_key: str):
        mock.get(
            "https:.../localhost/ServiceProviderConfig",
            json={
                "authenticationSchemes": [],
                "patch": {"supported": False},
                "bulk": {"supported": False},
                "filter": {"supported": True},
                "changePassword": {"supported": False},
                "sort": {"supported": False},
                "etag": {"supported": False},
            },
        )
        mock.post("https:.../localhost/Users", status_code=409)
        scim_id = generate_id()
        uid = generate_id()
        remote_user = {
            "id": scim_id,
            "userName": uid,
            "displayName": "Remote display name",
        }
        mock.get("https:.../localhost/Users", json={resources_key: [remote_user]})
    
        user = User.objects.create(username=uid, name=uid, email=f"{uid}@goauthentik.io")
    
>       connection = SCIMProviderUser.objects.get(provider=self.provider, user=user)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../scim/tests/test_user.py:122: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <django.db.models.manager.Manager object at 0x71ed713342d0>, args = ()
kwargs = {'provider': <SCIMProvider: SCIM Provider 0QYz6ecD6gzb4M04PoUadOkZEMMydIWxuIksGjxF>, 'user': <User: nTxVllVXaqIyCONQ2WGegXYEI1BWHUd2bHAGPRW5>}

    @wraps(method)
    def manager_method(self, *args, **kwargs):
>       return getattr(self.get_queryset(), name)(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.venv/lib/python3.14.../db/models/manager.py:87: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <QuerySet []>, args = ()
kwargs = {'provider': <SCIMProvider: SCIM Provider 0QYz6ecD6gzb4M04PoUadOkZEMMydIWxuIksGjxF>, 'user': <User: nTxVllVXaqIyCONQ2WGegXYEI1BWHUd2bHAGPRW5>}
clone = <QuerySet []>, limit = 21, num = 0

    def get(self, *args, **kwargs):
        """
        Perform the query and return a single object matching the given
        keyword arguments.
        """
        if self.query.combinator and (args or kwargs):
            raise NotSupportedError(
                "Calling QuerySet.get(...) with filters after %s() is not "
                "supported." % self.query.combinator
            )
        clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
        if self.query.can_filter() and not self.query.distinct_fields:
            clone = clone.order_by()
        limit = None
        if (
            not clone.query.select_for_update
            or connections[clone.db].features.supports_select_for_update_with_limit
        ):
            limit = MAX_GET_RESULTS
            clone.query.set_limits(high=limit)
        num = len(clone)
        if num == 1:
            return clone._result_cache[0]
        if not num:
>           raise self.model.DoesNotExist(
                "%s matching query does not exist." % self.model._meta.object_name
            )
E           authentik.providers.scim.models.SCIMProviderUser.DoesNotExist: SCIMProviderUser matching query does not exist.

.venv/lib/python3.14.../db/models/query.py:635: DoesNotExist

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@dewi-tik
dewi-tik enabled auto-merge (squash) September 14, 2026 17:21
fix scim user conflict resolution

Co-authored-by: Jens L. <[email protected]>
@GirlBossRush
GirlBossRush force-pushed the cherry-pick/25998-to-version-2026.5 branch from e2ad8e2 to f043413 Compare November 28, 2026 19:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants