use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.
the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_missingRequiredField_assertFalse.
public void testIsCertPolicyCompliant_missingRequiredField_assertFalse() throws Exception {
final TrustModel model = new TrustModel();
final PolicyFilter filter = mock(PolicyFilter.class);
doThrow(new PolicyRequiredException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
final PolicyResolver resolver = mock(PolicyResolver.class);
final PolicyExpression expression = mock(PolicyExpression.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
model.setTrustPolicyResolver(resolver);
model.setPolicyFilter(filter);
final X509Certificate cert = mock(X509Certificate.class);
assertFalse(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.
the class AuthorityInfoAccessOCSPLocExtentionField method injectReferenceValue.
/**
* {@inheritDoc}
*/
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
this.certificate = value;
final DERObject exValue = getExtensionValue(value);
if (exValue == null) {
if (isRequired())
throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
else {
final Collection<String> coll = Collections.emptyList();
this.policyValue = PolicyValueFactory.getInstance(coll);
return;
}
}
final AuthorityInformationAccess aia = AuthorityInformationAccess.getInstance(exValue);
final Collection<String> retVal = new ArrayList<String>();
for (AccessDescription accessDescription : aia.getAccessDescriptions()) {
if (accessDescription.getAccessMethod().equals(AccessDescription.id_ad_ocsp))
retVal.add(accessDescription.getAccessLocation().getName().toString());
}
if (retVal.isEmpty() && isRequired())
throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
this.policyValue = PolicyValueFactory.getInstance(retVal);
}
use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.
the class StackMachine_getCompilationReportTest method testGetCompilationReportTest_switchModes_assertCorrectReportSize.
public void testGetCompilationReportTest_switchModes_assertCorrectReportSize() throws Exception {
final X509Certificate cert1 = TestUtils.loadCertificate("umesh.der");
KeyUsageExtensionField keyExtendExp = new KeyUsageExtensionField(true);
final StackMachineCompiler machine = new StackMachineCompiler();
machine.setReportModeEnabled(true);
assertTrue(machine.isReportModeEnabled());
machine.compile(cert1, keyExtendExp);
assertEquals(1, machine.getCompilationReport().size());
// turn off report mode and make sure the report is empty
keyExtendExp = new KeyUsageExtensionField(true);
machine.setReportModeEnabled(false);
assertFalse(machine.isReportModeEnabled());
boolean exceptionOccured = false;
try {
machine.compile(cert1, keyExtendExp);
} catch (PolicyRequiredException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
assertTrue(machine.getCompilationReport().isEmpty());
}
use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.
the class StackMachine_getCompilationReportTest method testGetCompilationReportTest_missingRequiredField_reportModeOff_assertEmptyCollection.
public void testGetCompilationReportTest_missingRequiredField_reportModeOff_assertEmptyCollection() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("umesh.der");
final KeyUsageExtensionField keyExtendExp = new KeyUsageExtensionField(true);
final StackMachineCompiler machine = new StackMachineCompiler();
machine.setReportModeEnabled(false);
assertFalse(machine.isReportModeEnabled());
boolean exceptionOccured = false;
try {
machine.compile(cert, keyExtendExp);
} catch (PolicyRequiredException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
assertTrue(machine.getCompilationReport().isEmpty());
}
use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.
the class AuthorityKeyIdentifierKeyIdExtensionField_injectReferenceValueTest method testInjectRefereneValue_keyIdDoesNotExist_required_assertException.
public void testInjectRefereneValue_keyIdDoesNotExist_required_assertException() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("cernerDemosCaCert.der");
final AuthorityKeyIdentifierKeyIdExtensionField field = new AuthorityKeyIdentifierKeyIdExtensionField(true);
boolean exceptionOccured = false;
try {
field.injectReferenceValue(cert);
} catch (PolicyRequiredException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
Aggregations