Files
ad_testbed/docs/ad-sync-testing.md

7.8 KiB

Active Directory sync test plan

Run the same scenarios independently against Samba AD and Microsoft AD DS. Record the application commit, directory version, date, and result for each run.

Choose the directory in .env

The application uses one LDAP connection at a time. Keep exactly one of the # Samba DC and # Microsoft AD blocks enabled. The Microsoft AD block is active in the local checkout. To switch, comment out all assignments in the active block and uncomment all assignments in the other one. The shared settings above both blocks control the connection name, logging, timeout, SASL, scheduled sync, and the local administrator.

  • Samba DC uses the local Docker LDAPS mapping on port 1636. The LDAPS host must match the certificate. Set the CA path to the Samba CA and confirm that the bind account can read the sync OU.
  • Microsoft AD uses the domain controller's DNS hostname on port 636. Set the CA path to the PEM that establishes trust in that controller and use a read-only bind account.
  • Both blocks use LDAP_TLS=true and LDAP_STARTTLS=false for LDAPS. LDAP_BASE_DN identifies the directory naming context. AD_SYNC_BASE_DN limits synchronization to the selected OU. Keep the bind password in the environment and keep it out of shared docs and logs.

After switching, run php artisan config:clear and confirm the connection and search scope with php artisan ad:sync --email --dry-run. The command records audit history. Restart any long-running application processes that retain the previous configuration.

What the module does

  • Reads paged LDAP snapshots, normalizes binary objectGUID values, and uses the userAccountControl disable bit. Incomplete snapshots and overlapping runs are rejected.
  • Matches and updates users by their directory GUID within the configured scope. With --email, it can link an existing Laravel user by email. Creating a missing Laravel user requires --create-missing.
  • Blocks sign-in and existing sessions for disabled managed users and supports reactivation when the directory account is enabled again. Missing-user deactivation requires explicit approval and is bounded. The local administrator can preview and apply the reviewed changes from the sync status screen.
  • Provides dry runs, audit history, and console diagnostics. --debug displays normalized sync data and -dd displays selected LDAP properties. Scheduled runs can be enabled at ten-minute intervals.
  • Owns all three feature test files under Modules/ActiveDirectory/Tests/Feature. PHPUnit includes the directory in its Feature suite, and Pest applies the shared Laravel test case and database refresh. The move preserved all test contents.

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:

vendor/bin/pest --testsuite=Feature --filter 'ActiveDirectoryModuleTest|DirectorySyncTest|DirectorySyncAdminTest'
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:

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:

$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.

Checkout verification on 12 November 2026

Laravel's dotenv parser confirmed that reorganizing the file preserved the effective application settings. The Samba profile also parsed with all required LDAP fields. The obsolete AD_HOST, AD_PORT, AD_BASE_DN, AD_USERNAME, AD_PASSWORD, AD_USE_SSL, AD_USE_TLS, and LDAP_SSL keys were removed because the current LDAP configuration uses the profile keys above.

Suite Passed Assertions
Active Directory feature tests 33 219
Full Pest suite 72 314

Both suites exited with status 0. The automated checks cover the shared sync behavior. This run did not contact either domain controller. Use the live checklist above to verify each directory's certificate, bind, scope, and account lifecycle.