12
12
* information: "Portions copyright [year] [name of copyright owner]".
13
13
*
14
14
* Copyright 2013-2016 ForgeRock AS.
15
+ * Portions Copyright 2021 Wren Security.
15
16
*/
16
17
17
18
package org .forgerock .openam .authentication .modules .common ;
18
19
19
- import static org .mockito .BDDMockito .doThrow ;
20
- import static org .mockito .BDDMockito .*;
21
- import static org .mockito .Mockito .eq ;
22
- import static org .mockito .Mockito .isNull ;
20
+ import static org .mockito .ArgumentMatchers .any ;
21
+ import static org .mockito .ArgumentMatchers .eq ;
22
+ import static org .mockito .ArgumentMatchers .isNull ;
23
+ import static org .mockito .BDDMockito .given ;
24
+ import static org .mockito .Mockito .doThrow ;
23
25
import static org .mockito .Mockito .mock ;
24
26
import static org .mockito .Mockito .never ;
25
27
import static org .mockito .Mockito .verify ;
26
28
import static org .mockito .Mockito .verifyZeroInteractions ;
27
- import static org .testng .AssertJUnit .*;
29
+ import static org .testng .AssertJUnit .assertEquals ;
30
+ import static org .testng .AssertJUnit .assertTrue ;
28
31
29
32
import java .util .HashMap ;
30
33
import java .util .Map ;
31
34
32
- import javax .security .auth .callback .CallbackHandler ;
33
35
import javax .security .auth .message .AuthException ;
34
36
import javax .security .auth .message .AuthStatus ;
35
37
import javax .security .auth .message .MessageInfo ;
36
38
import javax .security .auth .message .module .ServerAuthModule ;
37
39
import javax .servlet .http .HttpServletRequest ;
38
40
import javax .servlet .http .HttpServletResponse ;
39
41
40
- import org .mockito .Matchers ;
41
42
import org .testng .annotations .BeforeMethod ;
42
43
import org .testng .annotations .Test ;
43
44
@@ -92,7 +93,7 @@ public void shouldCallOnLoginSuccessAndThrowAuthenticationExceptionWhenAuthExcep
92
93
HttpServletResponse response = mock (HttpServletResponse .class );
93
94
SSOToken ssoToken = mock (SSOToken .class );
94
95
95
- doThrow (AuthException .class ).when (jaspiAuthWrapper ).initialize (( CallbackHandler ) isNull (), eq (config ));
96
+ doThrow (AuthException .class ).when (jaspiAuthWrapper ).initialize (isNull (), eq (config ));
96
97
97
98
//When
98
99
boolean exceptionCaught = false ;
@@ -105,8 +106,8 @@ public void shouldCallOnLoginSuccessAndThrowAuthenticationExceptionWhenAuthExcep
105
106
}
106
107
107
108
//Then
108
- verify (jaspiAuthWrapper ).initialize (any (CallbackHandler . class ), eq (config ));
109
- verify (jaspiAuthWrapper , never ()).secureResponse (Matchers .< MessageInfo > anyObject ());
109
+ verify (jaspiAuthWrapper ).initialize (any (), eq (config ));
110
+ verify (jaspiAuthWrapper , never ()).secureResponse (any ());
110
111
assertTrue (exceptionCaught );
111
112
assertEquals (exception .getErrorCode (), "authFailed" );
112
113
}
@@ -120,16 +121,16 @@ public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendSuccess() throw
120
121
HttpServletResponse response = mock (HttpServletResponse .class );
121
122
SSOToken ssoToken = mock (SSOToken .class );
122
123
123
- given (jaspiAuthWrapper .secureResponse (Matchers .< MessageInfo > anyObject ()))
124
+ given (jaspiAuthWrapper .secureResponse (any ()))
124
125
.willReturn (AuthStatus .SEND_SUCCESS );
125
126
126
127
//When
127
128
jaspiPostAuthPlugin .onLoginSuccess (requestParamsMap , request , response , ssoToken );
128
129
129
130
//Then
130
- verify (jaspiAuthWrapper ).initialize (any (CallbackHandler . class ), eq (config ));
131
+ verify (jaspiAuthWrapper ).initialize (any (), eq (config ));
131
132
assertTrue (onLoginSuccessMethodCalled );
132
- verify (jaspiAuthWrapper ).secureResponse (Matchers .< MessageInfo > anyObject ());
133
+ verify (jaspiAuthWrapper ).secureResponse (any ());
133
134
}
134
135
135
136
@ Test
@@ -142,7 +143,7 @@ public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendFailure() throw
142
143
HttpServletResponse response = mock (HttpServletResponse .class );
143
144
SSOToken ssoToken = mock (SSOToken .class );
144
145
145
- given (jaspiAuthWrapper .secureResponse (Matchers .< MessageInfo > anyObject ()))
146
+ given (jaspiAuthWrapper .secureResponse (any ()))
146
147
.willReturn (AuthStatus .SEND_FAILURE );
147
148
148
149
//When
@@ -156,9 +157,9 @@ public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendFailure() throw
156
157
}
157
158
158
159
//Then
159
- verify (jaspiAuthWrapper ).initialize (any (CallbackHandler . class ), eq (config ));
160
+ verify (jaspiAuthWrapper ).initialize (any (), eq (config ));
160
161
assertTrue (onLoginSuccessMethodCalled );
161
- verify (jaspiAuthWrapper ).secureResponse (Matchers .< MessageInfo > anyObject ());
162
+ verify (jaspiAuthWrapper ).secureResponse (any ());
162
163
assertTrue (exceptionCaught );
163
164
assertEquals (exception .getErrorCode (), "authFailed" );
164
165
}
@@ -173,7 +174,7 @@ public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendContinue() thro
173
174
HttpServletResponse response = mock (HttpServletResponse .class );
174
175
SSOToken ssoToken = mock (SSOToken .class );
175
176
176
- given (jaspiAuthWrapper .secureResponse (Matchers .< MessageInfo > anyObject ()))
177
+ given (jaspiAuthWrapper .secureResponse (any ()))
177
178
.willReturn (AuthStatus .SEND_CONTINUE );
178
179
179
180
//When
@@ -187,9 +188,9 @@ public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendContinue() thro
187
188
}
188
189
189
190
//Then
190
- verify (jaspiAuthWrapper ).initialize (any (CallbackHandler . class ), eq (config ));
191
+ verify (jaspiAuthWrapper ).initialize (any (), eq (config ));
191
192
assertTrue (onLoginSuccessMethodCalled );
192
- verify (jaspiAuthWrapper ).secureResponse (Matchers .< MessageInfo > anyObject ());
193
+ verify (jaspiAuthWrapper ).secureResponse (any ());
193
194
assertTrue (exceptionCaught );
194
195
assertEquals (exception .getErrorCode (), "authFailed" );
195
196
}
@@ -203,7 +204,7 @@ public void shouldCallOnLoginSuccessWhenSecureResponseReturnsElse() throws Authe
203
204
HttpServletResponse response = mock (HttpServletResponse .class );
204
205
SSOToken ssoToken = mock (SSOToken .class );
205
206
206
- given (jaspiAuthWrapper .secureResponse (Matchers .< MessageInfo > anyObject ()))
207
+ given (jaspiAuthWrapper .secureResponse (any ()))
207
208
.willReturn (AuthStatus .SUCCESS );
208
209
209
210
//When
@@ -217,9 +218,9 @@ public void shouldCallOnLoginSuccessWhenSecureResponseReturnsElse() throws Authe
217
218
}
218
219
219
220
//Then
220
- verify (jaspiAuthWrapper ).initialize (any (CallbackHandler . class ), eq (config ));
221
+ verify (jaspiAuthWrapper ).initialize (any (), eq (config ));
221
222
assertTrue (onLoginSuccessMethodCalled );
222
- verify (jaspiAuthWrapper ).secureResponse (Matchers .< MessageInfo > anyObject ());
223
+ verify (jaspiAuthWrapper ).secureResponse (any ());
223
224
assertTrue (exceptionCaught );
224
225
assertEquals (exception .getErrorCode (), "authFailed" );
225
226
}
0 commit comments