Search in sources :

Example 11 with Parameters

use of org.junit.runners.Parameterized.Parameters in project cas by apereo.

the class ThresholdExpiredCRLRevocationPolicyTests method getTestParameters.

/**
     * Gets the unit test parameters.
     *
     * @return  Test parameter data.
     * @throws Exception if there is an exception getting the test parameters.
     */
@Parameters
public static Collection<Object[]> getTestParameters() throws Exception {
    final Collection<Object[]> params = new ArrayList<>();
    final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    final ZonedDateTime twoHoursAgo = now.minusHours(2);
    final ZonedDateTime oneHourAgo = now.minusHours(1);
    final ZonedDateTime halfHourAgo = now.minusMinutes(30);
    final X500Principal issuer = new X500Principal("CN=CAS");
    // Test case #1
    // Expect expired for zero leniency on CRL expiring 1ms ago
    final ThresholdExpiredCRLRevocationPolicy zeroThreshold = new ThresholdExpiredCRLRevocationPolicy(0);
    params.add(new Object[] { zeroThreshold, new MockX509CRL(issuer, DateTimeUtils.dateOf(oneHourAgo), DateTimeUtils.dateOf(now.minusSeconds(1))), new ExpiredCRLException("CN=CAS", ZonedDateTime.now(ZoneOffset.UTC)) });
    // Test case #2
    // Expect expired for 1h leniency on CRL expired 1 hour 1ms ago
    final ThresholdExpiredCRLRevocationPolicy oneHourThreshold = new ThresholdExpiredCRLRevocationPolicy(3600);
    params.add(new Object[] { oneHourThreshold, new MockX509CRL(issuer, DateTimeUtils.dateOf(twoHoursAgo), DateTimeUtils.dateOf(oneHourAgo.minusSeconds(1))), new ExpiredCRLException("CN=CAS", ZonedDateTime.now(ZoneOffset.UTC)) });
    // Test case #3
    // Expect valid for 1h leniency on CRL expired 30m ago
    params.add(new Object[] { oneHourThreshold, new MockX509CRL(issuer, DateTimeUtils.dateOf(twoHoursAgo), DateTimeUtils.dateOf(halfHourAgo)), null });
    return params;
}
Also used : ExpiredCRLException(org.apereo.cas.adaptors.x509.authentication.ExpiredCRLException) ZonedDateTime(java.time.ZonedDateTime) MockX509CRL(org.apereo.cas.adaptors.x509.util.MockX509CRL) ArrayList(java.util.ArrayList) X500Principal(javax.security.auth.x500.X500Principal) ThresholdExpiredCRLRevocationPolicy(org.apereo.cas.adaptors.x509.authentication.revocation.policy.ThresholdExpiredCRLRevocationPolicy) Parameters(org.junit.runners.Parameterized.Parameters)

Example 12 with Parameters

use of org.junit.runners.Parameterized.Parameters in project cas by apereo.

the class X509CredentialsAuthenticationHandlerTests method getTestParameters.

/**
     * Gets the unit test parameters.
     *
     * @return Test parameter data.
     * @throws Exception On test data setup errors.
     */
@Parameters
public static Collection<Object[]> getTestParameters() throws Exception {
    final Collection<Object[]> params = new ArrayList<>();
    X509CredentialsAuthenticationHandler handler;
    X509CertificateCredential credential;
    // Test case #1: Unsupported credential type
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"));
    params.add(new Object[] { handler, new UsernamePasswordCredential(), false, null });
    // Test case #2:Valid certificate
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"));
    credential = new X509CertificateCredential(createCertificates(USER_VALID_CRT));
    params.add(new Object[] { handler, credential, true, new DefaultHandlerResult(handler, credential, new DefaultPrincipalFactory().createPrincipal(credential.getId())) });
    // Test case #3: Expired certificate
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"));
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates("user-expired.crt")), true, new CertificateExpiredException() });
    // Test case #4: Untrusted issuer
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern("CN=\\w+,OU=CAS,O=Jasig,L=Westminster,ST=Colorado,C=US"), true, false, false);
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates("snake-oil.crt")), true, new FailedLoginException() });
    // Test case #5: Disallowed subject
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), true, RegexUtils.createPattern("CN=\\w+,OU=CAS,O=Jasig,L=Westminster,ST=Colorado,C=US"));
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates("snake-oil.crt")), true, new FailedLoginException() });
    // Test case #6: Check key usage on a cert without keyUsage extension
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), false, true, false);
    credential = new X509CertificateCredential(createCertificates(USER_VALID_CRT));
    params.add(new Object[] { handler, credential, true, new DefaultHandlerResult(handler, credential, new DefaultPrincipalFactory().createPrincipal(credential.getId())) });
    // Test case #7: Require key usage on a cert without keyUsage extension
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), false, true, true);
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates(USER_VALID_CRT)), true, new FailedLoginException() });
    // Test case #8: Require key usage on a cert with acceptable keyUsage extension values
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), false, true, true);
    credential = new X509CertificateCredential(createCertificates("user-valid-keyUsage.crt"));
    params.add(new Object[] { handler, credential, true, new DefaultHandlerResult(handler, credential, new DefaultPrincipalFactory().createPrincipal(credential.getId())) });
    // Test case #9: Require key usage on a cert with unacceptable keyUsage extension values
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), false, true, true);
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates("user-invalid-keyUsage.crt")), true, new FailedLoginException() });
    //===================================
    // Revocation tests
    //===================================
    ResourceCRLRevocationChecker checker;
    // Test case #10: Valid certificate with CRL checking
    checker = new ResourceCRLRevocationChecker(new ClassPathResource("userCA-valid.crl"));
    checker.init();
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), checker);
    credential = new X509CertificateCredential(createCertificates(USER_VALID_CRT));
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates(USER_VALID_CRT)), true, new DefaultHandlerResult(handler, credential, new DefaultPrincipalFactory().createPrincipal(credential.getId())) });
    // Test case #11: Revoked end user certificate
    checker = new ResourceCRLRevocationChecker(new ClassPathResource("userCA-valid.crl"));
    checker.init();
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), checker);
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates("user-revoked.crt")), true, new RevokedCertificateException(ZonedDateTime.now(ZoneOffset.UTC), null) });
    // Test case #12: Valid certificate on expired CRL data
    final ThresholdExpiredCRLRevocationPolicy zeroThresholdPolicy = new ThresholdExpiredCRLRevocationPolicy(0);
    checker = new ResourceCRLRevocationChecker(new ClassPathResource("userCA-expired.crl"), null, zeroThresholdPolicy);
    checker.init();
    handler = new X509CredentialsAuthenticationHandler(RegexUtils.createPattern(".*"), checker);
    params.add(new Object[] { handler, new X509CertificateCredential(createCertificates(USER_VALID_CRT)), true, new ExpiredCRLException(null, ZonedDateTime.now(ZoneOffset.UTC)) });
    return params;
}
Also used : RevokedCertificateException(org.apereo.cas.adaptors.x509.authentication.revocation.RevokedCertificateException) CertificateExpiredException(java.security.cert.CertificateExpiredException) ArrayList(java.util.ArrayList) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) ThresholdExpiredCRLRevocationPolicy(org.apereo.cas.adaptors.x509.authentication.revocation.policy.ThresholdExpiredCRLRevocationPolicy) ExpiredCRLException(org.apereo.cas.adaptors.x509.authentication.ExpiredCRLException) FailedLoginException(javax.security.auth.login.FailedLoginException) X509CertificateCredential(org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential) ResourceCRLRevocationChecker(org.apereo.cas.adaptors.x509.authentication.revocation.checker.ResourceCRLRevocationChecker) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Parameters(org.junit.runners.Parameterized.Parameters)

Example 13 with Parameters

use of org.junit.runners.Parameterized.Parameters in project cas by apereo.

the class X509SubjectPrincipalResolverTests method getTestParameters.

/**
     * Gets the unit test parameters.
     *
     * @return  Test parameter data.
     */
@Parameters
public static Collection<Object[]> getTestParameters() throws Exception {
    final Collection<Object[]> params = new ArrayList<>();
    // Test case #1
    // Use CN for principal ID
    params.add(new Object[] { new ClassPathResource("x509-ctop-resolver-hizzy.crt").getFile().getCanonicalPath(), "$CN", "Hizzogarthington I.S. Pleakinsense" });
    // Test case #2
    // Use email address for principal ID
    params.add(new Object[] { new ClassPathResource("x509-ctop-resolver-hizzy.crt").getFile().getCanonicalPath(), "$EMAILADDRESS", "hizzy@vt.edu" });
    // Test case #2
    // Use combination of ou and cn for principal ID
    params.add(new Object[] { new ClassPathResource("x509-ctop-resolver-hizzy.crt").getFile().getCanonicalPath(), "$OU $CN", "Middleware Hizzogarthington I.S. Pleakinsense" });
    // Test case #3
    // Use combination of serial number and cn for principal ID
    params.add(new Object[] { new ClassPathResource("x509-ctop-resolver-gazzo.crt").getFile().getCanonicalPath(), "$CN:$SERIALNUMBER", "Gazzaloddi P. Wishwashington:271828183" });
    // Test case #4
    // Build principal ID from multivalued attributes
    params.add(new Object[] { new ClassPathResource("x509-ctop-resolver-jacky.crt").getFile().getCanonicalPath(), "$UID@$DC.$DC", "jacky@vt.edu" });
    return params;
}
Also used : ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) Parameters(org.junit.runners.Parameterized.Parameters)

Example 14 with Parameters

use of org.junit.runners.Parameterized.Parameters in project opennms by OpenNMS.

the class CollectionResourceDTOTest method data.

@Parameters
public static Collection<Object[]> data() throws ParseException {
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    NumericAttribute attribute = new NumericAttribute("group-x", "cores", 1, AttributeType.GAUGE, "some-oid");
    CollectionResourceDTO dto = new CollectionResourceDTO();
    dto.setResource(nodeLevelResource);
    dto.getAttributes().add(attribute);
    return Arrays.asList(new Object[][] { { dto, "<collection-resource>\n" + "   <node-level-resource node-id=\"1\"/>\n" + "   <numeric-attribute group=\"group-x\" name=\"cores\" type=\"gauge\" identifier=\"some-oid\" value=\"1\"/>\n" + "</collection-resource>" } });
}
Also used : CollectionResourceDTO(org.opennms.netmgt.collection.dto.CollectionResourceDTO) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) NumericAttribute(org.opennms.netmgt.collection.support.builder.NumericAttribute) Parameters(org.junit.runners.Parameterized.Parameters)

Example 15 with Parameters

use of org.junit.runners.Parameterized.Parameters in project opennms by OpenNMS.

the class CollectionSetDTOTest method data.

@Parameters
public static Collection<Object[]> data() throws ParseException {
    CollectionAgent collectionAgent = mock(CollectionAgent.class);
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    InterfaceLevelResource interfaceLevelResource = new InterfaceLevelResource(nodeLevelResource, "eth0");
    ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
    when(rt.getName()).thenReturn("Charles");
    when(rt.getStorageStrategy().getClazz()).thenReturn(MockStorageStrategy.class.getCanonicalName());
    when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(MockPersistenceSelectorStrategy.class.getCanonicalName());
    DeferredGenericTypeResource deferredGenericTypeResource = new DeferredGenericTypeResource(nodeLevelResource, "Charles", "id");
    GenericTypeResource genericTypeResource = new GenericTypeResource(nodeLevelResource, rt, "idx");
    genericTypeResource.setTimestamp(new Date(0));
    ResourceTypeMapper.getInstance().setResourceTypeMapper((name) -> rt);
    // For complete coverage make sure that there is at least one attribute
    // for every different resource type, and that every different type
    // of attribute is represented at least once
    CollectionSet collectionSet = new CollectionSetBuilder(collectionAgent).withTimestamp(new Date(0)).withNumericAttribute(nodeLevelResource, "ucd-sysstat", "CpuRawIdle", 99, AttributeType.GAUGE).withNumericAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifHCInOctets", 1001, AttributeType.COUNTER).withStringAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifDescr", "LAN").withIdentifiedNumericAttribute(deferredGenericTypeResource, "net-snmp-disk", "ns-dsk1", 1024, AttributeType.GAUGE, "some-oid").withIdentifiedNumericAttribute(genericTypeResource, "net-snmp-disk", "ns-dskTotal", 1024, AttributeType.GAUGE, "some-oid").build();
    return Arrays.asList(new Object[][] { { collectionSet, "<collection-set status=\"SUCCEEDED\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + "   <agent type=\"0\" store-by-fs=\"false\" node-id=\"0\" sys-up-time=\"0\"/>\n" + "   <collection-resource>\n" + "      <node-level-resource node-id=\"1\"/>\n" + "      <numeric-attribute group=\"ucd-sysstat\" name=\"CpuRawIdle\" type=\"gauge\" value=\"99\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <interface-level-resource if-name=\"eth0\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </interface-level-resource>\n" + "      <numeric-attribute group=\"mib2-X-interfaces\" name=\"ifHCInOctets\" type=\"counter\" value=\"1001\"/>\n" + "      <string-attribute group=\"mib2-X-interfaces\" name=\"ifDescr\" type=\"string\" value=\"LAN\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <generic-type-resource name=\"Charles\" instance=\"id\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </generic-type-resource>\n" + "      <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dsk1\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <generic-type-resource name=\"Charles\" instance=\"idx\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </generic-type-resource>\n" + "      <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dskTotal\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + "   </collection-resource>\n" + "</collection-set>" } });
}
Also used : DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Date(java.util.Date) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

Parameters (org.junit.runners.Parameterized.Parameters)70 ArrayList (java.util.ArrayList)41 File (java.io.File)20 TestCaseContext (org.apache.asterix.testframework.context.TestCaseContext)6 Date (java.util.Date)5 SslContext (io.netty.handler.ssl.SslContext)4 ExpiredCRLException (org.apereo.cas.adaptors.x509.authentication.ExpiredCRLException)4 ThresholdExpiredCRLRevocationPolicy (org.apereo.cas.adaptors.x509.authentication.revocation.policy.ThresholdExpiredCRLRevocationPolicy)4 RunWith (org.junit.runner.RunWith)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 ZonedDateTime (java.time.ZonedDateTime)3 Configuration (org.apache.hadoop.conf.Configuration)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 RevokedCertificateException (org.apereo.cas.adaptors.x509.authentication.revocation.RevokedCertificateException)3 Parameterized (org.junit.runners.Parameterized)3 CollectionAgentDTO (org.opennms.netmgt.collection.dto.CollectionAgentDTO)3 FileFilter (java.io.FileFilter)2 Field (java.lang.reflect.Field)2 BigInteger (java.math.BigInteger)2 GeneralSecurityException (java.security.GeneralSecurityException)2