Skip to content

Commit

Permalink
[CAMEL-12605] Added test for enveloped request.
Browse files Browse the repository at this point in the history
  • Loading branch information
punkhorn authored and oscerd committed Aug 30, 2018
1 parent e4de63b commit d254c8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
Expand Up @@ -26,6 +26,10 @@ public interface AS2MediaType {
* Media Type for Application PKCS7 Signature * Media Type for Application PKCS7 Signature
*/ */
public static final String APPLICATION_PKCS7_SIGNATURE = "application/pkcs7-signature; name=smime.p7s; smime-type=signed-data"; 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 * Media Type for Text/Plain Data
*/ */
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.apache.camel.component.as2.api.entity.AS2MessageDispositionNotificationEntity; 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.ApplicationEDIEntity;
import org.apache.camel.component.as2.api.entity.ApplicationEDIFACTEntity; 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.ApplicationPkcs7SignatureEntity;
import org.apache.camel.component.as2.api.entity.DispositionMode; import org.apache.camel.component.as2.api.entity.DispositionMode;
import org.apache.camel.component.as2.api.entity.DispositionNotificationMultipartReportEntity; import org.apache.camel.component.as2.api.entity.DispositionNotificationMultipartReportEntity;
Expand Down Expand Up @@ -364,16 +365,17 @@ public void multipartSignedMessageTest() throws Exception {


} }


// @Test @Test
public void envelopeddMessageTest() throws Exception { public void envelopeddMessageTest() throws Exception {
AS2ClientConnection clientConnection = new AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN, AS2ClientConnection clientConnection = new AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN,
TARGET_HOST, TARGET_PORT); TARGET_HOST, TARGET_PORT);
AS2ClientManager clientManager = new AS2ClientManager(clientConnection); AS2ClientManager clientManager = new AS2ClientManager(clientConnection);


HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE, REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME, 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, 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(); HttpRequest request = httpContext.getRequest();
assertEquals("Unexpected method value", METHOD, request.getRequestLine().getMethod()); assertEquals("Unexpected method value", METHOD, request.getRequestLine().getMethod());
Expand All @@ -396,30 +398,22 @@ public void envelopeddMessageTest() throws Exception {
assertNotNull("Date value missing", request.getFirstHeader(AS2Header.DATE)); assertNotNull("Date value missing", request.getFirstHeader(AS2Header.DATE));
assertNotNull("Content length value missing", request.getFirstHeader(AS2Header.CONTENT_LENGTH)); assertNotNull("Content length value missing", request.getFirstHeader(AS2Header.CONTENT_LENGTH));
assertTrue("Unexpected content type for message", 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); assertTrue("Request does not contain entity", request instanceof BasicHttpEntityEnclosingRequest);
HttpEntity entity = ((BasicHttpEntityEnclosingRequest) request).getEntity(); HttpEntity entity = ((BasicHttpEntityEnclosingRequest) request).getEntity();
assertNotNull("Request does not contain entity", entity); assertNotNull("Request does not contain entity", entity);
assertTrue("Unexpected request entity type", entity instanceof MultipartSignedEntity); assertTrue("Unexpected request entity type", entity instanceof ApplicationPkcs7MimeEntity);
MultipartSignedEntity signedEntity = (MultipartSignedEntity) entity; ApplicationPkcs7MimeEntity envelopedEntity = (ApplicationPkcs7MimeEntity) entity;
assertTrue("Entity not set as main body of request", signedEntity.isMainBody()); assertTrue("Entity not set as main body of request", envelopedEntity.isMainBody());
assertTrue("Request contains invalid number of mime parts", signedEntity.getPartCount() == 2);

// Validated enveloped part.
// Validated first mime part. MimeEntity encryptedEntity = envelopedEntity.getEncryptedEntity(signingKP.getPrivate());
assertTrue("First mime part incorrect type ", signedEntity.getPart(0) instanceof ApplicationEDIFACTEntity); assertTrue("Enveloped mime part incorrect type ", encryptedEntity instanceof ApplicationEDIFACTEntity);
ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity) signedEntity.getPart(0); ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity) encryptedEntity;
assertTrue("Unexpected content type for first mime part", assertTrue("Unexpected content type for enveloped mime part",
ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT)); ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
assertFalse("First mime type set as main body of request", ediEntity.isMainBody()); assertFalse("Enveloped 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());


} }


Expand Down

0 comments on commit d254c8f

Please sign in to comment.