1313 */
1414package org .apache .hadoop .security .authentication .client ;
1515
16+ import static org .junit .jupiter .api .Assertions .assertEquals ;
17+ import static org .junit .jupiter .api .Assertions .assertTrue ;
18+ import static org .mockito .Mockito .mock ;
19+ import static org .mockito .Mockito .when ;
1620import static org .apache .hadoop .security .authentication .server .MultiSchemeAuthenticationHandler .SCHEMES_PROPERTY ;
1721import static org .apache .hadoop .security .authentication .server .MultiSchemeAuthenticationHandler .AUTH_HANDLER_PROPERTY ;
1822import static org .apache .hadoop .security .authentication .server .AuthenticationFilter .AUTH_TYPE ;
3438import org .apache .hadoop .security .authentication .server .MultiSchemeAuthenticationHandler ;
3539import org .apache .hadoop .security .authentication .server .PseudoAuthenticationHandler ;
3640import org .apache .hadoop .security .authentication .server .KerberosAuthenticationHandler ;
37- import org .junit .Assert ;
38- import org .junit .Before ;
39- import org .junit .Test ;
40- import org .mockito .Mockito ;
41+ import org .junit .jupiter .api .BeforeEach ;
42+ import org .junit .jupiter .api .Test ;
43+ import org .junit .jupiter .api .Timeout ;
4144
4245import java .io .File ;
4346import java .net .HttpURLConnection ;
@@ -54,7 +57,7 @@ public class TestKerberosAuthenticator extends KerberosSecurityTestcase {
5457 public TestKerberosAuthenticator () {
5558 }
5659
57- @ Before
60+ @ BeforeEach
5861 public void setup () throws Exception {
5962 // create keytab
6063 File keytabFile = new File (KerberosTestUtils .getKeytabFile ());
@@ -89,7 +92,8 @@ private Properties getMultiAuthHandlerConfiguration() {
8992 return props ;
9093 }
9194
92- @ Test (timeout =60000 )
95+ @ Test
96+ @ Timeout (value = 60 )
9397 public void testFallbacktoPseudoAuthenticator () throws Exception {
9498 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
9599 Properties props = new Properties ();
@@ -99,7 +103,8 @@ public void testFallbacktoPseudoAuthenticator() throws Exception {
99103 auth ._testAuthentication (new KerberosAuthenticator (), false );
100104 }
101105
102- @ Test (timeout =60000 )
106+ @ Test
107+ @ Timeout (value = 60 )
103108 public void testFallbacktoPseudoAuthenticatorAnonymous () throws Exception {
104109 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
105110 Properties props = new Properties ();
@@ -109,7 +114,8 @@ public void testFallbacktoPseudoAuthenticatorAnonymous() throws Exception {
109114 auth ._testAuthentication (new KerberosAuthenticator (), false );
110115 }
111116
112- @ Test (timeout =60000 )
117+ @ Test
118+ @ Timeout (value = 60 )
113119 public void testNotAuthenticated () throws Exception {
114120 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
115121 AuthenticatorTestCase .setAuthenticationHandlerConfig (getAuthenticationHandlerConfiguration ());
@@ -118,14 +124,15 @@ public void testNotAuthenticated() throws Exception {
118124 URL url = new URL (auth .getBaseURL ());
119125 HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
120126 conn .connect ();
121- Assert . assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
122- Assert . assertTrue (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
127+ assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
128+ assertTrue (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
123129 } finally {
124130 auth .stop ();
125131 }
126132 }
127133
128- @ Test (timeout =60000 )
134+ @ Test
135+ @ Timeout (value = 60 )
129136 public void testAuthentication () throws Exception {
130137 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
131138 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -139,7 +146,8 @@ public Void call() throws Exception {
139146 });
140147 }
141148
142- @ Test (timeout =60000 )
149+ @ Test
150+ @ Timeout (value = 60 )
143151 public void testAuthenticationPost () throws Exception {
144152 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
145153 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -153,7 +161,8 @@ public Void call() throws Exception {
153161 });
154162 }
155163
156- @ Test (timeout =60000 )
164+ @ Test
165+ @ Timeout (value = 60 )
157166 public void testAuthenticationHttpClient () throws Exception {
158167 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
159168 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -167,7 +176,8 @@ public Void call() throws Exception {
167176 });
168177 }
169178
170- @ Test (timeout =60000 )
179+ @ Test
180+ @ Timeout (value = 60 )
171181 public void testAuthenticationHttpClientPost () throws Exception {
172182 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
173183 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -181,7 +191,8 @@ public Void call() throws Exception {
181191 });
182192 }
183193
184- @ Test (timeout = 60000 )
194+ @ Test
195+ @ Timeout (value = 60 )
185196 public void testNotAuthenticatedWithMultiAuthHandler () throws Exception {
186197 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
187198 AuthenticatorTestCase
@@ -191,16 +202,17 @@ public void testNotAuthenticatedWithMultiAuthHandler() throws Exception {
191202 URL url = new URL (auth .getBaseURL ());
192203 HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
193204 conn .connect ();
194- Assert . assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED ,
205+ assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED ,
195206 conn .getResponseCode ());
196- Assert . assertTrue (conn
207+ assertTrue (conn
197208 .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
198209 } finally {
199210 auth .stop ();
200211 }
201212 }
202213
203- @ Test (timeout = 60000 )
214+ @ Test
215+ @ Timeout (value = 60 )
204216 public void testAuthenticationWithMultiAuthHandler () throws Exception {
205217 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
206218 AuthenticatorTestCase
@@ -214,7 +226,8 @@ public Void call() throws Exception {
214226 });
215227 }
216228
217- @ Test (timeout = 60000 )
229+ @ Test
230+ @ Timeout (value = 60 )
218231 public void testAuthenticationHttpClientPostWithMultiAuthHandler ()
219232 throws Exception {
220233 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
@@ -229,77 +242,81 @@ public Void call() throws Exception {
229242 });
230243 }
231244
232- @ Test (timeout = 60000 )
245+ @ Test
246+ @ Timeout (value = 60 )
233247 public void testWrapExceptionWithMessage () {
234248 IOException ex ;
235249 ex = new IOException ("Induced exception" );
236250 ex = KerberosAuthenticator .wrapExceptionWithMessage (ex , "Error while "
237251 + "authenticating with endpoint: localhost" );
238- Assert . assertEquals ("Induced exception" , ex .getCause ().getMessage ());
239- Assert . assertEquals ("Error while authenticating with endpoint: localhost" ,
252+ assertEquals ("Induced exception" , ex .getCause ().getMessage ());
253+ assertEquals ("Error while authenticating with endpoint: localhost" ,
240254 ex .getMessage ());
241255
242256 ex = new AuthenticationException ("Auth exception" );
243257 ex = KerberosAuthenticator .wrapExceptionWithMessage (ex , "Error while "
244258 + "authenticating with endpoint: localhost" );
245- Assert . assertEquals ("Auth exception" , ex .getCause ().getMessage ());
246- Assert . assertEquals ("Error while authenticating with endpoint: localhost" ,
259+ assertEquals ("Auth exception" , ex .getCause ().getMessage ());
260+ assertEquals ("Error while authenticating with endpoint: localhost" ,
247261 ex .getMessage ());
248262
249263 // Test for Exception with no (String) constructor
250264 // redirect the LOG to and check log message
251265 ex = new CharacterCodingException ();
252266 Exception ex2 = KerberosAuthenticator .wrapExceptionWithMessage (ex ,
253267 "Error while authenticating with endpoint: localhost" );
254- Assert . assertTrue (ex instanceof CharacterCodingException );
255- Assert . assertTrue (ex .equals (ex2 ));
268+ assertTrue (ex instanceof CharacterCodingException );
269+ assertTrue (ex .equals (ex2 ));
256270 }
257271
258- @ Test (timeout = 60000 )
272+ @ Test
273+ @ Timeout (value = 60 )
259274 public void testNegotiate () throws NoSuchMethodException , InvocationTargetException ,
260275 IllegalAccessException , IOException {
261276 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
262277
263- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
264- Mockito . when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE )).
278+ HttpURLConnection conn = mock (HttpURLConnection .class );
279+ when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE )).
265280 thenReturn (KerberosAuthenticator .NEGOTIATE );
266- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
281+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
267282
268283 Method method = KerberosAuthenticator .class .getDeclaredMethod ("isNegotiate" ,
269284 HttpURLConnection .class );
270285 method .setAccessible (true );
271286
272- Assert . assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
287+ assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
273288 }
274289
275- @ Test (timeout = 60000 )
290+ @ Test
291+ @ Timeout (value = 60 )
276292 public void testNegotiateLowerCase () throws NoSuchMethodException , InvocationTargetException ,
277293 IllegalAccessException , IOException {
278294 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
279295
280- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
281- Mockito . when (conn .getHeaderField ("www-authenticate" ))
296+ HttpURLConnection conn = mock (HttpURLConnection .class );
297+ when (conn .getHeaderField ("www-authenticate" ))
282298 .thenReturn (KerberosAuthenticator .NEGOTIATE );
283- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
299+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
284300
285301 Method method = KerberosAuthenticator .class .getDeclaredMethod ("isNegotiate" ,
286302 HttpURLConnection .class );
287303 method .setAccessible (true );
288304
289- Assert . assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
305+ assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
290306 }
291307
292- @ Test (timeout = 60000 )
308+ @ Test
309+ @ Timeout (value = 60 )
293310 public void testReadToken () throws NoSuchMethodException , IOException , IllegalAccessException ,
294311 InvocationTargetException {
295312 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
296313 FieldUtils .writeField (kerberosAuthenticator , "base64" , new Base64 (), true );
297314
298315 Base64 base64 = new Base64 ();
299316
300- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
301- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
302- Mockito . when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ))
317+ HttpURLConnection conn = mock (HttpURLConnection .class );
318+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
319+ when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ))
303320 .thenReturn (KerberosAuthenticator .NEGOTIATE + " " +
304321 Arrays .toString (base64 .encode ("foobar" .getBytes ())));
305322
@@ -310,17 +327,18 @@ public void testReadToken() throws NoSuchMethodException, IOException, IllegalAc
310327 method .invoke (kerberosAuthenticator , conn ); // expecting this not to throw an exception
311328 }
312329
313- @ Test (timeout = 60000 )
330+ @ Test
331+ @ Timeout (value = 60 )
314332 public void testReadTokenLowerCase () throws NoSuchMethodException , IOException ,
315333 IllegalAccessException , InvocationTargetException {
316334 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
317335 FieldUtils .writeField (kerberosAuthenticator , "base64" , new Base64 (), true );
318336
319337 Base64 base64 = new Base64 ();
320338
321- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
322- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
323- Mockito . when (conn .getHeaderField ("www-authenticate" ))
339+ HttpURLConnection conn = mock (HttpURLConnection .class );
340+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
341+ when (conn .getHeaderField ("www-authenticate" ))
324342 .thenReturn (KerberosAuthenticator .NEGOTIATE +
325343 Arrays .toString (base64 .encode ("foobar" .getBytes ())));
326344
0 commit comments