Skip to content

Commit

Permalink
Merge pull request #391 from DirectoryTree/laravel-9-support
Browse files Browse the repository at this point in the history
Laravel 9 support
  • Loading branch information
stevebauman authored Feb 9, 2022
2 parents 4826114 + 29d4b84 commit 6283cac
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 156 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [8.1, 8.0, 7.4, 7.3]
laravel: [8.*, 7.*, 6.*, 5.8.*]
laravel: [9.*, 8.*, 7.*, 6.*, 5.8.*]
dependency-version: [prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
Expand All @@ -26,6 +30,10 @@ jobs:
- laravel: 5.8.*
testbench: 3.8.*
exclude:
- laravel: 9.*
php: 7.4
- laravel: 9.*
php: 7.3
- laravel: 7.*
php: 8.1
- laravel: 6.*
Expand Down
19 changes: 13 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
{
"name": "directorytree/ldaprecord-laravel",
"description": "LDAP Authentication & Management for Laravel.",
"keywords": ["ldaprecord", "adldap2", "ldap", "laravel"],
"keywords": [
"ldaprecord",
"adldap2",
"ldap",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.3",
"ext-ldap": "*",
"ramsey/uuid": "*",
"directorytree/ldaprecord": "^2.4.4",
"illuminate/support": "^5.6|^6.0|^7.0|^8.0"
"illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0"
},
"require-dev": {
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~7.0|~8.0|~9.0",
"orchestra/testbench": "~3.7|~4.0|~5.0|~6.0",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.0|^8.0|^9.0",
"orchestra/testbench": "^3.7|^4.0|^5.0|^6.0|^7.0",
"spatie/ray": "^1.28"
},
"archive": {
"exclude": ["/tests"]
"exclude": [
"/tests"
]
},
"autoload": {
"psr-4": {
Expand Down
41 changes: 21 additions & 20 deletions tests/Feature/Emulator/EmulatedAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use LdapRecord\Laravel\Events\Auth\Binding;
use LdapRecord\Laravel\Events\Auth\Bound;
use LdapRecord\Laravel\Events\Auth\DiscoveredWithCredentials;
Expand All @@ -21,16 +22,7 @@ class EmulatedAuthenticationTest extends DatabaseTestCase

public function test_plain_ldap_authentication_passes()
{
$this->expectsEvents([
Binding::class,
Bound::class,
DiscoveredWithCredentials::class,
])->doesntExpectEvents([
Importing::class,
Imported::class,
Synchronizing::class,
Synchronized::class,
]);
Event::fake();

$fake = DirectoryEmulator::setup();

Expand All @@ -54,20 +46,20 @@ public function test_plain_ldap_authentication_passes()
$this->assertTrue($user->is($model));
$this->assertEquals($user->mail[0], $model->mail[0]);
$this->assertEquals($user->getDn(), $model->getDn());

Event::assertDispatched(Binding::class);
Event::assertDispatched(Bound::class);
Event::assertDispatched(DiscoveredWithCredentials::class);

Event::assertNotDispatched(Importing::class);
Event::assertNotDispatched(Imported::class);
Event::assertNotDispatched(Synchronizing::class);
Event::assertNotDispatched(Synchronized::class);
}

public function test_plain_ldap_authentication_fails()
{
$this->expectsEvents([
Binding::class,
DiscoveredWithCredentials::class,
])->doesntExpectEvents([
Bound::class,
Importing::class,
Imported::class,
Synchronizing::class,
Synchronized::class,
]);
Event::fake();

DirectoryEmulator::setup()->shouldBeConnected();

Expand All @@ -79,5 +71,14 @@ public function test_plain_ldap_authentication_fails()
]);

$this->assertFalse(Auth::attempt(['mail' => $user->mail[0], 'password' => 'secret']));

Event::assertDispatched(Binding::class);
Event::assertDispatched(DiscoveredWithCredentials::class);

Event::assertNotDispatched(Bound::class);
Event::assertNotDispatched(Importing::class);
Event::assertNotDispatched(Imported::class);
Event::assertNotDispatched(Synchronizing::class);
Event::assertNotDispatched(Synchronized::class);
}
}
79 changes: 40 additions & 39 deletions tests/Feature/Emulator/EmulatedDatabaseAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Foundation\Auth\User;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Hash;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
use LdapRecord\Laravel\Auth\HasLdapUser;
Expand All @@ -30,17 +31,7 @@ class EmulatedDatabaseAuthenticationTest extends DatabaseTestCase

public function test_database_sync_authentication_passes()
{
$this->expectsEvents([
DiscoveredWithCredentials::class,
Importing::class,
Imported::class,
Saved::class,
Synchronizing::class,
Synchronized::class,
Binding::class,
Bound::class,
Completed::class,
]);
Event::fake();

$fake = DirectoryEmulator::setup();

Expand Down Expand Up @@ -70,20 +61,21 @@ public function test_database_sync_authentication_passes()
$this->assertEquals($user->mail[0], $model->email);
$this->assertEquals($user->getConvertedGuid(), $model->guid);
$this->assertFalse(Auth::attempt(['mail' => 'invalid', 'password' => 'secret']));

Event::assertDispatched(DiscoveredWithCredentials::class);
Event::assertDispatched(Importing::class);
Event::assertDispatched(Imported::class);
Event::assertDispatched(Saved::class);
Event::assertDispatched(Synchronizing::class);
Event::assertDispatched(Synchronized::class);
Event::assertDispatched(Binding::class);
Event::assertDispatched(Bound::class);
Event::assertDispatched(Completed::class);
}

public function test_database_sync_authentication_fails()
{
$this->expectsEvents([
Binding::class,
Importing::class,
Synchronizing::class,
Synchronized::class,
DiscoveredWithCredentials::class,
])->doesntExpectEvents([
Bound::class,
Imported::class,
]);
Event::fake();

DirectoryEmulator::setup();

Expand All @@ -97,6 +89,15 @@ public function test_database_sync_authentication_fails()
]);

$this->assertFalse(Auth::attempt(['mail' => $user->mail[0], 'password' => 'secret']));

Event::assertDispatched(Binding::class);
Event::assertDispatched(Importing::class);
Event::assertDispatched(Synchronizing::class);
Event::assertDispatched(Synchronized::class);
Event::assertDispatched(DiscoveredWithCredentials::class);

Event::assertNotDispatched(Bound::class);
Event::assertNotDispatched(Imported::class);
}

public function test_database_sync_fails_without_object_guid()
Expand All @@ -120,15 +121,7 @@ public function test_database_sync_fails_without_object_guid()

public function test_database_authentication_fallback_works_when_enabled_and_exception_is_thrown()
{
$this->doesntExpectEvents([
Binding::class,
Bound::class,
DiscoveredWithCredentials::class,
Importing::class,
Imported::class,
Synchronizing::class,
Synchronized::class,
]);
Event::fake();

DirectoryEmulator::setup();

Expand Down Expand Up @@ -158,19 +151,19 @@ public function test_database_authentication_fallback_works_when_enabled_and_exc
'password' => 'secret',
],
]));

Event::assertNotDispatched(Binding::class);
Event::assertNotDispatched(Bound::class);
Event::assertNotDispatched(DiscoveredWithCredentials::class);
Event::assertNotDispatched(Importing::class);
Event::assertNotDispatched(Imported::class);
Event::assertNotDispatched(Synchronizing::class);
Event::assertNotDispatched(Synchronized::class);
}

public function test_database_authentication_fallback_works_when_enabled_and_null_is_returned()
{
$this->doesntExpectEvents([
Binding::class,
Bound::class,
DiscoveredWithCredentials::class,
Importing::class,
Imported::class,
Synchronizing::class,
Synchronized::class,
]);
Event::fake();

DirectoryEmulator::setup();

Expand Down Expand Up @@ -200,6 +193,14 @@ public function test_database_authentication_fallback_works_when_enabled_and_nul
'password' => 'secret',
],
]));

Event::assertNotDispatched(Binding::class);
Event::assertNotDispatched(Bound::class);
Event::assertNotDispatched(DiscoveredWithCredentials::class);
Event::assertNotDispatched(Importing::class);
Event::assertNotDispatched(Imported::class);
Event::assertNotDispatched(Synchronizing::class);
Event::assertNotDispatched(Synchronized::class);
}

public function test_database_authentication_fallback_is_not_performed_when_fallback_credentials_are_not_defined()
Expand Down
5 changes: 4 additions & 1 deletion tests/Feature/Emulator/EmulatedImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public function test_import_fails_when_required_attributes_are_missing()
{
User::create(['cn' => $this->faker->name]);

$this->expectsEvents(ImportFailed::class);
Event::fake();

$this->artisan('ldap:import', [
'provider' => 'ldap-database',
'--no-interaction',
])->assertExitCode(0);

Event::assertDispatched(ImportFailed::class);
}

public function test_disabled_users_are_soft_deleted_when_flag_is_set()
Expand All @@ -90,6 +92,7 @@ public function test_disabled_users_are_soft_deleted_when_flag_is_set()
])->assertExitCode(0);

$created = TestUserModelStub::withTrashed()->first();

$this->assertTrue($created->trashed());
}

Expand Down
41 changes: 21 additions & 20 deletions tests/Feature/Emulator/EmulatedWindowsAuthenticateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Event;
use LdapRecord\Laravel\Events\Auth\Binding;
use LdapRecord\Laravel\Events\Auth\Bound;
use LdapRecord\Laravel\Events\Auth\CompletedWithWindows;
Expand Down Expand Up @@ -40,16 +41,7 @@ protected function tearDown(): void

public function test_windows_authenticated_user_is_signed_in()
{
$this->expectsEvents([
Importing::class,
Imported::class,
Synchronizing::class,
Synchronized::class,
Binding::class,
Bound::class,
Saved::class,
CompletedWithWindows::class,
]);
Event::fake();

DirectoryEmulator::setup();

Expand All @@ -74,20 +66,20 @@ public function test_windows_authenticated_user_is_signed_in()
$this->assertTrue(auth()->check());
$this->assertEquals($user->getConvertedGuid(), auth()->user()->guid);
});

Event::assertDispatched(Importing::class);
Event::assertDispatched(Imported::class);
Event::assertDispatched(Synchronizing::class);
Event::assertDispatched(Synchronized::class);
Event::assertDispatched(Binding::class);
Event::assertDispatched(Bound::class);
Event::assertDispatched(Saved::class);
Event::assertDispatched(CompletedWithWindows::class);
}

public function test_kerberos_authenticated_user_is_signed_in()
{
$this->expectsEvents([
Importing::class,
Imported::class,
Synchronizing::class,
Synchronized::class,
Binding::class,
Bound::class,
Saved::class,
CompletedWithWindows::class,
]);
Event::fake();

DirectoryEmulator::setup();

Expand Down Expand Up @@ -122,5 +114,14 @@ public function test_kerberos_authenticated_user_is_signed_in()
$this->assertTrue(auth()->check());
$this->assertEquals($user->getConvertedGuid(), auth()->user()->guid);
});

Event::assertDispatched(Importing::class);
Event::assertDispatched(Imported::class);
Event::assertDispatched(Synchronizing::class);
Event::assertDispatched(Synchronized::class);
Event::assertDispatched(Binding::class);
Event::assertDispatched(Bound::class);
Event::assertDispatched(Saved::class);
Event::assertDispatched(CompletedWithWindows::class);
}
}
Loading

0 comments on commit 6283cac

Please sign in to comment.