RFR: 8365069: Refactor tests to use PEM API (Phase 1)

Anthony Scarpino ascarpino at openjdk.org
Tue Oct 28 21:57:21 UTC 2025


On Sat, 13 Sep 2025 04:44:13 GMT, Koushik Muthukrishnan Thirupattur <duke at openjdk.org> wrote:

> The following tests have been identified as candidates for phase 1 of this change.
> 2. test/jdk/javax/net/ssl/TLSCommon/TLSTest.java
> 3. test/jdk/sun/security/provider/certpath/DisabledAlgorithms/CPBuilder.java
> 4. test/jdk/sun/security/provider/certpath/DisabledAlgorithms/CPBuilderWithMD5.java
> 5. test/jdk/sun/security/provider/certpath/DisabledAlgorithms/CPValidatorEndEntity.java
> 9. test/jdk/sun/security/provider/certpath/DisabledAlgorithms/CPValidatorIntermediate.java
> 10. test/jdk/sun/security/ssl/X509TrustManagerImpl/PKIXExtendedTM.java
> 11. test/jdk/sun/security/ssl/X509TrustManagerImpl/SunX509ExtendedTM.java
> 13. test/jdk/java/security/cert/CertPathBuilder/selfIssued/KeyUsageMatters.java
> 16. test/jdk/java/security/cert/CertPathBuilder/selfIssued/DisableRevocation.java
> 17. test/jdk/java/security/cert/CertPathValidator/indirectCRL/CircularCRLOneLevel.java
> 18. test/jdk/java/security/cert/CertPathValidator/indirectCRL/CircularCRLOneLevelRevoked.java
> 20. test/jdk/java/security/KeyStore/PKCS12/WriteP12Test.java
> 21. test/jdk/java/security/cert/CertPathValidator/OCSP/FailoverToCRL.java
> 22. test/jdk/java/security/cert/CertPathValidator/nameConstraints/NameConstraintsWithRID.java
> 23. test/jdk/java/security/cert/CertPathValidator/nameConstraints/NameConstraintsWithUnexpectedRID.java
> 24. test/jdk/java/security/cert/CertPathValidator/nameConstraints/NameConstraintsWithoutRID.java
> 25. test/jdk/java/security/cert/CertPathValidator/trustAnchor/ValWithAnchorByName.java
> 30. test/jdk/java/security/KeyStore/TestKeyStoreBasic.java

test/jdk/java/security/KeyStore/PKCS12/WriteP12Test.java line 127:

> 125:     private final Certificate caCert;
> 126: 
> 127:     WriteP12Test() throws CertificateException {

As decode() only throws RuntimeExceptions, you don't need the throws anymore.  Also calling methods calling won't need to handle the exception either.

test/jdk/java/security/KeyStore/TestKeyStoreBasic.java line 40:

> 38: public class TestKeyStoreBasic {
> 39: 
> 40:     private static final String PRIVATE_KEY_PKCS8_BASE64 = """

nit:  this should probably be indented 4 chars from `private`.  Same location as the old code.

test/jdk/java/security/cert/CertPathBuilder/selfIssued/KeyUsageMatters.java line 202:

> 200: 
> 201:         // generate certificate from certificate string
> 202:         DEREncodable cert = PEM_DECODER.decode(targetCertStr, X509Certificate.class);

nit:  there is little value storing the decode() in a variable that is then added to `entries()`. You could do `entries.add(PEM_DECODER...)`

test/jdk/java/security/cert/CertPathValidator/OCSP/FailoverToCRL.java line 238:

> 236:         Collection<DEREncodable> crls = new HashSet<>();
> 237: 
> 238:         DEREncodable crl  = PEM_DECODER.decode(crlStr, X509CRL.class);

nit: similar to that storing in `crl` is not necessary.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27267#discussion_r2456316474
PR Review Comment: https://git.openjdk.org/jdk/pull/27267#discussion_r2456332014
PR Review Comment: https://git.openjdk.org/jdk/pull/27267#discussion_r2461897266
PR Review Comment: https://git.openjdk.org/jdk/pull/27267#discussion_r2461943735


More information about the security-dev mailing list