Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Backends/LDAPTest.php
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | class LDAPTest extends TestCase | ||||
public function testGroup(): void | public function testGroup(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$root_dn = \config('ldap.hosted.root_dn'); | $root_dn = \config('ldap.hosted.root_dn'); | ||||
$group = $this->getTestGroup('group@kolab.org', [ | $group = $this->getTestGroup('group@kolab.org', [ | ||||
'members' => ['member1@testldap.com', 'member2@testldap.com'] | 'members' => ['member1@testldap.com', 'member2@testldap.com'] | ||||
]); | ]); | ||||
$group->setSetting('sender_policy', '["test.com"]'); | |||||
// Create the group | // Create the group | ||||
LDAP::createGroup($group); | LDAP::createGroup($group); | ||||
$ldap_group = LDAP::getGroup($group->email); | $ldap_group = LDAP::getGroup($group->email); | ||||
$expected = [ | $expected = [ | ||||
'cn' => 'group', | 'cn' => 'group', | ||||
'dn' => 'cn=group,ou=Groups,ou=kolab.org,' . $root_dn, | 'dn' => 'cn=group,ou=Groups,ou=kolab.org,' . $root_dn, | ||||
'mail' => $group->email, | 'mail' => $group->email, | ||||
'objectclass' => [ | 'objectclass' => [ | ||||
'top', | 'top', | ||||
'groupofuniquenames', | 'groupofuniquenames', | ||||
'kolabgroupofuniquenames' | 'kolabgroupofuniquenames' | ||||
], | ], | ||||
'kolaballowsmtpsender' => 'test.com', | |||||
'uniquemember' => [ | 'uniquemember' => [ | ||||
'uid=member1@testldap.com,ou=People,ou=kolab.org,' . $root_dn, | 'uid=member1@testldap.com,ou=People,ou=kolab.org,' . $root_dn, | ||||
'uid=member2@testldap.com,ou=People,ou=kolab.org,' . $root_dn, | 'uid=member2@testldap.com,ou=People,ou=kolab.org,' . $root_dn, | ||||
], | ], | ||||
]; | ]; | ||||
foreach ($expected as $attr => $value) { | foreach ($expected as $attr => $value) { | ||||
$this->assertEquals($value, isset($ldap_group[$attr]) ? $ldap_group[$attr] : null, "Group $attr attribute"); | $this->assertEquals($value, isset($ldap_group[$attr]) ? $ldap_group[$attr] : null, "Group $attr attribute"); | ||||
} | } | ||||
// Update members | // Update members | ||||
$group->members = ['member3@testldap.com']; | $group->members = ['member3@testldap.com']; | ||||
$group->save(); | $group->save(); | ||||
$group->setSetting('sender_policy', '["test.com","-"]'); | |||||
LDAP::updateGroup($group); | LDAP::updateGroup($group); | ||||
// TODO: Should we force this to be always an array? | // TODO: Should we force this to be always an array? | ||||
$expected['uniquemember'] = 'uid=member3@testldap.com,ou=People,ou=kolab.org,' . $root_dn; | $expected['uniquemember'] = 'uid=member3@testldap.com,ou=People,ou=kolab.org,' . $root_dn; | ||||
$expected['kolaballowsmtpsender'] = ['test.com', '-']; | |||||
$ldap_group = LDAP::getGroup($group->email); | $ldap_group = LDAP::getGroup($group->email); | ||||
foreach ($expected as $attr => $value) { | foreach ($expected as $attr => $value) { | ||||
$this->assertEquals($value, isset($ldap_group[$attr]) ? $ldap_group[$attr] : null, "Group $attr attribute"); | $this->assertEquals($value, isset($ldap_group[$attr]) ? $ldap_group[$attr] : null, "Group $attr attribute"); | ||||
} | } | ||||
$this->assertSame(['member3@testldap.com'], $group->fresh()->members); | $this->assertSame(['member3@testldap.com'], $group->fresh()->members); | ||||
// Update members (add non-existing local member, expect it to be aot-removed from the group) | // Update members (add non-existing local member, expect it to be aot-removed from the group) | ||||
$group->members = ['member3@testldap.com', 'member-local@kolab.org']; | $group->members = ['member3@testldap.com', 'member-local@kolab.org']; | ||||
$group->save(); | $group->save(); | ||||
$group->setSetting('sender_policy', null); | |||||
LDAP::updateGroup($group); | LDAP::updateGroup($group); | ||||
// TODO: Should we force this to be always an array? | // TODO: Should we force this to be always an array? | ||||
$expected['uniquemember'] = 'uid=member3@testldap.com,ou=People,ou=kolab.org,' . $root_dn; | $expected['uniquemember'] = 'uid=member3@testldap.com,ou=People,ou=kolab.org,' . $root_dn; | ||||
$expected['kolaballowsmtpsender'] = null; | |||||
$ldap_group = LDAP::getGroup($group->email); | $ldap_group = LDAP::getGroup($group->email); | ||||
foreach ($expected as $attr => $value) { | foreach ($expected as $attr => $value) { | ||||
$this->assertEquals($value, isset($ldap_group[$attr]) ? $ldap_group[$attr] : null, "Group $attr attribute"); | $this->assertEquals($value, isset($ldap_group[$attr]) ? $ldap_group[$attr] : null, "Group $attr attribute"); | ||||
} | } | ||||
$this->assertSame(['member3@testldap.com'], $group->fresh()->members); | $this->assertSame(['member3@testldap.com'], $group->fresh()->members); | ||||
// We called save() twice, so we expect two update obs, this is making sure | // We called save() twice, and setSettings() three times, | ||||
// that there's no job executed by the LDAP backend | // this is making sure that there's no job executed by the LDAP backend | ||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 2); | Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 5); | ||||
// Delete the domain | // Delete the domain | ||||
LDAP::deleteGroup($group); | LDAP::deleteGroup($group); | ||||
$this->assertSame(null, LDAP::getGroup($group->email)); | $this->assertSame(null, LDAP::getGroup($group->email)); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | public function testUpdateDomainException(): void | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
'status' => Domain::STATUS_NEW | Domain::STATUS_ACTIVE, | 'status' => Domain::STATUS_NEW | Domain::STATUS_ACTIVE, | ||||
]); | ]); | ||||
LDAP::updateDomain($domain); | LDAP::updateDomain($domain); | ||||
} | } | ||||
/** | /** | ||||
* Test handling update of a non-existing group | |||||
* | |||||
* @group ldap | |||||
*/ | |||||
public function testUpdateGroupException(): void | |||||
{ | |||||
$this->expectException(\Exception::class); | |||||
$this->expectExceptionMessageMatches('/group not found/'); | |||||
$group = new Group([ | |||||
'email' => 'test@testldap.com', | |||||
'status' => Group::STATUS_NEW | Group::STATUS_ACTIVE, | |||||
]); | |||||
LDAP::updateGroup($group); | |||||
} | |||||
/** | |||||
* Test handling update of a non-existing user | * Test handling update of a non-existing user | ||||
* | * | ||||
* @group ldap | * @group ldap | ||||
*/ | */ | ||||
public function testUpdateUserException(): void | public function testUpdateUserException(): void | ||||
{ | { | ||||
$this->expectException(\Exception::class); | $this->expectException(\Exception::class); | ||||
$this->expectExceptionMessageMatches('/user not found/'); | $this->expectExceptionMessageMatches('/user not found/'); | ||||
Show All 9 Lines |