3737 * @library /test/lib /test/jdk/java/net/httpclient/lib
3838 * @modules java.base/sun.security.x509
3939 *
40- * @run junit NullCases
41- * @run junit/othervm -Djavax.net.debug=ssl:keymanager -Darg=debug NullCases
40+ * @run junit/othervm -Djavax.net.debug=ssl:keymanager NullCases
4241 */
4342
4443import jdk .test .lib .Asserts ;
6160import static jdk .httpclient .test .lib .common .DynamicKeyStoreUtil .generateCert ;
6261import static jdk .httpclient .test .lib .common .DynamicKeyStoreUtil .generateKeyStore ;
6362import static jdk .httpclient .test .lib .common .DynamicKeyStoreUtil .generateRSAKeyPair ;
64- import static org .junit .jupiter .api .Assumptions .assumeFalse ;
6563
6664
6765public class NullCases {
68- private static final String KEY_MGR_EXCEPTION_MESSAGE = "Exception thrown while getting an alias" ;
66+ private static final String KEY_MGR_EXCEPTION_MESSAGE =
67+ "Exception thrown while getting an alias" ;
6968
70- private static boolean isDebugLogging ;
7169 private static KeyManagerFactory kmf ;
7270 private static X509KeyManager km ;
7371 private final PrintStream initialErrStream = System .err ;
7472
7573 @ BeforeAll
7674 public static void beforeAll () throws Exception {
77- final String arg = System .getProperty ("arg" );
78- isDebugLogging = arg != null && arg .equals ("debug" );
79-
8075 kmf = KeyManagerFactory .getInstance ("NewSunX509" );
8176
8277 // creating a new keystore
8378 final SecureRandom secureRandom = new SecureRandom ();
8479 final KeyPair keyPair = generateRSAKeyPair (secureRandom );
85- final X509Certificate originServerCert = generateCert ( keyPair , secureRandom ,
86- "subject" );
80+ final X509Certificate originServerCert =
81+ generateCert ( keyPair , secureRandom , "subject" );
8782 final KeyStore ks = generateKeyStore (keyPair .getPrivate (),
8883 new Certificate []{originServerCert });
8984
@@ -100,15 +95,13 @@ private X509KeyManager generateNullKm() throws Exception {
10095 @ Test
10196 public void JDK6302126Test () throws Exception {
10297 // check for bug 6302126
103- assumeFalse (isDebugLogging );
10498
10599 generateNullKm ();
106100 }
107101
108102 @ Test
109103 public void JDK6302304Test () throws Exception {
110104 // check for bug 6302304
111- assumeFalse (isDebugLogging );
112105
113106 final X509KeyManager km = generateNullKm ();
114107
@@ -123,24 +116,29 @@ public void JDK6302304Test() throws Exception {
123116 @ Test
124117 public void JDK6302321Test () {
125118 // check for bug 6302321
126- assumeFalse (isDebugLogging );
127119
128- final X509Certificate [] certs = km .getCertificateChain ("doesnotexist" );
120+ final X509Certificate [] certs =
121+ km .getCertificateChain ("doesnotexist" );
129122 final PrivateKey priv = km .getPrivateKey ("doesnotexist" );
130- Asserts .assertNull (certs , "Should return null if the alias can't be found" );
131- Asserts .assertNull (priv , "Should return null if the alias can't be found" );
123+ Asserts .assertNull (certs ,
124+ "Should return null if the alias can't be found" );
125+ Asserts .assertNull (priv ,
126+ "Should return null if the alias can't be found" );
132127 }
133128
134129 @ Test
135130 public void JDK6302271Test () {
136131 // check for 6302271
137- assumeFalse (isDebugLogging );
138132
139- final String [] clis = km .getClientAliases ("doesnotexist" , null );
140- Asserts .assertFalse ((clis != null && clis .length == 0 ), "Should return null instead of empty array" );
133+ final String [] clis =
134+ km .getClientAliases ("doesnotexist" , null );
135+ Asserts .assertFalse ((clis != null && clis .length == 0 ),
136+ "Should return null instead of empty array" );
141137
142- final String [] srvs = km .getServerAliases ("doesnotexist" , null );
143- Asserts .assertFalse ((srvs != null && srvs .length == 0 ), "Should return null instead of empty array" );
138+ final String [] srvs =
139+ km .getServerAliases ("doesnotexist" , null );
140+ Asserts .assertFalse ((srvs != null && srvs .length == 0 ),
141+ "Should return null instead of empty array" );
144142 }
145143
146144 /**
@@ -157,13 +155,13 @@ private ByteArrayOutputStream replaceSystemError() {
157155
158156 @ Test
159157 public void incompleteChainAndKeyTest () {
160- assumeFalse (isDebugLogging );
161-
162158 final X509Certificate [] certs = km .getCertificateChain ("1.1" );
163159 final PrivateKey priv = km .getPrivateKey ("1.1" );
164160
165- Asserts .assertNull (certs , "Should return null if the alias can't be found" );
166- Asserts .assertNull (priv , "Should return null if the alias can't be found" );
161+ Asserts .assertNull (certs ,
162+ "Should return null if the alias can't be found" );
163+ Asserts .assertNull (priv ,
164+ "Should return null if the alias can't be found" );
167165 }
168166
169167 @ Test
@@ -174,60 +172,72 @@ public void nonexistentBuilderTest() {
174172 final X509Certificate [] certs = km .getCertificateChain ("RSA.1.1" );
175173 final PrivateKey priv = km .getPrivateKey ("RSA.1.1" );
176174
177- Asserts .assertNull (certs , "Should return null if the alias can't be found" );
178- Asserts .assertNull (priv , "Should return null if the alias can't be found" );
175+ Asserts .assertNull (certs ,
176+ "Should return null if the alias can't be found" );
177+ Asserts .assertNull (priv ,
178+ "Should return null if the alias can't be found" );
179179
180180 System .setErr (initialErrStream );
181181 System .err .println (" => nonexistentBuilderTest: \n " + outputStream );
182182
183- Asserts .assertFalse (isDebugLogging && !outputStream .toString ().contains (KEY_MGR_EXCEPTION_MESSAGE ),
183+ Asserts .assertFalse (
184+ !outputStream .toString ().contains (KEY_MGR_EXCEPTION_MESSAGE ),
184185 "No log triggered" );
185186 }
186187
187188 @ Test
188189 public void nonexistentKSTest () {
189- assumeFalse (isDebugLogging );
190190
191191 final X509Certificate [] certs = km .getCertificateChain ("RSA.0.1" );
192192 final PrivateKey priv = km .getPrivateKey ("RSA.0.1" );
193193
194- Asserts .assertNull (certs , "Should return null if the alias can't be found" );
195- Asserts .assertNull (priv , "Should return null if the alias can't be found" );
194+ Asserts .assertNull (certs ,
195+ "Should return null if the alias can't be found" );
196+ Asserts .assertNull (priv ,
197+ "Should return null if the alias can't be found" );
196198 }
197199
198200 @ Test
199201 public void wrongNumberFormatTest () {
200202 // recording logs to the output stream
201203 final ByteArrayOutputStream outputStream = replaceSystemError ();
202- final X509Certificate [] certs = km .getCertificateChain ("RSA.not.exist" );
204+ final X509Certificate [] certs =
205+ km .getCertificateChain ("RSA.not.exist" );
203206 final PrivateKey priv = km .getPrivateKey ("RSA.not.exist" );
204207
205- Asserts .assertNull (certs , "Should return null if the alias can't be found" );
206- Asserts .assertNull (priv , "Should return null if the alias can't be found" );
208+ Asserts .assertNull (certs ,
209+ "Should return null if the alias can't be found" );
210+ Asserts .assertNull (priv ,
211+ "Should return null if the alias can't be found" );
207212
208213 System .setErr (initialErrStream );
209214 System .err .println (" => wrongNumberFormatTest: \n " + outputStream );
210215
211- Asserts .assertFalse (isDebugLogging && !outputStream .toString ().contains (KEY_MGR_EXCEPTION_MESSAGE ),
216+ Asserts .assertFalse (
217+ !outputStream .toString ().contains (KEY_MGR_EXCEPTION_MESSAGE ),
212218 "No log triggered" );
213219
214220 }
215221
216222 @ ParameterizedTest
217- @ ValueSource (strings = {"..1" , ".9.123456789" })
223+ @ ValueSource (strings = {"1.." , ".1." , " ..1" , ".9.123456789" })
218224 public void invalidAliasTest (final String alias ) {
219225 // recording logs to the output stream
220226 final ByteArrayOutputStream outputStream = replaceSystemError ();
221227 final X509Certificate [] certs = km .getCertificateChain (alias );
222228 final PrivateKey priv = km .getPrivateKey (alias );
223229
224- Asserts .assertNull (certs , "Should return null if the alias can't be found" );
225- Asserts .assertNull (priv , "Should return null if the alias can't be found" );
230+ Asserts .assertNull (certs ,
231+ "Should return null if the alias can't be found" );
232+ Asserts .assertNull (priv ,
233+ "Should return null if the alias can't be found" );
226234
227235 System .setErr (initialErrStream );
228- System .err .println (" => wrongNumberFormatTest alias<" + alias + ">: \n " + outputStream );
236+ System .err .println (" => wrongNumberFormatTest alias<" + alias + ">: \n "
237+ + outputStream );
229238
230- Asserts .assertFalse (isDebugLogging && !outputStream .toString ().contains ("Invalid alias format:" ),
239+ Asserts .assertFalse (!outputStream .toString ()
240+ .contains ("Invalid alias format:" ),
231241 "No log triggered" );
232242
233243 }
0 commit comments