|
10 | 10 | import com.nimbusds.oauth2.sdk.id.State; |
11 | 11 | import io.quarkus.test.InjectMock; |
12 | 12 | import io.quarkus.test.common.http.TestHTTPEndpoint; |
| 13 | +import io.quarkus.test.junit.QuarkusMock; |
13 | 14 | import io.quarkus.test.junit.QuarkusTest; |
14 | 15 | import io.quarkus.test.junit.TestProfile; |
15 | 16 | import it.pagopa.oneid.common.model.exception.OneIdentityException; |
|
23 | 24 | import it.pagopa.oneid.service.SessionServiceImpl; |
24 | 25 | import it.pagopa.oneid.web.controller.interceptors.CurrentAuthDTO; |
25 | 26 | import it.pagopa.oneid.web.controller.mock.SAMLControllerTestProfile; |
| 27 | +import it.pagopa.oneid.web.dto.AuthorizationRequestDTOExtended; |
26 | 28 | import jakarta.inject.Inject; |
27 | 29 | import java.net.URLEncoder; |
28 | 30 | import java.nio.charset.StandardCharsets; |
@@ -413,43 +415,46 @@ void samlACS_exceptionInCreatingCallbackURI() { |
413 | 415 | Assertions.assertTrue(location.contains(headerLocation)); |
414 | 416 | } |
415 | 417 |
|
416 | | -// TODO re-enable this test when the feature is back |
417 | | -// @Test |
418 | | -// @SneakyThrows |
419 | | -// void samlACS_SAMLResponseWithMultipleSignatures() { |
420 | | -// // given |
421 | | -// CurrentAuthDTO mockAuthDTO = Mockito.mock(CurrentAuthDTO.class); |
422 | | -// QuarkusMock.installMockForType(mockAuthDTO, CurrentAuthDTO.class); |
423 | | -// |
424 | | -// Map<String, String> samlResponseDTO = new HashMap<>(); |
425 | | -// samlResponseDTO.put("SAMLResponse", "dummySAMLResponse"); |
426 | | -// samlResponseDTO.put("RelayState", "dummyRelayState"); |
427 | | -// |
428 | | -// // Mock CurrentAuthDTO to simulate multiple signatures scenario |
429 | | -// Mockito.when(mockAuthDTO.isResponseWithMultipleSignatures()).thenReturn(true); |
430 | | -// |
431 | | -// // Setup mocks for response and samlSession as usual, but flow will stop at the multiple signatures check |
432 | | -// Response response = Mockito.mock(Response.class); |
433 | | -// Mockito.when(response.getInResponseTo()).thenReturn("Dummy"); |
434 | | -// Mockito.when(samlServiceImpl.getSAMLResponseFromString(Mockito.any())).thenReturn(response); |
435 | | -// Mockito.when(mockAuthDTO.getResponse()).thenReturn(response); |
436 | | -// |
437 | | -// AuthorizationRequestDTOExtended dto = Mockito.mock(AuthorizationRequestDTOExtended.class); |
438 | | -// Mockito.when(dto.getIdp()).thenReturn("dummy-idp"); // Stub idp for cloudwatch metrics |
439 | | -// SAMLSession samlSession = Mockito.mock(SAMLSession.class); |
440 | | -// Mockito.when(samlSession.getAuthorizationRequestDTOExtended()).thenReturn(dto); |
441 | | -// Mockito.when(mockAuthDTO.getSamlSession()).thenReturn(samlSession); |
442 | | -// |
443 | | -// // HTTP 302 |
444 | | -// given() |
445 | | -// .formParams(samlResponseDTO) |
446 | | -// .when() |
447 | | -// .post("/acs") |
448 | | -// .then() |
449 | | -// .statusCode(302) |
450 | | -// .header("Location", containsString( |
451 | | -// ErrorCode.IDP_ERROR_MULTIPLE_SAMLRESPONSE_SIGNATURES_PRESENT.getErrorCode())); |
452 | | -// } |
| 418 | + @Test |
| 419 | + @SneakyThrows |
| 420 | + void samlACS_SAMLResponseWithMultipleSignatures() { |
| 421 | + // given |
| 422 | + CurrentAuthDTO mockAuthDTO = Mockito.mock(CurrentAuthDTO.class); |
| 423 | + QuarkusMock.installMockForType(mockAuthDTO, CurrentAuthDTO.class); |
| 424 | + |
| 425 | + Map<String, String> samlResponseDTO = new HashMap<>(); |
| 426 | + samlResponseDTO.put("SAMLResponse", "dummySAMLResponse"); |
| 427 | + samlResponseDTO.put("RelayState", "dummyRelayState"); |
| 428 | + |
| 429 | + // Mock CurrentAuthDTO to simulate multiple signatures scenario |
| 430 | + Mockito.when(mockAuthDTO.isResponseWithMultipleSignatures()).thenReturn(true); |
| 431 | + |
| 432 | + // Setup mocks for response and samlSession as usual, but flow will stop at the multiple signatures check |
| 433 | + Response response = Mockito.mock(Response.class); |
| 434 | + Mockito.when(response.getInResponseTo()).thenReturn("Dummy"); |
| 435 | + Mockito.when(samlServiceImpl.getSAMLResponseFromString(Mockito.any())).thenReturn(response); |
| 436 | + Mockito.when(mockAuthDTO.getResponse()).thenReturn(response); |
| 437 | + |
| 438 | + AuthorizationRequestDTOExtended dto = Mockito.mock(AuthorizationRequestDTOExtended.class); |
| 439 | + Mockito.when(dto.getIdp()).thenReturn("dummy-idp"); // Stub idp for cloudwatch metrics |
| 440 | + SAMLSession samlSession = Mockito.mock(SAMLSession.class); |
| 441 | + Mockito.when(samlSession.getAuthorizationRequestDTOExtended()).thenReturn(dto); |
| 442 | + Mockito.when(mockAuthDTO.getSamlSession()).thenReturn(samlSession); |
| 443 | + |
| 444 | + // HTTP 302 |
| 445 | + String location = given() |
| 446 | + .formParams(samlResponseDTO) |
| 447 | + .when() |
| 448 | + .post("/acs") |
| 449 | + .then() |
| 450 | + .statusCode(302) |
| 451 | + .extract() |
| 452 | + .header("location"); |
| 453 | + |
| 454 | + Assertions.assertTrue(location.contains( |
| 455 | + ErrorCode.IDP_ERROR_MULTIPLE_SAMLRESPONSE_SIGNATURES_PRESENT.getErrorCode())); |
| 456 | + |
| 457 | + } |
453 | 458 |
|
454 | 459 | @Test |
455 | 460 | void assertion_ok() { |
|
0 commit comments