Commit 83e7f9b9 authored by Komal Makkar's avatar Komal Makkar
Browse files

added case for handshake request header creation

parent 1a1b9356
Pipeline #13645 failed with stage
in 43 seconds
......@@ -57,15 +57,20 @@ public class CredentialHeadersProvider implements FactoryBean<DpsHeaders> {
case POST:
case PUT:
case PATCH: {
Map<String, String> attributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody();
try {
//extract headers from pubsub message
String dataPartitionId = attributes.get(DpsHeaders.DATA_PARTITION_ID);
String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId);
attributes.put(DpsHeaders.AUTHORIZATION, authToken);
return DpsHeaders.createFromMap(attributes);
} catch (AppException e) {
throw new Exception("Failed to generate headers for register service.");
if(this.pubsubRequestBodyExtractor.isHandshakeRequest()) {
// The headers are not needed for the handshake requests.
return new DpsHeaders();
} else {
Map<String, String> attributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody();
try {
//extract headers from pubsub message
String dataPartitionId = attributes.get(DpsHeaders.DATA_PARTITION_ID);
String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId);
attributes.put(DpsHeaders.AUTHORIZATION, authToken);
return DpsHeaders.createFromMap(attributes);
} catch (AppException e) {
throw new Exception("Failed to generate headers for register service.");
}
}
}
......
......@@ -5,6 +5,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.notification.provider.interfaces.IPubsubRequestBodyExtractor;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -18,6 +20,9 @@ public class CredentialHeadersProviderTest {
@Mock
private HttpServletRequest httpRequest;
@Mock
private IPubsubRequestBodyExtractor pubsubRequestBodyExtractor;
@InjectMocks
private CredentialHeadersProvider headersProvider;
......@@ -26,4 +31,19 @@ public class CredentialHeadersProviderTest {
when(httpRequest.getMethod()).thenReturn(RequestMethod.GET.toString());
assertNotNull(headersProvider.getObject());
}
@Test
public void testHandshake() throws Exception {
// set up
when(httpRequest.getMethod()).thenReturn(RequestMethod.GET.toString());
when(pubsubRequestBodyExtractor.isHandshakeRequest()).thenReturn(true);
// Act
DpsHeaders headers = headersProvider.getObject();
// Assert
assertNotNull(headers);
assertNull(headers.getCorrelationId());
assertNull(headers.getPartitionId());
}
}
\ 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