Commit cb565970 authored by Rucha Deshpande's avatar Rucha Deshpande
Browse files

Merge branch 'aws-xuserid-fix' into 'master'

Aws xuserid fix

See merge request !137
parents d8ed859d 4da32a9d
Pipeline #74152 failed with stages
in 21 minutes and 55 seconds
This diff is collapsed.
......@@ -112,6 +112,8 @@ public class AwsPubsubRequestBodyExtractor implements IPubsubRequestBodyExtracto
throw new AppException(HttpStatus.BAD_REQUEST.value(), INVALID_PUBSUB_MESSAGE,
"No tenant information from pubsub message.");
}
String x_user_id= request.getHeader("x-user-id");
lowerCase.put("x-user-id",x_user_id);
content.setAttributes(lowerCase);
String decoded = new String(Base64.getDecoder().decode(data));
......
......@@ -20,18 +20,31 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.AwsTestUtils;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.notification.HmacSecret;
import org.opengroup.osdu.core.common.model.notification.Subscription;
import org.opengroup.osdu.core.common.notification.ISubscriptionService;
import org.opengroup.osdu.core.common.notification.SubscriptionAPIConfig;
import org.opengroup.osdu.core.common.notification.SubscriptionException;
import org.opengroup.osdu.core.common.notification.SubscriptionFactory;
import org.opengroup.osdu.notification.util.*;
import com.sun.jersey.api.client.ClientResponse;
import java.util.HashMap;
import java.util.Map;
public class TestPubsubEndpointHMAC extends PubsubEndpointHMACTests {
private String subscriptionId = null;
private String notificationId = null;
private ISubscriptionService awssubscriptionService;
private static SubscriptionFactory awsfactory;
@BeforeClass
public static void classSetup() throws Exception {
PubsubEndpointHMACTests.classSetup();
SubscriptionAPIConfig config = SubscriptionAPIConfig.builder().rootUrl(Config.Instance().RegisterServicePath).build();
awsfactory = new SubscriptionFactory(config);
}
@AfterClass
......@@ -50,10 +63,73 @@ public class TestPubsubEndpointHMAC extends PubsubEndpointHMACTests {
this.testUtils = null;
}
@Override
protected String getArg() {
return this.notificationId;
}
@Test
@Override
public void should_return401_when_noAccessOnCustomerTenant() throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getArg(), getOsduTenantAdminCredentials());
assertEquals(error( response.getEntity(String.class)), 403, response.getStatus());
}
@Test
@Override
public void should_return400_when_makingHttpRequestWithoutToken() throws Exception {
ClientResponse response = descriptor.run(getArg(), "");
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
@Override
protected void createResource() throws Exception {
createResourceInPartition(TestUtils.getOsduTenant());
}
private void createResourceInPartition(String partitionId) throws Exception{
Map<String, String> headers = new HashMap<>();
headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken());
//hardcoding user here for 200 response tests. This is just initializing the subscription creation
headers.put("x-user-id", AwsConfig.getAWSCognitoUser());
DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers);
awssubscriptionService = awsfactory.create(dpsHeaders);
Map<String,String> h = dpsHeaders.getHeaders();
System.out.println(h);
//Create a new subscription to pub/sub
Subscription subscription = new Subscription();
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. Dont need to add the string
//subscription.setPushEndpoint(Config.Instance().HMACPushUrl + "hmac-integration-test");
subscription.setPushEndpoint(Config.Instance().HMACPushUrl);
HmacSecret secret = new HmacSecret();
secret.setValue(Config.Instance().hmacSecretValue);
subscription.setSecret(secret);
try {
Subscription subscriptionCreated = awssubscriptionService.create(subscription);
notificationId = subscriptionCreated.getNotificationId();
subscriptionId = subscriptionCreated.getId();
Config.Instance().NotificationId = notificationId;
}catch (SubscriptionException e){
System.out.println("Subscription exception inner response : " + e.getHttpResponse());
throw e;
}
}
@Override
protected void deleteResource() throws Exception {
awssubscriptionService.delete(subscriptionId);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment