use of org.apache.mailet.MailetConfig in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_initialization_Test method testValidMailetConfiguration_AssertProperWSInitialization.
public void testValidMailetConfiguration_AssertProperWSInitialization() throws Exception {
new TestPlan() {
private ConfigurationServiceProxy proxy;
@Override
protected MailetConfig getMailetConfig() throws Exception {
ConfigServiceRunner.startConfigService();
cleanConfig();
addDomains();
addTrustAnchors();
Map<String, String> params = new HashMap<String, String>();
params.put("ConfigURL", ConfigServiceRunner.getConfigServiceURL());
return new MockMailetConfig(params, "NHINDSecurityAndTrustMailet");
}
protected void addDomains() throws Exception {
Domain dom = new Domain();
dom.setDomainName("cerner.com");
dom.setPostMasterEmail("postmaster@cerner.com");
proxy.addDomain(dom);
dom = new Domain();
dom.setDomainName("securehealthemail.com");
dom.setPostMasterEmail("postmaster@securehealthemail.com");
proxy.addDomain(dom);
}
protected void addTrustAnchors() throws Exception {
Vector<Anchor> vec = new Vector<Anchor>();
Anchor anchor = new Anchor();
anchor.setData(getCertificateFileData("cacert.der"));
anchor.setOwner("cerner.com");
anchor.setIncoming(true);
anchor.setOutgoing(true);
vec.add(anchor);
anchor = new Anchor();
anchor.setData(getCertificateFileData("cacert.der"));
anchor.setOwner("securehealthemail.com");
anchor.setIncoming(true);
anchor.setOutgoing(true);
vec.add(anchor);
proxy.addAnchor(vec.toArray(new Anchor[vec.size()]));
}
protected void cleanConfig() throws Exception {
proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
// clean domains
int domainCount = proxy.getDomainCount();
Domain[] doms = proxy.listDomains(null, domainCount);
if (doms != null)
for (Domain dom : doms) {
// clean anchors
proxy.removeAnchorsForOwner(dom.getDomainName());
proxy.removeDomain(dom.getDomainName());
}
// clean certificates
Certificate[] certs = proxy.listCertificates(0, 0x8FFFF, null);
if (certs != null)
for (Certificate cert : certs) proxy.removeCertificatesForOwner(cert.getOwner());
// clean settings
Setting[] settings = proxy.getAllSettings();
if (settings != null)
for (Setting setting : settings) proxy.deleteSetting(new String[] { setting.getName() });
}
@Override
protected void doAssertions(NHINDSecurityAndTrustMailet agent) throws Exception {
assertNotNull(agent);
assertNotNull(agent.getInitParameter("ConfigURL"));
assertEquals(ConfigServiceRunner.getConfigServiceURL(), agent.getInitParameter("ConfigURL"));
}
}.perform();
}
use of org.apache.mailet.MailetConfig 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.MailetConfig 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.MailetConfig 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.MailetConfig 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