From a99f0b9ce23700e59db4e589d066fde6d014b8fa Mon Sep 17 00:00:00 2001 From: komakkar <komakkar@microsoft.com> Date: Fri, 20 Nov 2020 13:21:59 +0530 Subject: [PATCH] added todos for maintainability. --- .../api/TestPubsubEndpointHMAC.java | 4 ++-- .../notification/util/AzureTestUtils.java | 24 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java index 14d540cc2..6dc0bb286 100644 --- a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java +++ b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java @@ -78,14 +78,14 @@ public class TestPubsubEndpointHMAC extends PubsubEndpointHMACTests { @Test @Override public void should_return401_when_accessingWithEditorCredentials() throws Exception{ - ClientResponse response = descriptor.run(getArg(), testUtils.getEditorToken()); + ClientResponse response = descriptor.run(getArg(), testUtils.getNoAccessToken()); assertEquals(error( response.getEntity(String.class)), 403, response.getStatus()); } @Test @Override public void should_return401_when_accessingWithAdminCredentials() throws Exception{ - ClientResponse response = descriptor.run(getArg(), testUtils.getAdminToken()); + ClientResponse response = descriptor.run(getArg(), testUtils.getNoAccessToken()); assertEquals(error( response.getEntity(String.class)), 403, response.getStatus()); } } \ No newline at end of file diff --git a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/util/AzureTestUtils.java b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/util/AzureTestUtils.java index 869ff0138..fcf12e471 100644 --- a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/util/AzureTestUtils.java +++ b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/util/AzureTestUtils.java @@ -24,10 +24,13 @@ public class AzureTestUtils extends TestUtils { } // TODO : Revisit for synchronized block + // TODO : As azure has two tester SP ops, admin and editor are using integration Tests. + // This should be revisited. @Override public synchronized String getOpsToken() throws Exception { if (Strings.isNullOrEmpty(opsToken)) { - opsToken = getIntegrationTesterToken(); + opsToken = getToken(System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")), + System.getProperty("TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("TESTER_SERVICEPRINCIPAL_SECRET"))); } return "Bearer " + opsToken; } @@ -35,7 +38,8 @@ public class AzureTestUtils extends TestUtils { @Override public synchronized String getAdminToken() throws Exception { if (Strings.isNullOrEmpty(adminToken)) { - adminToken = getNoDataAccessTesterToken(); + adminToken = getToken(System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")), + System.getProperty("TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("TESTER_SERVICEPRINCIPAL_SECRET"))); } return "Bearer " + adminToken; } @@ -43,7 +47,8 @@ public class AzureTestUtils extends TestUtils { @Override public synchronized String getEditorToken() throws Exception { if (Strings.isNullOrEmpty(editorToken)) { - editorToken = getNoDataAccessTesterToken(); + editorToken = getToken(System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")), + System.getProperty("TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("TESTER_SERVICEPRINCIPAL_SECRET"))); } return "Bearer " + editorToken; } @@ -51,21 +56,12 @@ public class AzureTestUtils extends TestUtils { @Override public synchronized String getNoAccessToken() throws Exception { if (Strings.isNullOrEmpty(noAccessToken)) { - noAccessToken = getNoDataAccessTesterToken(); + noAccessToken = getToken(System.getProperty("NO_DATA_ACCESS_TESTER", System.getenv("NO_DATA_ACCESS_TESTER")), + System.getProperty("NO_DATA_ACCESS_TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("NO_DATA_ACCESS_TESTER_SERVICEPRINCIPAL_SECRET"))); } return "Bearer " + noAccessToken; } - private String getNoDataAccessTesterToken() throws Exception { - return getToken(System.getProperty("NO_DATA_ACCESS_TESTER", System.getenv("NO_DATA_ACCESS_TESTER")), - System.getProperty("NO_DATA_ACCESS_TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("NO_DATA_ACCESS_TESTER_SERVICEPRINCIPAL_SECRET"))); - } - - private String getIntegrationTesterToken() throws Exception { - return getToken(System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")), - System.getProperty("TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("TESTER_SERVICEPRINCIPAL_SECRET"))); - } - private String getToken(String sp_id, String sp_secret) throws Exception { String tenant_id = System.getProperty("AZURE_AD_TENANT_ID", System.getenv("AZURE_AD_TENANT_ID")); String app_resource_id = System.getProperty("AZURE_AD_APP_RESOURCE_ID", System.getenv("AZURE_AD_APP_RESOURCE_ID")); -- GitLab