Skip to content

Commit

Permalink
Merge pull request #556 from DirectoryTree/revert-506
Browse files Browse the repository at this point in the history
Revert #506
  • Loading branch information
stevebauman authored Mar 10, 2023
2 parents bb42c75 + fb5a980 commit f8cb5c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/Models/Concerns/HasPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,10 @@ protected function setChangedPassword($oldPassword, $newPassword, $attribute)
*/
protected function setPassword($password, $attribute)
{
$modtype = $this->exists
? LDAP_MODIFY_BATCH_REPLACE
: LDAP_MODIFY_BATCH_ADD;

$this->addModification(
$this->newBatchModification(
$attribute,
$modtype,
LDAP_MODIFY_BATCH_REPLACE,
[$password]
)
);
Expand Down
13 changes: 10 additions & 3 deletions tests/Unit/Models/ActiveDirectory/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use LdapRecord\Models\Attributes\AccountControl;
use LdapRecord\Models\Attributes\Password;
use LdapRecord\Models\Attributes\Timestamp;
use LdapRecord\Models\Concerns\HasPassword;
use LdapRecord\Models\Model;
use LdapRecord\Tests\TestCase;

Expand Down Expand Up @@ -56,7 +57,7 @@ public function test_set_password_on_new_user()

$this->assertEquals([
'attrib' => 'unicodepwd',
'modtype' => LDAP_MODIFY_BATCH_ADD,
'modtype' => LDAP_MODIFY_BATCH_REPLACE,
'values' => [Password::encode('foo')],
], $mods[0]);
}
Expand All @@ -78,15 +79,15 @@ public function test_set_password_on_existing_user()
], $mods[0]);
}

public function test_set_password_behaves_identically_on_non_user_models()
public function test_set_password_behaves_differently_on_non_user_models()
{
$user = new UserPasswordTestStub();

$user->unicodepwd = 'foo';

$nonUser = new NonUserPasswordTestStub();

$nonUser->unicodepwd = Password::encode('foo');
$nonUser->unicodepwd = 'foo';

$this->assertEquals($user->getModifications(), $nonUser->getModifications());
}
Expand Down Expand Up @@ -244,6 +245,12 @@ protected function validateSecureConnection()

class NonUserPasswordTestStub extends Model
{
use HasPassword;

protected $passwordAttribute = 'unicodepwd';

protected $passwordHashMethod = 'encode';

protected function validateSecureConnection()
{
return true;
Expand Down

0 comments on commit f8cb5c9

Please sign in to comment.