use of com.ingenico.connect.gateway.sdk.java.RequestHeader in project connect-sdk-java by Ingenico-ePayments.
the class WebhooksHelperTest method testUnmarshalNoSecretKeyAvailable.
@Test(expected = SecretKeyNotAvailableException.class)
public void testUnmarshalNoSecretKeyAvailable() throws IOException {
WebhooksHelper helper = createHelper();
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 WebhooksHelperTest method testUnmarshalStringInvalidBody.
@Test(expected = SignatureValidationException.class)
public void testUnmarshalStringInvalidBody() throws IOException {
WebhooksHelper helper = createHelper();
InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
String body = new String(readResource("invalid-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 WebhooksHelperTest method testUnmarshalStringInvalidSecretKey.
@Test(expected = SignatureValidationException.class)
public void testUnmarshalStringInvalidSecretKey() throws IOException {
WebhooksHelper helper = createHelper();
String invalidSecretKey = "1" + SECRET_KEY;
InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, invalidSecretKey);
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 WebhooksHelperTest method testUnmarshalBytesInvalidSecretKey.
@Test(expected = SignatureValidationException.class)
public void testUnmarshalBytesInvalidSecretKey() throws IOException {
WebhooksHelper helper = createHelper();
String invalidSecretKey = "1" + SECRET_KEY;
InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, invalidSecretKey);
ByteArrayInputStream bodyStream = new ByteArrayInputStream(readResource("valid-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 DefaultAuthenticatorTest method testToDataToSign.
@Test
public void testToDataToSign() {
DefaultAuthenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKeyId", "secretApiKey");
List<RequestHeader> httpHeaders = new ArrayList<RequestHeader>();
httpHeaders.add(new RequestHeader("X-GCS-ServerMetaInfo", "{\"platformIdentifier\":\"Windows 7/6.1 Java/1.7 (Oracle Corporation; Java HotSpot(TM) 64-Bit Server VM; 1.7.0_45)\",\"sdkIdentifier\":\"1.0\"}"));
httpHeaders.add(new RequestHeader("Content-Type", "application/json"));
httpHeaders.add(new RequestHeader("X-GCS-ClientMetaInfo", "{\"aap\",\"noot\"}"));
httpHeaders.add(new RequestHeader("User-Agent", "Apache-HttpClient/4.3.4 (java 1.5)"));
httpHeaders.add(new RequestHeader("Date", "Mon, 07 Jul 2014 12:12:40 GMT"));
String dataToSign = authenticator.toDataToSign("POST", URI.create("http://localhost:8080/v1/9991/services%20bla/convert/amount?aap=noot&mies=geen%20noot"), httpHeaders);
String expectedStart = "POST\n" + "application/json\n";
String expectedEnd = "x-gcs-clientmetainfo:{\"aap\",\"noot\"}\n" + "x-gcs-servermetainfo:{\"platformIdentifier\":\"Windows 7/6.1 Java/1.7 (Oracle Corporation; Java HotSpot(TM) 64-Bit Server VM; 1.7.0_45)\",\"sdkIdentifier\":\"1.0\"}\n" + "/v1/9991/services%20bla/convert/amount?aap=noot&mies=geen noot\n";
String actualStart = dataToSign.substring(0, 22);
String actualEnd = dataToSign.substring(52, 308);
Assert.assertEquals(expectedStart, actualStart);
Assert.assertEquals(expectedEnd, actualEnd);
}
Aggregations