diff --git a/pom.xml b/pom.xml index 969c5dc547ed5c20cebdc2a9a0156991da2bb018..af61b5909ef872ec1723ea74b318fbb6ef8f8ca7 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <os-core-common.version>0.3.12</os-core-common.version> + <os-core-common.version>0.3.16</os-core-common.version> <tomcat_embed_core_version>9.0.37</tomcat_embed_core_version> </properties> diff --git a/provider/partition-azure/pom.xml b/provider/partition-azure/pom.xml index 57c1fad1217abf8d4c31cdb29a476ce00a72bf20..6e8d259f2bbeb842aa42bc4c83efda4c9f1d54c7 100644 --- a/provider/partition-azure/pom.xml +++ b/provider/partition-azure/pom.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>partition</artifactId> <groupId>org.opengroup.osdu</groupId> @@ -15,14 +16,53 @@ <packaging>jar</packaging> <properties> + <osdu.partition-core.version>1.0.0</osdu.partition-core.version> + <osdu.corelibazure.version>0.0.44</osdu.corelibazure.version> + <osdu.oscorecommon.version>0.3.16</osdu.oscorecommon.version> <azure.version>2.3.5</azure.version> + <junit.version>4.12</junit.version> + <mockito.version>2.25.0</mockito.version> + <powermock.version>2.0.2</powermock.version> + <nimbus-jose-jwt>7.9</nimbus-jose-jwt> + <jwks-rsa>0.12.0</jwks-rsa> </properties> + + <dependencyManagement> + <dependencies> + <!-- Inherit managed dependencies from core-lib-azure --> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>core-lib-azure</artifactId> + <version>${osdu.corelibazure.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> + <!-- OSDU dependencies --> <dependency> - <groupId>com.microsoft.azure</groupId> - <artifactId>azure-active-directory-spring-boot-starter</artifactId> - <version>${azure.version}</version> + <groupId>org.opengroup.osdu</groupId> + <artifactId>partition-core</artifactId> + <version>${osdu.partition-core.version}</version> </dependency> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>core-lib-azure</artifactId> + <version>${osdu.corelibazure.version}</version> + </dependency> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>os-core-common</artifactId> + <exclusions> + <exclusion> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-client</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> @@ -41,134 +81,71 @@ <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-client</artifactId> </dependency> - <dependency> - <groupId>com.azure</groupId> - <artifactId>azure-security-keyvault-secrets</artifactId> - <version>4.2.0</version> - </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-jose</artifactId> </dependency> + + <!-- Azure dependencies --> <dependency> - <groupId>com.auth0</groupId> - <artifactId>jwks-rsa</artifactId> - <version>0.12.0</version> + <groupId>com.microsoft.azure</groupId> + <artifactId>azure-spring-boot-metrics-starter</artifactId> </dependency> <dependency> - <groupId>com.azure</groupId> - <artifactId>azure-core-http-netty</artifactId> - <version>1.5.4</version> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> <dependency> <groupId>com.microsoft.azure</groupId> - <artifactId>msal4j</artifactId> - <version>0.5.0-preview</version> + <artifactId>azure-storage</artifactId> + <version>8.6.5</version> </dependency> <dependency> - <groupId>com.nimbusds</groupId> - <artifactId>nimbus-jose-jwt</artifactId> - <version>7.9</version> + <groupId>com.microsoft.azure</groupId> + <artifactId>azure-active-directory-spring-boot-starter</artifactId> </dependency> <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>core-lib-azure</artifactId> - <version>0.0.39</version> - <exclusions> - <exclusion> - <groupId>com.nimbusds</groupId> - <artifactId>nimbus-jose-jwt</artifactId> - </exclusion> - <exclusion> - <groupId>com.microsoft.azure</groupId> - <artifactId>msal4j</artifactId> - </exclusion> - <exclusion> - <groupId>org.opengroup.osdu</groupId> - <artifactId>os-core-common</artifactId> - </exclusion> - <exclusion> - <groupId>com.microsoft.azure</groupId> - <artifactId>applicationinsights-spring-boot-starter</artifactId> - </exclusion> - <exclusion> - <groupId>com.microsoft.azure</groupId> - <artifactId>azure-spring-boot-metrics-starter</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-log4j2</artifactId> - </exclusion> - <exclusion> - <groupId>com.microsoft.azure</groupId> - <artifactId>applicationinsights-logging-log4j2</artifactId> - </exclusion> - </exclusions> + <groupId>com.microsoft.azure</groupId> + <artifactId>msal4j</artifactId> </dependency> + <!-- Other dependencies --> <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>os-core-common</artifactId> - <version>${os-core-common.version}</version> - <exclusions> - <exclusion> - <groupId>org.elasticsearch.client</groupId> - <artifactId>elasticsearch-rest-client</artifactId> - </exclusion> - </exclusions> + <groupId>com.auth0</groupId> + <artifactId>jwks-rsa</artifactId> + <version>${jwks-rsa}</version> </dependency> <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>partition-core</artifactId> - <version>1.0.0</version> + <groupId>com.nimbusds</groupId> + <artifactId>nimbus-jose-jwt</artifactId> + <version>${nimbus-jose-jwt}</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> - <!-- - Override the spring-boot version of these dependencies to the ones - required by the azure-core library. This needs to be done for each - app that depends on this library - --> - <dependency> - <groupId>io.projectreactor.netty</groupId> - <artifactId>reactor-netty</artifactId> - <version>0.9.10.RELEASE</version> - </dependency> - <dependency> - <groupId>io.projectreactor</groupId> - <artifactId>reactor-core</artifactId> - <version>3.3.8.RELEASE</version> - </dependency> - - <dependency> - <groupId>com.microsoft.azure</groupId> - <artifactId>azure-storage</artifactId> - <version>8.6.5</version> - </dependency> - + <!-- Test dependencies --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.12</version> + <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> - <version>2.25.0</version> + <version>${mockito.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito2</artifactId> - <version>2.0.2</version> + <version>${powermock.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> - <version>2.0.2</version> + <version>${powermock.version}</version> <scope>test</scope> </dependency> <dependency> @@ -191,30 +168,6 @@ <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> - - <!-- App Insights dependencies --> - <dependency> - <groupId>com.microsoft.azure</groupId> - <artifactId>applicationinsights-spring-boot-starter</artifactId> - <version>2.6.1</version> - </dependency> - <dependency> - <groupId>com.microsoft.azure</groupId> - <artifactId>azure-spring-boot-metrics-starter</artifactId> - <version>2.3.3</version> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-log4j2</artifactId> - <version>2.3.1.RELEASE</version> - </dependency> - <dependency> - <groupId>com.microsoft.azure</groupId> - <artifactId>applicationinsights-logging-log4j2</artifactId> - <version>2.6.1</version> - </dependency> - - </dependencies> <build> diff --git a/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/AADSecurityConfigTest.java b/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/AADSecurityConfigTest.java index dcfe639002f1b094d8cd8dcfb79976d2d404d6e6..dba07af802f01c2cf68bce3b22d4ed71b955f8a5 100644 --- a/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/AADSecurityConfigTest.java +++ b/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/AADSecurityConfigTest.java @@ -55,12 +55,6 @@ public class AADSecurityConfigTest { } @Test - @Ignore - // temporary disabled because it is failed on build machine, is not reproducible locally - // from logs: 'Server returned HTTP response code: 400 for URL: http://169.254.169.254/... ' - // IP is Azure Instance Metadata Service, why it is reached is not clear from logs (trimmed) - // tried locally to set breakpoint, disable network and logout from azure, I can't reproduce - // don't have time for more investigations now public void testOptions() throws Exception { mockMvc.perform(options("/swagger")) .andExpect(status().is2xxSuccessful()); diff --git a/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/WhoamiControllerTest.java b/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/WhoamiControllerTest.java index ce71a468c137cb19de7da02c2a83d8caa124c618..5d0bf231bafb8c08025f18215fdcbfb6e6b23bd1 100644 --- a/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/WhoamiControllerTest.java +++ b/provider/partition-azure/src/test/java/org/opengroup/osdu/partition/provider/azure/security/WhoamiControllerTest.java @@ -17,43 +17,57 @@ package org.opengroup.osdu.partition.provider.azure.security; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +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.http.MediaType; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; -import static org.mockito.Mockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(PowerMockRunner.class) +import com.microsoft.azure.spring.autoconfigure.aad.AADAppRoleStatelessAuthenticationFilter; +import com.microsoft.azure.spring.autoconfigure.aad.UserPrincipalManager; + +@RunWith(SpringRunner.class) @PrepareForTest(SecurityContextHolder.class) +@SpringBootTest(classes = {WhoamiController.class, AADSecurityConfig.class, + AADAppRoleStatelessAuthenticationFilter.class}) +@WebAppConfiguration public class WhoamiControllerTest { private MockMvc mockMvc; + @Autowired + private WebApplicationContext context; + @MockBean + private UserPrincipalManager userPrincipalManager; + @Before public void setup() { - mockMvc = MockMvcBuilders.standaloneSetup(WhoamiController.class).build(); + mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); } @Test public void whoami() throws Exception { - mockStatic(SecurityContextHolder.class); - - SecurityContext securityContext = mock(SecurityContext.class); - when(securityContext.getAuthentication()).thenReturn(mock(Authentication.class)); - when(SecurityContextHolder.getContext()).thenReturn(securityContext); + Authentication authentication = Mockito.mock(Authentication.class); + SecurityContext securityContext = Mockito.mock(SecurityContext.class); + Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); + SecurityContextHolder.setContext(securityContext); mockMvc.perform(post("/whoami") - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()); + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); } } \ No newline at end of file