|
40 | 40 | import org.zowe.apiml.product.constants.CoreService;
|
41 | 41 | import org.zowe.apiml.security.SecurityUtils;
|
42 | 42 | import org.zowe.apiml.security.common.config.AuthConfigurationProperties;
|
43 |
| -import org.zowe.apiml.security.common.token.QueryResponse; |
44 |
| -import org.zowe.apiml.security.common.token.TokenAuthentication; |
45 |
| -import org.zowe.apiml.security.common.token.TokenExpireException; |
46 |
| -import org.zowe.apiml.security.common.token.TokenNotValidException; |
| 43 | +import org.zowe.apiml.security.common.token.*; |
47 | 44 | import org.zowe.apiml.util.CacheUtils;
|
48 | 45 | import org.zowe.apiml.util.EurekaUtils;
|
49 | 46 |
|
50 | 47 | import javax.servlet.http.Cookie;
|
51 |
| -import java.security.Key; |
52 |
| -import java.security.KeyPair; |
53 |
| -import java.security.PublicKey; |
| 48 | +import java.security.*; |
54 | 49 | import java.util.*;
|
55 | 50 | import java.util.function.Consumer;
|
56 | 51 |
|
|
62 | 57 | CacheConfig.class,
|
63 | 58 | MockedAuthenticationServiceContext.class
|
64 | 59 | })
|
65 |
| - |
66 |
| -public class AuthenticationServiceTest { |
| 60 | +public class AuthenticationServiceTest { //NOSONAR, needs to be public |
67 | 61 |
|
68 | 62 | public static final String ZOSMF = "zosmf";
|
69 | 63 | private static final String ZOSMF_HOSTNAME = "zosmfhostname";
|
@@ -180,6 +174,7 @@ void shouldThrowExceptionWhenTokenIsExpired() {
|
180 | 174 | );
|
181 | 175 | }
|
182 | 176 |
|
| 177 | + |
183 | 178 | @Test
|
184 | 179 | void shouldThrowExceptionWhenOccurUnexpectedException() {
|
185 | 180 | assertThrows(
|
@@ -267,10 +262,12 @@ void shouldThrowExceptionWhenTokenIsExpiredWhileExtractingLtpa() {
|
267 | 262 | }
|
268 | 263 |
|
269 | 264 | private String createExpiredJwtToken(Key secretKey) {
|
270 |
| - long expiredTimeMillis = System.currentTimeMillis() - 1000; |
| 265 | + return createJwtTokenWithExpiry(secretKey, System.currentTimeMillis() - 1000); |
| 266 | + } |
271 | 267 |
|
| 268 | + private String createJwtTokenWithExpiry(Key secretKey, long expireAt) { |
272 | 269 | return Jwts.builder()
|
273 |
| - .setExpiration(new Date(expiredTimeMillis)) |
| 270 | + .setExpiration(new Date(expireAt)) |
274 | 271 | .setIssuer(authConfigurationProperties.getTokenProperties().getIssuer())
|
275 | 272 | .signWith(ALGORITHM, secretKey)
|
276 | 273 | .compact();
|
|
0 commit comments