Skip to content

Commit

Permalink
Add JSON array claims to backend JWT test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HeshanSudarshana committed Jan 19, 2023
1 parent 3626ffe commit 285b7fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public void testEnableJWTAndClaimsForJWTApp() throws Exception {
assertTrue("JWT claim givenname not received" + claim, claim.contains("first name".concat(endUser)));
claim = jsonObject.getString("http://wso2.org/claims/lastname");
assertTrue("JWT claim lastname not received" + claim, claim.contains("last name".concat(endUser)));
claim = jsonObject.getString("http://wso2.org/claims/region");
assertTrue("JWT claim region not received" + claim,
claim.contains("[{\"areaId\":\"71224\",\"areaName\":\"20-NYU\"}]"));
claim = jsonObject.getString("mobile");
assertTrue("JWT claim mobile not received" + claim, claim.contains("94123456987"));
claim = jsonObject.getString("organization");
Expand Down Expand Up @@ -531,6 +534,8 @@ private void createUser() throws RemoteException,
"http://wso2.org/claims/givenname", "first name".concat(user), DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
"http://wso2.org/claims/lastname", "last name".concat(user), DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
"http://wso2.org/claims/region", "[{'areaId':'71224','areaName':'20-NYU'}]", DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
"http://wso2.org/claims/organization", "ABC".concat(user), DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
Expand Down Expand Up @@ -660,7 +665,7 @@ private void updateServiceProviderWithRequiredClaims(String consumerKey)
throws OAuthAdminServiceIdentityOAuthAdminException, RemoteException,
IdentityApplicationManagementServiceIdentityApplicationManagementException {
String[] requestedClaims = { "http://wso2.org/claims/givenname", "http://wso2.org/claims/lastname",
"http://wso2.org/claims/mobile", "http://wso2.org/claims/organization",
"http://wso2.org/claims/region", "http://wso2.org/claims/mobile", "http://wso2.org/claims/organization",
"http://wso2.org/claims/telephone", "http://wso2.org/claims/emailaddress" };
OAuthConsumerAppDTO oAuthApplicationData = oAuthAdminServiceClient.getOAuthApplicationData(consumerKey);
String applicationName = oAuthApplicationData.getApplicationName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ public void testEnableJWTAndClaimsForJWTApp() throws Exception {
assertTrue("JWT claim givenname not received" + claim, claim.contains("first name".concat(endUser)));
claim = jsonObject.getString("http://wso2.org/claims/lastname");
assertTrue("JWT claim lastname not received" + claim, claim.contains("last name".concat(endUser)));
claim = jsonObject.getString("http://wso2.org/claims/region");
assertTrue("JWT claim region not received" + claim,
claim.contains("[{\"areaId\":\"71224\",\"areaName\":\"20-NYU\"}]"));
claim = jsonObject.getString("mobile");
assertTrue("JWT claim mobile not received" + claim, claim.contains("94123456987"));
claim = jsonObject.getString("organization");
Expand Down Expand Up @@ -510,6 +513,8 @@ private void createUser() throws RemoteException,
"http://wso2.org/claims/givenname", "first name".concat(user), DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
"http://wso2.org/claims/lastname", "last name".concat(user), DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
"http://wso2.org/claims/region", "[{'areaId':'71224','areaName':'20-NYU'}]", DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
"http://wso2.org/claims/organization", "ABC".concat(user), DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(user,
Expand All @@ -532,8 +537,8 @@ private void createClaimMapping() throws RemoteException, ClaimMetadataManagemen
private void updateServiceProviderWithRequiredClaims(String consumerKey)
throws OAuthAdminServiceIdentityOAuthAdminException, RemoteException,
IdentityApplicationManagementServiceIdentityApplicationManagementException {
String[] requestedClaims = {"http://wso2.org/claims/givenname","http://wso2.org/claims/lastname","http://wso2" +
".org/claims/organization","http://wso2.org/claims/mobile"};
String[] requestedClaims = {"http://wso2.org/claims/givenname","http://wso2.org/claims/lastname",
"http://wso2.org/claims/region","http://wso2.org/claims/organization","http://wso2.org/claims/mobile"};
OAuthConsumerAppDTO oAuthApplicationData = oAuthAdminServiceClient.getOAuthApplicationData(consumerKey);
String applicationName = oAuthApplicationData.getApplicationName();
ServiceProvider application = applicationManagementClient.getApplication(applicationName);
Expand Down Expand Up @@ -694,6 +699,9 @@ private void verifyUserProfileInfoClaims(JSONObject decodedJWTJSONObject, String
assertTrue("JWT claim givenname not received" + claim, claim.contains("first name".concat(endUser)));
claim = decodedJWTJSONObject.getString("http://wso2.org/claims/lastname");
assertTrue("JWT claim lastname not received" + claim, claim.contains("last name".concat(endUser)));
claim = decodedJWTJSONObject.getString("http://wso2.org/claims/region");
assertTrue("JWT claim region not received" + claim,
claim.contains("[{\"areaId\":\"71224\",\"areaName\":\"20-NYU\"}]"));
claim = decodedJWTJSONObject.getString("http://wso2.org/claims/mobile");
assertTrue("JWT claim mobile not received" + claim, claim.contains("94123456987"));
claim = decodedJWTJSONObject.getString("http://wso2.org/claims/organization");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public void testEnableJWTAndClaimsForOauthApp() throws Exception {
assertTrue("JWT claim givenname not received" + claim, claim.contains("first name"));
claim = jsonObject.getString("http://wso2.org/claims/lastname");
assertTrue("JWT claim lastname not received" + claim, claim.contains("last name"));
claim = jsonObject.getString("http://wso2.org/claims/region");
assertTrue("JWT claim region not received" + claim,
claim.contains("[{\"areaId\":\"71224\",\"areaName\":\"20-NYU\"}]"));
boolean bExceptionOccured = false;
try {
jsonObject.getString("http://wso2.org/claims/wrongclaim");
Expand Down Expand Up @@ -276,6 +279,8 @@ private void createUser() throws RemoteException,
"http://wso2.org/claims/givenname", "first name", DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(enduserName,
"http://wso2.org/claims/lastname", "last name", DEFAULT_PROFILE);
remoteUserStoreManagerServiceClient.setUserClaimValue(enduserName,
"http://wso2.org/claims/region", "[{'areaId':'71224','areaName':'20-NYU'}]", DEFAULT_PROFILE);

}

Expand Down

0 comments on commit 285b7fc

Please sign in to comment.