/** * @tests javax.net.ssl.CertPathTrustManagerParameters#getParameters() */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getParameters", args = {} ) public void test_getParameters() { CertPathParameters parameters = new MyCertPathParameters(); CertPathTrustManagerParameters p = new CertPathTrustManagerParameters( parameters); if (!(p.getParameters() instanceof MyCertPathParameters)) { fail("incorrect parameters"); } assertNotSame("Parameters were cloned incorrectly", parameters, p.getParameters()); }
private static TrustManager[] loadTrustManager(final String trustStoreProvider, final String trustStorePath, final String trustStorePassword, final boolean trustAll, final String crlPath) throws Exception { if (trustAll) { //This is useful for testing but not should be used outside of that purpose return InsecureTrustManagerFactory.INSTANCE.getTrustManagers(); } else if (trustStorePath == null && (trustStoreProvider == null || !"PKCS11".equals(trustStoreProvider.toUpperCase()))) { return null; } else { TrustManagerFactory trustMgrFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); KeyStore trustStore = SSLSupport.loadKeystore(trustStoreProvider, trustStorePath, trustStorePassword); boolean ocsp = Boolean.valueOf(Security.getProperty("ocsp.enable")); boolean initialized = false; if ((ocsp || crlPath != null) && TrustManagerFactory.getDefaultAlgorithm().equalsIgnoreCase("PKIX")) { PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(trustStore, new X509CertSelector()); if (crlPath != null) { pkixParams.setRevocationEnabled(true); Collection<? extends CRL> crlList = loadCRL(crlPath); if (crlList != null) { pkixParams.addCertStore(CertStore.getInstance("Collection", new CollectionCertStoreParameters(crlList))); } } trustMgrFactory.init(new CertPathTrustManagerParameters(pkixParams)); initialized = true; } if (!initialized) { trustMgrFactory.init(trustStore); } return trustMgrFactory.getTrustManagers(); } }
/** * @tests javax.net.ssl.CertPathTrustManagerParameters# * CertPathTrustManagerParameters(java.security.cert.CertPathParameters) * Case 1: Try to construct object. * Case 2: Check NullPointerException. */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "CertPathTrustManagerParameters", args = {java.security.cert.CertPathParameters.class} ) public void test_ConstructorLjava_security_cert_CertPathParameters() { // case 1: Try to construct object. try { CertPathParameters parameters = new MyCertPathParameters(); CertPathTrustManagerParameters p = new CertPathTrustManagerParameters(parameters); assertNotSame("Parameters were cloned incorrectly", parameters, p.getParameters()); } catch (Exception e) { fail("Unexpected exception " + e.toString()); } // case 2: Check NullPointerException. try { new CertPathTrustManagerParameters(null); fail("Expected CertPathTrustManagerParameters was not thrown"); } catch (NullPointerException npe) { // expected } }
public void testCertPathTrustManagerParameters() { CertPathParameters parameters = new MyCertPathParameters(); CertPathTrustManagerParameters p = new CertPathTrustManagerParameters( parameters); if (!(p.getParameters() instanceof MyCertPathParameters)) { fail("incorrect parameters"); } }