use of com.ingenico.connect.gateway.sdk.java.RequestHeader in project connect-sdk-java by Ingenico-ePayments.
the class WebhooksHelperTest method testUnmarshalDuplicateHeaders.
@Test(expected = SignatureValidationException.class)
public void testUnmarshalDuplicateHeaders() throws IOException {
WebhooksHelper helper = createHelper();
InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
String body = new String(readResource("valid-body"), CHARSET);
List<RequestHeader> requestHeaders = Arrays.asList(new RequestHeader(SIGNATURE_HEADER, SIGNATURE), new RequestHeader(KEY_ID_HEADER, KEY_ID), new RequestHeader(SIGNATURE_HEADER, SIGNATURE + "1"));
helper.unmarshal(body, requestHeaders);
}
use of com.ingenico.connect.gateway.sdk.java.RequestHeader in project connect-sdk-java by Ingenico-ePayments.
the class WebhooksHelperTest method testUnmarshalBytesInvalidBody.
@Test(expected = SignatureValidationException.class)
public void testUnmarshalBytesInvalidBody() throws IOException {
WebhooksHelper helper = createHelper();
InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
ByteArrayInputStream bodyStream = new ByteArrayInputStream(readResource("invalid-body"));
List<RequestHeader> requestHeaders = Arrays.asList(new RequestHeader(SIGNATURE_HEADER, SIGNATURE), new RequestHeader(KEY_ID_HEADER, KEY_ID));
helper.unmarshal(bodyStream, requestHeaders);
}
use of com.ingenico.connect.gateway.sdk.java.RequestHeader in project connect-sdk-java by Ingenico-ePayments.
the class WebhooksHelperTest method testUnmarshalApiVersionMismatch.
@Test(expected = ApiVersionMismatchException.class)
public void testUnmarshalApiVersionMismatch() throws IOException {
Marshaller marshaller = Mockito.mock(Marshaller.class);
Mockito.when(marshaller.unmarshal(Matchers.anyString(), Matchers.<Class<?>>any())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String responseJson = invocation.getArgumentAt(0, String.class);
Class<?> type = invocation.getArgumentAt(1, Class.class);
WebhooksEvent event = (WebhooksEvent) DefaultMarshaller.INSTANCE.unmarshal(responseJson, type);
event.setApiVersion("v0");
return event;
}
});
WebhooksHelper helper = createHelper(marshaller);
InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
String body = new String(readResource("valid-body"), CHARSET);
List<RequestHeader> requestHeaders = Arrays.asList(new RequestHeader(SIGNATURE_HEADER, SIGNATURE), new RequestHeader(KEY_ID_HEADER, KEY_ID));
helper.unmarshal(body, requestHeaders);
}
use of com.ingenico.connect.gateway.sdk.java.RequestHeader in project connect-sdk-java by Ingenico-ePayments.
the class DefaultAuthenticator method toDataToSign.
String toDataToSign(String httpMethod, URI resourceUri, List<RequestHeader> httpHeaders) {
String contentType = null;
String date = null;
String canonicalizedResource = toCanonicalizedResource(resourceUri);
List<RequestHeader> xgcsHttpHeaders = new ArrayList<RequestHeader>();
if (httpHeaders != null) {
for (RequestHeader httpHeader : httpHeaders) {
if ("Content-Type".equalsIgnoreCase(httpHeader.getName())) {
contentType = httpHeader.getValue();
} else if ("Date".equalsIgnoreCase(httpHeader.getName())) {
date = httpHeader.getValue();
} else {
String name = toCanonicalizeHeaderName(httpHeader.getName());
if (name.startsWith("x-gcs")) {
String value = toCanonicalizeHeaderValue(httpHeader.getValue());
RequestHeader xgcsHttpHeader = new RequestHeader(name, value);
xgcsHttpHeaders.add(xgcsHttpHeader);
}
}
}
}
Collections.sort(xgcsHttpHeaders, REQUEST_HEADER_COMPARATOR);
StringBuilder sb = new StringBuilder(100);
sb.append(httpMethod.toUpperCase()).append('\n');
if (contentType != null) {
sb.append(contentType).append('\n');
} else {
sb.append('\n');
}
sb.append(date).append('\n');
for (RequestHeader xgcsHttpHeader : xgcsHttpHeaders) {
sb.append(xgcsHttpHeader.getName()).append(':').append(xgcsHttpHeader.getValue()).append('\n');
}
sb.append(canonicalizedResource).append('\n');
return sb.toString();
}
Aggregations