use of org.apache.mailet.Mailet in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_functionalTest method testProcessOutgoingMessageEndToEnd_multipleProcessThreads.
public void testProcessOutgoingMessageEndToEnd_multipleProcessThreads() throws Exception {
new TestPlan() {
protected String getMessageToProcess() throws Exception {
return TestUtils.readMessageResource("PlainOutgoingMessage.txt");
}
final class MessageEncrypter implements Callable<MimeMessage> {
private final Mailet theMailet;
public MessageEncrypter(Mailet theMailet) {
this.theMailet = theMailet;
}
public MimeMessage call() throws Exception {
// encrypt
String originalMessage = getMessageToProcess();
MimeMessage msg = EntitySerializer.Default.deserialize(originalMessage);
// add an MDN request
msg.setHeader(MDNStandard.Headers.DispositionNotificationTo, msg.getHeader(MailStandard.Headers.From, ","));
MockMail theMessage = new MockMail(msg);
theMailet.service(theMessage);
assertNotNull(theMessage);
assertNotNull(theMessage.getMessage());
msg = theMessage.getMessage();
return msg;
}
}
protected void performInner() throws Exception {
ExecutorService execService = Executors.newFixedThreadPool(10);
String originalMessage = getMessageToProcess();
// execute 100 times
GatewayState.getInstance().setSettingsUpdateInterval(1);
Mailet theMailet = getMailet("ValidConfig.xml");
List<Future<MimeMessage>> futures = new ArrayList<Future<MimeMessage>>();
for (int i = 0; i < 100; ++i) {
futures.add(execService.submit(new MessageEncrypter(theMailet)));
}
assertEquals(100, futures.size());
GatewayState.getInstance().setSettingsUpdateInterval(300);
for (Future<MimeMessage> future : futures) {
// decrypt
theMailet = getMailet("ValidConfigStateLine.txt");
MockMail theMessage = new MockMail(future.get());
theMailet.service(theMessage);
assertNotNull(theMessage);
assertNotNull(theMessage.getMessage());
MimeMessage msg = theMessage.getMessage();
assertFalse(SMIMEStandard.isEncrypted(msg));
assertEquals(theMessage.getState(), Mail.TRANSPORT);
Message compareMessage = new Message(theMessage.getMessage());
// remove the MDN before comparison
compareMessage.removeHeader(MDNStandard.Headers.DispositionNotificationTo);
assertEquals(originalMessage, compareMessage.toString());
}
}
}.perform();
}
use of org.apache.mailet.Mailet in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_functionalTest method testProcessOutgoingMessageEndToEnd_tamperedRoutingHeaders_rejectPolicyOn_assertRejected.
public void testProcessOutgoingMessageEndToEnd_tamperedRoutingHeaders_rejectPolicyOn_assertRejected() throws Exception {
new TestPlan() {
protected String getMessageToProcess() throws Exception {
return TestUtils.readMessageResource("PlainOutgoingMessage.txt");
}
@Override
protected Mailet getMailet(String configurationFileName) throws Exception {
Mailet retVal = null;
String configfile = TestUtils.getTestConfigFile(configurationFileName);
Map<String, String> params = new HashMap<String, String>();
if (configurationFileName.startsWith("http"))
params.put("ConfigURL", ConfigServiceRunner.getConfigServiceURL());
else
params.put("ConfigURL", "file://" + configfile);
params.put(SecurityAndTrustMailetOptions.REJECT_ON_ROUTING_TAMPER, "true");
retVal = new NHINDSecurityAndTrustMailet();
MailetConfig mailetConfig = new MockMailetConfig(params, "NHINDSecurityAndTrustMailet");
retVal.init(mailetConfig);
return retVal;
}
protected void performInner() throws Exception {
// encrypt
String originalMessage = getMessageToProcess();
MimeMessage msg = EntitySerializer.Default.deserialize(originalMessage);
// add an MDN request
msg.setHeader(MDNStandard.Headers.DispositionNotificationTo, msg.getHeader(MailStandard.Headers.From, ","));
MockMail theMessage = new MockMail(msg);
Mailet theMailet = getMailet("ValidConfig.xml");
theMailet.service(theMessage);
assertNotNull(theMessage);
assertNotNull(theMessage.getMessage());
msg = theMessage.getMessage();
assertTrue(SMIMEStandard.isEncrypted(msg));
assertEquals(theMessage.getState(), Mail.TRANSPORT);
// decrypt
theMailet = getMailet("ValidConfigStateLine.txt");
theMessage = new MockMail(msg);
final MailAddress validAddress = new MailAddress(msg.getRecipients(RecipientType.TO)[0].toString());
final MailAddress injectedAttackAddress = new MailAddress("externUser2@starugh-stateline.com");
theMessage.setRecipients(Arrays.asList(validAddress, injectedAttackAddress));
theMailet.service(theMessage);
// rejected and ghosted
assertEquals(Mail.GHOST, theMessage.getState());
}
}.perform();
}
use of org.apache.mailet.Mailet in project nhin-d by DirectProject.
the class RefreshSecurityAndTrustStateMailet_refreshStateTest method getMailet.
protected Mailet getMailet(String configurationFileName) throws Exception {
Mailet retVal = null;
String configfile = TestUtils.getTestConfigFile(configurationFileName);
Map<String, String> params = new HashMap<String, String>();
if (configurationFileName.startsWith("http"))
params.put("ConfigURL", ConfigServiceRunner.getConfigServiceURL());
else
params.put("ConfigURL", "file://" + configfile);
retVal = new NHINDSecurityAndTrustMailet();
MailetConfig mailetConfig = new MockMailetConfig(params, "NHINDSecurityAndTrustMailet");
retVal.init(mailetConfig);
return retVal;
}
use of org.apache.mailet.Mailet in project nhin-d by DirectProject.
the class TimelyAndReliableLocalDelivery_serviceTest method testService_failedDelivery_assertDSNCreated.
public void testService_failedDelivery_assertDSNCreated() throws Exception {
new TestPlan() {
@Override
protected void setupMocks() {
theMailet = new TimelyAndReliableLocalDelivery() {
protected Object createLocalDeliveryClass() throws Exception {
Mailet mailet = mock(Mailet.class);
doThrow(new RuntimeException()).when(mailet).service((Mail) any());
return mailet;
}
};
try {
MailetConfig config = getMailetConfig();
theMailet.init(config);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
protected void doAssertions(MockMailetContext context) throws Exception {
assertEquals(1, context.getSentMessages().size());
MimeMessage dsnMessage = context.getSentMessages().iterator().next().getMessage();
assertEquals(TxMessageType.DSN, TxUtil.getMessageType(dsnMessage));
String originalMessageString = TestUtils.readMessageResource(getMessageToSend());
MimeMessage originalMsg = EntitySerializer.Default.deserialize(originalMessageString);
NHINDAddress originalRecipAddress = new NHINDAddress(MailStandard.getHeader(originalMsg, MailStandard.Headers.To));
NHINDAddress dsnFromAddress = new NHINDAddress(MailStandard.getHeader(dsnMessage, MailStandard.Headers.From));
assertTrue(dsnFromAddress.getHost().toLowerCase(Locale.getDefault()).contains(originalRecipAddress.getHost().toLowerCase(Locale.getDefault())));
}
}.perform();
}
use of org.apache.mailet.Mailet in project nhin-d by DirectProject.
the class TimelyAndReliableLocalDelivery_serviceTest method testService_failedDelivery_nonIMF_assertDSNNotCreated.
public void testService_failedDelivery_nonIMF_assertDSNNotCreated() throws Exception {
new TestPlan() {
@Override
protected void setupMocks() {
theMailet = new TimelyAndReliableLocalDelivery() {
protected Object createLocalDeliveryClass() throws Exception {
Mailet mailet = mock(Mailet.class);
doThrow(new RuntimeException()).when(mailet).service((Mail) any());
return mailet;
}
};
try {
MailetConfig config = getMailetConfig();
theMailet.init(config);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
protected String getMessageToSend() {
return "MDNMessage.txt";
}
@Override
protected void doAssertions(MockMailetContext context) throws Exception {
assertEquals(0, context.getSentMessages().size());
}
}.perform();
}
Aggregations