Search in sources :

Example 1 with RequestHeader

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);
}
Also used : RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Example 2 with RequestHeader

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);
}
Also used : RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Example 3 with RequestHeader

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);
}
Also used : RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Example 4 with RequestHeader

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Example 5 with RequestHeader

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);
}
Also used : ArrayList(java.util.ArrayList) RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Aggregations

RequestHeader (com.ingenico.connect.gateway.sdk.java.RequestHeader)14 Test (org.junit.Test)13 ByteArrayInputStream (java.io.ByteArrayInputStream)4 WebhooksEvent (com.ingenico.connect.gateway.sdk.java.domain.webhooks.WebhooksEvent)3 ArrayList (java.util.ArrayList)2 Client (com.ingenico.connect.gateway.sdk.java.Client)1 CommunicatorConfiguration (com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration)1 Marshaller (com.ingenico.connect.gateway.sdk.java.Marshaller)1 MetaDataProvider (com.ingenico.connect.gateway.sdk.java.MetaDataProvider)1 MetaDataProviderBuilder (com.ingenico.connect.gateway.sdk.java.MetaDataProviderBuilder)1 Session (com.ingenico.connect.gateway.sdk.java.Session)1 DefaultMarshaller (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultMarshaller)1 Directory (com.ingenico.connect.gateway.sdk.java.domain.product.Directory)1 DirectoryParams (com.ingenico.connect.gateway.sdk.java.merchant.products.DirectoryParams)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1