34
34
import org .apache .hadoop .security .authentication .server .MultiSchemeAuthenticationHandler ;
35
35
import org .apache .hadoop .security .authentication .server .PseudoAuthenticationHandler ;
36
36
import org .apache .hadoop .security .authentication .server .KerberosAuthenticationHandler ;
37
- import org .junit .Assert ;
38
- import org .junit .Before ;
39
- import org .junit .Test ;
37
+ import org .junit .jupiter .api .Assertions ;
38
+ import org .junit .jupiter .api .BeforeEach ;
39
+ import org .junit .jupiter .api .Test ;
40
+ import org .junit .jupiter .api .Timeout ;
40
41
import org .mockito .Mockito ;
41
42
42
43
import java .io .File ;
@@ -54,7 +55,7 @@ public class TestKerberosAuthenticator extends KerberosSecurityTestcase {
54
55
public TestKerberosAuthenticator () {
55
56
}
56
57
57
- @ Before
58
+ @ BeforeEach
58
59
public void setup () throws Exception {
59
60
// create keytab
60
61
File keytabFile = new File (KerberosTestUtils .getKeytabFile ());
@@ -89,7 +90,8 @@ private Properties getMultiAuthHandlerConfiguration() {
89
90
return props ;
90
91
}
91
92
92
- @ Test (timeout =60000 )
93
+ @ Test
94
+ @ Timeout (value = 60 )
93
95
public void testFallbacktoPseudoAuthenticator () throws Exception {
94
96
AuthenticatorTestCase auth = new AuthenticatorTestCase ();
95
97
Properties props = new Properties ();
@@ -99,7 +101,8 @@ public void testFallbacktoPseudoAuthenticator() throws Exception {
99
101
auth ._testAuthentication (new KerberosAuthenticator (), false );
100
102
}
101
103
102
- @ Test (timeout =60000 )
104
+ @ Test
105
+ @ Timeout (value = 60 )
103
106
public void testFallbacktoPseudoAuthenticatorAnonymous () throws Exception {
104
107
AuthenticatorTestCase auth = new AuthenticatorTestCase ();
105
108
Properties props = new Properties ();
@@ -109,7 +112,8 @@ public void testFallbacktoPseudoAuthenticatorAnonymous() throws Exception {
109
112
auth ._testAuthentication (new KerberosAuthenticator (), false );
110
113
}
111
114
112
- @ Test (timeout =60000 )
115
+ @ Test
116
+ @ Timeout (value = 60 )
113
117
public void testNotAuthenticated () throws Exception {
114
118
AuthenticatorTestCase auth = new AuthenticatorTestCase ();
115
119
AuthenticatorTestCase .setAuthenticationHandlerConfig (getAuthenticationHandlerConfiguration ());
@@ -118,14 +122,15 @@ public void testNotAuthenticated() throws Exception {
118
122
URL url = new URL (auth .getBaseURL ());
119
123
HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
120
124
conn .connect ();
121
- Assert .assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
122
- Assert .assertTrue (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
125
+ Assertions .assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED , conn .getResponseCode ());
126
+ Assertions .assertTrue (conn .getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
123
127
} finally {
124
128
auth
10000
.stop ();
125
129
}
126
130
}
127
131
128
- @ Test (timeout =60000 )
132
+ @ Test
133
+ @ Timeout (value = 60 )
129
134
public void testAuthentication () throws Exception {
130
135
final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
131
136
AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -139,7 +144,8 @@ public Void call() throws Exception {
139
144
});
140
145
}
141
146
142
- @ Test (timeout =60000 )
147
+ @ Test
148
+ @ Timeout (value = 60 )
143
149
public void testAuthenticationPost () throws Exception {
144
150
final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
145
151
AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -153,7 +159,8 @@ public Void call() throws Exception {
153
159
});
154
160
}
155
161
156
- @ Test (timeout =60000 )
162
+ @ Test
163
+ @ Timeout (value = 60 )
157
164
public void testAuthenticationHttpClient () throws Exception {
158
165
final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
159
166
AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -167,7 +174,8 @@ public Void call() throws Exception {
167
174
});
168
175
}
169
176
170
- @ Test (timeout =60000 )
177
+ @ Test
178
+ @ Timeout (value = 60 )
171
179
public void testAuthenticationHttpClientPost () throws Exception {
172
180
final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
173
181
AuthenticatorTestCase .setAuthenticationHandlerConfig (
@@ -181,7 +189,8 @@ public Void call() throws Exception {
181
189
});
182
190
}
183
191
184
- @ Test (timeout = 60000 )
192
+ @ Test
193
+ @ Timeout (value = 60 )
185
194
public void testNotAuthenticatedWithMultiAuthHandler () throws Exception {
186
195
AuthenticatorTestCase auth = new AuthenticatorTestCase ();
187
196
AuthenticatorTestCase
@@ -191,16 +200,17 @@ public void testNotAuthenticatedWithMultiAuthHandler() throws Exception {
191
200
URL url = new URL (auth .getBaseURL ());
192
201
HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
193
202
conn .connect ();
194
- Assert .assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED ,
203
+ Assertions .assertEquals (HttpURLConnection .HTTP_UNAUTHORIZED ,
195
204
conn .getResponseCode ());
196
- Assert .assertTrue (conn
205
+ Assertions .assertTrue (conn
197
206
.getHeaderField (KerberosAuthenticator .WWW_AUTHENTICATE ) != null );
198
207
} finally {
199
208
auth .stop ();
200
209
}
201
210
}
202
211
203
- @ Test (timeout = 60000 )
212
+ @ Test
213
+ @ Timeout (value = 60 )
204
214
public void testAuthenticationWithMultiAuthHandler () throws Exception {
205
215
final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
206
216
AuthenticatorTestCase
@@ -214,7 +224,8 @@ public Void call() throws Exception {
214
224
});
215
225
}
216
226
217
- @ Test (timeout = 60000 )
227
+ @ Test
228
+ @ Timeout (value = 60 )
218
229
public void testAuthenticationHttpClientPostWithMultiAuthHandler ()
219
230
throws Exception {
220
231
final AuthenticatorTestCase auth = new AuthenticatorTestCase ();
@@ -229,33 +240,35 @@ public Void call() throws Exception {
229
240
});
230
241
}
231
242
232
- @ Test (timeout = 60000 )
243
+ @ Test
244
+ @ Timeout (value = 60 )
233
245
public void testWrapExceptionWithMessage () {
234
246
IOException ex ;
235
247
ex = new IOException ("Induced exception" );
236
248
ex = KerberosAuthenticator .wrapExceptionWithMessage (ex , "Error while "
237
249
+ "authenticating with endpoint: localhost" );
238
- Assert .assertEquals ("Induced exception" , ex .getCause ().getMessage ());
239
- Assert .assertEquals ("Error while authenticating with endpoint: localhost" ,
250
+ Assertions .assertEquals ("Induced exception" , ex .getCause ().getMessage ());
251
+ Assertions .assertEquals ("Error while authenticating with endpoint: localhost" ,
240
252
ex .getMessage ());
241
253
242
254
ex = new AuthenticationException ("Auth exception" );
243
255
ex = KerberosAuthenticator .wrapExceptionWithMessage (ex , "Error while "
244
256
+ "authenticating with endpoint: localhost" );
245
- Assert .assertEquals ("Auth exception" , ex .getCause ().getMessage ());
246
- Assert .assertEquals ("Error while authenticating with endpoint: localhost" ,
257
+ Assertions .assertEquals ("Auth exception" , ex .getCause ().getMessage ());
258
+ Assertions .assertEquals ("Error while authenticating with endpoint: localhost" ,
247
259
ex .getMessage ());
248
260
249
261
// Test for Exception with no (String) constructor
250
262
// redirect the LOG to and check log message
251
263
ex = new CharacterCodingException ();
252
264
Exception ex2 = KerberosAuthenticator .wrapExceptionWithMessage (ex ,
253
265
"Error while authenticating with endpoint: localhost" );
254
- Assert .assertTrue (ex instanceof CharacterCodingException );
255
- Assert .assertTrue (ex .equals (ex2 ));
266
+ Assertions .assertTrue (ex instanceof CharacterCodingException );
267
+ Assertions .assertTrue (ex .equals (ex2 ));
256
268
}
257
269
258
- @ Test (timeout = 60000 )
270
+ @ Test
271
+ @ Timeout (value = 60 )
259
272
public void testNegotiate () throws NoSuchMethodException , InvocationTargetException ,
260
273
IllegalAccessException , IOException {
261
274
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
@@ -269,10 +282,11 @@ public void testNegotiate() throws NoSuchMethodException, InvocationTargetExcept
269
282
HttpURLConnection .class );
270
283
method .setAccessible (true );
271
284
272
- Assert .assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
285
+ Assertions .assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
273
286
}
274
287
275
- @ Test (timeout = 60000 )
288
+ @ Test
289
+ @ Timeout (value = 60 )
276
290
public void testNegotiateLowerCase () throws NoSuchMethodException , InvocationTargetException ,
277
291
IllegalAccessException , IOException {
278
292
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
@@ -286,10 +300,11 @@ public void testNegotiateLowerCase() throws NoSuchMethodException, InvocationTar
286
300
HttpURLConnection .class );
287
301
method .setAccessible (true );
288
302
289
- Assert .assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
303
+ Assertions .assertTrue ((boolean )method .invoke (kerberosAuthenticator , conn ));
290
304
}
291
305
292
- @ Test (timeout = 60000 )
306
+ @ Test
307
+ @ Timeout (value = 60 )
293
308
public void testReadToken () throws NoSuchMethodException , IOException , IllegalAccessException ,
294
309
InvocationTargetException {
295
310
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
@@ -310,7 +325,8 @@ public void testReadToken() throws NoSuchMethodException, IOException, IllegalAc
310
325
method .invoke (kerberosAuthenticator , conn ); // expecting this not to throw an exception
311
326
}
312
327
313
- @ Test (timeout = 60000 )
328
+ @ Test
329
+ @ Timeout (value = 60 )
314
330
public void testReadTokenLowerCase () throws NoSuchMethodException , IOException ,
315
331
IllegalAccessException , InvocationTargetException {
316
332
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator ();
0 commit comments