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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations