wip: group inquiries and booking

This commit is contained in:
Björn Fromme committed 2026-07-16 09:03:42 +02:00
1 parent 1e59d38eb4
commit 12760844e2
34 files changed
+1810 -436

No files matched your search

@@ -8,6 +8,8 @@ use App\Entity\Groups\AccommodationBooking;
use App\Service\AccommodationBookingLinkSigner;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class AccommodationBookingLinkSignerTest extends TestCase
@@ -94,6 +96,77 @@ class AccommodationBookingLinkSignerTest extends TestCase
self::assertSame('2026-04-01T00:00:00+00:00', $signer->expiresAt($booking)?->format(\DATE_ATOM));
}
public function testSessionIsAuthorizedAfterAuthorizeSession(): void
{
$booking = $this->bookingWithAccessLink();
$signer = $this->createSigner();
$request = $this->requestWithSession();
self::assertFalse($signer->isSessionAuthorized($request, $booking));
$signer->authorizeSession($request, $booking);
self::assertTrue($signer->isSessionAuthorized($request, $booking));
}
public function testSessionAuthorizationIsPerBooking(): void
{
$booking = $this->bookingWithAccessLink();
$otherBooking = $this->bookingWithAccessLink();
$signer = $this->createSigner();
$request = $this->requestWithSession();
$signer->authorizeSession($request, $booking);
self::assertTrue($signer->isSessionAuthorized($request, $booking));
self::assertFalse($signer->isSessionAuthorized($request, $otherBooking));
}
public function testSessionAuthorizationIsRevokedWhenLinkIsRegenerated(): void
{
$booking = $this->bookingWithAccessLink();
$signer = $this->createSigner();
$request = $this->requestWithSession();
$signer->authorizeSession($request, $booking);
self::assertTrue($signer->isSessionAuthorized($request, $booking));
// Regenerating the access link overwrites accessLinkIssuedAt — the
// previously-authorized session no longer matches.
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable('+1 minute'));
self::assertFalse($signer->isSessionAuthorized($request, $booking));
}
public function testSessionAuthorizationFailsPastTtlEvenIfSessionMatches(): void
{
$booking = new AccommodationBooking();
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable('-91 days'));
$signer = $this->createSigner();
$request = $this->requestWithSession();
$signer->authorizeSession($request, $booking);
self::assertFalse($signer->isSessionAuthorized($request, $booking));
}
public function testSessionAuthorizationFailsWithoutAccessLinkIssuedAt(): void
{
$booking = new AccommodationBooking();
$signer = $this->createSigner();
$request = $this->requestWithSession();
self::assertFalse($signer->isSessionAuthorized($request, $booking));
}
private function requestWithSession(): Request
{
$request = Request::create('https://example.com/');
$request->setSession(new Session(new MockArraySessionStorage()));
return $request;
}
private function bookingWithAccessLink(): AccommodationBooking
{
$booking = new AccommodationBooking();