Search in sources :

Example 6 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression 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));
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) InternetAddress(javax.mail.internet.InternetAddress) PolicyFilter(org.nhindirect.policy.PolicyFilter) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) X509Certificate(java.security.cert.X509Certificate)

Example 7 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_policyNotCompliant_assertFalse.

public void testIsCertPolicyCompliant_policyNotCompliant_assertFalse() throws Exception {
    final TrustModel model = new TrustModel();
    final PolicyFilter filter = mock(PolicyFilter.class);
    when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(false);
    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));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyFilter(org.nhindirect.policy.PolicyFilter) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) X509Certificate(java.security.cert.X509Certificate)

Example 8 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DomainPolicyResolver_contstuctTest method testConstruct_differentForIncomingAndOutgoing_assertAttributes.

public void testConstruct_differentForIncomingAndOutgoing_assertAttributes() {
    final PolicyExpression expression1 = mock(PolicyExpression.class);
    final List<PolicyExpression> expressions1 = Arrays.asList(expression1);
    final Map<String, Collection<PolicyExpression>> outgoingPolicies = new HashMap<String, Collection<PolicyExpression>>();
    outgoingPolicies.put("testdomain.com", expressions1);
    final PolicyExpression expression2 = mock(PolicyExpression.class);
    final PolicyExpression expression3 = mock(PolicyExpression.class);
    final List<PolicyExpression> expressions2 = Arrays.asList(expression2, expression3);
    final Map<String, Collection<PolicyExpression>> incomingPolicies = new HashMap<String, Collection<PolicyExpression>>();
    incomingPolicies.put("testdomain.com", expressions2);
    final DomainPolicyResolver resolver = new DomainPolicyResolver(incomingPolicies, outgoingPolicies);
    assertNotNull(resolver);
    assertEquals(1, resolver.outgoingPolicies.size());
    Collection<PolicyExpression> retrievedExpressions = resolver.outgoingPolicies.get("TESTDOMAIN.COM");
    assertEquals(1, retrievedExpressions.size());
    assertNotNull(retrievedExpressions);
    assertEquals(1, resolver.incomingPolicies.size());
    retrievedExpressions = resolver.incomingPolicies.get("TESTDOMAIN.COM");
    assertEquals(2, retrievedExpressions.size());
    assertNotNull(retrievedExpressions);
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Example 9 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DomainPolicyResolver_contstuctTest method testConstruct_sameForIncomingAndOutgoing_assertAttributes.

public void testConstruct_sameForIncomingAndOutgoing_assertAttributes() {
    final PolicyExpression expression = mock(PolicyExpression.class);
    final List<PolicyExpression> expressions = Arrays.asList(expression);
    final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
    policies.put("testdomain.com", expressions);
    final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
    assertNotNull(resolver);
    assertEquals(1, resolver.incomingPolicies.size());
    Collection<PolicyExpression> retrievedExpressions = resolver.incomingPolicies.get("TESTDOMAIN.COM");
    assertNotNull(retrievedExpressions);
    assertEquals(1, resolver.outgoingPolicies.size());
    retrievedExpressions = resolver.outgoingPolicies.get("TESTDOMAIN.COM");
    assertNotNull(retrievedExpressions);
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Example 10 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DomainPolicyResolver_getPolicyTest method testGetPolicy_outgoingPolicyDoesNotExist_assertEmpty.

public void testGetPolicy_outgoingPolicyDoesNotExist_assertEmpty() throws Exception {
    final PolicyExpression expression = mock(PolicyExpression.class);
    final List<PolicyExpression> expressions = Arrays.asList(expression);
    final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
    policies.put("testdomain.com", expressions);
    final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
    Collection<PolicyExpression> retrievedExpressions = resolver.getOutgoingPolicy(new InternetAddress("me@testdomainother.com"));
    assertNotNull(retrievedExpressions);
    assertEquals(0, retrievedExpressions.size());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Aggregations

PolicyExpression (org.nhindirect.policy.PolicyExpression)54 X509Certificate (java.security.cert.X509Certificate)21 InternetAddress (javax.mail.internet.InternetAddress)18 LiteralPolicyExpression (org.nhindirect.policy.LiteralPolicyExpression)16 OperationPolicyExpression (org.nhindirect.policy.OperationPolicyExpression)16 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)12 InputStream (java.io.InputStream)11 PolicyFilter (org.nhindirect.policy.PolicyFilter)10 Vector (java.util.Vector)9 Collection (java.util.Collection)8 HashMap (java.util.HashMap)8 Opcode (org.nhindirect.policy.Opcode)7 KeyUsageExtensionField (org.nhindirect.policy.x509.KeyUsageExtensionField)7 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)7 TrustAnchorResolver (org.nhindirect.stagent.trust.TrustAnchorResolver)7 File (java.io.File)6 StackMachineCompiler (org.nhindirect.policy.impl.machine.StackMachineCompiler)6 ExtendedKeyUsageExtensionField (org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5