Search in sources :

Example 36 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class UserMessageCompressionTest method testUserMessageWithCompressedSignedSuccessful.

@Test
public void testUserMessageWithCompressedSignedSuccessful() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr));
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments);
    final Document aDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSOAPVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSOAPVersion, aDoc, aAttachments);
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 37 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class UserMessageCompressionTest method testUserMessageCompressedSignedEncrpytedSuccessful.

@Test
public void testUserMessageCompressedSignedEncrpytedSuccessful() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr));
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments);
    final Document aDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSOAPVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
    final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSOAPVersion, aDoc, aAttachments, m_aCryptoFactory, false, s_aResMgr, m_aCryptParams);
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 38 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class UserMessageFailureForgeryTest method testUserMessageEncryptedMimeAttachmentForged.

// Encryption
// Cannot be tested easily, since the error gets only thrown if the SPI tries
// to read the stream of the attachment
// @Ignore
@Test
public void testUserMessageEncryptedMimeAttachmentForged() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().build(), s_aResMgr));
    final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSoapVersion, MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments).getAsSoapDocument(), aAttachments, m_aCryptoFactory, true, s_aResMgr, m_aCryptParams);
    final SoapMimeMultipart aMultipart = (SoapMimeMultipart) aMimeMsg.getContent();
    // Since we want to change the attachment
    final MimeBodyPart aMimeBodyPart = (MimeBodyPart) aMultipart.getBodyPart(1);
    aMimeBodyPart.setContent("Crappy text".getBytes(StandardCharsets.ISO_8859_1), CMimeType.APPLICATION_OCTET_STREAM.getAsString());
    aMimeMsg.saveChanges();
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_FAILED_DECRYPTION.getErrorCode());
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) SoapMimeMultipart(com.helger.phase4.messaging.mime.SoapMimeMultipart) MimeBodyPart(javax.mail.internet.MimeBodyPart) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 39 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class UserMessageFailureForgeryTest method testUserMessageWithMoreAttachmentsThenPartInfo.

@Test
public void testUserMessageWithMoreAttachmentsThenPartInfo() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_XML_GZ)).mimeType(CMimeType.APPLICATION_GZIP).build(), s_aResMgr));
    final Document aSoapDoc = MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments).getAsSoapDocument();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)).mimeType(CMimeType.IMAGE_JPG).build(), s_aResMgr));
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_IMG2_JPG)).mimeType(CMimeType.IMAGE_JPG).build(), s_aResMgr));
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aSoapDoc, aAttachments);
    aMimeMsg.saveChanges();
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getErrorCode());
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 40 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class UserMessageFailureForgeryTest method testWrongAttachmentIDShouldFail.

@Test
public void testWrongAttachmentIDShouldFail() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_XML_GZ)).mimeType(CMimeType.APPLICATION_GZIP).build(), s_aResMgr));
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments);
    final Document aDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSoapVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
    final NodeList nList = aDoc.getElementsByTagName("eb:PartInfo");
    for (int i = 0; i < nList.getLength(); i++) {
        final Node nNode = nList.item(i);
        final Element aElement = (Element) nNode;
        if (aElement.hasAttribute("href"))
            aElement.setAttribute("href", MessageHelperMethods.PREFIX_CID + "invalid" + i);
    }
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aDoc, aAttachments);
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Aggregations

HttpMimeMessageEntity (com.helger.phase4.http.HttpMimeMessageEntity)43 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)43 Test (org.junit.Test)41 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)36 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)36 Document (org.w3c.dom.Document)20 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)16 IStringMap (com.helger.commons.collection.attr.IStringMap)3 StringMap (com.helger.commons.collection.attr.StringMap)3 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)3 ScopedConfig (com.helger.phase4.ScopedConfig)3 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)3 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)3 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)3 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)3 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)3 HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)3 DefaultHttpProxyServer (org.littleshoot.proxy.impl.DefaultHttpProxyServer)3 Node (org.w3c.dom.Node)3 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)2