use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.
the class CryptoExtensions_registerJCEProvidersTest method testRegisterJCEProviders_invalidProvider_assertException.
public void testRegisterJCEProviders_invalidProvider_assertException() {
Security.removeProvider("BC");
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.JCE_PROVIDER_CLASSES, "bogusProvider"));
assertNotNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES));
assertEquals("bogusProvider", OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES).getParamValue());
assertNull(Security.getProvider("BC"));
boolean exceptionOccured = false;
try {
CryptoExtensions.registerJCEProviders();
} catch (IllegalStateException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
assertNotNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES));
assertEquals("bogusProvider", OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES).getParamValue());
assertNull(Security.getProvider("BC"));
}
use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.
the class CryptoExtensions_registerJCEProvidersTest method testRegisterJCEProviders_emptyOptionValue_providerNotAlreadyRegistered.
public void testRegisterJCEProviders_emptyOptionValue_providerNotAlreadyRegistered() {
Security.removeProvider("BC");
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.JCE_PROVIDER_CLASSES, ""));
assertNotNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES));
assertEquals("", OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES).getParamValue());
assertNull(Security.getProvider("BC"));
CryptoExtensions.registerJCEProviders();
assertNotNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES));
assertEquals("", OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES).getParamValue());
assertNotNull(Security.getProvider("BC"));
}
use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.
the class CryptoExtensions_registerJCEProvidersTest method testRegisterJCEProviders_nullOptionValue_providerNotAlreadyRegistered.
public void testRegisterJCEProviders_nullOptionValue_providerNotAlreadyRegistered() {
Security.removeProvider("BC");
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.JCE_PROVIDER_CLASSES, null));
assertNotNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES));
assertNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES).getParamValue());
assertNull(Security.getProvider("BC"));
CryptoExtensions.registerJCEProviders();
assertNotNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES));
assertNull(OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER_CLASSES).getParamValue());
assertNotNull(Security.getProvider("BC"));
}
use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.
the class NHINDAgentTest method testIncomingMDN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted.
public void testIncomingMDN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted() throws Exception {
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS, "true"));
// first create the encyrpted message
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.com" }));
String testMessage = TestUtils.readResource("MDNMessage.txt");
final OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
;
assertNotNull(SMIMEenvMessage);
// now send received the MDN
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "Cerner.com" }));
DefaultTrustAnchorResolver resolver = (DefaultTrustAnchorResolver) agent.getTrustAnchors();
CertificateResolver mockResolver = mock(CertificateResolver.class);
DefaultTrustAnchorResolver newResolver = new DefaultTrustAnchorResolver(resolver.getOutgoingAnchors(), mockResolver);
agent.setTrustAnchorResolver(newResolver);
IncomingMessage incomingMessage = agent.processIncoming(SMIMEenvMessage.getMessage());
assertNotNull(incomingMessage);
}
use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.
the class NHINDAgentTest method testRejectMessageOnRoutingTamper_policyTrue_assertMessageRejected.
public void testRejectMessageOnRoutingTamper_policyTrue_assertMessageRejected() throws Exception {
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.REJECT_ON_ROUTING_TAMPER, "true"));
/*
* EncryptedMessage2
*/
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
String testMessage = TestUtils.readResource("EncryptedMessage2.txt");
Message originalMsg = new Message(new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII"))));
// add an extra recipient that should not receive this message
final NHINDAddressCollection tamperedRecips = new NHINDAddressCollection();
tamperedRecips.add(new NHINDAddress("ryan@securehealthemail.com"));
tamperedRecips.add(new NHINDAddress("john@securehealthemail.com"));
final IncomingMessage inMessage = new IncomingMessage(originalMsg, tamperedRecips, new NHINDAddress(originalMsg.getFrom()[0].toString()));
boolean exceptionOccured = false;
try {
agent.processIncoming(inMessage);
} catch (AgentException e) {
assertEquals(AgentError.MessageTamperDectection, e.getError());
exceptionOccured = true;
}
assertTrue(exceptionOccured);
OptionsManager.destroyInstance();
}
Aggregations