Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
43 lines
1.8 KiB
PHP
43 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Identity;
|
|
|
|
use App\Identity\IdentityException;
|
|
use App\Identity\IdentitySync;
|
|
use App\Models\IdentityProvider;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class EmailLinkingTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private function provider(string $type, array $config = []): IdentityProvider
|
|
{
|
|
return IdentityProvider::query()->create(['type' => $type, 'name' => ucfirst($type), 'slug' => $type, 'enabled' => true, 'config' => ['link_by_email' => true, ...$config]]);
|
|
}
|
|
|
|
public function test_privileged_accounts_are_not_linked_by_an_unverified_address(): void
|
|
{
|
|
$admin = User::factory()->admin()->create(['email' => 'chef@firma.de']);
|
|
|
|
$this->expectException(IdentityException::class);
|
|
app(IdentitySync::class)->resolveUser($this->provider('ldap'), 'uid=eve', ['email' => 'chef@firma.de'], true);
|
|
}
|
|
|
|
public function test_accounts_without_password_and_rights_still_link(): void
|
|
{
|
|
$user = User::factory()->create(['email' => 'anna@firma.de', 'password' => null]);
|
|
|
|
$this->assertTrue(app(IdentitySync::class)->resolveUser($this->provider('saml'), 'anna', ['email' => 'anna@firma.de'], true)->is($user));
|
|
}
|
|
|
|
public function test_verified_or_trusted_addresses_link_privileged_accounts(): void
|
|
{
|
|
$admin = User::factory()->admin()->create(['email' => 'chef@firma.de']);
|
|
|
|
$this->assertTrue(app(IdentitySync::class)->resolveUser($this->provider('oidc'), 'sub-1', ['email' => 'chef@firma.de', 'email_verified' => true], true)->is($admin));
|
|
$this->assertTrue(app(IdentitySync::class)->resolveUser($this->provider('ldap', ['trust_email' => true]), 'uid=chef', ['email' => 'chef@firma.de'], true)->is($admin));
|
|
}
|
|
}
|