Commit d42827a5 authored by Kelly Domico's avatar Kelly Domico
Browse files

Fix case for final static variables

parent 08d78bc6
Pipeline #21291 failed with stages
in 49 seconds
......@@ -12,65 +12,65 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class AuthUtilsTest {
// Mock JWT Token: {"aud": "audience","appid": "application-id","oid": "my-oid","sub": "my-sub","tid": "my-tenant"}
private static final String jwtToken = "part1.eyJhdWQiOiJhdWRpZW5jZSIsImFwcGlkIjoiYXBwbGljYXRpb24taWQiLCJvaWQiOiJteS1vaWQiLCJzdWIiOiJteS1zdWIiLCJ0aWQiOiJteS10ZW5hbnQifQ.part3";
private static final String invalidJwtToken = "invalidjwttoken";
private static final String invalidJwtTokenClaims = "part1.invalidclaims.part2";
private static final String emptyJwtTokenClaims = "part1.e30.part3";
private static final String tokenAudience = "audience";
private static final String tokenSubject = "my-sub";
private static final String tokenOid = "my-oid";
private static final String tokenTenant = "my-tenant";
private static final String tokenAppid = "application-id";
private static final String JWT_TOKEN = "part1.eyJhdWQiOiJhdWRpZW5jZSIsImFwcGlkIjoiYXBwbGljYXRpb24taWQiLCJvaWQiOiJteS1vaWQiLCJzdWIiOiJteS1zdWIiLCJ0aWQiOiJteS10ZW5hbnQifQ.part3";
private static final String INVALID_JWT_TOKEN = "invalidjwttoken";
private static final String INVALID_JWT_TOKEN_CLAIMS = "part1.invalidclaims.part2";
private static final String EMPTY_JWT_TOKEN_CLAIMS = "part1.e30.part3";
private static final String TOKEN_AUDIENCE = "audience";
private static final String TOKEN_SUBJECT = "my-sub";
private static final String TOKEN_OID = "my-oid";
private static final String TOKEN_TENANT = "my-tenant";
private static final String TOKEN_APPID = "application-id";
@InjectMocks
private AuthUtils authUtils;
@Test
public void ShouldSuccessfullyGetClaims() throws Exception {
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(jwtToken);
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(JWT_TOKEN);
assertEquals(5, claims.getClaims().size());
assertEquals(1, claims.getAudience().size());
assertEquals(tokenAudience, claims.getAudience().get(0));
assertEquals(tokenSubject, claims.getSubject());
assertEquals(tokenAppid, claims.getStringClaim("appid"));
assertEquals(tokenOid, claims.getStringClaim("oid"));
assertEquals(tokenTenant, claims.getStringClaim("tid"));
assertEquals(TOKEN_AUDIENCE, claims.getAudience().get(0));
assertEquals(TOKEN_SUBJECT, claims.getSubject());
assertEquals(TOKEN_APPID, claims.getStringClaim("appid"));
assertEquals(TOKEN_OID, claims.getStringClaim("oid"));
assertEquals(TOKEN_TENANT, claims.getStringClaim("tid"));
}
@Test
public void ShouldReturnNullForInvalidToken() throws Exception {
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(invalidJwtToken);
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(INVALID_JWT_TOKEN);
assertEquals(null, claims);
}
@Test
public void ShouldReturnNullForInvalidTokenClaims() throws Exception {
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(invalidJwtTokenClaims);
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(INVALID_JWT_TOKEN_CLAIMS);
assertEquals(null, claims);
}
@Test
public void ShouldReturnEmptySetForEmptyTokenClaims() throws Exception {
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(emptyJwtTokenClaims);
JWTClaimsSet claims = authUtils.getClaimsFromJwtToken(EMPTY_JWT_TOKEN_CLAIMS);
assertEquals(0, claims.getClaims().size());
}
@Test
public void ShouldReturnOidForValidTokenWithOid() throws Exception {
String oid = authUtils.getOidFromJwtToken(jwtToken);
assertEquals(tokenOid, oid);
String oid = authUtils.getOidFromJwtToken(JWT_TOKEN);
assertEquals(TOKEN_OID, oid);
}
@Test
public void ShouldReturnNullOidForInvalidToken() throws Exception {
String oid = authUtils.getOidFromJwtToken(invalidJwtToken);
String oid = authUtils.getOidFromJwtToken(INVALID_JWT_TOKEN);
assertEquals(null, oid);
}
@Test
public void ShouldReturnNullOidForEmptyToken() throws Exception {
String oid = authUtils.getOidFromJwtToken(emptyJwtTokenClaims);
String oid = authUtils.getOidFromJwtToken(EMPTY_JWT_TOKEN_CLAIMS);
assertEquals(null, oid);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment