From: tushar.mohanty@t-systems.com Date: Tue, 1 Jul 2025 06:13:28 +0000 (+0200) Subject: springboot 2.7 upgrade X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=db65b4502d003e5750fff95da1da0757b4a9527a;p=aai%2Fbabel.git springboot 2.7 upgrade Issue-ID: AAI-4184 Change-Id: If5b1479872f009960e4504798c75df158b64e040 Signed-off-by: tushar.mohanty@t-systems.com --- diff --git a/pom.xml b/pom.xml index c5d2b70..2029f0b 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ org.onap.aai.aai-common aai-parent - 1.13.3 + 1.15.5 org.onap.aai @@ -41,6 +41,7 @@ + UTF-8 UTF-8 @@ -57,7 +58,7 @@ - 0.8.7 + 0.8.11 jacoco ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml @@ -87,22 +88,21 @@ 1.6.5 1.9.4 - 1.2.11 3.0.13 - 2020.0.2 + 2021.0.8 1.27.0 2.16.1 1.15 - + 2.3.0 2.1.1 0.15.1 org.onap.aai.schema-service - 1.12.7 + 1.12.10 3.12.0 1.6.4 - + 1.13.0 1.4.5 1.6 @@ -289,15 +289,16 @@ org.onap.aai.logging-service common-logging + ${common.logging.version} ch.qos.logback logback-classic + compile ch.qos.logback logback-core - ${logback.core.version} commons-codec @@ -332,6 +333,7 @@ org.onap.aai rest-client + ${aai.rest.client.version} @@ -369,6 +371,10 @@ xmlunit-legacy test + + javax.xml.bind + jaxb-api + javax.xml.ws jaxws-api @@ -376,6 +382,12 @@ com.sun.xml.bind jaxb-core + ${jaxb.version} + + + com.sun.xml.bind + jaxb-impl + ${jaxb.version} jakarta.activation @@ -396,19 +408,11 @@ 1.18.32 provided - - net.logstash.logback - logstash-logback-encoder - 6.6 - - - javax.xml.bind - jaxb-api - - - com.sun.xml.bind - jaxb-impl - + + org.slf4j + slf4j-api + 2.0.9 + @@ -755,7 +759,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.0.0-M5 + 3.1.2 @@ -781,4 +785,4 @@ - + \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6bd8991..77835f3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=9516 -security.require-ssl=false +#security.require-ssl=false server.ssl.enabled=false server.ssl.key-store=${CONFIG_HOME}/auth/tomcat_keystore server.ssl.client-auth=need diff --git a/src/test/java/org/onap/aai/babel/TestApplication.java b/src/test/java/org/onap/aai/babel/TestApplication.java index a665119..c8e96e3 100644 --- a/src/test/java/org/onap/aai/babel/TestApplication.java +++ b/src/test/java/org/onap/aai/babel/TestApplication.java @@ -24,16 +24,24 @@ package org.onap.aai.babel; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; -@SpringBootTest(classes = BabelApplication.class) +@SpringBootTest( + classes = BabelApplication.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT +) +@ActiveProfiles("test") +@TestPropertySource(properties = { + "APP_HOME=.", + "CONFIG_HOME=src/test/resources" +}) public class TestApplication { - /** - * Initialize System Properties. - */ @BeforeEach public void init() { System.setProperty("APP_HOME", "."); @@ -43,7 +51,7 @@ public class TestApplication { @Test public void testApplicationStarts() { assertDoesNotThrow(() -> { - BabelApplication.main(new String[]{}); + BabelApplication.main(new String[] {}); BabelApplication.exit(); }); } @@ -51,7 +59,7 @@ public class TestApplication { @Test public void testApplicationStartsWithObfuscatedPassword() { assertDoesNotThrow(() -> { - BabelApplication.main(new String[]{}); + BabelApplication.main(new String[] {}); BabelApplication.exit(); }); } diff --git a/src/test/java/org/onap/aai/babel/filters/AuthenticationRequestFilterTest.java b/src/test/java/org/onap/aai/babel/filters/AuthenticationRequestFilterTest.java index d8f2965..ac72b6d 100644 --- a/src/test/java/org/onap/aai/babel/filters/AuthenticationRequestFilterTest.java +++ b/src/test/java/org/onap/aai/babel/filters/AuthenticationRequestFilterTest.java @@ -21,92 +21,89 @@ package org.onap.aai.babel.filters; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.aai.auth.AAIAuthException; import org.onap.aai.auth.AAIMicroServiceAuth; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.web.reactive.server.WebTestClient; +import org.onap.aai.auth.AAIMicroServiceAuthCore.HTTP_METHODS; + +import java.io.IOException; +import java.util.List; import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.PathSegment; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; -import java.time.Duration; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class AuthenticationRequestFilterTest { - @LocalServerPort - private int port; + @Mock + private AAIMicroServiceAuth authService; + + @Mock + private HttpServletRequest servletRequest; - @Autowired - private WebTestClient webTestClient; + @Mock + private ContainerRequestContext requestContext; - @MockBean - private AAIMicroServiceAuth authService; + @Mock + private UriInfo uriInfo; + + @Mock + private PathSegment pathSegment; + + private AuthenticationRequestFilter filter; @BeforeEach public void setUp() { MockitoAnnotations.openMocks(this); - webTestClient = webTestClient.mutate() - .responseTimeout(Duration.ofMillis(300000)) - .build(); - } + filter = new AuthenticationRequestFilter(authService, servletRequest); - @Test - public void testAuthorizedRequest() throws AAIAuthException { - // Mocking authService to return true - when(authService.validateRequest(any(), any(HttpServletRequest.class), any(), anyString())).thenReturn(true); - - webTestClient.post() - .uri("/v1/app/generateArtifacts") - .exchange() - .expectStatus().is5xxServerError(); + when(requestContext.getUriInfo()).thenReturn(uriInfo); + when(uriInfo.getPathSegments()).thenReturn(List.of(pathSegment)); + when(pathSegment.getPath()).thenReturn("some-segment"); } @Test - @Disabled - public void testUnauthorizedRequest() throws AAIAuthException { - // Mocking authService to return false - when(authService.validateRequest(any(), any(HttpServletRequest.class), any(), anyString())).thenReturn(false); - - webTestClient.post() - .uri("/services/babel-service/v1/app/generateArtifacts") - .exchange() - .expectStatus().isUnauthorized(); - } + public void testAuthorizedRequest() throws IOException, AAIAuthException { + when(requestContext.getMethod()).thenReturn("GET"); + when(authService.validateRequest(any(), eq(servletRequest), eq(HTTP_METHODS.GET), eq("some-segment"))) + .thenReturn(true); - // @TestConfiguration - // static class TestConfig { + filter.filter(requestContext); - // @Bean - // public FilterRegistrationBean loggingFilter(AAIMicroServiceAuth authService, HttpServletRequest servletRequest) { - // FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + verify(requestContext, never()).abortWith(any()); + } - // registrationBean.setFilter(new AuthenticationRequestFilter(authService, servletRequest)); - // registrationBean.addUrlPatterns("/test"); + @Test + public void testUnauthorizedRequest() throws IOException, AAIAuthException { + when(requestContext.getMethod()).thenReturn("POST"); + when(authService.validateRequest(any(), eq(servletRequest), eq(HTTP_METHODS.POST), eq("some-segment"))) + .thenReturn(false); - // return registrationBean; - // } + filter.filter(requestContext); - // @Bean - // public HttpServletRequest httpServletRequest() { - // return new MockHttpServletRequest(); - // } - // } + ArgumentCaptor captor = ArgumentCaptor.forClass(Response.class); + verify(requestContext).abortWith(captor.capture()); + assertEquals(Response.Status.FORBIDDEN.getStatusCode(), captor.getValue().getStatus()); + } - // @RestController - // static class TestController { + @Test + public void testExceptionDuringValidation() throws IOException, AAIAuthException { + when(requestContext.getMethod()).thenReturn("DELETE"); + when(authService.validateRequest(any(), eq(servletRequest), eq(HTTP_METHODS.DELETE), eq("some-segment"))) + .thenThrow(new RuntimeException("Failure")); + + filter.filter(requestContext); - // @GetMapping("/test") - // public ResponseEntity testEndpoint() { - // return ResponseEntity.ok("Authorized"); - // } - // } + ArgumentCaptor captor = ArgumentCaptor.forClass(Response.class); + verify(requestContext).abortWith(captor.capture()); + assertEquals(Response.Status.FORBIDDEN.getStatusCode(), captor.getValue().getStatus()); + } } diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 8c3bd59..d4ab747 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1 +1,3 @@ spring.sleuth.enabled=false +server.port= 0 +spring.main.allow-bean-definition-overriding= true