26
26
27
27
import java .io .File ;
28
28
import java .util .Properties ;
29
+ import java .util .concurrent .TimeUnit ;
29
30
30
31
import javax .servlet .http .HttpServletRequest ;
31
32
import javax .servlet .http .HttpServletResponse ;
38
39
import org .apache .directory .server .core .annotations .CreateDS ;
39
40
import org .apache .directory .server .core .annotations .CreatePartition ;
40
41
import org .apache .directory .server .core .integ .AbstractLdapTestUnit ;
41
- import org .apache .directory .server .core .integ .FrameworkRunner ;
42
+ import org .apache .directory .server .core .integ .ApacheDSTestExtension ;
42
43
import org .apache .hadoop .minikdc .KerberosSecurityTestcase ;
43
44
import org .apache .hadoop .security .authentication .KerberosTestUtils ;
44
45
import org .apache .hadoop .security .authentication .client .AuthenticationException ;
45
- import org .junit .After ;
46
- import org .junit .Assert ;
47
- import org .junit .Before ;
48
- import org .junit .Test ;
49
- import org .junit .runner .RunWith ;
46
+ import org .junit .jupiter .api .AfterEach ;
47
+ import org .junit .jupiter .api .Assertions ;
48
+ import org .junit .jupiter .api .BeforeEach ;
49
+ import org .junit .jupiter .api .Test ;
50
+ import org .junit .jupiter .api .Timeout ;
51
+ import org .junit .jupiter .api .extension .ExtendWith ;
50
52
import org .mockito .Mockito ;
51
53
52
54
/**
53
55
* This unit test verifies the functionality of "multi-scheme" auth handler.
54
56
*/
55
- @ RunWith ( FrameworkRunner .class )
57
+ @ ExtendWith ( ApacheDSTestExtension .class )
56
58
@ CreateLdapServer (
57
59
transports =
58
60
{
@@ -79,7 +81,7 @@ public class TestMultiSchemeAuthenticationHandler
79
81
private KerberosSecurityTestcase krbTest = new KerberosSecurityTestcase ();
80
82
private MultiSchemeAuthenticationHandler handler ;
81
83
82
- @ Before
84
+ @ BeforeEach
83
85
public void setUp () throws Exception {
84
86
krbTest .startMiniKdc ();
85
87
@@ -99,7 +101,7 @@ public void setUp() throws Exception {
99
101
}
100
102
}
101
103
102
- @ After
104
+ @ AfterEach
103
105
public void tearDown () throws Exception {
104
106
krbTest .stopMiniKdc ();
105
107
}
@@ -122,18 +124,20 @@ private Properties getDefaultProperties() {
122
124
return p ;
123
125
}
124
126
125
- @ Test (timeout = 60000 )
127
+ @ Test
128
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
126
129
public void testRequestWithoutAuthorization () throws Exception {
127
130
HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
128
131
HttpServletResponse response = Mockito .mock (HttpServletResponse .class );
129
132
130
- Assert .assertNull (handler .authenticate (request , response ));
133
+ Assertions .assertNull (handler .authenticate (request , response ));
131
134
Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , BASIC );
132
135
Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , NEGOTIATE );
133
136
Mockito .verify (response ).setStatus (HttpServletResponse .SC_UNAUTHORIZED );
134
137
}
135
138
136
- @ Test (timeout = 60000 )
139
+ @ Test
140
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
137
141
public void testRequestWithInvalidAuthorization () throws Exception {
138
142
HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
139
143
HttpServletResponse response = Mockito .mock (HttpServletResponse .class );
@@ -142,13 +146,14 @@ public void testRequestWithInvalidAuthorization() throws Exception {
142
146
String credentials = "bjones:invalidpassword" ;
143
147
Mockito .when (request .getHeader (AUTHORIZATION_HEADER ))
144
148
.thenReturn (base64 .encodeToString (credentials .getBytes ()));
145
- Assert .assertNull (handler .authenticate (request , response ));
149
+ Assertions .assertNull (handler .authenticate (request , response ));
146
150
Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , BASIC );
147
151
Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , NEGOTIATE );
148
152
Mockito .verify (response ).setStatus (HttpServletResponse .SC_UNAUTHORIZED );
149
153
}
150
154
151
- @ Test (timeout = 60000 )
155
+ @ Test
156
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
152
157
public void testRequestWithLdapAuthorization () throws Exception {
153
158
HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
154
159
HttpServletResponse response = Mockito .mock (HttpServletResponse .class );
@@ -159,14 +164,15 @@ public void testRequestWithLdapAuthorization() throws Exception {
159
164
Mockito .when (request .getHeader (AUTHORIZATION_HEADER ))
160
165
.thenReturn (authHeader );
161
166
AuthenticationToken token = handler .authenticate (request , response );
162
- Assert .assertNotNull (token );
167
+ Assertions .assertNotNull (token );
163
168
Mockito .verify (response ).setStatus (HttpServletResponse .SC_OK );
164
- Assert .assertEquals (TYPE , token .getType ());
165
- Assert .assertEquals ("bjones" , token .getUserName ());
166
- Assert .assertEquals ("bjones" , token .getName ());
169
+ Assertions .assertEquals (TYPE , token .getType ());
170
+ Assertions .assertEquals (token .getUserName (), "bjones" );
171
+ Assertions .assertEquals (token .getName (), "bjones" );
167
172
}
168
173
169
- @ Test (timeout = 60000 )
174
+ @ Test
175
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
170
176
public void testRequestWithInvalidKerberosAuthorization () throws Exception {
171
177
String token = new Base64 (0 ).encodeToString (new byte []{0 , 1 , 2 });
172
178
@@ -178,11 +184,11 @@ public void testRequestWithInvalidKerberosAuthorization() throws Exception {
178
184
179
185
try {
180
186
handler .authenticate (request , response );
181
- Assert .fail ();
187
+ Assertions .fail ();
182
188
} catch (AuthenticationException ex ) {
183
189
// Expected
184
190
} catch (Exception ex ) {
185
- Assert .fail ("Wrong exception :" +ex );
191
+ Assertions .fail ("Wrong exception :" +ex );
186
192
}
187
193
}
188
194
0 commit comments