You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/08/30 06:16:39 UTC

[camel] branch master updated: [CAMEL-12605] Added test for enveloped request.

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new d254c8f  [CAMEL-12605] Added test for enveloped request.
d254c8f is described below

commit d254c8fbfe201d89c9cbc282e93babd0b3d8e860
Author: William Collins <pu...@gmail.com>
AuthorDate: Wed Aug 29 11:23:32 2018 -0400

    [CAMEL-12605] Added test for enveloped request.
---
 .../camel/component/as2/api/AS2MediaType.java      |  4 +++
 .../camel/component/as2/api/AS2MessageTest.java    | 38 +++++++++-------------
 2 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MediaType.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MediaType.java
index 08fbcd9..d6c4934 100644
--- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MediaType.java
+++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MediaType.java
@@ -27,6 +27,10 @@ public interface AS2MediaType {
      */
     public static final String APPLICATION_PKCS7_SIGNATURE = "application/pkcs7-signature; name=smime.p7s; smime-type=signed-data";
     /**
+     * Media Type for Application PKCS7 Signature
+     */
+    public static final String APPLICATION_PKCS7_MIME = "application/pkcs7-mime; name=smime.p7m; smime-type=enveloped-data; name=smime.p7m";
+    /**
      * Media Type for Text/Plain Data
      */
     public static final String TEXT_PLAIN = "text/plain";
diff --git a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
index 65684b7..708c203 100644
--- a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
+++ b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
@@ -33,6 +33,7 @@ import org.apache.camel.component.as2.api.entity.AS2DispositionType;
 import org.apache.camel.component.as2.api.entity.AS2MessageDispositionNotificationEntity;
 import org.apache.camel.component.as2.api.entity.ApplicationEDIEntity;
 import org.apache.camel.component.as2.api.entity.ApplicationEDIFACTEntity;
+import org.apache.camel.component.as2.api.entity.ApplicationPkcs7MimeEntity;
 import org.apache.camel.component.as2.api.entity.ApplicationPkcs7SignatureEntity;
 import org.apache.camel.component.as2.api.entity.DispositionMode;
 import org.apache.camel.component.as2.api.entity.DispositionNotificationMultipartReportEntity;
@@ -364,16 +365,17 @@ public class AS2MessageTest {
 
     }
 
-//    @Test
+    @Test
     public void envelopeddMessageTest() throws Exception {
         AS2ClientConnection clientConnection = new AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN,
                 TARGET_HOST, TARGET_PORT);
         AS2ClientManager clientManager = new AS2ClientManager(clientConnection);
 
         HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE, REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
-                AS2MessageStructure.SIGNED, ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII),
+                AS2MessageStructure.ENCRYPTED, ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII),
                 null, certList.toArray(new Certificate[0]), signingKP.getPrivate(), DISPOSITION_NOTIFICATION_TO,
-                SIGNED_RECEIPT_MIC_ALGORITHMS, null, null, null);
+                SIGNED_RECEIPT_MIC_ALGORITHMS, AS2AlgorithmConstants.AES128_CCM, certList.toArray(new Certificate[0]),
+                signingKP.getPrivate());
 
         HttpRequest request = httpContext.getRequest();
         assertEquals("Unexpected method value", METHOD, request.getRequestLine().getMethod());
@@ -396,30 +398,22 @@ public class AS2MessageTest {
         assertNotNull("Date value missing", request.getFirstHeader(AS2Header.DATE));
         assertNotNull("Content length value missing", request.getFirstHeader(AS2Header.CONTENT_LENGTH));
         assertTrue("Unexpected content type for message",
-                request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.MULTIPART_SIGNED));
+                request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MimeType.APPLICATION_PKCS7_MIME));
 
         assertTrue("Request does not contain entity", request instanceof BasicHttpEntityEnclosingRequest);
         HttpEntity entity = ((BasicHttpEntityEnclosingRequest) request).getEntity();
         assertNotNull("Request does not contain entity", entity);
-        assertTrue("Unexpected request entity type", entity instanceof MultipartSignedEntity);
-        MultipartSignedEntity signedEntity = (MultipartSignedEntity) entity;
-        assertTrue("Entity not set as main body of request", signedEntity.isMainBody());
-        assertTrue("Request contains invalid number of mime parts", signedEntity.getPartCount() == 2);
-
-        // Validated first mime part.
-        assertTrue("First mime part incorrect type ", signedEntity.getPart(0) instanceof ApplicationEDIFACTEntity);
-        ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity) signedEntity.getPart(0);
-        assertTrue("Unexpected content type for first mime part",
+        assertTrue("Unexpected request entity type", entity instanceof ApplicationPkcs7MimeEntity);
+        ApplicationPkcs7MimeEntity envelopedEntity = (ApplicationPkcs7MimeEntity) entity;
+        assertTrue("Entity not set as main body of request", envelopedEntity.isMainBody());
+
+        // Validated enveloped part.
+        MimeEntity encryptedEntity = envelopedEntity.getEncryptedEntity(signingKP.getPrivate());
+        assertTrue("Enveloped mime part incorrect type ", encryptedEntity instanceof ApplicationEDIFACTEntity);
+        ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity) encryptedEntity;
+        assertTrue("Unexpected content type for enveloped mime part",
                 ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
-        assertFalse("First mime type set as main body of request", ediEntity.isMainBody());
-
-        // Validate second mime part.
-        assertTrue("Second mime part incorrect type ",
-                signedEntity.getPart(1) instanceof ApplicationPkcs7SignatureEntity);
-        ApplicationPkcs7SignatureEntity signatureEntity = (ApplicationPkcs7SignatureEntity) signedEntity.getPart(1);
-        assertTrue("Unexpected content type for second mime part",
-                signatureEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_PKCS7_SIGNATURE));
-        assertFalse("First mime type set as main body of request", signatureEntity.isMainBody());
+        assertFalse("Enveloped mime type set as main body of request", ediEntity.isMainBody());
 
     }