From fec7480f3e378c990a927fcabfb8f12df7ed66c9 Mon Sep 17 00:00:00 2001 From: "Rostislav Dublin (EPAM)" <rostislav_dublin@epam.com> Date: Wed, 18 Nov 2020 17:38:45 -0500 Subject: [PATCH] GONRG-1035 *Logs for Subscription exception response *Docs improvement --- testing/notification-test-gcp/pom.xml | 13 ++++++++++--- .../osdu/notification/util/GCPTestUtils.java | 7 +++++-- .../notification/util/GoogleServiceAccount.java | 16 ++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/testing/notification-test-gcp/pom.xml b/testing/notification-test-gcp/pom.xml index ef6c4b850..a830652b5 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 55f7a6710..639eeecb1 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 132ff38b8..a7540b1a7 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(); } } -- GitLab