From 41519781fc0fb6549718d006cad38c3d63c2b3f5 Mon Sep 17 00:00:00 2001 From: JAndrewCH Date: Thu, 25 Jul 2024 16:04:31 +0100 Subject: [PATCH 1/2] get list should allow trailing / --- .../controller/CompanyPscController.java | 2 +- .../controller/CompanyPscControllerTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java b/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java index 5f8f7d1..2cb9f1a 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java @@ -343,7 +343,7 @@ public ResponseEntity getSuperSecureBeneficialOwnerP * @param companyNumber The number of the company * @return ResponseEntity */ - @GetMapping("") + @GetMapping({"", "/"}) public ResponseEntity searchPscListSummary( @PathVariable("company_number") String companyNumber, @RequestParam(value = "items_per_page", diff --git a/src/test/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscControllerTest.java b/src/test/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscControllerTest.java index 06d7ec1..2a2f5a0 100644 --- a/src/test/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscControllerTest.java +++ b/src/test/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscControllerTest.java @@ -753,6 +753,25 @@ void callPscListGetRequestWithParams() throws Exception { .andExpect(status().isOk()); } + @Test + void callPscListGetRequestWithTrailingSlash() throws Exception { + when(companyPscService.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER, 2, false, 5)) + .thenReturn(new PscList()); + + mockMvc.perform(MockMvcRequestBuilders + .get(GET_List_Summary_URL+"/") + .contentType(MediaType.APPLICATION_JSON) + .header("ERIC-Identity", ERIC_IDENTITY) + .header("ERIC-Identity-Type", ERIC_IDENTITY_TYPE) + .contentType(APPLICATION_JSON) + .header("x-request-id", X_REQUEST_ID) + .header("ERIC-Authorised-Key-Roles", ERIC_PRIVILEGES) + .header("ERIC-Authorised-Key-Privileges", ERIC_AUTH) + .header("items_per_page", 5) + .header("start_index", 2)) + .andExpect(status().isOk()); + } + @Test void callPscListGetRequestWithRegisterView() throws Exception { when(companyPscService.retrievePscListSummaryFromDb(MOCK_COMPANY_NUMBER, 2, true, 5)) From 731105e4d94065d2f273bd39e3f8d60b1d00e21c Mon Sep 17 00:00:00 2001 From: JAndrewCH Date: Thu, 25 Jul 2024 16:25:23 +0100 Subject: [PATCH 2/2] set use trailing slash --- .../companieshouse/pscdataapi/config/WebSecurityConfig.java | 6 ++++++ .../pscdataapi/controller/CompanyPscController.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/config/WebSecurityConfig.java b/src/main/java/uk/gov/companieshouse/pscdataapi/config/WebSecurityConfig.java index 65d2775..f4c9cdf 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/config/WebSecurityConfig.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/config/WebSecurityConfig.java @@ -10,6 +10,7 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.csrf.CsrfFilter; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import uk.gov.companieshouse.api.filter.CustomCorsFilter; @@ -26,6 +27,11 @@ public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(userAuthenticationInterceptor()); } + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + configurer.setUseTrailingSlashMatch(true); + } + @Bean public InternalUserInterceptor internalUserInterceptor() { return new InternalUserInterceptor(); diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java b/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java index 2cb9f1a..5f8f7d1 100644 --- a/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java +++ b/src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java @@ -343,7 +343,7 @@ public ResponseEntity getSuperSecureBeneficialOwnerP * @param companyNumber The number of the company * @return ResponseEntity */ - @GetMapping({"", "/"}) + @GetMapping("") public ResponseEntity searchPscListSummary( @PathVariable("company_number") String companyNumber, @RequestParam(value = "items_per_page",