Skip to content

Commit 574c42c

Browse files
committed
fix checkstyle.
1 parent c7ac68c commit 574c42c

File tree

10 files changed

+247
-333
lines changed

10 files changed

+247
-333
lines changed

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/TestKerberosAuthenticator.java

+44-62
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
*/
1414
package 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;
2016
import static org.apache.hadoop.security.authentication.server.MultiSchemeAuthenticationHandler.SCHEMES_PROPERTY;
2117
import static org.apache.hadoop.security.authentication.server.MultiSchemeAuthenticationHandler.AUTH_HANDLER_PROPERTY;
2218
import static org.apache.hadoop.security.authentication.server.AuthenticationFilter.AUTH_TYPE;
@@ -38,9 +34,10 @@
3834
import org.apache.hadoop.security.authentication.server.MultiSchemeAuthenticationHandler;
3935
import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
4036
import 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

4542
import java.io.File;
4643
import 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

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAltKerberosAuthenticationHandler.java

+18-38
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@
1313
*/
1414
package org.apache.hadoop.security.authentication.server;
1515

16-
import static org.junit.jupiter.api.Assertions.assertEquals;
17-
import static org.mockito.Mockito.mock;
18-
import static org.mockito.Mockito.when;
19-
2016
import java.io.IOException;
2117
import java.util.Properties;
2218
import javax.servlet.http.HttpServletRequest;
2319
import javax.servlet.http.HttpServletResponse;
2420
import org.apache.hadoop.security.authentication.client.AuthenticationException;
25-
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.Timeout;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
import org.mockito.Mockito;
2724

2825
public class TestAltKerberosAuthenticationHandler
2926
extends TestKerberosAuthenticationHandler {
@@ -50,41 +47,25 @@ protected String getExpectedType() {
5047
return AltKerberosAuthenticationHandler.TYPE;
5148
}
5249

53-
@Test
54-
@Timeout(value = 60)
50+
@Test(timeout=60000)
5551
public void testAlternateAuthenticationAsBrowser() throws Exception {
56-
if (handler != null) {
57-
handler.destroy();
58-
handler = null;
59-
}
60-
handler = getNewAuthenticationHandler();
61-
Properties props = getDefaultProperties();
62-
props.setProperty("alt-kerberos.non-browser.user-agents", "foo, bar");
63-
try {
64-
handler.init(props);
65-
} catch (Exception ex) {
66-
handler = null;
67-
throw ex;
68-
}
69-
70-
HttpServletRequest request = mock(HttpServletRequest.class);
71-
HttpServletResponse response = mock(HttpServletResponse.class);
52+
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
53+
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
7254

7355
// By default, a User-Agent without "java", "curl", "wget", or "perl" in it
7456
// is considered a browser
75-
when(request.getHeader("User-Agent")).thenReturn("Some Browser");
57+
Mockito.when(request.getHeader("User-Agent")).thenReturn("Some Browser");
7658

7759
AuthenticationToken token = handler.authenticate(request, response);
78-
assertEquals("A", token.getUserName());
79-
assertEquals("B", token.getName());
80-
assertEquals(getExpectedType(), token.getType());
60+
Assert.assertEquals("A", token.getUserName());
61+
Assert.assertEquals("B", token.getName());
62+
Assert.assertEquals(getExpectedType(), token.getType());
8163
}
8264

83-
@Test
84-
@Timeout(value = 60)
65+
@Test(timeout=60000)
8566
public void testNonDefaultNonBrowserUserAgentAsBrowser() throws Exception {
86-
HttpServletRequest request = mock(HttpServletRequest.class);
87-
HttpServletResponse response = mock(HttpServletResponse.class);
67+
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
68+
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
8869

8970
if (handler != null) {
9071
handler.destroy();
@@ -101,16 +82,15 @@ public void testNonDefaultNonBrowserUserAgentAsBrowser() throws Exception {
10182
}
10283

10384
// Pretend we're something that will not match with "foo" (or "bar")
104-
when(request.getHeader("User-Agent")).thenReturn("blah");
85+
Mockito.when(request.getHeader("User-Agent")).thenReturn("blah");
10586
// Should use alt authentication
10687
AuthenticationToken token = handler.authenticate(request, response);
107-
assertEquals("A", token.getUserName());
108-
assertEquals("B", token.getName());
109-
assertEquals(getExpectedType(), token.getType());
88+
Assert.assertEquals("A", token.getUserName());
89+
Assert.assertEquals("B", token.getName());
90+
Assert.assertEquals(getExpectedType(), token.getType());
11091
}
11192

112-
@Test
113-
@Timeout(value = 60)
93+
@Test(timeout=60000)
11494
public void testNonDefaultNonBrowserUserAgentAsNonBrowser() throws Exception {
11595
if (handler != null) {
11696
handler.destroy();

0 commit comments

Comments
 (0)