diff --git a/src/test/php/de/thekid/cas/unittest/LoginTest.php b/src/test/php/de/thekid/cas/unittest/LoginTest.php index 280d5d7..fb7abd7 100755 --- a/src/test/php/de/thekid/cas/unittest/LoginTest.php +++ b/src/test/php/de/thekid/cas/unittest/LoginTest.php @@ -12,18 +12,18 @@ class LoginTest extends HandlerTest { public const SERVICE = 'https://example.org/'; - private $templates, $signed, $flow; + private $persistence, $templates, $signed, $flow; #[Before] public function initialize() { - $this->tickets= new TestingTickets(); + $this->persistence= new TestingPersistence(users: new TestingUsers(['root' => 'secret'])); $this->signed= new Signed('secret'); $this->flow= new Flow([ new UseService(new class() implements Services { public fn validate($url) => LoginTest::SERVICE === $url; }), - new EnterCredentials(new TestingUsers(['root' => 'secret'])), - new RedirectToService($this->tickets, $this->signed), + new EnterCredentials($this->persistence), + new RedirectToService($this->persistence, $this->signed), new DisplaySuccess(), ]); } @@ -201,10 +201,10 @@ public function issues_ticket_and_redirect_to_service() { 'attributes' => null, ], ], - $this->tickets->validate(0), + $this->persistence->tickets()->validate(0), ); Assert::equals( - self::SERVICE.'?ticket='.$this->signed->id(0, $this->tickets->prefix()), + self::SERVICE.'?ticket='.$this->signed->id(0, $this->persistence->tickets()->prefix()), $res->headers()['Location'] ); } @@ -229,10 +229,10 @@ public function issues_ticket_and_redirect_to_service_directly_when_user_in_sess 'attributes' => null, ], ], - $this->tickets->validate(1), + $this->persistence->tickets()->validate(1), ); Assert::equals( - self::SERVICE.'?ticket='.$this->signed->id(1, $this->tickets->prefix()), + self::SERVICE.'?ticket='.$this->signed->id(1, $this->persistence->tickets()->prefix()), $res->headers()['Location'] ); } diff --git a/src/test/php/de/thekid/cas/unittest/TestingPersistence.php b/src/test/php/de/thekid/cas/unittest/TestingPersistence.php new file mode 100755 index 0000000..df66758 --- /dev/null +++ b/src/test/php/de/thekid/cas/unittest/TestingPersistence.php @@ -0,0 +1,19 @@ + $this->users; + + /* Tickets accessor */ + public fn tickets(): Tickets => $this->tickets; +} \ No newline at end of file diff --git a/src/test/php/de/thekid/cas/unittest/ValidateTest.php b/src/test/php/de/thekid/cas/unittest/ValidateTest.php index 9485b9c..1f3934a 100755 --- a/src/test/php/de/thekid/cas/unittest/ValidateTest.php +++ b/src/test/php/de/thekid/cas/unittest/ValidateTest.php @@ -7,11 +7,11 @@ use web\{Request, Response}; class ValidateTest { - private $tickets, $signed; + private $persistence, $signed; #[Before] public function initialize() { - $this->tickets= new TestingTickets(); + $this->persistence= new TestingPersistence(); $this->signed= new Signed('testing-secret'); } @@ -33,7 +33,7 @@ private function assertResponse($expected, $actual) { * @return string */ private function handle($uri) { - $fixture= new Validate($this->tickets, $this->signed); + $fixture= new Validate($this->persistence, $this->signed); $req= new Request(new TestInput('GET', $uri)); $res= new Response(TestOutput::buffered()); @@ -44,14 +44,15 @@ private function handle($uri) { #[Test] public function can_create() { - new Validate($this->tickets, $this->signed); + new Validate($this->persistence, $this->signed); } #[Test] public function validation_success() { + $tickets= $this->persistence->tickets(); $ticket= $this->signed->id( - $this->tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), - $this->tickets->prefix(), + $tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), + $tickets->prefix(), ); $this->assertResponse( ' @@ -113,7 +114,7 @@ public function invalid_ticket_parameter() { #[Test] public function missing_ticket() { - $ticket= $this->signed->id(1, $this->tickets->prefix()); + $ticket= $this->signed->id(1, $this->persistence->tickets()->prefix()); $response= sprintf(' @@ -127,9 +128,10 @@ public function missing_ticket() { #[Test] public function invalid_service() { + $tickets= $this->persistence->tickets(); $ticket= $this->signed->id( - $this->tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), - $this->tickets->prefix(), + $tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), + $tickets->prefix(), ); $this->assertResponse( ' @@ -143,9 +145,10 @@ public function invalid_service() { #[Test] public function success_using_explicit_xml_format() { + $tickets= $this->persistence->tickets(); $ticket= $this->signed->id( - $this->tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), - $this->tickets->prefix(), + $tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), + $tickets->prefix(), ); $this->assertResponse( ' @@ -159,9 +162,10 @@ public function success_using_explicit_xml_format() { #[Test] public function success_using_json_format() { + $tickets= $this->persistence->tickets(); $ticket= $this->signed->id( - $this->tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), - $this->tickets->prefix(), + $tickets->create(['user' => ['username' => 'test'], 'service' => 'http://example.org']), + $tickets->prefix(), ); $this->assertResponse( '{