diff --git a/testing/notification-test-gcp/pom.xml b/testing/notification-test-gcp/pom.xml index ef6c4b850d626340c7532f2abe11ddd50655678c..a830652b5f463d0cc1157a7aa0a7485c34125142 100644 --- a/testing/notification-test-gcp/pom.xml +++ b/testing/notification-test-gcp/pom.xml @@ -27,7 +27,6 @@ <relativePath>../pom.xml</relativePath> </parent> - <groupId>org.opengroup.osdu</groupId> <artifactId>notification-test-gcp</artifactId> <version>1.0-SNAPSHOT</version> <name>notification-test-gcp</name> @@ -51,8 +50,16 @@ <artifactId>os-core-common</artifactId> <version>0.3.6</version> </dependency> - - + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.8</version> + </dependency> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>core-test-lib-gcp</artifactId> + <version>0.0.2</version> + </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> diff --git a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java index 55f7a6710483ddb023fd8577c6ec0b3ca93249d8..639eeecb1e1c3084fbcc4256fce4b0cd7acfe909 100644 --- a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java +++ b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java @@ -1,7 +1,9 @@ package org.opengroup.osdu.notification.util; import com.google.common.base.Strings; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class GCPTestUtils extends TestUtils { public GCPTestUtils() { @@ -41,12 +43,13 @@ public class GCPTestUtils extends TestUtils { } private String getToken(String testerEnvVar) throws Exception { - String serviceAccountFile = System.getProperty(testerEnvVar, System.getenv(testerEnvVar)); + log.info("Get {} credentials", testerEnvVar); + String serviceAccountValue = System.getProperty(testerEnvVar, System.getenv(testerEnvVar)); String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE", System.getenv("INTEGRATION_TEST_AUDIENCE")); if (Strings.isNullOrEmpty(audience)) { audience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com"; } - String token = new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience); + String token = new GoogleServiceAccount(serviceAccountValue).getAuthToken(audience); return "Bearer " + token; } } diff --git a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java index 132ff38b89f9c78139805c7f46262c8e5de22096..a7540b1a7bc70caca2d12843b1322cef2f0bbb39 100644 --- a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java +++ b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java @@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; +import org.opengroup.osdu.config.util.DecodedContentExtractor; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -24,14 +25,14 @@ import java.util.Base64; import java.util.HashMap; import java.util.Map; +import static org.opengroup.osdu.config.util.DecodedContentExtractorUtil.NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER; + public class GoogleServiceAccount { - public GoogleServiceAccount(String serviceAccountEncoded)throws IOException { - this(Base64.getDecoder().decode(serviceAccountEncoded)); - } - public GoogleServiceAccount(byte[] serviceAccountJson)throws IOException { - try(InputStream inputStream = new ByteArrayInputStream(serviceAccountJson)) { + public GoogleServiceAccount(String serviceAccountValue)throws IOException { + serviceAccountValue = new DecodedContentExtractor(serviceAccountValue, NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER).getContent(); - serviceAccount = ServiceAccountCredentials.fromStream(inputStream); + try (InputStream inputStream = new ByteArrayInputStream(serviceAccountValue.getBytes())) { + this.serviceAccount = ServiceAccountCredentials.fromStream(inputStream); } } @@ -77,7 +78,6 @@ public class GoogleServiceAccount { if(auth == null){ throw new IOException("Failed to retrieve auth token for credentials " + jwt); } - String output = auth.getAsString(); - return output; + return auth.getAsString(); } }