Page MenuHomePhorge

D1678.1775348025.diff
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

D1678.1775348025.diff

diff --git a/src/app/Backends/LDAP.php b/src/app/Backends/LDAP.php
--- a/src/app/Backends/LDAP.php
+++ b/src/app/Backends/LDAP.php
@@ -230,7 +230,11 @@
'nsroledn' => []
];
- if (!self::getUserEntry($ldap, $user->email, $dn) && $dn) {
+ if (!self::getUserEntry($ldap, $user->email, $dn)) {
+ if (empty($dn)) {
+ self::throwException($ldap, "Failed to create user {$user->email} in LDAP");
+ }
+
self::setUserAttributes($user, $entry);
$result = $ldap->add_entry($dn, $entry);
diff --git a/src/tests/Feature/Backends/LDAPTest.php b/src/tests/Feature/Backends/LDAPTest.php
--- a/src/tests/Feature/Backends/LDAPTest.php
+++ b/src/tests/Feature/Backends/LDAPTest.php
@@ -221,6 +221,24 @@
$this->assertSame(null, LDAP::getUser($user->email));
}
+ /**
+ * Test handling errors on user creation
+ *
+ * @group ldap
+ */
+ public function testCreateUserException(): void
+ {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessageMatches('/Failed to create user/');
+
+ $user = new User([
+ 'email' => 'test-non-existing-ldap@non-existing.org',
+ 'status' => User::STATUS_ACTIVE,
+ ]);
+
+ LDAP::createUser($user);
+ }
+
/**
* Test handling update of a non-existing domain
*

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 5, 12:13 AM (18 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831674
Default Alt Text
D1678.1775348025.diff (1 KB)

Event Timeline