|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2026 SURFnet B.V. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +namespace OpenConext\EngineBlockBundle\Tests; |
| 20 | + |
| 21 | +use PHPUnit\Framework\Attributes\Test; |
| 22 | +use Symfony\Component\HttpFoundation\Response; |
| 23 | + |
| 24 | +final class FeedbackControllerTest extends FunctionalWebTestCase |
| 25 | +{ |
| 26 | + #[Test] |
| 27 | + public function session_lost_returns_400_with_expected_content(): void |
| 28 | + { |
| 29 | + $this->assertFeedbackPage('/authentication/feedback/session-lost', Response::HTTP_BAD_REQUEST, 'your session was lost'); |
| 30 | + } |
| 31 | + |
| 32 | + #[Test] |
| 33 | + public function session_not_started_returns_400_with_expected_content(): void |
| 34 | + { |
| 35 | + $this->assertFeedbackPage('/authentication/feedback/session-not-started', Response::HTTP_BAD_REQUEST, 'No session found'); |
| 36 | + } |
| 37 | + |
| 38 | + #[Test] |
| 39 | + public function unsolicited_response_returns_400_with_expected_content(): void |
| 40 | + { |
| 41 | + $this->assertFeedbackPage('/authentication/feedback/unsolicited-response', Response::HTTP_BAD_REQUEST, 'Sign-in could not be completed'); |
| 42 | + } |
| 43 | + |
| 44 | + #[Test] |
| 45 | + public function invalid_acs_binding_returns_400_with_expected_content(): void |
| 46 | + { |
| 47 | + $this->assertFeedbackPage('/authentication/feedback/invalid-acs-binding', Response::HTTP_BAD_REQUEST, 'Invalid ACS binding type'); |
| 48 | + } |
| 49 | + |
| 50 | + #[Test] |
| 51 | + public function received_error_status_code_returns_400_with_expected_content(): void |
| 52 | + { |
| 53 | + $this->assertFeedbackPage('/authentication/feedback/received-error-status-code', Response::HTTP_BAD_REQUEST, 'Identity Provider error'); |
| 54 | + } |
| 55 | + |
| 56 | + #[Test] |
| 57 | + public function unable_to_receive_message_returns_400_with_expected_content(): void |
| 58 | + { |
| 59 | + $this->assertFeedbackPage('/authentication/feedback/unable-to-receive-message', Response::HTTP_BAD_REQUEST, 'No message received'); |
| 60 | + } |
| 61 | + |
| 62 | + #[Test] |
| 63 | + public function unknown_requesterid_in_authnrequest_returns_400_with_expected_content(): void |
| 64 | + { |
| 65 | + $this->assertFeedbackPage('/authentication/feedback/unknown_requesterid_in_authnrequest', Response::HTTP_BAD_REQUEST, 'Unknown service'); |
| 66 | + } |
| 67 | + |
| 68 | + #[Test] |
| 69 | + public function authentication_limit_exceeded_returns_429_with_expected_content(): void |
| 70 | + { |
| 71 | + $this->assertFeedbackPage('/authentication/feedback/authentication-limit-exceeded', Response::HTTP_TOO_MANY_REQUESTS, 'too many authentications in progress'); |
| 72 | + } |
| 73 | + |
| 74 | + #[Test] |
| 75 | + public function stepup_callout_unknown_returns_400_with_expected_content(): void |
| 76 | + { |
| 77 | + $this->assertFeedbackPage('/authentication/feedback/stepup-callout-unknown', Response::HTTP_BAD_REQUEST, 'Unknown strong authentication failure'); |
| 78 | + } |
| 79 | + |
| 80 | + #[Test] |
| 81 | + public function stepup_callout_user_cancelled_returns_400_with_expected_content(): void |
| 82 | + { |
| 83 | + $this->assertFeedbackPage('/authentication/feedback/stepup-callout-user-cancelled', Response::HTTP_BAD_REQUEST, 'Logging in cancelled'); |
| 84 | + } |
| 85 | + |
| 86 | + #[Test] |
| 87 | + public function invalid_acs_location_returns_400_with_expected_content(): void |
| 88 | + { |
| 89 | + $this->assertFeedbackPage('/authentication/feedback/invalidAcsLocation', Response::HTTP_BAD_REQUEST, 'Invalid ACS location'); |
| 90 | + } |
| 91 | + |
| 92 | + #[Test] |
| 93 | + public function feedback_data_from_session_is_rendered_on_the_real_route(): void |
| 94 | + { |
| 95 | + $client = self::createClient(); |
| 96 | + |
| 97 | + // First prime, the session, then visit the actual route |
| 98 | + $client->request('GET', 'https://engine.dev.openconext.local/functional-testing/feedback?template=session-lost'); |
| 99 | + $client->request('GET', 'https://engine.dev.openconext.local/authentication/feedback/session-lost'); |
| 100 | + |
| 101 | + $content = $client->getResponse()->getContent(); |
| 102 | + $this->assertStringContainsString('feedback-info--requestid', $content); |
| 103 | + $this->assertStringContainsString('feedback-info--ipaddress', $content); |
| 104 | + } |
| 105 | + |
| 106 | + private function assertFeedbackPage(string $path, int $expectedStatus, string $expectedPhrase): void |
| 107 | + { |
| 108 | + $client = self::createClient(); |
| 109 | + $client->request('GET', 'https://engine.dev.openconext.local' . $path); |
| 110 | + |
| 111 | + $this->assertEquals($expectedStatus, $client->getResponse()->getStatusCode()); |
| 112 | + $this->assertStringContainsString($expectedPhrase, $client->getResponse()->getContent()); |
| 113 | + } |
| 114 | +} |
0 commit comments