<parent>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-parent</artifactId>
- <version>1.13.3</version>
+ <version>1.15.5</version>
</parent>
<groupId>org.onap.aai</groupId>
<properties>
<!-- Spring boot version -->
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<sonar.jacoco.itReportPath />
<sonar.jacoco.reportMissing.force.zero />
- <jacoco-maven-plugin.version>0.8.7</jacoco-maven-plugin.version>
+ <jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sdc.tosca.version>1.6.5</sdc.tosca.version>
<aai.common.version>1.9.4</aai.common.version>
- <logback.core.version>1.2.11</logback.core.version>
<groovy.version>3.0.13</groovy.version>
- <spring-cloud.version>2020.0.2</spring-cloud.version>
+ <spring-cloud.version>2021.0.8</spring-cloud.version>
<commons.compress.version>1.27.0</commons.compress.version>
<commons.io.version>2.16.1</commons.io.version>
<commons.codec.version>1.15</commons.codec.version>
-
+ <jaxb.version>2.3.0</jaxb.version>
<javax.ws.rs.version>2.1.1</javax.ws.rs.version>
<mvn.jaxb2.version>0.15.1</mvn.jaxb2.version>
<aai-schema.group.id>org.onap.aai.schema-service</aai-schema.group.id>
- <aai-schema.version>1.12.7</aai-schema.version>
+ <aai-schema.version>1.12.10</aai-schema.version>
<commons.lang3.version>3.12.0</commons.lang3.version>
<aai.rest.client.version>1.6.4</aai.rest.client.version>
-
+ <common.logging.version>1.13.0</common.logging.version>
<sdc.distribution.client.version>1.4.5</sdc.distribution.client.version>
<!-- TODO: use xml-legacy -->
<xmlunit.version>1.6</xmlunit.version>
<dependency>
<groupId>org.onap.aai.logging-service</groupId>
<artifactId>common-logging</artifactId>
+ <version>${common.logging.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
- <version>${logback.core.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<dependency>
<groupId>org.onap.aai</groupId>
<artifactId>rest-client</artifactId>
+ <version>${aai.rest.client.version}</version>
</dependency>
<!-- Testing -->
<artifactId>xmlunit-legacy</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ </dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
+ <version>${jaxb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>net.logstash.logback</groupId>
- <artifactId>logstash-logback-encoder</artifactId>
- <version>6.6</version>
- </dependency>
- <dependency>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- </dependency>
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>2.0.9</version>
+ </dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
- <version>3.0.0-M5</version>
+ <version>3.1.2</version>
<executions>
<!-- Ensures that both integration-test and verify goals of the Failsafe
Maven plugin are executed. -->
</plugins>
</build>
-</project>
+</project>
\ No newline at end of file
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
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", ".");
@Test
public void testApplicationStarts() {
assertDoesNotThrow(() -> {
- BabelApplication.main(new String[]{});
+ BabelApplication.main(new String[] {});
BabelApplication.exit();
});
}
@Test
public void testApplicationStartsWithObfuscatedPassword() {
assertDoesNotThrow(() -> {
- BabelApplication.main(new String[]{});
+ BabelApplication.main(new String[] {});
BabelApplication.exit();
});
}
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<AuthenticationRequestFilter> loggingFilter(AAIMicroServiceAuth authService, HttpServletRequest servletRequest) {
- // FilterRegistrationBean<AuthenticationRequestFilter> 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<Response> 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<String> testEndpoint() {
- // return ResponseEntity.ok("Authorized");
- // }
- // }
+ ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
+ verify(requestContext).abortWith(captor.capture());
+ assertEquals(Response.Status.FORBIDDEN.getStatusCode(), captor.getValue().getStatus());
+ }
}
spring.sleuth.enabled=false
+server.port= 0
+spring.main.allow-bean-definition-overriding= true