diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1e7cff86098bef60c9d5171ba0e09a6b41069523..67606948fc1c96a9fea8234a02713d5814fbc429 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,9 @@ +variables: + OSDU_GCP_APPLICATION_NAME: os-notification + OSDU_GCP_VENDOR: gcp + OSDU_GCP_SERVICE: notification + OSDU_GCP_ENV_VARS: APP_PROJECT=${OSDU_GCP_PROJECT},APP_ENTITLEMENTS=${OSDU_GCP_ENTITLEMENTS_URL},APP_REGISTER=${OSDU_GCP_REGISTER_URL},APP_GOOGLEAUDIENCE=${GOOGLE_AUDIENCE} + include: - project: 'osdu/platform/ci-cd-pipelines' ref: 'master' @@ -14,3 +20,10 @@ include: - project: 'osdu/platform/ci-cd-pipelines' ref: 'master' file: 'scanners/gitlab-ultimate.yml' + + - project: 'osdu/platform/ci-cd-pipelines' + ref: 'master' + file: 'cloud-providers/osdu-gcp-cloudrun.yml' + +osdu-gcp-test: + allow_failure: true diff --git a/provider/notification-azure/lombok.config b/provider/notification-azure/lombok.config new file mode 100644 index 0000000000000000000000000000000000000000..830508fe89ceb1ad0507662c9891484eb99f3988 --- /dev/null +++ b/provider/notification-azure/lombok.config @@ -0,0 +1,3 @@ +# The file makes Jacoco understand that the Lambok's @Data's creation, should not be accounted for Jacoco's analysis. +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true \ No newline at end of file diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/cache/JwtCache.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/cache/JwtCache.java index 4c3dffbc9348b8955843476b3207dd2737801d06..8ffe8fdda9bfe8946b3c915783a3213cde490609 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/cache/JwtCache.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/cache/JwtCache.java @@ -19,11 +19,8 @@ import org.opengroup.osdu.core.common.model.search.IdToken; import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; import org.opengroup.osdu.notification.provider.azure.util.AppProperties; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import javax.inject.Named; - @Component public class JwtCache implements IJwtCache<String, IdToken> { private VmCache<String, IdToken> cache; @@ -31,7 +28,9 @@ public class JwtCache implements IJwtCache<String, IdToken> { // Azure service account id_token can be requested only for 1 hr private final static int EXPIRED_AFTER = 59; - public JwtCache(@Named("MAX_CACHE_VALUE_SIZE") String cacheSize){ + @Autowired + public JwtCache(AppProperties appProperties){ + String cacheSize = appProperties.getMaxCacheSize(); cache = new VmCache<>(EXPIRED_AFTER * 60, Integer.parseInt(cacheSize)); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/security/SecurityConfig.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/security/SecurityConfig.java index 5c7b8c02943e94e35c4ec110d4251a016a836bfd..af924979e88863b67ec943824ac1a7c4a6d6903e 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/security/SecurityConfig.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/security/SecurityConfig.java @@ -14,37 +14,17 @@ package org.opengroup.osdu.notification.provider.azure.security; -import com.microsoft.azure.spring.autoconfigure.aad.AADAppRoleStatelessAuthenticationFilter; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Autowired - private AADAppRoleStatelessAuthenticationFilter appRoleAuthFilter; - @Override - protected void configure(HttpSecurity httpSecurity) throws Exception { - httpSecurity - .csrf().disable() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER) - .and() - .authorizeRequests() - .antMatchers("/", - "/swagger", - "/v2/api-docs", - "/swagger-resources/**", - "/swagger-ui.html", - "/webjars/**").permitAll() - .anyRequest().authenticated() - .and() - .addFilterBefore(appRoleAuthFilter, UsernamePasswordAuthenticationFilter.class); + public void configure(HttpSecurity http) throws Exception { + http.httpBasic().disable().csrf().disable(); } } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java index 32f048a4696abb2945f66091a1505a5e259eda2a..f1bd15890fd4eba7503faaa7047447248aba2038 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java @@ -17,16 +17,12 @@ package org.opengroup.osdu.notification.provider.azure.util; import com.azure.security.keyvault.secrets.SecretClient; import com.azure.security.keyvault.secrets.models.KeyVaultSecret; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Component; +import org.springframework.context.annotation.Configuration; -import javax.inject.Named; - -@Component +@Configuration public class AppProperties implements IAppProperties { @Value("${app.entitlements}") @@ -44,15 +40,9 @@ public class AppProperties implements IAppProperties { @Value("${aad.oboApi}") private String aadOboAPI; - @Value("${app.maxCacheSize") - private String CacheValueSize; - @Autowired private SecretClient secretClient; - @Autowired - private JaxRsDpsLog logger; - private String authURL; private String authClientID; @@ -97,8 +87,6 @@ public class AppProperties implements IAppProperties { return this.authURL; } - @Bean - @Named("MAX_CACHE_VALUE_SIZE") public String getMaxCacheSize() { return maxCacheSize; } @@ -106,13 +94,11 @@ public class AppProperties implements IAppProperties { private String getKeyVaultSecret(SecretClient kv, String secretName) { KeyVaultSecret secret = kv.getSecret(secretName); if (secret == null) { - logger.error(String.format("Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); throw new IllegalStateException(String.format("No secret found with name %s", secretName)); } String secretValue = secret.getValue(); if (secretValue == null) { - logger.error(String.format("Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); throw new IllegalStateException(String.format( "Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java index abf78fedad1433d7694cdcc4918c8a370d393bb2..27232c16675d8466a0d94918c984f6e3951b0d47 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java @@ -14,20 +14,17 @@ package org.opengroup.osdu.notification.provider.azure.util; -import lombok.SneakyThrows; import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; import org.springframework.stereotype.Component; - -import javax.naming.AuthenticationNotSupportedException; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; @Component public class GoogleServiceAccountImpl implements IGoogleServiceAccount { - @SneakyThrows @Override public String getIdToken(String keyString, String audience) { // TODO : Check if it is to be supported - throw new AuthenticationNotSupportedException(); + throw new NotImplementedException(); } } diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/cache/JWTCacheTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/cache/JWTCacheTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7a2a35188c45146d16f7791d9ca0209b2a0ec327 --- /dev/null +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/cache/JWTCacheTest.java @@ -0,0 +1,158 @@ +// Copyright © Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.notification.cache; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.model.search.IdToken; +import org.opengroup.osdu.notification.provider.azure.cache.JwtCache; +import org.opengroup.osdu.notification.provider.azure.util.AppProperties; + +import static org.junit.Assert.fail; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +@RunWith(MockitoJUnitRunner.class) +public class JWTCacheTest { + private static String testTenantName = "testTenant"; + + @Mock + private AppProperties appProperties; + + @Mock + private IdToken idToken; + + private JwtCache sut; + + @Before + public void setup() { + initMocks(this); + when(appProperties.getMaxCacheSize()).thenReturn("10"); + sut = new JwtCache(appProperties); + } + + @Test + public void should_throwWhenCacheSizeIsInvalid_JwtCache(){ + // Set up + when(appProperties.getMaxCacheSize()).thenReturn(null); + try { + + // Act + sut = new JwtCache(appProperties); + + // Assert + fail("Should throw exception"); + } catch (Exception exception){ + Assertions.assertEquals(exception.getClass(), NumberFormatException.class); + } + + // Set Up + when(appProperties.getMaxCacheSize()).thenReturn(""); + try { + + // Act + sut = new JwtCache(appProperties); + + // Assert + fail("Should throw exception"); + } catch (Exception exception){ + Assertions.assertEquals(exception.getClass(), NumberFormatException.class); + } + + // Set Up + when(appProperties.getMaxCacheSize()).thenReturn("-1"); + try { + + // Act + sut = new JwtCache(appProperties); + + // Assert + fail("Should throw exception"); + } catch (Exception exception){ + Assertions.assertEquals(exception.getClass(), IllegalArgumentException.class); + } + } + + @Test + public void should_return_getPut(){ + // Act + IdToken observed = sut.get("test Tenant"); + + // Assert + Assert.assertNull(observed); + + // Set Up + sut.put(testTenantName, idToken); + + // Act + observed = sut.get(testTenantName); + + // Asset + Assert.assertEquals(idToken, observed); + + // Act + observed = sut.get("notInCache"); + + // Assert + Assert.assertNull(observed); + + try { + // Act + sut.put(null, null); + } catch (Exception e){ + Assert.assertEquals(NullPointerException.class, e.getClass()); + } + } + + @Test + public void should_returnAppropriate_delete() { + // Set Up + sut.put(testTenantName, idToken); + + // Act + sut.delete(testTenantName); + + // Assert + IdToken observed = sut.get(testTenantName); + Assert.assertNull(observed); + try { + + // Act + sut.delete("notInCache"); + + // Assert + } catch (Exception e){ + Assert.assertEquals(NullPointerException.class, e.getClass()); + } + } + + @Test + public void should_returnAppropriate_clearAll() { + // Set Up + sut.put(testTenantName, idToken); + + // Act + sut.clearAll(); + + // Assert + IdToken observed = sut.get(testTenantName); + Assert.assertNull(observed); + } +} diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/di/ServiceAccountJwtClientFactoryTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/di/ServiceAccountJwtClientFactoryTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ad50951406d501ecd89b1222aa4cf62081893821 --- /dev/null +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/di/ServiceAccountJwtClientFactoryTest.java @@ -0,0 +1,56 @@ +// Copyright © Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.notification.di; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.notification.provider.azure.di.ServiceAccountJwtClientFactory; +import org.opengroup.osdu.notification.provider.azure.util.ServiceAccountJwtAzureClientImpl; + +import static org.junit.Assert.fail; +import static org.mockito.MockitoAnnotations.initMocks; + +public class ServiceAccountJwtClientFactoryTest { + + @InjectMocks + ServiceAccountJwtClientFactory sut; + + @Before + public void init() { + initMocks(this); + } + + @Test + public void testGettingInstance() { + try { + // Act + Class<?> objectType = sut.getObjectType(); + // Assert + Assert.assertEquals(IServiceAccountJwtClient.class, objectType); + + // Act + IServiceAccountJwtClient serviceAccountJwtClient = sut.createInstance(); + // Assert + Assert.assertNotNull("Should not be null", serviceAccountJwtClient); + Assert.assertEquals(serviceAccountJwtClient.getClass(), ServiceAccountJwtAzureClientImpl.class); + } catch (Exception exception) { + fail("Should not throw this exception" + exception.getMessage()); + } + } + +} \ No newline at end of file diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java index bce964c17c1fe8f000a66c41954a63c792618285..453e174b8daa8ff9d25dab85cbbab3f168edf711 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java @@ -17,6 +17,7 @@ package org.opengroup.osdu.notification.provider.azure; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; @@ -31,6 +32,7 @@ import java.io.StringReader; import java.util.Map; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -113,13 +115,13 @@ public class EventGridRequestBodyExtractorTest { " \"eventType\": \"recordInserted\",\n" + " \"subject\": \"myapp/vehicles/motorcycles\",\n" + " \"data\": {\n" + - " \"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n" + + " \"data\": \"dGVzdA==\",\n" + " \"messageId\": \"136969346945\"\n" + " },\n" + " \"dataVersion\": \"1.0\",\n" + " \"metadataVersion\": \"1\",\n" + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + - " \"topic\": \"/subscriptions/c99e2bf3-1777-412b-baba-d823676589c2/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + " }]"; BufferedReader reader = new BufferedReader(new StringReader(requestRootWithoutAttributes)); when(this.httpServletRequest.getReader()).thenReturn(reader); @@ -154,7 +156,7 @@ public class EventGridRequestBodyExtractorTest { " \"dataVersion\": \"1.0\",\n" + " \"metadataVersion\": \"1\",\n" + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + - " \"topic\": \"/subscriptions/c99e2bf3-1777-412b-baba-d823676589c2/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + " }]"; BufferedReader reader = new BufferedReader(new StringReader(requestRootWithoutData)); when(this.httpServletRequest.getReader()).thenReturn(reader); @@ -183,13 +185,13 @@ public class EventGridRequestBodyExtractorTest { " \"attributes\": {\n" + " \"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\"\n" + " },\n" + - " \"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n"+ + " \"data\": \"dGVzdA==\",\n"+ " \"messageId\": \"136969346945\"\n" + " },\n" + " \"dataVersion\": \"1.0\",\n" + " \"metadataVersion\": \"1\",\n" + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + - " \"topic\": \"/subscriptions/c99e2bf3-1777-412b-baba-d823676589c2/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + " }]"; BufferedReader reader = new BufferedReader(new StringReader(requestRootWithoutDataPartitionId)); when(this.httpServletRequest.getReader()).thenReturn(reader); @@ -219,16 +221,16 @@ public class EventGridRequestBodyExtractorTest { " \"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" + " \"data-partition-id\": \"opendes \"\n" + " },\n" + - " \"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n" + + " \"data\": \"dGVzdA==\",\n" + " \"messageId\": \"136969346945\"\n" + " },\n" + " \"dataVersion\": \"1.0\",\n" + " \"metadataVersion\": \"1\",\n" + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + - " \"topic\": \"/subscriptions/c99e2bf3-1777-412b-baba-d823676589c2/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + " }]"; - String expectedData = "[{\"kind\":\"testkind\",\"id\":\"testid\",\"operationtype\":\"create\"},{\"kind\":\"testkind2\",\"id\":\"testid2\",\"operationtype\":\"update\"}]"; + String expectedData = "test"; BufferedReader reader = new BufferedReader(new StringReader(vaidRequestRoot)); when(this.httpServletRequest.getReader()).thenReturn(reader); @@ -253,13 +255,13 @@ public class EventGridRequestBodyExtractorTest { " \"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" + " \"data-partition-id\": \"opendes\"\n" + " },\n" + - " \"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n" + + " \"data\": \"dGVzdA==\",\n" + " \"messageId\": \"136969346945\"\n" + " },\n" + " \"dataVersion\": \"1.0\",\n" + " \"metadataVersion\": \"1\",\n" + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + - " \"topic\": \"/subscriptions/c99e2bf3-1777-412b-baba-d823676589c2/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + " }]"; BufferedReader reader = new BufferedReader(new StringReader(vaidRequestRoot)); when(this.httpServletRequest.getReader()).thenReturn(reader); @@ -301,4 +303,110 @@ public class EventGridRequestBodyExtractorTest { // Assert Assert.assertEquals(observedResponse, expectedResponse); } + + @Test + public void should_throwWhenNotHandshakeRequest_getHandshakeResponse() throws IOException { + // Set up + String validHandshakeRequestRoot = + "[{\n" + + " \"id\": \"2425\",\n" + + " \"eventType\": \"recordInserted\",\n" + + " \"subject\": \"myapp/vehicles/motorcycles\",\n" + + " \"data\": {\n" + + " \"attributes\": {\n" + + " \"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" + + " \"data-partition-id\": \"opendes\"\n" + + " },\n" + + " \"data\": \"dGVzdA==\",\n" + + " \"messageId\": \"136969346945\"\n" + + " },\n" + + " \"dataVersion\": \"1.0\",\n" + + " \"metadataVersion\": \"1\",\n" + + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " }]"; + String expectedResponse = null; + BufferedReader reader = new BufferedReader(new StringReader(validHandshakeRequestRoot)); + when(this.httpServletRequest.getReader()).thenReturn(reader); + sut = new EventGridRequestBodyExtractor(httpServletRequest, log); + + // Act + String observedResponse = this.sut.getValidationCodeForHandshake(); + + // Assert + Assert.assertNull(observedResponse); + } + + @Test + public void should_throwWhenHandshakeRequest_extractDataFromRequestBody() throws IOException { + String inVaidRequestRoot = " [{\n" + + " \"id\": \"testId\",\n" + + " \"topic\": \"testTopic\",\n" + + " \"subject\": \"\",\n" + + " \"data\": {\n" + + " \"validationCode\": \"testValidationCode\",\n" + + " \"validationUrl\": \"testURL\"\n" + + " },\n" + + " \"eventType\": \"Microsoft.EventGrid.SubscriptionValidationEvent\",\n" + + " \"eventTime\": \"2020-08-14T11:18:55.9278057Z\",\n" + + " \"metadataVersion\": \"1\",\n" + + " \"dataVersion\": \"2\"\n" + + " }]"; + BufferedReader reader = new BufferedReader(new StringReader(inVaidRequestRoot)); + when(this.httpServletRequest.getReader()).thenReturn(reader); + sut = new EventGridRequestBodyExtractor(httpServletRequest, log); + + // Act + Map<String, String> observedAttributes = this.sut.extractAttributesFromRequestBody(); + + Assert.assertNull(observedAttributes); + } + + @Test + public void should_returnNotificationId_extractNotificationIdFromRequestBody() throws IOException { + // Set Up + String vaidRequestRoot = "[{\n" + + " \"id\": \"2425\",\n" + + " \"eventType\": \"recordInserted\",\n" + + " \"subject\": \"myapp/vehicles/motorcycles\",\n" + + " \"data\": {\n" + + " \"attributes\": {\n" + + " \"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" + + " \"data-partition-id\": \"opendes\"\n" + + " },\n" + + " \"data\": \"dGVzdA==\",\n" + + " \"messageId\": \"136969346945\"\n" + + " },\n" + + " \"dataVersion\": \"1.0\",\n" + + " \"metadataVersion\": \"1\",\n" + + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " }]"; + BufferedReader reader = new BufferedReader(new StringReader(vaidRequestRoot)); + when(this.httpServletRequest.getReader()).thenReturn(reader); + when(this.httpServletRequest.getHeader("Aeg-Subscription-Name")).thenReturn("NotificationId"); + sut = new EventGridRequestBodyExtractor(httpServletRequest, log); + + // Act + String observed = sut.extractNotificationIdFromRequestBody(); + + // Assert + Assert.assertEquals("NotificationId", observed); + + // Set Up + when(this.httpServletRequest.getHeader("Aeg-Subscription-Name")).thenReturn(null); + + try { + // Act + this.sut.extractNotificationIdFromRequestBody(); + + // Asset + fail("Should Throw Exception"); + } catch (AppException appException){ + Assert.assertEquals(HttpStatus.BAD_REQUEST.value(), appException.getError().getCode()); + Assert.assertEquals("Subscription ID not found", appException.getError().getMessage()); + } catch (Exception exception) { + fail("Should Throw AppException"); + } + } } diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTests.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTest.java similarity index 71% rename from provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTests.java rename to provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTest.java index da92ed9550a5a1d6e2df79bac29884a2478958dc..578a36d1899921f1587f2af0d300f8bf8b6834fa 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTests.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTest.java @@ -20,7 +20,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.notification.provider.azure.util.AppProperties; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -28,7 +27,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.doReturn; import static org.mockito.MockitoAnnotations.initMocks; -public class AppPropertiesTests { +public class AppPropertiesTest { + + @InjectMocks + private AppProperties sut; @Mock private SecretClient kv; @@ -36,12 +38,6 @@ public class AppPropertiesTests { @Mock private KeyVaultSecret secret; - @Mock - private JaxRsDpsLog logger; - - @InjectMocks - private AppProperties sut; - @Before public void init() { initMocks(this); @@ -50,30 +46,13 @@ public class AppPropertiesTests { @Test public void should_throwWhenSecretNameIsNull_getKeyVaultSecret() { // Set-Up - doReturn(null).when(kv).getSecret("secret-name"); + doReturn(null).when(kv).getSecret("app-dev-sp-password"); // Act - IllegalStateException exception = assertThrows(IllegalStateException.class, () ->{ - sut.getAuthClientSecret(); - }); + IllegalStateException exception = assertThrows(IllegalStateException.class, () -> sut.getAuthClientSecret()); // Assert - assertEquals("No secret found with name secret-name", exception.getMessage()); - } - - @Test - public void should_throwWhenSecretIsMissing_getKeyVaultSecret() { - // Set-Up - doReturn(null).when(secret).getValue(); - doReturn(secret).when(kv).getSecret("secret-name"); - - // Act - IllegalStateException exception = assertThrows(IllegalStateException.class, () ->{ - sut.getAuthClientSecret(); - }); - - // Assert - assertEquals("Secret unexpectedly missing from KeyVault response for secret with name secret-name", exception.getMessage()); + assertEquals("No secret found with name app-dev-sp-password", exception.getMessage()); } @Test @@ -105,14 +84,13 @@ public class AppPropertiesTests { @Test public void should_returnRightAuthURL_getCosmosKey() { // Set-Up - doReturn("cosmos-endpoint-secret").when(secret).getValue(); + doReturn("test").when(secret).getValue(); doReturn(secret).when(kv).getSecret("app-dev-sp-tenant-id"); // Act String secretValue = sut.getAuthURL(); // Assert - assertEquals( "cosmos-endpoint-secret", secretValue); + assertEquals( "https://login.microsoftonline.com/test/oauth2/token/", secretValue); } - } diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java index 4c05c9aa7c5386d362b3dbdf91e1fb3c3f62cab0..4280d1d1b562ee1969d4a5e771d02fa86a591d5f 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java @@ -20,7 +20,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.notification.provider.azure.util.AzureCosmosProperties; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -39,9 +38,6 @@ public class AzureCosmosPropertiesTest { @Mock private KeyVaultSecret secret; - @Mock - private JaxRsDpsLog logger; - @Before public void init() { initMocks(this); @@ -53,9 +49,7 @@ public class AzureCosmosPropertiesTest { doReturn(null).when(kv).getSecret("secret-name"); // Act - IllegalStateException exception = assertThrows(IllegalStateException.class, () ->{ - sut.cosmosKey(kv); - }); + IllegalStateException exception = assertThrows(IllegalStateException.class, () -> sut.cosmosKey(kv)); // Assert assertEquals("No secret found with name cosmos-primary-key", exception.getMessage()); diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java index 606e68bdc94f71a1031a7f294269f6482062c50c..53eb8361fbb699f009cc4450e856e73e67e46f52 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java @@ -26,11 +26,11 @@ import org.opengroup.osdu.notification.provider.azure.util.AppProperties; import org.opengroup.osdu.notification.provider.azure.util.AzureServiceAccountValidatorImpl; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; -@RunWith(MockitoJUnitRunner.class) public class AzureServiceAccountValidatorImplTest { private static String invalidAADClientID = "testInvalidAADClientID"; - private static String invalidJWT = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJkdW1teUBkdW1teS5jb20iLCJpc3MiOiJkdW1teUBkdW1teS5jb20iLCJhdWQiOiJkdW1teS5kdW1teS5jb20iLCJpYXQiOjE1NTYxMzcyNzMsImV4cCI6MTU1NjIzMDk3OSwicHJvdmlkZXIiOiJkdW1teS5jb20iLCJjbGllbnQiOiJkdW1teS5jb20iLCJ1c2VyaWQiOiJkdW1teXRlc3Rlci5jb20iLCJlbWFpbCI6ImR1bW15dGVzdGVyLmNvbSIsImF1dGh6IjoiIiwibGFzdG5hbWUiOiJkdW1teSIsImZpcnN0bmFtZSI6ImR1bW15IiwiY291bnRyeSI6IiIsImNvbXBhbnkiOiIiLCJqb2J0aXRsZSI6IiIsInN1YmlkIjoiZHVtbXlpZCIsImlkcCI6ImR1bW15IiwiaGQiOiJkdW1teS5jb20iLCJkZXNpZCI6ImR1bW15aWQiLCJjb250YWN0X2VtYWlsIjoiZHVtbXlAZHVtbXkuY29tIiwianRpIjoiNGEyMWYyYzItZjU5Yy00NWZhLTk0MTAtNDNkNDdhMTg4ODgwIn0.nkiyKtfXXxAlC60iDjXuB2EAGDfZiVglP-CyU1T4etc"; + private static String invalidJWT = "invalidJWT"; @Mock private AppProperties appProperties; @@ -41,6 +41,7 @@ public class AzureServiceAccountValidatorImplTest { @Before public void setup() { + initMocks(this); when(this.appProperties.getAadClientID()).thenReturn(invalidAADClientID); } diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccountImpTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccountImpTest.java new file mode 100644 index 0000000000000000000000000000000000000000..00996ddc1fda3d387c264013be80716ebc15eba4 --- /dev/null +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccountImpTest.java @@ -0,0 +1,42 @@ +// Copyright © Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.notification.util; + +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.opengroup.osdu.notification.provider.azure.util.GoogleServiceAccountImpl; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import static org.junit.Assert.fail; + +public class GoogleServiceAccountImpTest { + + @Test + public void should_throw_getIdToken() { + // Setup + String audience = "testAudience"; + String keyString = "keyString"; + + try { + // Act + new GoogleServiceAccountImpl().getIdToken(keyString, audience); + + // Assert + fail("Should throw exception"); + } catch (Exception e) { + Assertions.assertEquals(e.getClass(), NotImplementedException.class); + } + } +} diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java index 6951d39a9653b1309709c3b0091782eb67635e0f..f567cd985334216cba0ebbed41e04625a904e4f5 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java @@ -43,8 +43,7 @@ import static org.mockito.Mockito.when; public class ServiceAccountClientImplTest { final String tenantName = "Test Tenant"; - final String validToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJkdW1teUBkdW1teS5jb20iLCJpc3MiOiJkdW1teUBkdW1teS5jb20iLCJhdWQiOiJkdW1teS5kdW1teS5jb20iLCJpYXQiOjE1NTYxMzcyNzMsImV4cCI6MTU1NjIzMDk3OSwicHJvdmlkZXIiOiJkdW1teS5jb20iLCJjbGllbnQiOiJkdW1teS5jb20iLCJ1c2VyaWQiOiJkdW1teXRlc3Rlci5jb20iLCJlbWFpbCI6ImR1bW15dGVzdGVyLmNvbSIsImF1dGh6IjoiIiwibGFzdG5hbWUiOiJkdW1teSIsImZpcnN0bmFtZSI6ImR1bW15IiwiY291bnRyeSI6IiIsImNvbXBhbnkiOiIiLCJqb2J0aXRsZSI6IiIsInN1YmlkIjoiZHVtbXlpZCIsImlkcCI6ImR1bW15IiwiaGQiOiJkdW1teS5jb20iLCJkZXNpZCI6ImR1bW15aWQiLCJjb250YWN0X2VtYWlsIjoiZHVtbXlAZHVtbXkuY29tIiwianRpIjoiNGEyMWYyYzItZjU5Yy00NWZhLTk0MTAtNDNkNDdhMTg4ODgwIn0.nkiyKtfXXxAlC60iDjXuB2EAGDfZiVglP-CyU1T4etc"; - final String invalidToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJkdW1teUBkdW1teS5jb20iLCJpc3MiOiJkdW1teUBkdW1teS5jb20iLCJhdWQiOiJkdW1teS5kdW1teS5jb20iLCJpYXQiOjE1NTYxMzcyNzMsImV4cCI6MTU1NjIzMDk3OSwicHJvdmlkZXIiOiJkdW1teS5jb20iLCJjbGllbnQiOiJkdW1teS5jb20iLCJ1c2VyaWQiOiJkdW1teXRlc3Rlci5jb20iLCJlbWFpbCI6ImR1bW15dGVzdGVyLmNvbSIsImF1dGh6IjoiIiwibGFzdG5hbWUiOiJkdW1teSIsImZpcnN0bmFtZSI6ImR1bW15IiwiY291bnRyeSI6IiIsImNvbXBhbnkiOiIiLCJqb2J0aXRsZSI6IiIsInN1YmlkIjoiZHVtbXlpZCIsImlkcCI6ImR1bW15IiwiaGQiOiJkdW1teS5jb20iLCJkZXNpZCI6ImR1bW15aWQiLCJjb250YWN0X2VtYWlsIjoiZHVtbXlAZHVtbXkuY29tIiwianRpIjoiNGEyMWYyYzItZjU5Yy00NWZhLTk0MTAtNDNkNDdhMTg4ODgwIn0.nkiyKtfXXxAlC60iDjXuB2EAGDfZiVglP-CyU1T4etc"; + final String validToken = "validToken"; @Mock private ITenantFactory tenantInfoServiceProvider; diff --git a/provider/notification-gcp/cloudbuild/Dockerfile.cloudbuild b/provider/notification-gcp/cloudbuild/Dockerfile.cloudbuild new file mode 100644 index 0000000000000000000000000000000000000000..add6982053a6b2d7caa76087c44e74fb0f73ce3f --- /dev/null +++ b/provider/notification-gcp/cloudbuild/Dockerfile.cloudbuild @@ -0,0 +1,12 @@ +# Use the official AdoptOpenJDK for a base image. +# https://hub.docker.com/_/openjdk +FROM openjdk:8-slim +WORKDIR /app +ARG PROVIDER_NAME +ENV PROVIDER_NAME $PROVIDER_NAME +ARG PORT +ENV PORT $PORT +# Copy the jar to the production image from the builder stage. +COPY provider/notification-${PROVIDER_NAME}/target/notification-${PROVIDER_NAME}-*-spring-boot.jar notification-${PROVIDER_NAME}.jar +# Run the web service on container startup. +CMD java -Djava.security.egd=file:/dev/./urandom -Dserver.port=${PORT} -jar /app/notification-${PROVIDER_NAME}.jar diff --git a/provider/notification-gcp/cloudbuild/cloudbuild.yaml b/provider/notification-gcp/cloudbuild/cloudbuild.yaml new file mode 100644 index 0000000000000000000000000000000000000000..43513ffc22854357bd847b8e4baafa2ad6ffd455 --- /dev/null +++ b/provider/notification-gcp/cloudbuild/cloudbuild.yaml @@ -0,0 +1,30 @@ +# Copyright 2020 Google LLC +# Copyright 2017-2019, Schlumberger +# Copyright 2020 EPAM +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +steps: + - name: 'gcr.io/cloud-builders/docker' + args: [ + 'build', + '--build-arg', 'PROVIDER_NAME=${_PROVIDER_NAME}', + '--build-arg', 'PORT=${_PORT}', + '-t', 'gcr.io/$PROJECT_ID/os-notification/notification-${_PROVIDER_NAME}:${_SHORT_SHA}', + '-t', 'gcr.io/$PROJECT_ID/os-notification/notification-${_PROVIDER_NAME}:latest', + '-f', 'provider/notification-${_PROVIDER_NAME}/cloudbuild/Dockerfile.cloudbuild', + '.' + ] + +images: + - 'gcr.io/$PROJECT_ID/os-notification/notification-${_PROVIDER_NAME}' diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java index 3dbea65398b173700bdb8d677b9b91b94abcece7..74f6d6abb047b6fdae83c68f506a4cdb63ce40e5 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java @@ -1,17 +1,20 @@ /* - * Copyright 2017-2020, Schlumberger + + * Copyright 2020 IBM Corp. All Rights Reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + + */ package org.opengroup.osdu.notification.provider.ibm.security; @@ -24,11 +27,17 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity httpSecurity) throws Exception { - httpSecurity - .httpBasic().disable() - .csrf().disable(); //disable default authN. AuthN handled by endpoints proxy - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests() + .antMatchers("/test/challenge/**", + "/v1/api-docs", + "/configuration/ui", + "/swagger-resources/**", + "/configuration/security", + "/swagger-ui.html", + "/webjars/**") + .permitAll().anyRequest().authenticated().and().oauth2ResourceServer().jwt(); + } + } \ No newline at end of file diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java index 5a492f2e0047855f5bf2b37a5b63356ea98927d9..7d4384f576c0da7f1c5a1f746703d755843ff0a0 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java @@ -34,7 +34,7 @@ public class IBMServiceAccountValidatorImpl implements IServiceAccountValidator //call isValidServiceAccount() // Check whether IBM have to implement the service account verification for PubSub Role // Marking it to return true, for the integration tests. - return true; + return false; } @Override diff --git a/testing/notification-test-ibm/pom.xml b/testing/notification-test-ibm/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..c34117e9775c4592cbc327398016eb9edc2418c5 --- /dev/null +++ b/testing/notification-test-ibm/pom.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2020 IBM Corp. All Rights Reserved. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<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"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.opengroup.osdu</groupId> + <artifactId>notification-test-ibm</artifactId> + <version>1.0-SNAPSHOT</version> + <name>notification-test-ibm</name> + <description>Integration tests IBM for notification</description> + <packaging>jar</packaging> + + <properties> + <java.version>8</java.version> + <maven.compiler.target>${java.version}</maven.compiler.target> + <maven.compiler.source>${java.version}</maven.compiler.source> + <os-core-lib-ibm.version>0.3.8-SNAPSHOT</os-core-lib-ibm.version> + </properties> + + <repositories> + <repository> + <id>${gitlab-server}</id> + <url>https://community.opengroup.org/api/v4/groups/17/-/packages/maven</url> + </repository> + </repositories> + + <distributionManagement> + <repository> + <id>${gitlab-server}</id> + <url>https://community.opengroup.org/api/v4/projects/143/packages/maven</url> + </repository> + <snapshotRepository> + <id>${gitlab-server}</id> + <url>https://community.opengroup.org/api/v4/projects/143/packages/maven</url> + </snapshotRepository> + </distributionManagement> + + <dependencies> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>os-core-lib-ibm</artifactId> + <version>${os-core-lib-ibm.version}</version> + </dependency> + <dependency> + <groupId>org.opengroup.osdu.notification</groupId> + <artifactId>notification-test-core</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>os-core-common</artifactId> + <version>0.3.6</version> + </dependency> + + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + </dependency> + </dependencies> + +</project> diff --git a/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointGSA.java b/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointGSA.java new file mode 100644 index 0000000000000000000000000000000000000000..789fc351f66f1f137b387f971d6e6031c6656f4e --- /dev/null +++ b/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointGSA.java @@ -0,0 +1,71 @@ +package org.opengroup.osdu.notification.api; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.opengroup.osdu.notification.util.Config; +import org.opengroup.osdu.notification.util.IBMTestUtils; +import org.opengroup.osdu.notification.util.RestDescriptor; + +import com.sun.jersey.api.client.ClientResponse; + +public class TestPubsubEndpointGSA extends PubsubEndpointGSATests { + + private static final IBMTestUtils gcpTestUtils = new IBMTestUtils(); + + + @BeforeClass + public static void classSetup() throws Exception { + PubsubEndpointGSATests.classSetup(gcpTestUtils.getOpsToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new IBMTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } + + + @Override + public void should_return307_when_makingHttpRequest() throws Exception { + // No implementation for GSA in IBM + } + + @Override + public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception { + // No implementation for GSA in IBM + } + + @Override + public void should_return20X_when_usingCredentialsWithOpsPermission() throws Exception{ + + } + + @Override + public void should_returnOk_when_makingHttpOptionsRequest() throws Exception{ + + } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + + ClientResponse response = descriptor.run(getArg(), ""); + assertEquals(error( response.getEntity(String.class)), 401, response.getStatus()); + + } + + +} \ No newline at end of file diff --git a/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java b/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java new file mode 100644 index 0000000000000000000000000000000000000000..c0894c1c3e53d3f5523e5a7ce9df9a83d5ef434c --- /dev/null +++ b/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java @@ -0,0 +1,44 @@ +package org.opengroup.osdu.notification.api; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.opengroup.osdu.notification.util.Config; +import org.opengroup.osdu.notification.util.IBMTestUtils; +import org.opengroup.osdu.notification.util.RestDescriptor; +import org.opengroup.osdu.notification.util.TestUtils; + +import com.sun.jersey.api.client.ClientResponse; + +public class TestPubsubEndpointHMAC extends PubsubEndpointHMACTests { + + @BeforeClass + public static void classSetup() throws Exception { + PubsubEndpointHMACTests.classSetup(); + } + + @AfterClass + public static void classTearDown() throws Exception { + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new IBMTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken()throws Exception{ + ClientResponse response = descriptor.run(getArg(), ""); + assertEquals(error( response.getEntity(String.class)), 401, response.getStatus()); + } +} \ No newline at end of file diff --git a/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/util/IBMTestUtils.java b/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/util/IBMTestUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..b42eada47b8f625a48f48b6af0ac08b202f7aa46 --- /dev/null +++ b/testing/notification-test-ibm/src/test/java/org/opengroup/osdu/notification/util/IBMTestUtils.java @@ -0,0 +1,49 @@ +package org.opengroup.osdu.notification.util; + +import org.opengroup.osdu.core.ibm.util.IdentityClient; + +import com.google.common.base.Strings; + +public class IBMTestUtils extends TestUtils { + + public IBMTestUtils() { + + } + + @Override + public synchronized String getOpsToken() throws Exception { + if (Strings.isNullOrEmpty(opsToken)) { + opsToken=IdentityClient.getTokenForUserWithAccess(); + } + return "Bearer " + opsToken; + } + + @Override + public synchronized String getAdminToken() throws Exception { + if(Strings.isNullOrEmpty(adminToken)) { + adminToken = IdentityClient.getTokenForUserWithAdminsAccess(); + } + return "Bearer " + adminToken; + + } + + @Override + public synchronized String getEditorToken() throws Exception { + if(Strings.isNullOrEmpty(editorToken)) { + editorToken = IdentityClient.getTokenForUserWithEditorsAccess(); + } + return "Bearer " + editorToken; + + } + + @Override + public synchronized String getNoAccessToken() throws Exception { + if(Strings.isNullOrEmpty(noAccessToken)) { + noAccessToken = IdentityClient.getTokenForUserWithNoAccess(); + } + + return "Bearer " + noAccessToken; + + } + +}