Files
ad_testbed/tests/Feature/ActiveDirectoryModuleTest.php
T

36 lines
1.7 KiB
PHP

<?php
use App\Models\User;
use Modules\ActiveDirectory\Constants\AccountControl;
use Modules\ActiveDirectory\Services\ActiveDirectory;
it('does not import missing directory accounts by default', function () {
$this->mock(ActiveDirectory::class)->shouldReceive('users')->once()->andReturn([
['guid' => '00112233-4455-6677-8899-aabbccddeeff', 'email' => '[email protected]', 'name' => 'Missing', 'enabled' => true],
]);
$this->artisan('ad:sync --email')->assertSuccessful();
expect(User::count())->toBe(0);
});
it('matches an existing Laravel user by email without creating a new user', function () {
$user = User::factory()->create(['email' => '[email protected]']);
$this->mock(ActiveDirectory::class)->shouldReceive('users')->once()->andReturn([
['guid' => '00112233-4455-6677-8899-aabbccddeeff', 'email' => '[email protected]', 'name' => 'Existing', 'enabled' => false],
]);
$this->artisan('ad:sync --email')->assertSuccessful();
expect(User::count())->toBe(1)
->and($user->refresh()->ad_guid)->toBe('00112233-4455-6677-8899-aabbccddeeff')
->and($user->ad_disabled_at)->not->toBeNull();
});
it('decodes Microsoft and Samba user account control bitmasks', function () {
$flags = AccountControl::flags(AccountControl::NORMAL_ACCOUNT | AccountControl::ACCOUNTDISABLE | AccountControl::DONT_EXPIRE_PASSWORD);
expect($flags)->toContain('NORMAL_ACCOUNT', 'ACCOUNTDISABLE', 'DONT_EXPIRE_PASSWORD')
->not->toContain('LOCKOUT');
});
it('exposes the ActiveDirectory module and its sync command', function () {
expect(file_exists(base_path('Modules/ActiveDirectory/module.json')))->toBeTrue();
$this->artisan('list')->assertSuccessful();
});