[ https://issues.apache.org/jira/browse/CAMEL-12605?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16597096#comment-16597096 ]
ASF GitHub Bot commented on CAMEL-12605: ---------------------------------------- oscerd closed pull request #2500: [CAMEL-12605] Added test for enveloped request. URL: https://github.com/apache/camel/pull/2500 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): 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 08fbcd99d9a..d6c4934a657 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 @@ -26,6 +26,10 @@ * Media Type for Application PKCS7 Signature */ 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 */ 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 65684b77bff..708c203315a 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.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 void multipartSignedMessageTest() throws Exception { } -// @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 void envelopeddMessageTest() throws Exception { 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()); } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Enhance the AS2 Component to send and receive encrypted AS2 messages > -------------------------------------------------------------------- > > Key: CAMEL-12605 > URL: https://issues.apache.org/jira/browse/CAMEL-12605 > Project: Camel > Issue Type: Improvement > Affects Versions: 2.23.0 > Reporter: William Collins > Assignee: William Collins > Priority: Major > > Enhance the AS2 Component to support encrypted AS2 messages per RFC4130 -- This message was sent by Atlassian JIRA (v7.6.3#76005)