@@ -309,6 +309,47 @@ public function users_without_a_guid_are_synchronized_properly()
309309 $ this ->assertEquals (1 , EloquentUser::count ());
310310 }
311311
312+ /** @test */
313+ public function users_without_a_guid_and_a_changed_username_have_new_record_created ()
314+ {
315+ // Create an existing synchronized user.
316+ EloquentUser::create ([
317+ 318+ 'name ' => 'John Doe ' ,
319+ 'password ' => Hash::make ('Password123 ' ),
320+ ]);
321+
322+ $ credentials = [
323+ 324+ 'password ' => 'Password123 ' ,
325+ ];
326+
327+ // Generate an LDAP user with a changed UPN and Mail.
328+ $ ldapUser = $ this ->makeLdapUser ([
329+ 'objectguid ' => ['cc07cacc-5d9d-fa40-a9fb-3a4d50a172b0 ' ],
330+ 'samaccountname ' => ['jdoe ' ],
331+ 'userprincipalname ' => [
'[email protected] ' ],
332+ 333+ 'cn ' => ['John Doe ' ],
334+ ]);
335+
336+ Resolver::shouldReceive ('byCredentials ' )->once ()->andReturn ($ ldapUser )
337+ ->shouldReceive ('getDatabaseIdColumn ' )->andReturn ('objectguid ' )
338+ ->shouldReceive ('getDatabaseUsernameColumn ' )->andReturn ('email ' )
339+ ->shouldReceive ('getLdapDiscoveryAttribute ' )->andReturn ('userprincipalname ' )
340+ ->shouldReceive ('byModel ' )->once ()->andReturn ($ ldapUser )
341+ ->shouldReceive ('authenticate ' )->once ()->andReturn (true );
342+
343+ $ this ->assertTrue (Auth::attempt ($ credentials ));
344+
345+ $ user = Auth::user ();
346+
347+ $ this ->assertInstanceOf ('Adldap\Laravel\Tests\Models\TestUser ' , $ user );
348+ $ this ->assertEquals ($ user ->objectguid , $ ldapUser ->getConvertedGuid ());
349+ $ this ->
assertEquals (
'[email protected] ' ,
$ user->
email );
350+ $ this ->assertEquals (2 , EloquentUser::count ());
351+ }
352+
312353 /** @test */
313354 public function passwords_are_not_updated_when_sync_is_disabled ()
314355 {
0 commit comments