Closed Jacobs63 closed 2 months ago
Hi @Jacobs63,
This can't be done with an Active Directory server. Active Directory does not allow you to retrieve the unicodepwd
attribute. The directory emulator is working as intended as to replicate this behaviour 👍
Got it, thank you 💯
No problem! If you're looking to test a set or change password operation against the emulated server, you can use the LdapFake
utility.
Here's how this is done in the core LdapRecord package:
use LdapRecord\Testing\LdapFake;
use LdapRecord\Testing\DirectoryFake;
use LdapRecord\Models\ActiveDirectory\User;
use LdapRecord\Models\Attributes\AccountControl;
public function test_create_user_with_password()
{
DirectoryFake::setup()
->getLdapConnection()
->expect([
LdapFake::operation('isUsingSSL')->once()->andReturnTrue(),
LdapFake::operation('add')->once()->with(fn ($dn) => true, fn ($attributes) => (
$attributes['unicodepwd'] === [Password::encode('foobar')]
&& $attributes['useraccountcontrol'] = 512
))->andReturnTrue(),
]);
$user = new User();
$user->password = 'foobar';
$user->userAccountControl = 512;
$user->save();
}
That's great to know, will do so, appreciate your help :)
Environment:
Describe the bug: When running the
DirectoryEmulator
and updating user's password, theunicodewd
is not updated on the user. I'm not entirely sure, whether this is intended or not - manually callingrefresh
fixes this issue and assertions are then correct.Test case:
User model: