Skip to content
Snippets Groups Projects
Commit 141702ab authored by Rucha Deshpande's avatar Rucha Deshpande
Browse files

AWS Notification int. tests

commit 0b9beed3 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Fri Oct 23 2020 09:10:09 GMT-0500 (Central Daylight Time) 

    Update fossa.yml for aws


commit 3871c9fe 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 22 2020 16:35:39 GMT-0500 (Central Daylight Time) 

    update unit test


commit cf057e5a 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 22 2020 14:53:11 GMT-0500 (Central Daylight Time) 

    Update chmod permissions


commit e91dcd6a 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 22 2020 14:43:24 GMT-0500 (Central Daylight Time) 

    Update to AWS int tests


commit 7f4cb8e1 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 22 2020 14:12:13 GMT-0500 (Central Daylight Time) 

    Update for AWS int tests
parent c3b1bb1a
No related branches found
No related tags found
1 merge request!30Feat/aws impl
Pipeline #12908 failed
Showing
with 632 additions and 17 deletions
......@@ -23,4 +23,8 @@ analyze:
- name: notification-azure
type: mvn
target: provider/notification-azure/pom.xml
path: .
- name: notification-aws
type: mvn
target: provider/notification-aws/pom.xml
path: .
\ No newline at end of file
......@@ -4,6 +4,11 @@ variables:
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}
AWS_BUILD_SUBDIR: provider/notification-aws/build-aws
AWS_TEST_SUBDIR: testing/notification-test-aws
AWS_SERVICE: notification
AWS_ENVIRONMENT: dev
include:
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
......@@ -25,5 +30,8 @@ include:
ref: 'master'
file: 'cloud-providers/osdu-gcp-cloudrun.yml'
- project: 'osdu/platform/ci-cd-pipelines'
file: 'cloud-providers/aws.yml'
osdu-gcp-test:
allow_failure: true
......@@ -53,8 +53,8 @@ phases:
- echo "Building primary service assemblies..."
- mvn -B test install -pl notification-core,provider/notification-aws -Ddeployment.environment=prod
#- echo "Building integration testing assemblies and gathering artifacts..."
#- ./testing/notification-test-aws/build-aws/prepare-dist.sh
- echo "Building integration testing assemblies and gathering artifacts..."
- ./testing/notification-test-aws/build-aws/prepare-dist.sh
- echo "Building docker image..."
- docker build -f provider/notification-aws/build-aws/Dockerfile -t ${ECR_IMAGE} .
......
......@@ -37,6 +37,7 @@
<java.version>8</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<aws.version>1.11.637</aws.version>
</properties>
<repositories>
......@@ -70,6 +71,13 @@
<version>0.3.11-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-secretsmanager -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>notification-core</artifactId>
......
......@@ -48,6 +48,13 @@ public class AwsPubsubRequestBodyExtractor implements IPubsubRequestBodyExtracto
@Autowired
private JaxRsDpsLog log;
@Autowired
public AwsPubsubRequestBodyExtractor(HttpServletRequest httpServletRequest) {
this.request = httpServletRequest;
}
public Map<String, String> extractAttributesFromRequestBody() {
if (this.messageContent == null) {
this.messageContent = this.extractPubsubMessageFromRequestBody();
......
// Copyright © 2020 Amazon Web Services
// 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.provider.aws.impl;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
import com.amazonaws.services.secretsmanager.model.*;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
import com.amazonaws.services.simplesystemsmanagement.model.*;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.opengroup.osdu.core.aws.iam.IAMConfig;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
import org.opengroup.osdu.notification.provider.aws.utils.AwsCognitoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class ServiceAccountJwtAwsClientImpl implements IServiceAccountJwtClient {
@Value("${aws.region}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public String amazonRegion;
@Value("${aws.ssm}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public Boolean ssmEnabled;
@Value("${aws.environment}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public String environment;
@Autowired
private JaxRsDpsLog log;
String password;
String clientid;
String userpoolid;
String serviceprincipaluser;
AwsCognitoClient cognitoClient;
private AWSCredentialsProvider amazonAWSCredentials;
private AWSSimpleSystemsManagement ssmManager;
@PostConstruct
public void init() {
if (ssmEnabled) {
String secretKey = "service_principal_password";
String secretName = "/osdu/" + environment + "/service_principal_password";
String cognito_user_pool_id = "/osdu/" + environment + "/cognito-user-pool-id";
String cognito_client_id = "/osdu/" + environment + "/cognito-client-id";
String service_principal = "/osdu/" + environment + "/service-principal-user";
amazonAWSCredentials = IAMConfig.amazonAWSCredentials();
ssmManager = AWSSimpleSystemsManagementClientBuilder.standard()
.withCredentials(amazonAWSCredentials)
.withRegion(amazonRegion)
.build();
GetParametersRequest paramRequest = new GetParametersRequest()
.withNames(cognito_user_pool_id,cognito_client_id,service_principal)
.withWithDecryption(true);
GetParametersResult paramResult = new GetParametersResult();
paramResult = ssmManager.getParameters(paramRequest);
List<Parameter> paramsResultList = new ArrayList<>();
List<String> paramsResultListInvalid = new ArrayList<>();
paramsResultList = paramResult.getParameters();
paramsResultListInvalid = paramResult.getInvalidParameters();
if(paramsResultListInvalid.size() >0)
{
log.error("SSM did not retrieve all parameters");
}
for (Parameter s : paramsResultList) {
if (s.getName().equalsIgnoreCase(cognito_user_pool_id)) {
userpoolid = s.getValue();
}
if (s.getName().equalsIgnoreCase(cognito_client_id)) {
clientid = s.getValue();
}
if (s.getName().equalsIgnoreCase(service_principal)) {
serviceprincipaluser = s.getValue();
}
}
password = getSecret(secretName,amazonRegion,secretKey);
cognitoClient = new AwsCognitoClient(amazonRegion,clientid,"USER_PASSWORD_AUTH", serviceprincipaluser,password);
cognitoClient.setPassword(serviceprincipaluser,password,userpoolid);
}
}
@Override
public String getIdToken(String s) {
String token ="not used";
String token= getServicePrincipalCredentials();
return token;
}
public String getServicePrincipalCredentials()
{
String token = cognitoClient.getToken(serviceprincipaluser,password,"bearer");
return token;
}
public String getSecret(String secretName, String region,String secretKey) {
String secretVaue="";
// Create a Secrets Manager client
AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard()
.withRegion(region)
.build();
String secret="", decodedBinarySecret="";
GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest()
.withSecretId(secretName);
GetSecretValueResult getSecretValueResult = null;
try {
getSecretValueResult = client.getSecretValue(getSecretValueRequest);
} catch (DecryptionFailureException e) {
// Secrets Manager can't decrypt the protected secret text using the provided KMS key.
// Deal with the exception here, and/or rethrow at your discretion.
log.error("Error while setting up ServicePrincipalAccount"+e.getMessage());
throw e;
} catch (InternalServiceErrorException e) {
// An error occurred on the server side.
// Deal with the exception here, and/or rethrow at your discretion.
log.error("Error while setting up ServicePrincipalAccount"+e.getMessage());
throw e;
} catch (InvalidParameterException e) {
// You provided an invalid value for a parameter.
// Deal with the exception here, and/or rethrow at your discretion.
log.error("Error while setting up ServicePrincipalAccount"+e.getMessage());
throw e;
} catch (InvalidRequestException e) {
// You provided a parameter value that is not valid for the current state of the resource.
// Deal with the exception here, and/or rethrow at your discretion.
log.error("Error while setting up ServicePrincipalAccount"+e.getMessage());
throw e;
} catch (ResourceNotFoundException e) {
// We can't find the resource that you asked for.
// Deal with the exception here, and/or rethrow at your discretion.
log.error("Error while setting up ServicePrincipalAccount"+e.getMessage());
throw e;
}
// Decrypts secret using the associated KMS CMK.
// Depending on whether the secret is a string or binary, one of these fields will be populated.
if (getSecretValueResult.getSecretString() != null) {
secret = getSecretValueResult.getSecretString();
Map<String, String> secretMap=null;
try
{
secretMap = new ObjectMapper().readValue(secret.getBytes(), Map.class);
} catch (JsonParseException e) {
log.error(e.getMessage());
} catch (JsonMappingException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
secretVaue = secretMap.get(secretKey);
}
return secretVaue;
}
}
// Copyright © 2020 Amazon Web Services
//
// 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.provider.aws.utils;
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
import com.amazonaws.services.cognitoidp.model.AdminSetUserPasswordRequest;
import com.amazonaws.services.cognitoidp.model.AdminSetUserPasswordResult;
import com.amazonaws.services.cognitoidp.model.InitiateAuthRequest;
import com.amazonaws.services.cognitoidp.model.InitiateAuthResult;
import org.opengroup.osdu.core.aws.iam.IAMConfig;
import java.util.HashMap;
import java.util.Map;
public class AwsCognitoClient {
// Parameter value locations
private final static String USERNAME_PARAM = "USERNAME";
private final static String PASSWORD_PARAM = "PASSWORD";
private final static String COGNITO_CLIENT_ID_PROPERTY = "AWS_COGNITO_CLIENT_ID";
private final static String COGNITO_AUTH_FLOW_PROPERTY = "AWS_COGNITO_AUTH_FLOW";
private final static String COGNITO_AUTH_PARAMS_USER_PROPERTY = "AWS_COGNITO_AUTH_PARAMS_USER";
private final static String COGNITO_AUTH_PARAMS_PASSWORD_PROPERTY = "AWS_COGNITO_AUTH_PARAMS_PASSWORD";
String awsCognitoClientId;
String awsCognitoAuthFlow;
String awsCognitoAuthParamsUser;
String awsCognitoAuthParamsPassword;
AWSCognitoIdentityProvider provider;
public AwsCognitoClient(String region,String awsCognitoClientId, String awsCognitoAuthFlow, String awsCognitoAuthParamsUser
, String awsCognitoAuthParamsPassword) {
this.awsCognitoClientId = awsCognitoClientId;
this.awsCognitoAuthFlow = awsCognitoAuthFlow;
this.awsCognitoAuthParamsUser = awsCognitoAuthParamsUser;
this.awsCognitoAuthParamsPassword = awsCognitoAuthParamsPassword;
this.provider = generateCognitoClient(region);
}
public String getToken(String username, String password,String tokenType){
Map<String, String> authParameters = new HashMap<>();
authParameters.put(USERNAME_PARAM, username);
authParameters.put(PASSWORD_PARAM, password);
InitiateAuthRequest request = new InitiateAuthRequest();
request.setClientId(awsCognitoClientId);
request.setAuthFlow(awsCognitoAuthFlow);
request.setAuthParameters(authParameters);
String token="";
InitiateAuthResult result = this.provider.initiateAuth(request);
if(tokenType.equals("session"))
token= result.getSession();
else if(tokenType.equals("bearer"))
token= "Bearer "+ result.getAuthenticationResult().getAccessToken();
return token;
}
public AWSCognitoIdentityProvider getProvider() {
return provider;
}
public static AWSCognitoIdentityProvider generateCognitoClient(String region)
{
return AWSCognitoIdentityProviderClientBuilder.standard()
.withCredentials(IAMConfig.amazonAWSCredentials())
.withRegion(region)
.build();
}
public void setPassword(String username, String password,String userPoolId){
AdminSetUserPasswordRequest request = new AdminSetUserPasswordRequest()
.withUsername(username)
.withPassword(password)
.withPermanent(true)
.withUserPoolId(userPoolId);
AdminSetUserPasswordResult result = this.provider.adminSetUserPassword(request);
}
}
......@@ -21,6 +21,8 @@ AUTHORIZE_API=${ENTITLEMENTS_BASE_URL}/api/entitlements/v1
REGISTER_SERVICE_URL=${REGISTER_BASE_URL}/api/register/v1
aws.ssm=${SSM_ENABLED:True}
aws.environment=${RESOURCE_PREFIX}
## AWS DynamoDB configuration
aws.region=${AWS_REGION}
aws.dynamodb.table.prefix=${RESOURCE_PREFIX}-
......
// Copyright © 2020 Amazon Web Services
//
// 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.provider.aws;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDeleteExpression;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.notification.provider.aws.impl.AwsPubsubRequestBodyExtractor;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Map;
@RunWith(MockitoJUnitRunner.class)
public class AwsPubsubRequestBodyExtractorTest {
@Mock
private DpsHeaders dpsHeaders;
@Mock
private JaxRsDpsLog logger;
@Mock
private HttpServletRequest request;
@Mock
private AwsPubsubRequestBodyExtractor service;
@Before
public void init() {
}
@Test
public void should_returnValidData_extractDataFromRequestBody() throws IOException {
String stringRequest = "{\n" +
"\t\"Type\": \"Notification\",\n" +
"\t\"message\": {\n" +
"\t\"attributes\": {\n" +
"\t\"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" +
"\t\"data-partition-id\": \"" + TestUtils.getDataPartitionId() + "\"\n" +
"\t},\n" +
"\t\"data\": \"dGVzdERhdGE=\",\n" +
"\t\"messageId\": \"136969346945\"\n" +
"\t},\n" +
"\t\"subscription\": \""+ "de12345" +"\"\n" +
"}\n";
BufferedReader reader = new BufferedReader(new StringReader(stringRequest));
Mockito.when(request.getReader()).thenReturn(reader);
String expectedData = "testData";
service = new AwsPubsubRequestBodyExtractor(request);
String receivedData = service.extractDataFromRequestBody();
Assert.assertEquals(expectedData,receivedData);
}
@Test
public void should_returnValidNotificationId_FromRequestBody() throws IOException {
String stringRequest = "{\n" +
"\t\"Type\": \"Notification\",\n" +
"\t\"message\": {\n" +
"\t\"attributes\": {\n" +
"\t\"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" +
"\t\"data-partition-id\": \"" + TestUtils.getDataPartitionId() + "\"\n" +
"\t},\n" +
"\t\"data\": \"dGVzdERhdGE=\",\n" +
"\t\"messageId\": \"136969346945\"\n" +
"\t},\n" +
"\t\"subscription\": \""+ "de12345" +"\"\n" +
"}\n";
BufferedReader reader = new BufferedReader(new StringReader(stringRequest));
Mockito.when(request.getReader()).thenReturn(reader);
String expectedData = "de12345";
service = new AwsPubsubRequestBodyExtractor(request);
String receivedData = service.extractNotificationIdFromRequestBody();
Assert.assertEquals(expectedData,receivedData);
}
@Test
public void should_returnValidAttributes_FromRequestBody() throws IOException {
String stringRequest = "{\n" +
"\t\"Type\": \"Notification\",\n" +
"\t\"message\": {\n" +
"\t\"attributes\": {\n" +
"\t\"correlation-id\": \"39137f49-123-456\",\n" +
"\t\"data-partition-id\": \"" + TestUtils.getDataPartitionId() + "\"\n" +
"\t},\n" +
"\t\"data\": \"dGVzdERhdGE=\",\n" +
"\t\"messageId\": \"136969346945\"\n" +
"\t},\n" +
"\t\"subscription\": \""+ "de12345" +"\"\n" +
"}\n";
BufferedReader reader = new BufferedReader(new StringReader(stringRequest));
Mockito.when(request.getReader()).thenReturn(reader);
String expectedData = "de12345";
service = new AwsPubsubRequestBodyExtractor(request);
// Act
Map<String, String> receivedAttributes = service.extractAttributesFromRequestBody();
// Asset
Assert.assertEquals(receivedAttributes.get("correlation-id"),"39137f49-123-456");
Assert.assertEquals(receivedAttributes.get("data-partition-id"),"opendes");
}
}
// Copyright © 2020 Amazon Web Services
//
// 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.provider.aws;
public class TestUtils {
private TestUtils() {
}
private static final String dataPartitionId = "opendes";
public static String getDataPartitionId() {
return dataPartitionId;
}
}
File mode changed from 100644 to 100755
......@@ -36,14 +36,11 @@ export AWS_COGNITO_AUTH_PARAMS_PASSWORD=$ADMIN_PASSWORD
export AWS_COGNITO_AUTH_PARAMS_USER=$ADMIN_USER
export AWS_COGNITO_AUTH_PARAMS_USER_NO_ACCESS=$USER_NO_ACCESS
export ENVIRONMENT=DEV
export REGISTER_BASE_URL=$REGISTER_BASE_URL
export NOTIFICATION_REGISTER_BASE_URL=$NOTIFICATION_REGISTER_BASE_URL
export HMAC_SECRET=02030405060708090A0B0C0D0E0F
export REGISTER_CUSTOM_PUSH_PATH=api/register/v1/awstest/aws/challenge
export REGISTER_CUSTOM_PUSH_PATH1=api/register/v1/awstest/aws/challenge/1
export REGISTER_CUSTOM_PUSH_URL=$REGISTER_BASE_URL$REGISTER_CUSTOM_PUSH_PATH
export REGISTER_CUSTOM_PUSH_URL1=$REGISTER_BASE_URL$REGISTER_CUSTOM_PUSH_PATH1
export REGISTER_CUSTOM_PUSH_PATH=/api/register/v1/awstest/aws/challenge/1
export REGISTER_CUSTOM_PUSH_URL_HMAC=$NOTIFICATION_REGISTER_BASE_URL$REGISTER_CUSTOM_PUSH_PATH
export NOTIFICATION_BASE_URL=$NOTIFICATION_BASE_URL
#### RUN INTEGRATION TEST #########################################################################
......
// Copyright © 2020 Amazon Web Services
// 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.api;
import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import java.util.HashMap;
import java.util.Map;
public class PubsubEndpointHMACDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "push-handlers/records-changed";
}
@Override
public String getHttpMethod() {
return "POST";
}
@Override
public String getValidBody() {
return "{\n" +
"\t\"Type\": \"Notification\",\n" +
"\t\"message\": {\n" +
"\t\"attributes\": {\n" +
"\t\"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" +
"\t\"data-partition-id\": \"" + TestUtils.getOsduTenant() + "\"\n" +
"\t},\n" +
"\t\"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n" +
"\t\"messageId\": \"136969346945\"\n" +
"\t},\n" +
"\t\"subscription\": \""+ arg() +"\"\n" +
"}\n";
}
@Override
public Map<String,String> getOsduTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().OsduTenant);
return headers;
}
@Override
public Map<String,String> getCustomerTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
}
// Copyright © 2020 Amazon Web Services
//
// 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.api;
import static org.junit.Assert.assertEquals;
......
......@@ -31,22 +31,24 @@ public class AwsTestUtils extends TestUtils{
return opsToken;
}
//These users don't have access to the API, so getting the token for NoAccessUser
@Override
public String getAdminToken() throws Exception {
if (adminToken==null || StringUtils.isEmpty(adminToken)) {
adminToken=client.getToken(AwsConfig.getAWSCognitoUser(),AwsConfig.getAWSCognitoPassword(),"bearer");
adminToken=client.getToken(AwsConfig.getAWSCognitoNoAccessUser(),AwsConfig.getAWSCognitoPassword(),"bearer");
}
return adminToken;
}
//These users don't have access to the API, so getting the token for NoAccessUser
@Override
public String getEditorToken() throws Exception {
if (editorToken==null || StringUtils.isEmpty(editorToken)) {
editorToken=client.getToken(AwsConfig.getAWSCognitoUser(),AwsConfig.getAWSCognitoPassword(),"bearer");
editorToken=client.getToken(AwsConfig.getAWSCognitoNoAccessUser(),AwsConfig.getAWSCognitoPassword(),"bearer");
}
return editorToken;
}
//These users don't have access to the API, so getting the token for NoAccessUser
@Override
public String getNoAccessToken() throws Exception {
if (noAccessToken==null || StringUtils.isEmpty(noAccessToken)) {
......
......@@ -84,7 +84,7 @@ public abstract class PubsubEndpointHMACTests extends BaseTestTemplate {
subscription.setName("subscription-integration-test-hmac");
subscription.setDescription("subscription created for hmac integration test");
subscription.setTopic(Config.Instance().Topic);
//This seems to be a bug
//This seems to be a bug. Dont need to add the string
//subscription.setPushEndpoint(Config.Instance().HMACPushUrl + "hmac-integration-test");
subscription.setPushEndpoint(Config.Instance().HMACPushUrl);
HmacSecret secret = new HmacSecret();
......
......@@ -17,6 +17,7 @@
package org.opengroup.osdu.notification.util;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.Ignore;
import org.junit.Test;
import java.util.ArrayList;
......@@ -107,6 +108,7 @@ public abstract class BaseTestTemplate extends TestBase {
ClientResponse response = descriptor.runOptions(getArg(), testUtils.getEditorToken());
assertEquals(error( response.getEntity(String.class)), 200, response.getStatus());
}
@Ignore("Issue logged in GL")
@Test
public void should_return307_when_makingHttpRequest()throws Exception{
if(Config.Instance().isLocalHost() || Config.isGke())
......
......@@ -53,10 +53,26 @@ public class Config {
String registerUrl = System.getProperty("REGISTER_BASE_URL", System.getenv("REGISTER_BASE_URL"));
config.HostUrl = System.getProperty("NOTIFICATION_BASE_URL", System.getenv("NOTIFICATION_BASE_URL"));
config.GSAPushUrl = registerUrl+"/test/gsa-challenge/";
config.HMACPushUrl = registerUrl+"/test/challenge/";
config.RegisterServicePath = registerUrl;
//Adding this so CPs can point to custom HMAC push endpoints
config.HMACPushUrl = getEnvironmentVariableOrDefaultValue("REGISTER_CUSTOM_PUSH_URL_HMAC",registerUrl+"/test/challenge/");
//Adding a new variable NOTIFICATION_REGISTER_BASE_URL since REGISTER_BASE_URL is used by Register integration tests which needs a trailing \
String regUrl= getEnvironmentVariable("NOTIFICATION_REGISTER_BASE_URL");
if(regUrl==null)
{
config.RegisterServicePath = registerUrl;
}
else
{
config.RegisterServicePath = regUrl+"/api/register/v1";
}
}else
throw new RuntimeException("$ENVIRONMENT environment variable not provided");
System.out.println("HostUrl="+config.HostUrl);
System.out.println("config.Topic="+ config.Topic);
System.out.println("config.HMACPushUrl="+ config.HMACPushUrl);
System.out.println("config.RegisterServicePath="+ config.RegisterServicePath);
return config;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment