Skip to content

Commit

Permalink
adding required tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanehcine committed Mar 7, 2024
1 parent d5ef0fa commit 11764eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.georchestra.gateway.filter.headers.providers;

import static org.georchestra.commons.security.SecurityHeaders.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -115,16 +116,17 @@ void testContributesHeadersFromUser() {
HttpHeaders target = new HttpHeaders();
contributor.accept(target);

assertEquals(List.of(user.getId()), target.get("sec-userid"));
assertEquals(List.of(user.getUsername()), target.get("sec-username"));
assertEquals(List.of(user.getFirstName()), target.get("sec-firstname"));
assertEquals(List.of(user.getLastName()), target.get("sec-lastname"));
assertEquals(List.of(user.getOrganization()), target.get("sec-org"));
assertEquals(List.of(user.getEmail()), target.get("sec-email"));
assertEquals(List.of(user.getTelephoneNumber()), target.get("sec-tel"));
assertEquals(List.of(user.getPostalAddress()), target.get("sec-address"));
assertEquals(List.of(user.getTitle()), target.get("sec-title"));
assertEquals(List.of(user.getNotes()), target.get("sec-notes"));
assertEquals(List.of(user.getId()), target.get(SEC_USERID));
assertEquals(List.of(user.getUsername()), target.get(SEC_USERNAME));
assertEquals(List.of(user.getFirstName()), target.get(SEC_FIRSTNAME));
assertEquals(List.of(user.getLastName()), target.get(SEC_LASTNAME));
assertEquals(List.of(user.getOrganization()), target.get(SEC_ORG));
assertEquals(List.of(user.getEmail()), target.get(SEC_EMAIL));
assertEquals(List.of(user.getTelephoneNumber()), target.get(SEC_TEL));
assertEquals(List.of(user.getPostalAddress()), target.get(SEC_ADDRESS));
assertEquals(List.of(user.getTitle()), target.get(SEC_TITLE));
assertEquals(List.of(user.getNotes()), target.get(SEC_NOTES));
assertEquals(List.of(String.valueOf(user.getIsExternalAuth())), target.get(SEC_EXTERNAL_AUTHENTICATION));

String roles = user.getRoles().stream().collect(Collectors.joining(";"));
assertEquals(List.of(roles), target.get("sec-roles"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.georchestra.commons.security.SecurityHeaders.SEC_EXTERNAL_AUTHENTICATION;
import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(classes = GeorchestraGatewayApplication.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureWebTestClient(timeout = "PT20S")
Expand Down Expand Up @@ -96,4 +96,18 @@ static void registerPgProperties(DynamicPropertyRegistry registry) {
assertFalse(req.getHeader("sec-roles").isEmpty());
});
}

public @Test void testProxifiedRequestWithExternalAuthenticationHeaderAttribute() {
mockService.stubFor(get(urlMatching("/test"))//
.willReturn(ok()));

testClient.get().uri("/test").exchange().expectStatus().is2xxSuccessful();

List<LoggedRequest> requests = mockService.findAll(getRequestedFor(urlEqualTo("/test")));
requests.forEach(req -> {
assertEquals(1, (int) req.getHeaders().keys().stream()
.filter(h -> h.startsWith(SEC_EXTERNAL_AUTHENTICATION)).count());

});
}
}

0 comments on commit 11764eb

Please sign in to comment.