Skip to content

Commit 05de7d6

Browse files
committed
add unit tests
1 parent 53f27a7 commit 05de7d6

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/tokenprocessor/DefaultRefreshTokenGrantProcessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ public AccessTokenDO createAccessTokenBean(OAuthTokenReqMessageContext tokReqMsg
120120
tokReqMsgCtx.setConsentedToken(true);
121121
}
122122
}
123+
if (log.isDebugEnabled()) {
124+
log.debug("Setting access token extended attributes for token request in refresh token flow for client: "
125+
+ tokenReq.getClientId() + " with token id: " + tokenId);
126+
}
123127
accessTokenDO.setAccessTokenExtendedAttributes(
124128
new AccessTokenExtendedAttributes(
125129
new HashMap<>(tokenReq.getAccessTokenExtendedAttributes().getParameters())));

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/JWTTokenIssuer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ protected JWTClaimsSet createJWTClaimSet(OAuthAuthzReqMessageContext authAuthzRe
696696
.getParameters();
697697
if (customClaims != null && !customClaims.isEmpty()) {
698698
customClaims.remove(OAuthConstants.IMPERSONATING_ACTOR);
699+
if (log.isDebugEnabled()) {
700+
log.debug("Processing custom claims for JWT token. Total claims count: " + customClaims.size());
701+
}
699702
for (Map.Entry<String, String> entry : customClaims.entrySet()) {
700703
jwtClaimsSetBuilder.claim(entry.getKey(), entry.getValue());
701704
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/AbstractAuthorizationGrantHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,15 +929,22 @@ private OAuth2AccessTokenRespDTO createResponseWithTokenBean(OAuthTokenReqMessag
929929
if (issueRefreshToken(existingAccessTokenDO.getTokenType()) &&
930930
OAuthServerConfiguration.getInstance().getSupportedGrantTypes().containsKey(
931931
GrantType.REFRESH_TOKEN.toString())) {
932+
log.info("mathu first call");
932933
String grantTypes = oAuthAppDO.getGrantTypes();
933934
List<String> supportedGrantTypes = new ArrayList<>();
934935
if (StringUtils.isNotEmpty(grantTypes)) {
935936
supportedGrantTypes = Arrays.asList(grantTypes.split(" "));
936937
}
938+
log.info("mathu second call : " + supportedGrantTypes);
937939
if (supportedGrantTypes.contains(OAuthConstants.GrantTypes.REFRESH_TOKEN)) {
938940
if (!tokenReqMessageContext.isImpersonationRequest()
939941
|| OAuth2Util.isImpersonatedRefreshTokenEnabled()) {
940942
tokenRespDTO.setRefreshToken(existingAccessTokenDO.getRefreshToken());
943+
} else {
944+
if (log.isDebugEnabled()) {
945+
log.debug("Impersonation request is not allowed to have a refresh token for client_id : " +
946+
consumerKey + ", therefore not issuing a refresh token.");
947+
}
941948
}
942949
} else {
943950
if (log.isDebugEnabled()) {

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/RefreshGrantHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ private void setPropertiesForTokenGeneration(OAuthTokenReqMessageContext tokReqM
309309

310310
private void propagateImpersonationInfo(OAuthTokenReqMessageContext tokenReqMessageContext) {
311311

312+
log.debug("Checking for impersonation information in token request");
312313
if (tokenReqMessageContext != null && tokenReqMessageContext.getOauth2AccessTokenReqDTO() != null &&
313314
tokenReqMessageContext.getOauth2AccessTokenReqDTO().getAccessTokenExtendedAttributes() != null) {
314315
String impersonator = tokenReqMessageContext.getOauth2AccessTokenReqDTO()

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/util/OAuth2Util.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5892,6 +5892,10 @@ public static boolean isImpersonatedRefreshTokenEnabled() {
58925892
if (IdentityUtil.getProperty(OAuth2Constants.IMPERSONATED_REFRESH_TOKEN_ENABLE) != null) {
58935893
return Boolean.parseBoolean(IdentityUtil.getProperty(OAuth2Constants.IMPERSONATED_REFRESH_TOKEN_ENABLE));
58945894
}
5895+
if (log.isDebugEnabled()) {
5896+
log.debug("Impersonated refresh token configuration not found, " +
5897+
"using default: " + OAuth2Constants.DEFAULT_IMPERSONATED_REFRESH_TOKEN_ENABLED);
5898+
}
58955899
return OAuth2Constants.DEFAULT_IMPERSONATED_REFRESH_TOKEN_ENABLED;
58965900
}
58975901

components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/oauth2/token/JWTTokenIssuerTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO;
5959
import org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO;
6060
import org.wso2.carbon.identity.oauth2.internal.OAuth2ServiceComponentHolder;
61+
import org.wso2.carbon.identity.oauth2.model.AccessTokenExtendedAttributes;
6162
import org.wso2.carbon.identity.oauth2.token.bindings.TokenBinding;
6263
import org.wso2.carbon.identity.oauth2.token.handlers.claims.JWTAccessTokenClaimProvider;
6364
import org.wso2.carbon.identity.oauth2.token.handlers.grant.AuthorizationGrantHandler;
@@ -335,6 +336,13 @@ public Object[][] provideClaimSetData() {
335336
OAuth2AccessTokenReqDTO tokenReqDTO = new OAuth2AccessTokenReqDTO();
336337
tokenReqDTO.setGrantType(APPLICATION_ACCESS_TOKEN_GRANT_TYPE);
337338
tokenReqDTO.setTenantDomain("super.wso2");
339+
AccessTokenExtendedAttributes accessTokenExtendedAttributes = new AccessTokenExtendedAttributes();
340+
accessTokenExtendedAttributes.setExtendedToken(true);
341+
HashMap<String, String> params = new HashMap<>();
342+
params.put("testExtendingKey", "testExtendingValue");
343+
params.put(OAuthConstants.IMPERSONATING_ACTOR, "DUMMY_ACTOR");
344+
accessTokenExtendedAttributes.setParameters(params);
345+
tokenReqDTO.setAccessTokenExtendedAttributes(accessTokenExtendedAttributes);
338346
OAuthTokenReqMessageContext tokenReqMessageContext = new OAuthTokenReqMessageContext(tokenReqDTO);
339347
AuthenticatedUser authenticatedUserForTokenReq = new AuthenticatedUser(authenticatedUserForAuthz);
340348
tokenReqMessageContext.setAuthorizedUser(authenticatedUserForTokenReq);
@@ -438,6 +446,12 @@ public void testCreateJWTClaimSet(Object authzReqMessageContext,
438446
assertNotNull(jwtClaimSet.getIssueTime());
439447
assertNotNull(jwtClaimSet.getExpirationTime());
440448

449+
if (tokenReqMessageContext != null) {
450+
assertNotNull(jwtClaimSet.getClaim("testExtendingKey"));
451+
assertEquals(jwtClaimSet.getClaim("testExtendingKey"), "testExtendingValue");
452+
assertNull(jwtClaimSet.getClaim(OAuthConstants.IMPERSONATING_ACTOR));
453+
}
454+
441455
if (tokenReqMessageContext != null
442456
&& ((OAuthTokenReqMessageContext) tokenReqMessageContext).getProperty(EXPIRY_TIME_JWT)
443457
!= null) {

components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/oauth2/util/OAuth2UtilTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,6 +3177,26 @@ public void testGetAppResidentTenantDomain(String appResidentOrgId, String expec
31773177
assertEquals(OAuth2Util.getAppResidentTenantDomain(), expected);
31783178
}
31793179

3180+
@DataProvider(name = "impersonatedRefreshTokenEnabledProvider")
3181+
public Object[][] impersonatedRefreshTokenEnabledProvider() {
3182+
return new Object[][]{
3183+
{"true", true},
3184+
{"false", false},
3185+
{null, true}
3186+
};
3187+
}
3188+
3189+
@Test(dataProvider = "impersonatedRefreshTokenEnabledProvider")
3190+
public void testIsImpersonatedRefreshTokenEnabled(String configValue, boolean expected) {
3191+
3192+
try (MockedStatic<IdentityUtil> identityUtil = mockStatic(IdentityUtil.class)) {
3193+
3194+
identityUtil.when(() -> IdentityUtil.getProperty(OAuth2Constants.IMPERSONATED_REFRESH_TOKEN_ENABLE))
3195+
.thenReturn(configValue);
3196+
assertEquals(OAuth2Util.isImpersonatedRefreshTokenEnabled(), expected);
3197+
}
3198+
}
3199+
31803200
@Test(expectedExceptions = IdentityOAuth2Exception.class,
31813201
expectedExceptionsMessageRegExp = "Error occurred while resolving the tenant domain for the " +
31823202
"organization id.")

0 commit comments

Comments
 (0)