# Active Directory sync test plan Run the same scenarios independently against [Samba AD](samba-ad.md) and [Microsoft AD DS](microsoft-ad.md). Record the application commit, directory version, date, and result for each run. ## Test setup - Use a dedicated sync OU and a disposable Laravel database for each directory. Disable scheduled sync during manual testing. - Create two enabled AD test accounts in the OU, each with a unique `mail` value. Create a Laravel user with the same email as the first account. Leave the second account absent from Laravel. - Use the same domain controller for directory changes and LDAP reads. If different controllers are involved, confirm replication before checking the result. - Keep credentials and identifiable LDAP output out of shared test records. ## Automated checks From the project root: ```sh php artisan test tests/Feature/DirectorySyncTest.php tests/Feature/ActiveDirectoryModuleTest.php --compact php artisan test --compact vendor/bin/pint --test git diff --check ``` The suite covers LDAP paging and partial results, the shared lock, case-insensitive email collisions, audit output, directory scope, and scheduler registration. Record formatting failures separately from test failures. ## Live checks for each directory | Check | Action | Expected result | | --- | --- | --- | | LDAPS and search scope | Run `php artisan ad:sync --email --dry-run -dd`. Compare the returned DNs, GUIDs, emails and account control with the directory tools below. | Both test accounts appear with matching properties. Laravel user records remain unchanged. | | Default no-create | Run `php artisan ad:sync --email`. | The first account links to the existing Laravel user by email. The second account is absent from Laravel and the summary reports `created=0`. | | Explicit import | Preview with `php artisan ad:sync --email --create-missing --dry-run`, then repeat without `--dry-run`. | The preview reports one planned creation. The live run creates exactly one Laravel user and records its AD GUID. | | Disable | Disable the first AD account. Preview, then run `php artisan ad:sync --email`. | AD has the `ACCOUNTDISABLE` bit set. Laravel reports one deactivation, sets `ad_disabled_at` and `deleted_at`, records `directory_disabled`, and blocks login. | | Re-enable | Re-enable the first AD account and run `php artisan ad:sync --email`. | Laravel reports one reactivation, clears the disable and deletion fields, and allows the account through its login checks. | | Repeatability | Run `php artisan ad:sync --email` again. | Both users are unchanged. | | Console diagnostics | Compare a normal dry run with `-v`, `-vv`, `-vvv`, `--debug`, and `-dd`. Use a pending test-user change to exercise the per-change output. | Verbosity adds run and audit detail. `--debug` shows normalized sync accounts. `-dd` shows the selected LDAP properties. | | Paging | In a dedicated OU with more than 500 valid test accounts, count the directory users and compare with the number of `AD properties` records from a `-dd` dry run. | Counts match and no GUID is repeated. | | Scheduler | In the test environment, set `AD_SYNC_SCHEDULED=true`, reload Laravel configuration, and run `php artisan schedule:list`. Restore the original setting afterwards. | One `ad:sync` job appears on a ten-minute schedule. The automated test verifies overlap protection and the command arguments. | Dry runs still record audit history. After manual tests, restore both directory accounts to their initial states and remove only the test data you created. ## Directory commands For Samba AD: ```sh docker exec samba-ad samba-tool user show sync-test --attributes=distinguishedName,objectGUID,mail,userAccountControl docker exec samba-ad samba-tool user disable sync-test docker exec samba-ad samba-tool user enable sync-test ``` For Microsoft AD DS, run PowerShell with the Active Directory module. Replace the example hostname: ```powershell $dc = 'dc01.corp.example.net' Get-ADUser -Server $dc -Identity 'sync-test' -Properties mail,userAccountControl | Select-Object DistinguishedName,ObjectGUID,mail,Enabled,userAccountControl Disable-ADAccount -Server $dc -Identity 'sync-test' Enable-ADAccount -Server $dc -Identity 'sync-test' ``` Run the disable and enable commands at their respective steps so Laravel can observe each state. ## Results | Directory | Run date | App commit and directory version | Checks passed | Pending or failed checks | | --- | --- | --- | --- | --- | | Samba AD | | | | | | Microsoft AD DS | | | | | Previous Samba runs exercised LDAPS, diagnostics, import of a disabled user, and subsequent reactivation. A live Windows AD DS run is pending.