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 ;
2016import static org .apache .hadoop .security .authentication .server .MultiSchemeAuthenticationHandler .SCHEMES_PROPERTY ;
2117import static org .apache .hadoop .security .authentication .server .MultiSchemeAuthenticationHandler .AUTH_HANDLER_PROPERTY ;
2218import static org .apache .hadoop .security .authentication .server .AuthenticationFilter .AUTH_TYPE ;
3834import org .apache .hadoop .security .authentication .server .MultiSchemeAuthenticationHandler ;
3935import org .apache .hadoop .security .authentication .server .PseudoAuthenticationHandler ;
4036import org .apache .hadoop .security .authentication .server .KerberosAuthenticationHandler ;
41- import org .junit .jupiter .api .BeforeEach ;
42- import org .junit .jupiter .api .Test ;
43- import org .junit .jupiter .api .Timeout ;
37+ import org .junit .Assert ;
38+ import org .junit .Before ;
39+ import org .junit .Test ;
40+ import org .mockito .Mockito ;
4441
4542import java .io .File ;
4643import java .net .HttpURLConnection ;
@@ -57,7 +54,7 @@ public class TestKerberosAuthenticator extends KerberosSecurityTestcase {
5754 public TestKerberosAuthenticator () {
5855 }
5956
60- @ BeforeEach
57+ @ Before
6158 public void setup () throws Exception {
6259 // create keytab
6360 File keytabFile = new File (KerberosTestUtils .getKeytabFile ());
@@ -92,8 +89,7 @@ private Properties getMultiAuthHandlerConfiguration() {
9289 return props ;
9390 }
9491
95- @ Test
96- @ Timeout (value = 60 )
92+ @ Test (timeout =60000 )
9793 public void testFallbacktoPseudoAuthenticator () throws Exception {
9894 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
9995 Properties props = new Properties ();
@@ -103,8 +99,7 @@ public void testFallbacktoPseudoAuthenticator() throws Exception {
10399 auth ._testAuthentication (new KerberosAuthenticator (), false );
104100 }
105101
106- @ Test
107- @ Timeout (value = 60 )
102+ @ Test (timeout =60000 )
108103 public void testFallbacktoPseudoAuthenticatorAnonymous () throws Exception {
109104 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
110105 Properties props = new Properties ();
@@ -114,8 +109,7 @@ public void testFallbacktoPseudoAuthenticatorAnonymous() throws Exception {
114109 auth ._testAuthentication (new KerberosAuthenticator (), false );
115110 }
116111
117- @ Test
118- @ Timeout (value = 60 )
112+ @ Test (timeout =60000 )
119113 public void testNotAuthenticated () throws Exception {
120114 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
121115 AuthenticatorTestCase .setAuthenticationHandlerConfig (getAuthenticationHandlerConfiguration ());
@@ -124,15 +118,14 @@ public void testNotAuthenticated() throws Exception {
124118 URL url = new URL (auth .getBaseURL ());
125119 HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
126120 conn .connect ();
127- assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
128- assertTrue (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
121+ Assert . assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
122+ Assert . assertTrue (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
129123 } finally {
130124 auth .stop ();
131125 }
132126 }
133127
134- @ Test
135- @ Timeout (value = 60 )
128+ @ Test (timeout =60000 )
136129 public void testAuthentication () throws Exception {
137130 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
138131 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -146,8 +139,7 @@ public Void call() throws Exception {
146139 });
147140 }
148141
149- @ Test
150- @ Timeout (value = 60 )
142+ @ Test (timeout =60000 )
151143 public void testAuthenticationPost () throws Exception {
152144 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
153145 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -161,8 +153,7 @@ public Void call() throws Exception {
161153 });
162154 }
163155
164- @ Test
165- @ Timeout (value = 60 )
156+ @ Test (timeout =60000 )
166157 public void testAuthenticationHttpClient () throws Exception {
167158 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
168159 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -176,8 +167,7 @@ public Void call() throws Exception {
176167 });
177168 }
178169
179- @ Test
180- @ Timeout (value = 60 )
170+ @ Test (timeout =60000 )
181171 public void testAuthenticationHttpClientPost () throws Exception {
182172 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
183173 AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -191,8 +181,7 @@ public Void call() throws Exception {
191181 });
192182 }
193183
194- @ Test
195- @ Timeout (value = 60 )
184+ @ Test (timeout = 60000 )
196185 public void testNotAuthenticatedWithMultiAuthHandler () throws Exception {
197186 AuthenticatorTestCase auth = new AuthenticatorTestCase ();
198187 AuthenticatorTestCase
@@ -202,17 +191,16 @@ public void testNotAuthenticatedWithMultiAuthHandler() throws Exception {
202191 URL url = new URL (auth .getBaseURL ());
203192 HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
204193 conn .connect ();
205- assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED ,
194+ Assert . assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED ,
206195 conn .getResponseCode ());
207- assertTrue (conn
196+ Assert . assertTrue (conn
208197 .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
209198 } finally {
210199 auth .stop ();
211200 }
212201 }
213202
214- @ Test
215- @ Timeout (value = 60 )
203+ @ Test (timeout = 60000 )
216204 public void testAuthenticationWithMultiAuthHandler () throws Exception {
217205 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
218206 AuthenticatorTestCase
@@ -226,8 +214,7 @@ public Void call() throws Exception {
226214 });
227215 }
228216
229- @ Test
230- @ Timeout (value = 60 )
217+ @ Test (timeout = 60000 )
231218 public void testAuthenticationHttpClientPostWithMultiAuthHandler ()
232219 throws Exception {
233220 final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
@@ -242,81 +229,77 @@ public Void call() throws Exception {
242229 });
243230 }
244231
245- @ Test
246- @ Timeout (value = 60 )
232+ @ Test (timeout = 60000 )
247233 public void testWrapExceptionWithMessage () {
248234 IOException ex ;
249235 ex = new IOException ("Induced exception" );
250236 ex = KerberosAuthenticator .wrapExceptionWithMessage (ex , "Error while "
251237 + "authenticating with endpoint: localhost" );
252- assertEquals ("Induced exception" , ex .getCause ().getMessage ());
253- assertEquals ("Error while authenticating with endpoint: localhost" ,
238+ Assert . assertEquals ("Induced exception" , ex .getCause ().getMessage ());
239+ Assert . assertEquals ("Error while authenticating with endpoint: localhost" ,
254240 ex .getMessage ());
255241
256242 ex = new AuthenticationException ("Auth exception" );
257243 ex = KerberosAuthenticator .wrapExceptionWithMessage (ex , "Error while "
258244 + "authenticating with endpoint: localhost" );
259- assertEquals ("Auth exception" , ex .getCause ().getMessage ());
260- assertEquals ("Error while authenticating with endpoint: localhost" ,
245+ Assert . assertEquals ("Auth exception" , ex .getCause ().getMessage ());
246+ Assert . assertEquals ("Error while authenticating with endpoint: localhost" ,
261247 ex .getMessage ());
262248
263249 // Test for Exception with no (String) constructor
264250 // redirect the LOG to and check log message
265251 ex = new CharacterCodingException ();
266252 Exception ex2 = KerberosAuthenticator .wrapExceptionWithMessage (ex ,
267253 "Error while authenticating with endpoint: localhost" );
268- assertTrue (ex instanceof CharacterCodingException );
269- assertTrue (ex .equals (ex2 ));
254+ Assert . assertTrue (ex instanceof CharacterCodingException );
255+ Assert . assertTrue (ex .equals (ex2 ));
270256 }
271257
272- @ Test
273- @ Timeout (value = 60 )
258+ @ Test (timeout = 60000 )
274259 public void testNegotiate () throws NoSuchMethodException , InvocationTargetException ,
275260 IllegalAccessException , IOException {
276261 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
277262
278- HttpURLConnection conn = mock (HttpURLConnection .class );
279- when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE )).
263+ HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
264+ Mockito . when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE )).
280265 thenReturn (KerberosAuthenticator .NEGOTIATE );
281- when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
266+ Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
282267
283268 Method method = KerberosAuthenticator .class .getDeclaredMethod ("isNegotiate" ,
284269 HttpURLConnection .class );
285270 method .setAccessible (true );
286271
287- assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
272+ Assert . assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
288273 }
289274
290- @ Test
291- @ Timeout (value = 60 )
275+ @ Test (timeout = 60000 )
292276 public void testNegotiateLowerCase () throws NoSuchMethodException , InvocationTargetException ,
293277 IllegalAccessException , IOException {
294278 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
295279
296- HttpURLConnection conn = mock (HttpURLConnection .class );
297- when (conn .getHeaderField ("www-authenticate" ))
280+ HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
281+ Mockito . when (conn .getHeaderField ("www-authenticate" ))
298282 .thenReturn (KerberosAuthenticator .NEGOTIATE );
299- when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
283+ Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
300284
301285 Method method = KerberosAuthenticator .class .getDeclaredMethod ("isNegotiate" ,
302286 HttpURLConnection .class );
303287 method .setAccessible (true );
304288
305- assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
289+ Assert . assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
306290 }
307291
308- @ Test
309- @ Timeout (value = 60 )
292+ @ Test (timeout = 60000 )
310293 public void testReadToken () throws NoSuchMethodException , IOException , IllegalAccessException ,
311294 InvocationTargetException {
312295 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
313296 FieldUtils .writeField (kerberosAuthenticator , "base64" , new Base64 (), true );
314297
315298 Base64 base64 = new Base64 ();
316299
317- HttpURLConnection conn = mock (HttpURLConnection .class );
318- when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
319- when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ))
300+ HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
301+ Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
302+ Mockito . when (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ))
320303 .thenReturn (KerberosAuthenticator .NEGOTIATE + " " +
321304 Arrays .toString (base64 .encode ("foobar" .getBytes ())));
322305
@@ -327,18 +310,17 @@ public void testReadToken() throws NoSuchMethodException, IOException, IllegalAc
327310 method .invoke (kerberosAuthenticator , conn ); // expecting this not to throw an exception
328311 }
329312
330- @ Test
331- @ Timeout (value = 60 )
313+ @ Test (timeout = 60000 )
332314 public void testReadTokenLowerCase () throws NoSuchMethodException , IOException ,
333315 IllegalAccessException , InvocationTargetException {
334316 KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
335317 FieldUtils .writeField (kerberosAuthenticator , "base64" , new Base64 (), true );
336318
337319 Base64 base64 = new Base64 ();
338320
339- HttpURLConnection conn = mock (HttpURLConnection .class );
340- when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
341- when (conn .getHeaderField ("www-authenticate" ))
321+ HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
322+ Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
323+ Mockito . when (conn .getHeaderField ("www-authenticate" ))
342324 .thenReturn (KerberosAuthenticator .NEGOTIATE +
343325 Arrays .toString (base64 .encode ("foobar" .getBytes ())));
344326
0 commit comments