Skip to content

Commit 0150aa8

Browse files
committed
Consolidate simple feedback routes into generic feedbackAction
Prior to this change, there were many 'empty' identical twig templates in the error process. This change replaces them with a 'generic-error' twig template. Resolves #1758
1 parent b50a07a commit 0150aa8

17 files changed

Lines changed: 87 additions & 161 deletions

config/services/ci/controllers.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
arguments:
2727
- '@twig'
2828
- '@OpenConext\EngineBlock\Service\FeedbackStateHelper'
29+
- '@OpenConext\EngineBlockBundle\Controller\FeedbackController'
2930

3031
engineblock.functional_test.controller.consent:
3132
class: OpenConext\EngineBlockFunctionalTestingBundle\Controllers\ConsentController

src/OpenConext/EngineBlockBundle/Controller/FeedbackController.php

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,73 @@ public function unableToReceiveMessageAction()
6666
#[Route(
6767
path: '/authentication/feedback/unsolicited-response',
6868
name: 'authentication_feedback_unsolicited_response',
69+
defaults: [
70+
'pageIdentifier' => 'unsolicited-response',
71+
'statusCode' => 400
72+
],
6973
methods: ['GET']
7074
)]
71-
public function unsolicitedResponseAction(): Response
75+
#[Route(
76+
path: '/authentication/feedback/session-lost',
77+
name: 'authentication_feedback_session_lost',
78+
defaults: [
79+
'pageIdentifier' => 'session-lost',
80+
'statusCode' => 400
81+
],
82+
methods: ['GET']
83+
)]
84+
#[Route(
85+
path: '/authentication/feedback/session-not-started',
86+
name: 'authentication_feedback_session_not_started',
87+
defaults: [
88+
'pageIdentifier' => 'session-not-started',
89+
'statusCode' => 400
90+
],
91+
methods: ['GET']
92+
)]
93+
#[Route(
94+
path: '/authentication/feedback/invalid-acs-binding',
95+
name: 'authentication_feedback_invalid_acs_binding',
96+
defaults: [
97+
'pageIdentifier' => 'invalid-acs-binding',
98+
'statusCode' => 400
99+
],
100+
methods: ['GET']
101+
)]
102+
#[Route(
103+
path: '/authentication/feedback/received-error-status-code',
104+
name: 'authentication_feedback_received_error_status_code',
105+
defaults: [
106+
'pageIdentifier' => 'received-error-status-code',
107+
'statusCode' => 400
108+
],
109+
methods: ['GET']
110+
)]
111+
#[Route(
112+
path: '/authentication/feedback/unknown_requesterid_in_authnrequest',
113+
name: 'authentication_feedback_unknown_requesterid_in_authnrequest',
114+
defaults: [
115+
'pageIdentifier' => 'unknown-requesterid-in-authnrequest',
116+
'statusCode' => 400
117+
],
118+
methods: ['GET']
119+
)]
120+
#[Route(
121+
path: '/authentication/feedback/authentication-limit-exceeded',
122+
name: 'authentication_feedback_authentication_limit_exceeded',
123+
defaults: [
124+
'pageIdentifier' => 'authentication-limit-exceeded',
125+
'statusCode' => 429
126+
],
127+
methods: ['GET']
128+
)]
129+
public function feedbackAction(string $pageIdentifier, int $statusCode): Response
72130
{
73131
return new Response(
74-
$this->twig->render('@theme/Authentication/View/Feedback/unsolicited-response.html.twig'),
75-
400
132+
$this->twig->render('@theme/Authentication/View/Feedback/generic-error.html.twig', [
133+
'pageIdentifier' => $pageIdentifier,
134+
]),
135+
$statusCode
76136
);
77137
}
78138

@@ -85,19 +145,6 @@ public function unknownErrorAction()
85145
);
86146
}
87147

88-
89-
#[Route(path: '/authentication/feedback/session-lost', name: 'authentication_feedback_session_lost', methods: ['GET'])]
90-
public function sessionLostAction()
91-
{
92-
return new Response($this->twig->render('@theme/Authentication/View/Feedback/session-lost.html.twig'), 400);
93-
}
94-
95-
#[Route(path: '/authentication/feedback/session-not-started', name: 'authentication_feedback_session_not_started', methods: ['GET'])]
96-
public function sessionNotStartedAction()
97-
{
98-
return new Response($this->twig->render('@theme/Authentication/View/Feedback/session-not-started.html.twig'), 400);
99-
}
100-
101148
#[Route(path: '/authentication/feedback/no-idps', name: 'authentication_feedback_no_idps', methods: ['GET'])]
102149
public function noIdpsAction()
103150
{
@@ -310,26 +357,6 @@ public function customAction(Request $request)
310357
);
311358
}
312359

313-
#[Route(path: '/authentication/feedback/invalid-acs-binding', name: 'authentication_feedback_invalid_acs_binding', methods: ['GET'])]
314-
public function invalidAcsBindingAction()
315-
{
316-
// @todo Send 4xx or 5xx header depending on invalid binding came from request or configured metadata
317-
return new Response($this->twig->render('@theme/Authentication/View/Feedback/invalid-acs-binding.html.twig'));
318-
}
319-
320-
#[Route(
321-
path: '/authentication/feedback/received-error-status-code',
322-
name: 'authentication_feedback_received_error_status_code',
323-
methods: ['GET']
324-
)]
325-
public function receivedErrorStatusCodeAction()
326-
{
327-
// @todo Send 4xx or 5xx header?
328-
return new Response(
329-
$this->twig->render('@theme/Authentication/View/Feedback/received-error-status-code.html.twig')
330-
);
331-
}
332-
333360
#[Route(
334361
path: '/authentication/feedback/received-invalid-signed-response',
335362
name: 'authentication_feedback_signature_verification_failed',
@@ -352,20 +379,6 @@ public function receivedInvalidResponseAction()
352379
);
353380
}
354381

355-
#[Route(
356-
path: '/authentication/feedback/unknown_requesterid_in_authnrequest',
357-
name: 'authentication_feedback_unknown_requesterid_in_authnrequest',
358-
methods: ['GET']
359-
)]
360-
public function unknownRequesterIdInAuthnRequestAction()
361-
{
362-
return new Response(
363-
$this->twig->render('@theme/Authentication/View/Feedback/unknown-requesterid-in-authnrequest.html.twig'),
364-
400
365-
);
366-
}
367-
368-
369382
#[Route(path: '/authentication/feedback/authorization-policy-violation', name: 'authentication_feedback_pep_violation', methods: ['GET'])]
370383
public function authorizationPolicyViolationAction(Request $request)
371384
{
@@ -442,19 +455,6 @@ public function stuckInAuthenticationLoopAction()
442455
);
443456
}
444457

445-
#[Route(
446-
path: '/authentication/feedback/authentication-limit-exceeded',
447-
name: 'authentication_feedback_authentication_limit_exceeded',
448-
methods: ['GET']
449-
)]
450-
public function authenticationLimitExceededAction()
451-
{
452-
return new Response(
453-
$this->twig->render('@theme/Authentication/View/Feedback/authentication-limit-exceeded.html.twig'),
454-
429
455-
);
456-
}
457-
458458
#[Route(
459459
path: '/authentication/feedback/invalid-request-method-on-sso',
460460
name: 'authentication_feedback_no_authentication_request_received',

src/OpenConext/EngineBlockFunctionalTestingBundle/Controllers/FeedbackController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace OpenConext\EngineBlockFunctionalTestingBundle\Controllers;
2020

2121
use OpenConext\EngineBlock\Service\FeedbackStateHelperInterface;
22+
use OpenConext\EngineBlockBundle\Controller\FeedbackController as RealFeedbackController;
2223
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2324
use Symfony\Component\HttpFoundation\Request;
2425
use Symfony\Component\HttpFoundation\Response;
@@ -35,12 +36,16 @@ class FeedbackController extends AbstractController
3536

3637
private FeedbackStateHelperInterface $feedbackStateHelper;
3738

39+
private RealFeedbackController $feedbackController;
40+
3841
public function __construct(
3942
Environment $twig,
40-
FeedbackStateHelperInterface $feedbackStateHelper
43+
FeedbackStateHelperInterface $feedbackStateHelper,
44+
RealFeedbackController $feedbackController
4145
) {
4246
$this->twig = $twig;
4347
$this->feedbackStateHelper = $feedbackStateHelper;
48+
$this->feedbackController = $feedbackController;
4449
}
4550

4651
/**
@@ -56,12 +61,16 @@ public function feedbackAction(Request $request)
5661
$feedbackInfo = $this->getFeedbackInfo($request);
5762
$parameters = $this->getTemplateParameters($request);
5863

64+
$this->feedbackStateHelper->storeFeedbackInfo($feedbackInfo);
65+
5966
$template = sprintf(
6067
'@theme/Authentication/View/Feedback/%s.html.twig',
6168
$key
6269
);
6370

64-
$this->feedbackStateHelper->storeFeedbackInfo($feedbackInfo);
71+
if (!$this->twig->getLoader()->exists($template)) {
72+
return $this->feedbackController->feedbackAction($key, 200);
73+
}
6574

6675
return new Response($this->twig->render($template, $parameters), 200);
6776
}
@@ -106,14 +115,12 @@ private function getFeedbackInfo(Request $request)
106115
* @param Request $request
107116
* @return mixed|string
108117
*/
109-
private function getTemplateParameters(Request $request)
118+
private function getTemplateParameters(Request $request): array
110119
{
111120
$default = '{}';
112121

113122
$parameters = $request->query->getString('parameters', $default);
114123

115-
$parameters = json_decode($parameters, true);
116-
117-
return $parameters;
124+
return json_decode($parameters, true);
118125
}
119126
}

src/OpenConext/EngineBlockFunctionalTestingBundle/Features/FeedbackFooters.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Feature:
4949
When I go to Engineblock URL "/functional-testing/feedback?template=session-lost&feedback-info=%7B%22requestId%22%3A%22test-abc%22%2C%22ipAddress%22%3A%221.2.3.4%22%2C%22artCode%22%3A%2231914%22%7D"
5050
Then I should see "your session was lost"
5151

52+
Scenario: The session-lost feedback route renders correctly
53+
When I go to Engineblock URL "/authentication/feedback/session-lost"
54+
Then I should see "your session was lost"
55+
5256
Scenario: When a IdP specific error page is shown and a translation is not configured the support emailaddress of the IdP should be hidden
5357
Given The clock on the IdP "Dummy Idp" is ahead
5458
And I have configured the following translations:

theme/base/templates/modules/Authentication/View/Feedback/authentication-limit-exceeded.html.twig renamed to theme/base/templates/modules/Authentication/View/Feedback/generic-error.html.twig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{% extends '@theme/Default/View/Error/error.html.twig' %}
22

3-
{% set pageTitle = 'error_authentication_limit_exceeded'|trans %}
3+
{% set _key = 'error_' ~ pageIdentifier|replace({'-': '_'}) %}
4+
{% set pageTitle = (_key)|trans %}
45
{% block pageTitle %}{{ pageTitle }}{% endblock %}
56
{% block title %}{{ parent() }}{% endblock %}
67
{% block pageHeading %}{{ pageTitle }}{% endblock %}
78

8-
{% block errorMessage %}{{ 'error_authentication_limit_exceeded_desc'|trans }}{% endblock %}
9+
{% block errorMessage %}{{ (_key ~ '_desc')|trans }}{% endblock %}

theme/base/templates/modules/Authentication/View/Feedback/received-error-status-code.html.twig

Lines changed: 0 additions & 8 deletions
This file was deleted.

theme/base/templates/modules/Authentication/View/Feedback/session-lost.html.twig

Lines changed: 0 additions & 8 deletions
This file was deleted.

theme/base/templates/modules/Authentication/View/Feedback/session-not-started.html.twig

Lines changed: 0 additions & 8 deletions
This file was deleted.

theme/base/templates/modules/Authentication/View/Feedback/unknown-requesterid-in-authnrequest.html.twig

Lines changed: 0 additions & 8 deletions
This file was deleted.

theme/base/templates/modules/Authentication/View/Feedback/unsolicited-response.html.twig

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)