sources/ldap: fix parent_group not being applied

closes #2464

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-03-14 22:11:26 +01:00
parent dcaa8d6322
commit a3df414f24
4 changed files with 18 additions and 11 deletions

View File

@ -37,6 +37,7 @@ class GroupLDAPSynchronizer(BaseLDAPSynchronizer):
uniq = self._flatten(attributes[self._source.object_uniqueness_field])
try:
defaults = self.build_group_properties(group_dn, **attributes)
defaults["parent"] = self._source.sync_parent_group
self._logger.debug("Creating group with attributes", **defaults)
if "name" not in defaults:
raise IntegrityError("Name was not set by propertymappings")
@ -47,7 +48,6 @@ class GroupLDAPSynchronizer(BaseLDAPSynchronizer):
Group,
{
f"attributes__{LDAP_UNIQUENESS}": uniq,
"parent": self._source.sync_parent_group,
},
defaults,
)

View File

@ -5,6 +5,7 @@ from django.db.models import Q
from django.test import TestCase
from authentik.core.models import Group, User
from authentik.core.tests.utils import create_test_admin_user
from authentik.events.models import Event, EventAction
from authentik.lib.generators import generate_key
from authentik.managed.manager import ObjectManager
@ -24,7 +25,7 @@ class LDAPSyncTests(TestCase):
def setUp(self):
ObjectManager().run()
self.source = LDAPSource.objects.create(
self.source: LDAPSource = LDAPSource.objects.create(
name="ldap",
slug="ldap",
base_dn="dc=goauthentik,dc=io",
@ -120,6 +121,9 @@ class LDAPSyncTests(TestCase):
self.source.property_mappings_group.set(
LDAPPropertyMapping.objects.filter(managed="goauthentik.io/sources/ldap/default-name")
)
_user = create_test_admin_user()
parent_group = Group.objects.get(name=_user.username)
self.source.sync_parent_group = parent_group
connection = PropertyMock(return_value=mock_ad_connection(LDAP_PASSWORD))
with patch("authentik.sources.ldap.models.LDAPSource.connection", connection):
self.source.save()
@ -127,8 +131,9 @@ class LDAPSyncTests(TestCase):
group_sync.sync()
membership_sync = MembershipLDAPSynchronizer(self.source)
membership_sync.sync()
group = Group.objects.filter(name="test-group")
self.assertTrue(group.exists())
group: Group = Group.objects.filter(name="test-group").first()
self.assertIsNotNone(group)
self.assertEqual(group.parent, parent_group)
def test_sync_groups_openldap(self):
"""Test group sync"""

View File

@ -165,9 +165,9 @@ export class LibraryPage extends LitElement {
<section class="pf-c-page__main-section">
${loading(
this.apps,
html`${((this.apps?.results || []).filter((app) => {
html`${(this.apps?.results || []).filter((app) => {
return app.launchUrl !== null;
})).length > 0
}).length > 0
? this.renderApps(config)
: this.renderEmptyState()}`,
)}

View File

@ -101,11 +101,13 @@ export class UserSettingsFlowExecutor extends LitElement implements StageHost {
if (!this.flowSlug) {
return;
}
new FlowsApi(DEFAULT_CONFIG).flowsInstancesExecuteRetrieve({
new FlowsApi(DEFAULT_CONFIG)
.flowsInstancesExecuteRetrieve({
slug: this.flowSlug || "",
}).then(() => {
this.nextChallenge();
})
.then(() => {
this.nextChallenge();
});
});
}