mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-12 06:48:55 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support;
|
|
|
|
use App\Modules\Identity\Ldap\LdapDirectory;
|
|
use App\Modules\Identity\Ldap\LdapIdentity;
|
|
use App\Modules\Identity\Ldap\LdapProbeResult;
|
|
|
|
/**
|
|
* A directory that lives in an array.
|
|
*
|
|
* Swapped in with `$this->swap(LdapDirectory::class, ...)`, this exercises
|
|
* everything above the wire — which account types may authenticate,
|
|
* provisioning, the two-factor hand-off, rate limiting — with no server
|
|
* anywhere. It also counts calls, so a test can assert the directory was
|
|
* *not* consulted, which is how the "staff never reach LDAP" and "a valid
|
|
* local password costs no directory traffic" properties are proven.
|
|
*/
|
|
class FakeLdapDirectory implements LdapDirectory
|
|
{
|
|
public int $calls = 0;
|
|
|
|
/** @var list<string> */
|
|
public array $attemptedEmails = [];
|
|
|
|
/**
|
|
* @param array<string, array{password: string, name?: string, dn?: string}> $entries keyed by email
|
|
*/
|
|
public function __construct(private readonly array $entries = []) {}
|
|
|
|
public function authenticate(string $email, string $password): ?LdapIdentity
|
|
{
|
|
$this->calls++;
|
|
$this->attemptedEmails[] = $email;
|
|
|
|
$entry = $this->entries[$email] ?? null;
|
|
|
|
if ($entry === null || $entry['password'] !== $password) {
|
|
return null;
|
|
}
|
|
|
|
return new LdapIdentity(
|
|
dn: $entry['dn'] ?? "uid={$email},ou=people,dc=example,dc=test",
|
|
email: $email,
|
|
name: $entry['name'] ?? 'Directory Person',
|
|
);
|
|
}
|
|
|
|
public function probe(?string $email = null, ?string $password = null): LdapProbeResult
|
|
{
|
|
return LdapProbeResult::ok(LdapProbeResult::STAGE_SERVICE_BIND, 'Fake directory reachable.');
|
|
}
|
|
}
|