From dd9f674be8f9a5b6b93c075108ae4089d48e6e5b Mon Sep 17 00:00:00 2001 From: Ashan Thamara Palihakkara <75057725+ashanthamara@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:55:45 +0530 Subject: [PATCH 1/7] Fixed minor-formatting issues. --- .../OAuth2BackChannelLogoutTestCase.java | 2 + .../test/oauth2/OAuth2DeviceFlowTestCase.java | 6 +- .../OAuth2IDTokenEncryptionTestCase.java | 11 +- ...uestObjectSignatureValidationTestCase.java | 7 +- .../test/oauth2/OAuth2RoleClaimTestCase.java | 4 + .../OAuth2ServiceAbstractIntegrationTest.java | 270 ++++++++++-------- ...OAuth2ServiceClientCredentialTestCase.java | 3 + .../OAuth2ServiceErrorResponseTest.java | 3 + .../OAuth2ServiceImplicitGrantTestCase.java | 4 + .../OAuth2ServiceIntrospectionTestCase.java | 5 + ...Auth2ServiceRefreshTokenGrantTestCase.java | 7 + ...OAuth2ServiceRegexCallbackUrlTestCase.java | 6 + .../OAuth2ServiceResourceOwnerTestCase.java | 3 + ...OAuth2ServiceSAML2BearerGrantTestCase.java | 19 +- ...ithMultipleSessionTerminationTestCase.java | 2 +- ...TokenRevocationWithRevokedAccessToken.java | 1 + .../test/oauth2/Oauth2OPIframeTestCase.java | 1 + .../v1/model/ApplicationPatchModel.java | 2 +- .../AssertionEncryptionConfiguration.java | 2 +- .../restclients/AuthenticatorRestClient.java | 7 +- .../restclients/EmailTemplatesRestClient.java | 10 +- .../IdentityGovernanceRestClient.java | 8 +- .../test/restclients/OAuth2RestClient.java | 52 +++- .../test/restclients/RestBaseClient.java | 30 +- .../test/restclients/SCIM2RestClient.java | 49 +++- 25 files changed, 344 insertions(+), 170 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2BackChannelLogoutTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2BackChannelLogoutTestCase.java index 13fec1c66f6..5c7b28717e6 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2BackChannelLogoutTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2BackChannelLogoutTestCase.java @@ -145,6 +145,7 @@ public void testOIDCLogout() throws IOException { } private void createOIDCApplication() throws Exception { + ApplicationModel application = new ApplicationModel(); List grantTypes = new ArrayList<>(); @@ -310,6 +311,7 @@ private List getOIDCInitiationRequestParams() { } private void addAdminUser() throws Exception { + UserObject userInfo = new UserObject(); userInfo.setUserName(USERNAME); userInfo.setPassword(PASSWORD); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java index 1ac77785246..b85c7d39064 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java @@ -326,10 +326,10 @@ public HttpResponse sendGetRequest(HttpClient client, String locationURL) throws } /** - * Create Application with the given app configurations + * Create Application with the given app configurations. * - * @return ApplicationResponseModel - * @throws Exception exception + * @return ApplicationResponseModel. + * @throws Exception exception. */ private ApplicationResponseModel createApp() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java index caf83db18c1..088e34c72a2 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java @@ -123,6 +123,7 @@ public void testInit() throws Exception { @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + deleteApp(application.getId()); consumerKey = null; @@ -437,7 +438,7 @@ private String getLocationHeaderValue(HttpResponse response) { /** * Initiate service provider keys required for the tests. * - * @throws Exception error + * @throws Exception error. */ private void initServiceProviderKeys() throws Exception { @@ -464,8 +465,8 @@ private void initServiceProviderKeys() throws Exception { * @param client CloseableHttpClient object to send the login post. * @param sessionDataKey String sessionDataKey obtained. * @return Extracted sessionDataKeyConsent. - * @throws IOException Error - * @throws URISyntaxException Error + * @throws IOException Error. + * @throws URISyntaxException Error. */ private String getSessionDataKeyConsent(CloseableHttpClient client, String sessionDataKey) throws IOException, URISyntaxException { @@ -497,8 +498,8 @@ private String getSessionDataKeyConsent(CloseableHttpClient client, String sessi * @param idToken Encrypted ID token to be decrypted and checked. * @param audience Audience value that should be appeared in the token. * @return Boolean True if audience matches, False otherwise. - * @throws ParseException Error - * @throws JOSEException Error + * @throws ParseException Error. + * @throws JOSEException Error. */ private boolean decryptAndCheckIDToken(String idToken, String audience) throws ParseException, JOSEException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java index ddb2b5679e2..d9639fe0978 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java @@ -42,7 +42,8 @@ import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; -import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.*; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration; import org.wso2.identity.integration.test.utils.OAuth2Constant; import java.io.File; @@ -57,7 +58,7 @@ import java.util.UUID; /** - Integration tests for Signed Request Object validation. + * Integration tests for Signed Request Object validation. */ public class OAuth2RequestObjectSignatureValidationTestCase extends OAuth2ServiceAbstractIntegrationTest { @@ -76,6 +77,7 @@ public void testInit() throws Exception { @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + deleteApp(application.getId()); consumerKey = null; @@ -264,6 +266,7 @@ private JWTClaimsSet getJwtClaimsSet(String consumerKey) { } private String buildSignedJWT(String consumerKey, RSAPrivateKey privateKey) throws Exception { + // Create RSA-signer with the private key JWSSigner rsaSigner = new RSASSASigner(privateKey); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RoleClaimTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RoleClaimTestCase.java index e49388243a0..6b2a7bb33b1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RoleClaimTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RoleClaimTestCase.java @@ -91,6 +91,7 @@ public void testInit() throws Exception { @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + deleteApp(applicationId); scim2RestClient.deleteRole(roleId); scim2RestClient.deleteUser(userId); @@ -189,6 +190,7 @@ public void testSendAuthorizedPostAfterRoleUpdate() throws Exception { } private UserObject getUserCreationInfo() { + UserObject userInfo = new UserObject(); userInfo.setUserName(USER_USERNAME); @@ -221,6 +223,7 @@ private UserObject getUserCreationInfo() { } private RoleRequestObject getRoleCreationInfo() { + RoleRequestObject roleInfo = new RoleRequestObject(); roleInfo.setDisplayName(OAUTH_ROLE); @@ -228,6 +231,7 @@ private RoleRequestObject getRoleCreationInfo() { } private PatchOperationRequestObject getAddUserPatchRole(String userId) { + RoleItemAddGroupobj patchRoleItem = new RoleItemAddGroupobj(); patchRoleItem.setOp(RoleItemAddGroupobj.OpEnum.ADD); patchRoleItem.setPath(USERS_PATH); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java index 67e1eddab1c..dfd2843970c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java @@ -53,8 +53,19 @@ import org.wso2.identity.integration.common.utils.ISIntegrationTest; import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.APIResourceListItem; import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.ScopeGetModel; -import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.*; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.AdvancedApplicationConfiguration; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationModel; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationPatchModel; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.AuthorizedAPICreationModel; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Certificate; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ClaimConfiguration; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ClaimConfiguration.DialectEnum; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ClaimMappings; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.InboundProtocols; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.RequestedClaimConfiguration; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.SAML2ServiceProvider; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.util.Utils; import org.wso2.identity.integration.test.utils.OAuth2Constant; @@ -70,9 +81,10 @@ import static org.wso2.identity.integration.test.utils.OAuth2Constant.OAUTH_APPLICATION_NAME; /** -* OAuth2 test integration abstraction -*/ + * OAuth2 test integration abstraction. + */ public class OAuth2ServiceAbstractIntegrationTest extends ISIntegrationTest { + protected String consumerKey; protected String consumerSecret; @@ -96,12 +108,13 @@ public class OAuth2ServiceAbstractIntegrationTest extends ISIntegrationTest { /** - * Initialize + * Initialize. * - * @param userMode - User Id - * @throws Exception Exception + * @param userMode - User Id. + * @throws Exception Exception. */ protected void init(TestUserMode userMode) throws Exception { + super.init(userMode); appMgtclient = new ApplicationManagementServiceClient(sessionCookie, backendURL, null); adminClient = new OauthAdminClient(backendURL, sessionCookie); @@ -110,12 +123,13 @@ protected void init(TestUserMode userMode) throws Exception { } /** - * Create Application with the given app configurations + * Create Application with the given app configurations. * - * @return OAuthConsumerAppDTO - * @throws Exception Exception + * @return OAuthConsumerAppDTO. + * @throws Exception Exception. */ public OAuthConsumerAppDTO createApplication() throws Exception { + OAuthConsumerAppDTO appDTO = new OAuthConsumerAppDTO(); appDTO.setApplicationName(OAuth2Constant.OAUTH_APPLICATION_NAME); appDTO.setCallbackUrl(OAuth2Constant.CALLBACK_URL); @@ -207,74 +221,81 @@ ServiceProvider setServiceProviderClaimConfig(ServiceProvider serviceProvider) { } /** - * Create Application with a given ApplicationModel + * Create Application with a given ApplicationModel. * - * @param application application creation object - * @return application id - * @throws Exception Exception + * @param application Application creation object. + * @return Application id. + * @throws Exception Exception. */ public String addApplication(ApplicationModel application) throws Exception { + return restClient.createApplication(application); } /** - * Get Application details with a given id + * Get Application details with a given id. * - * @param appId application Id - * @return ApplicationResponseModel - * @throws Exception Exception + * @param appId Application Id. + * @return ApplicationResponseModel. + * @throws Exception Exception. */ public ApplicationResponseModel getApplication(String appId) throws Exception { + return restClient.getApplication(appId); } /** - * Get Application details with a given id + * Get Application details with a given id. * - * @param appId application Id - * @param application application update patch object - * @throws Exception Exception + * @param appId Application Id. + * @param application Application update patch object. + * @throws Exception Exception. */ public void updateApplication(String appId, ApplicationPatchModel application) throws Exception { + restClient.updateApplication(appId, application); } /** - * Get Application oidc inbound configuration details with a given id + * Get Application oidc inbound configuration details with a given id. * - * @param appId application Id - * @return OpenIDConnectConfiguration - * @throws Exception Exception + * @param appId Application Id. + * @return OpenIDConnectConfiguration. + * @throws Exception Exception. */ public OpenIDConnectConfiguration getOIDCInboundDetailsOfApplication(String appId) throws Exception { + return restClient.getOIDCInboundDetails(appId); } /** - * Get Application saml inbound configuration details with a given id + * Get Application saml inbound configuration details with a given id. * - * @param appId application Id - * @return SAML2ServiceProvider - * @throws Exception Exception + * @param appId Application Id. + * @return SAML2ServiceProvider. + * @throws Exception Exception. */ public SAML2ServiceProvider getSAMLInboundDetailsOfApplication(String appId) throws Exception { + return restClient.getSAMLInboundDetails(appId); } /** - * Update Application inbound configuration details with a given id and the inbound Type + * Update Application inbound configuration details with a given id and the inbound Type. * - * @param appId application Id - * @param InboundConfig InboundConfig object - * @param inboundType inbound configuration type + * @param appId Application Id. + * @param InboundConfig InboundConfig object. + * @param inboundType inbound configuration type. */ public void updateApplicationInboundConfig(String appId, Object InboundConfig, String inboundType) throws IOException { + restClient.updateInboundDetailsOfApplication(appId, InboundConfig, inboundType); } public OAuthConsumerAppDTO createApplication(OAuthConsumerAppDTO appDTO, String serviceProviderName) throws Exception { + OAuthConsumerAppDTO appDtoResult = null; adminClient.registerOAuthApplicationData(appDTO); @@ -365,28 +386,31 @@ private ClaimConfiguration getClaimConfigurations() { } private ClaimMappings getClaimMapping(String claimUri) { + ClaimMappings claim = new ClaimMappings().applicationClaim(claimUri); claim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(claimUri)); return claim; } private RequestedClaimConfiguration getRequestedClaim(String claimUri) { + RequestedClaimConfiguration requestedClaim = new RequestedClaimConfiguration(); requestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(claimUri)); return requestedClaim; } /** - * Send post request with parameters - * @param client HttpClient - * @param urlParameters url parameters - * @param url endpoint - * @return HttpResponse - * @throws ClientProtocolException ClientProtocolException - * @throws java.io.IOException java.io.IOException + * Send post request with parameters. + * @param client HttpClient. + * @param urlParameters Url parameters. + * @param url Endpoint. + * @return HttpResponse. + * @throws ClientProtocolException ClientProtocolException. + * @throws java.io.IOException java.io.IOException. */ public HttpResponse sendPostRequestWithParameters(HttpClient client, List urlParameters, String url) throws ClientProtocolException, IOException { + HttpPost request = new HttpPost(url); request.setHeader("User-Agent", OAuth2Constant.USER_AGENT); request.setEntity(new UrlEncodedFormEntity(urlParameters)); @@ -395,15 +419,16 @@ public HttpResponse sendPostRequestWithParameters(HttpClient client, List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("username", userInfo.getUserName())); urlParameters.add(new BasicNameValuePair("password", userInfo.getPassword())); @@ -478,8 +505,8 @@ public HttpResponse sendLoginPost(HttpClient client, String sessionDataKey) thro * @param username Username. * @param password Password. * @return Http response. - * @throws ClientProtocolException ClientProtocolException - * @throws IOException IOException + * @throws ClientProtocolException ClientProtocolException. + * @throws IOException IOException. */ public HttpResponse sendLoginPostForCustomUsers(HttpClient client, String sessionDataKey, String username, String password) throws ClientProtocolException, IOException { @@ -502,8 +529,8 @@ public HttpResponse sendLoginPostForCustomUsers(HttpClient client, String sessio * @param password Password. * @param tenantDomain Tenant domain. * @return Http response. - * @throws ClientProtocolException ClientProtocolException - * @throws IOException IOException + * @throws ClientProtocolException ClientProtocolException. + * @throws IOException IOException. */ public HttpResponse sendLoginPostForCustomUsers(HttpClient client, String sessionDataKey, String username, String password, String tenantDomain) @@ -519,16 +546,17 @@ public HttpResponse sendLoginPostForCustomUsers(HttpClient client, String sessio } /** - * Send approval post request + * Send approval post request. * - * @param client - http client - * @param sessionDataKeyConsent - session consent data - * @return http response - * @throws ClientProtocolException ClientProtocolException - * @throws java.io.IOException java.io.IOException + * @param client - Http client. + * @param sessionDataKeyConsent - Session consent data. + * @return Http response. + * @throws ClientProtocolException ClientProtocolException. + * @throws java.io.IOException java.io.IOException. */ public HttpResponse sendApprovalPost(HttpClient client, String sessionDataKeyConsent) throws ClientProtocolException, IOException { + List urlParameters = new ArrayList(); urlParameters.add(new BasicNameValuePair("consent", "approve")); urlParameters.add(new BasicNameValuePair("sessionDataKeyConsent", sessionDataKeyConsent)); @@ -538,13 +566,13 @@ public HttpResponse sendApprovalPost(HttpClient client, String sessionDataKeyCon } /** - * Send approval post request with consent + * Send approval post request with consent. * - * @param client http client - * @param sessionDataKeyConsent session consent data - * @param consentClaims claims requiring user consent - * @return http response - * @throws java.io.IOException java.io.IOException + * @param client Http client. + * @param sessionDataKeyConsent Session consent data. + * @param consentClaims Claims requiring user consent. + * @return Http response. + * @throws java.io.IOException java.io.IOException. */ public HttpResponse sendApprovalPostWithConsent(HttpClient client, String sessionDataKeyConsent, List consentClaims) throws IOException { @@ -565,11 +593,11 @@ public HttpResponse sendApprovalPostWithConsent(HttpClient client, String sessio /** * Send approval post request for tenant with consent. * - * @param client http client. - * @param sessionDataKeyConsent session consent data. - * @param consentClaims claims requiring user consent. - * @param tenantDomain tenant domain. - * @return http response. + * @param client Http client. + * @param sessionDataKeyConsent Session consent data. + * @param consentClaims Claims requiring user consent. + * @param tenantDomain Tenant domain. + * @return Http response. * @throws java.io.IOException IOException. */ public HttpResponse sendApprovalPostWithConsent(HttpClient client, String sessionDataKeyConsent, @@ -590,13 +618,13 @@ public HttpResponse sendApprovalPostWithConsent(HttpClient client, String sessio } /** - * Send approval post request + * Send approval post request. * - * @param client - http client - * @param consumerSecret - consumer secret - * @return http response - * @throws ClientProtocolException ClientProtocolException - * @throws java.io.IOException java.io.IOException + * @param client - Http client. + * @param consumerSecret - Consumer secret. + * @return Http response. + * @throws ClientProtocolException ClientProtocolException. + * @throws java.io.IOException java.io.IOException. */ public HttpResponse sendGetAccessTokenPost(HttpClient client, String consumerSecret) throws ClientProtocolException, IOException { @@ -609,12 +637,12 @@ public HttpResponse sendGetAccessTokenPost(HttpClient client, String consumerSec } /** - * Send validate access token post request - * @param client - http client - * @param accessToken - access token - * @return http response - * @throws ClientProtocolException ClientProtocolException - * @throws java.io.IOException java.io.IOException + * Send validate access token post request. + * @param client - Http client. + * @param accessToken - Access token. + * @return Http response. + * @throws ClientProtocolException ClientProtocolException. + * @throws java.io.IOException java.io.IOException. */ public HttpResponse sendValidateAccessTokenPost(HttpClient client, String accessToken) throws ClientProtocolException, @@ -627,11 +655,11 @@ public HttpResponse sendValidateAccessTokenPost(HttpClient client, String access /** * Send token introspection post request according to the tenant domain. - * @param client - http client - * @param accessToken - access token + * @param client - Http client. + * @param accessToken - Access token. * @param endpoint - Introspection URL of the tenant domain. * @return JSON object of the response. - * @throws Exception Exception + * @throws Exception Exception. */ public JSONObject introspectTokenWithTenant(HttpClient client, String accessToken, String endpoint, String key, String secret) throws Exception { @@ -642,39 +670,43 @@ public JSONObject introspectTokenWithTenant(HttpClient client, String accessToke } /** - * Delete Application + * Delete Application. * - * @throws Exception Exception + * @throws Exception Exception. */ public void deleteApplication() throws Exception { + appMgtclient.deleteApplication(SERVICE_PROVIDER_NAME); } public void deleteApp(String appId) throws Exception { + restClient.deleteApplication(appId); } /** - * Remove OAuth Application + * Remove OAuth Application. * - * @throws Exception Exception + * @throws Exception Exception. */ public void removeOAuthApplicationData() throws Exception { + adminClient.removeOAuthApplicationData(consumerKey); } /** - * Request access token from the given token generation endpoint + * Request access token from the given token generation endpoint. * - * @param consumerKey consumer key of the application - * @param consumerSecret consumer secret of the application - * @param backendUrl token generation API endpoint - * @return token - * @throws Exception if something went wrong when requesting token + * @param consumerKey Consumer key of the application. + * @param consumerSecret Consumer secret of the application. + * @param backendUrl Token generation API endpoint. + * @return Token. + * @throws Exception If something went wrong when requesting token. */ public String requestAccessToken(String consumerKey, String consumerSecret, String backendUrl, String username, String password) throws Exception { - List postParameters; + + List postParameters; HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(backendUrl); //generate post request @@ -700,16 +732,24 @@ public String requestAccessToken(String consumerKey, String consumerSecret, } /** - * Get base64 encoded string of consumer key and secret + * Get base64 encoded string of consumer key and secret. * - * @param consumerKey consumer key of the application - * @param consumerSecret consumer secret of the application - * @return base 64 encoded string + * @param consumerKey Consumer key of the application. + * @param consumerSecret Consumer secret of the application. + * @return Base 64 encoded string. */ public String getBase64EncodedString(String consumerKey, String consumerSecret) { - return new String(Base64.encodeBase64((consumerKey + ":" + consumerSecret).getBytes())); + + return new String(Base64.encodeBase64((consumerKey + ":" + consumerSecret).getBytes())); } + /** + * Update the certificate of an application. + * + * @param appId Application Id. + * @param sp1X509PublicCert X509 certificate of the application. + * @throws Exception If an error occurred while updating the certificate of the application. + */ public void updateApplicationCertificate(String appId, X509Certificate sp1X509PublicCert) throws Exception { Certificate certificate = new Certificate(); @@ -728,7 +768,7 @@ public void updateApplicationCertificate(String appId, X509Certificate sp1X509Pu * * @param x509Certificate Certificate in x509 format. * @return Certificate in pem format. - * @throws CertificateEncodingException CertificateEncodingException + * @throws CertificateEncodingException CertificateEncodingException. */ public String convertToPem(X509Certificate x509Certificate) throws CertificateEncodingException { @@ -759,6 +799,7 @@ public OAuthConsumerAppDTO getBasicOAuthApp(String callBackURL) { * * @param callBackURL String callback URL. * @return ApplicationResponseModel object. + * @throws Exception If an error occurred while creating a basic oauth application. */ public ApplicationResponseModel getBasicOAuthApplication(String callBackURL) throws Exception { @@ -792,7 +833,7 @@ public ApplicationResponseModel getBasicOAuthApplication(String callBackURL) thr * * @param appDTO OAuthConsumerAppDTO of the service provider. * @return Registered service provider. - * @throws Exception Exception + * @throws Exception Exception. */ public ServiceProvider registerServiceProviderWithOAuthInboundConfigs(OAuthConsumerAppDTO appDTO) throws Exception { @@ -864,7 +905,7 @@ private void setInboundOAuthConfig(List auth * @param client httpclient. * @param authorizationHeader Authentication header. * @return JSON object of the response. - * @throws Exception Exception + * @throws Exception Exception. */ private JSONObject responseObject(HttpClient client, String endpoint, List postParameters, String authorizationHeader) throws Exception { @@ -890,9 +931,10 @@ private JSONObject responseObject(HttpClient client, String endpoint, List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_IMPLICIT)); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceImplicitGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceImplicitGrantTestCase.java index 237c7276016..093aa3ffaaa 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceImplicitGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceImplicitGrantTestCase.java @@ -78,6 +78,7 @@ public class OAuth2ServiceImplicitGrantTestCase extends OAuth2ServiceAbstractInt @DataProvider(name = "configProvider") public static Object[][] configProvider() { + return new Object[][]{{TestUserMode.SUPER_TENANT_ADMIN}, {TestUserMode.TENANT_ADMIN}}; } @@ -122,6 +123,7 @@ public void atEnd() throws Exception { @Test(groups = "wso2.is", description = "Check Oauth2 application registration") public void testRegisterApplication() throws Exception { + ApplicationResponseModel application = addApplication(); Assert.assertNotNull(application, "OAuth App creation failed."); @@ -138,6 +140,7 @@ public void testRegisterApplication() throws Exception { @Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testRegisterApplication") public void testSendAuthorozedPost() throws Exception { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_IMPLICIT)); @@ -175,6 +178,7 @@ public void testSendAuthorozedPost() throws Exception { @Test(groups = "wso2.is", description = "Send login post request", dependsOnMethods = "testSendAuthorozedPost") public void testSendLoginPost() throws Exception { + HttpResponse response = sendLoginPost(client, sessionDataKey); Assert.assertNotNull(response, "Login request failed. Login response is null."); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceIntrospectionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceIntrospectionTestCase.java index 4f3db82aef9..f852ee6acbb 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceIntrospectionTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceIntrospectionTestCase.java @@ -54,11 +54,13 @@ public class OAuth2ServiceIntrospectionTestCase extends OAuth2ServiceAbstractInt @DataProvider(name = "configProvider") public static Object[][] configProvider() { + return new Object[][]{{TestUserMode.SUPER_TENANT_ADMIN}, {TestUserMode.TENANT_ADMIN}}; } @Factory(dataProvider = "configProvider") public OAuth2ServiceIntrospectionTestCase(TestUserMode userMode) throws Exception { + super.init(userMode); } @@ -82,6 +84,7 @@ public void atEnd() throws Exception { @Test(groups = "wso2.is", description = "Check Oauth2 application registration") public void testRegisterApplication() throws Exception { + ApplicationResponseModel application = addApplication(); Assert.assertNotNull(application, "OAuth App creation failed."); @@ -98,6 +101,7 @@ public void testRegisterApplication() throws Exception { @Test(groups = "wso2.is", description = "Send authorize user request and get access token", dependsOnMethods = "testRegisterApplication") public void testGetAccessToken() throws Exception { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair( "grantType", @@ -130,6 +134,7 @@ public void testGetAccessToken() throws Exception { @Test(groups = "wso2.is", description = "Test introspection endpoint", dependsOnMethods = "testGetAccessToken") public void testIntrospectionEndpoint() throws Exception { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("accessToken", accessToken)); urlParameters.add(new BasicNameValuePair("resource_url", "https://localhost:9443/oauth2/introspect")); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRefreshTokenGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRefreshTokenGrantTestCase.java index 587cc8588e6..3fac83cbe89 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRefreshTokenGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRefreshTokenGrantTestCase.java @@ -41,6 +41,7 @@ import java.util.List; public class OAuth2ServiceRefreshTokenGrantTestCase extends OAuth2ServiceAbstractIntegrationTest { + private String adminUsername; private String adminPassword; private String refreshToken; @@ -52,6 +53,7 @@ public class OAuth2ServiceRefreshTokenGrantTestCase extends OAuth2ServiceAbstrac @BeforeClass(alwaysRun = true) public void testInit() throws Exception { + super.init(TestUserMode.SUPER_TENANT_USER); adminUsername = userInfo.getUserNameWithoutDomain(); adminPassword = userInfo.getPassword(); @@ -62,6 +64,7 @@ public void testInit() throws Exception { @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + deleteApp(applicationId); consumerKey = null; @@ -73,6 +76,7 @@ public void atEnd() throws Exception { @Test(alwaysRun = true, description = "Check Oauth2 application registration") public void testRegisterApplication() throws Exception { + ApplicationResponseModel application = addApplication(); Assert.assertNotNull(application, "OAuth App creation failed."); @@ -89,6 +93,7 @@ public void testRegisterApplication() throws Exception { @Test(groups = "wso2.is", description = "Validate refresh token", dependsOnMethods = "testRegisterApplication") public void testSendAuthorizedPost() throws Exception { + List postParameters = new ArrayList<>(); postParameters.add(new BasicNameValuePair("username", adminUsername)); postParameters.add(new BasicNameValuePair("password", adminPassword)); @@ -101,6 +106,7 @@ public void testSendAuthorizedPost() throws Exception { @Test(groups = "wso2.is", description = "Validate refresh token", dependsOnMethods = "testSendAuthorizedPost") public void testRefreshTokenGrant() throws Exception { + List postParameters = new ArrayList<>(); postParameters.add(new BasicNameValuePair("grant_type", OAuth2Constant.OAUTH2_GRANT_TYPE_REFRESH_TOKEN)); postParameters.add(new BasicNameValuePair(OAuth2Constant.OAUTH2_GRANT_TYPE_REFRESH_TOKEN, refreshToken)); @@ -111,6 +117,7 @@ public void testRefreshTokenGrant() throws Exception { } private JSONObject responseObject(List postParameters) throws Exception { + HttpPost httpPost = new HttpPost(getTenantQualifiedURL( OAuth2Constant.ACCESS_TOKEN_ENDPOINT, tenantInfo.getDomain())); //generate post request diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRegexCallbackUrlTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRegexCallbackUrlTestCase.java index 4306db249c5..540fb75d5c4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRegexCallbackUrlTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceRegexCallbackUrlTestCase.java @@ -69,6 +69,7 @@ public class OAuth2ServiceRegexCallbackUrlTestCase extends OAuth2ServiceAbstract @BeforeClass(alwaysRun = true) public void testInit() throws Exception { + super.init(TestUserMode.SUPER_TENANT_USER); setSystemproperties(); @@ -98,6 +99,7 @@ public void atEnd() throws Exception { @Test(groups = "wso2.is", description = "Check Oauth2 application registration") public void testRegisterApplication() throws Exception { + ApplicationResponseModel application = createTestApplication(); applicationId = application.getId(); @@ -111,6 +113,7 @@ public void testRegisterApplication() throws Exception { @Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testRegisterApplication") public void testSendAuthorozedPost() throws Exception { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_IMPLICIT)); @@ -146,6 +149,7 @@ public void testSendAuthorozedPost() throws Exception { @Test(groups = "wso2.is", description = "Send login post request", dependsOnMethods = "testSendAuthorozedPost") public void testSendLoginPost() throws Exception { + HttpResponse response = sendLoginPost(client, sessionDataKey); Assert.assertNotNull(response, "Login request failed. Login response is null."); @@ -200,6 +204,7 @@ public void testSendApprovalPost() throws Exception { @Test(groups = "wso2.is", description = "Validate access token", dependsOnMethods = "testSendApprovalPost") public void testValidateAccessToken() throws Exception { + HttpResponse response = sendValidateAccessTokenPost(client, accessToken); Assert.assertNotNull(response, "Validate access token response is invalid."); @@ -217,6 +222,7 @@ public void testValidateAccessToken() throws Exception { } private ApplicationResponseModel createTestApplication() throws Exception { + ApplicationModel application = new ApplicationModel(); List grantTypes = new ArrayList<>(); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceResourceOwnerTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceResourceOwnerTestCase.java index 9a59294f19c..0e6e676cf57 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceResourceOwnerTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceResourceOwnerTestCase.java @@ -80,6 +80,7 @@ public class OAuth2ServiceResourceOwnerTestCase extends OAuth2ServiceAbstractInt @DataProvider(name = "configProvider") public static Object[][] configProvider() { + return new Object[][]{{TestUserMode.SUPER_TENANT_ADMIN}, {TestUserMode.TENANT_ADMIN}}; } @@ -123,6 +124,7 @@ public void atEnd() throws Exception { @Test(groups = "wso2.is", description = "Check Oauth2 application registration") public void testRegisterApplication() throws Exception { + ApplicationResponseModel application = addApplication(); Assert.assertNotNull(application, "OAuth App creation failed."); applicationId = application.getId(); @@ -138,6 +140,7 @@ public void testRegisterApplication() throws Exception { @Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testRegisterApplication") public void testSendAuthorozedPost() throws Exception { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_RESOURCE_OWNER)); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceSAML2BearerGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceSAML2BearerGrantTestCase.java index 443b5dbd8ba..cc35e742ecd 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceSAML2BearerGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceSAML2BearerGrantTestCase.java @@ -194,9 +194,10 @@ public void testSAML2BearerInvalidAudience() { * Create a SAML Application for testing. * * @return ApplicationResponseModel application. - * @throws Exception Exception + * @throws Exception Exception. */ private ApplicationResponseModel createSAMLApplication() throws Exception { + ApplicationModel applicationCreationModel = new ApplicationModel().name(SERVICE_PROVIDER_NAME); applicationCreationModel.inboundProtocolConfiguration(new InboundProtocols().oidc(getOIDCConfigurations())); applicationCreationModel.getInboundProtocolConfiguration().setSaml(getSAMLConfigurations()); @@ -209,9 +210,10 @@ private ApplicationResponseModel createSAMLApplication() throws Exception { /** * Create OIDC Configured ApplicationModel object. * - * @return ApplicationModel application. + * @return ApplicationModel Application. */ private OpenIDConnectConfiguration getOIDCConfigurations() { + List grantTypes = new ArrayList<>(); Collections.addAll(grantTypes, "urn:ietf:params:oauth:grant-type:saml2-bearer"); @@ -231,6 +233,7 @@ private OpenIDConnectConfiguration getOIDCConfigurations() { * @return ApplicationModel application. */ private SAML2Configuration getSAMLConfigurations() { + SAML2ServiceProvider serviceProvider = new SAML2ServiceProvider(); serviceProvider.setIssuer(ISSUER); serviceProvider.addAssertionConsumerUrl(String.format("http://localhost:8490/%s/home.jsp", ISSUER)); @@ -258,7 +261,7 @@ private SAML2Configuration getSAMLConfigurations() { * Get the SAML response by calling the default SAML endpoint. * * @return SAML response. - * @throws Exception Exception + * @throws Exception Exception. */ private String getSAMLResponse() throws Exception { @@ -318,9 +321,9 @@ private String getSAMLResponse() throws Exception { * * @param samlResponse SAML response. * @return Extracted SAML assertion. - * @throws ParserConfigurationException Exception - * @throws IOException Exception - * @throws SAXException Exception + * @throws ParserConfigurationException Exception. + * @throws IOException Exception. + * @throws SAXException Exception. */ private String getSAMLAssersion(String samlResponse) throws ParserConfigurationException, IOException, SAXException { @@ -348,7 +351,7 @@ private String getSAMLAssersion(String samlResponse) throws ParserConfigurationE * * @param samlMsgValue Message value. * @return HTTP Response object that we get from calling the SAML endpoint. - * @throws IOException Exception + * @throws IOException Exception. */ private HttpResponse sendSAMLRequest(String samlMsgValue) throws IOException { @@ -369,7 +372,7 @@ private HttpResponse sendSAMLRequest(String samlMsgValue) throws IOException { * * @param samlAssertion SAML assertion. * @return HTTP Response object that we get from calling the token endpoint. - * @throws IOException Exception + * @throws IOException Exception. */ private HttpResponse sendSAMLAssertion(String samlAssertion) throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithMultipleSessionTerminationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithMultipleSessionTerminationTestCase.java index 7d5c90143da..e48d109ccca 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithMultipleSessionTerminationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithMultipleSessionTerminationTestCase.java @@ -217,7 +217,7 @@ public void testTokensRevocationSessionsAreTerminated() throws Exception { * @param key Basic authentication key. * @param secret Basic authentication secret. * @return JSON object of the response. - * @throws Exception Exception + * @throws Exception Exception. */ private JSONObject responseObject(HttpClient client, String endpoint, List postParameters, String key, String secret) throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithRevokedAccessToken.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithRevokedAccessToken.java index 69e296b62f1..9d3f31e644f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithRevokedAccessToken.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithRevokedAccessToken.java @@ -273,6 +273,7 @@ private TokenIntrospectionResponse introspectAccessToken(AccessToken accessToken } private ApplicationResponseModel createApp() throws Exception { + ApplicationModel application = new ApplicationModel(); List grantTypes = new ArrayList<>(); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/Oauth2OPIframeTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/Oauth2OPIframeTestCase.java index fb4715fe0ce..0746bce4eaf 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/Oauth2OPIframeTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/Oauth2OPIframeTestCase.java @@ -55,6 +55,7 @@ public class Oauth2OPIframeTestCase extends OAuth2ServiceAbstractIntegrationTest @DataProvider(name = "configProvider") public static Object[][] configProvider() { + return new Object[][]{{TestUserMode.SUPER_TENANT_ADMIN}, {TestUserMode.TENANT_ADMIN}}; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/ApplicationPatchModel.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/ApplicationPatchModel.java index 63939cb093a..0f4185d7396 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/ApplicationPatchModel.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/ApplicationPatchModel.java @@ -279,4 +279,4 @@ private String toIndentedString(java.lang.Object o) { } return o.toString().replace("\n", "\n"); } -} \ No newline at end of file +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AssertionEncryptionConfiguration.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AssertionEncryptionConfiguration.java index 081f6c6d59f..1f777d09509 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AssertionEncryptionConfiguration.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AssertionEncryptionConfiguration.java @@ -134,4 +134,4 @@ private String toIndentedString(Object o) { return o.toString(); } -} \ No newline at end of file +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java index 9d2c8569053..6ad22854eda 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java @@ -39,11 +39,12 @@ public AuthenticatorRestClient(String serverUrl) { } /** - * Login operation + * Login operation. * * @param username username. * @param password password. * @return JSONObject with login details. + * @throws Exception If an error occurred while authenticating. */ public JSONObject login(String username, String password) throws Exception { @@ -60,13 +61,17 @@ public JSONObject login(String username, String password) throws Exception { } private Header[] getHeaders() { + return new Header[]{new BasicHeader(CONTENT_TYPE_ATTRIBUTE, String.valueOf(ContentType.JSON))}; } /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java index d6a0c1710da..698532635b4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java @@ -45,6 +45,7 @@ public class EmailTemplatesRestClient extends RestBaseClient { private final String password; public EmailTemplatesRestClient(String backendURL, Tenant tenantInfo) { + client = HttpClients.createDefault(); this.username = tenantInfo.getContextUser().getUserName(); @@ -57,13 +58,15 @@ public EmailTemplatesRestClient(String backendURL, Tenant tenantInfo) { } /** - * Get Email template + * Get Email template. * * @param templateTypeId Template type id. * @param templateId Template id. * @return JSONObject with email template details. + * @throws Exception If an error occurred while getting Email Template. */ public JSONObject getEmailTemplate(String templateTypeId, String templateId) throws Exception { + String endPointUrl = emailTemplateApiBasePath + PATH_SEPARATOR + getEncodedEmailTemplateTypeId(templateTypeId) + EMAIL_TEMPLATES_PATH + PATH_SEPARATOR + templateId; @@ -74,6 +77,7 @@ public JSONObject getEmailTemplate(String templateTypeId, String templateId) thr } private Header[] getHeaders() { + Header[] headerList = new Header[2]; headerList[0] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + Base64.encodeBase64String((username + ":" + password).getBytes()).trim()); @@ -83,13 +87,17 @@ private Header[] getHeaders() { } private String getEncodedEmailTemplateTypeId(String emailTemplateTypeId) { + return Base64.encodeBase64String(emailTemplateTypeId.getBytes()); } /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java index be1811b8a95..bbfeb3922a9 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java @@ -47,6 +47,7 @@ public class IdentityGovernanceRestClient extends RestBaseClient { private final String password; public IdentityGovernanceRestClient(String backendURL, Tenant tenantInfo) { + client = HttpClients.createDefault(); this.username = tenantInfo.getContextUser().getUserName(); @@ -59,14 +60,16 @@ public IdentityGovernanceRestClient(String backendURL, Tenant tenantInfo) { } /** - * Update connector properties + * Update connector properties. * * @param categoryId Connector category id. * @param connectorId Connector id. * @param connectorPatch Connector patch request object. + * @throws IOException If an error occurred while updating the governance connectors. */ public void updateConnectors(String categoryId, String connectorId, ConnectorsPatchReq connectorPatch) throws IOException { + String jsonRequest = toJSONString(connectorPatch); String endPointUrl = identityGovernanceApiBasePath + PATH_SEPARATOR + categoryId + CONNECTORS_BASE_PATH + PATH_SEPARATOR + connectorId; @@ -89,8 +92,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java index fa2e126f805..6a3250e54b1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java @@ -69,6 +69,7 @@ public class OAuth2RestClient extends RestBaseClient { private final String password; public OAuth2RestClient(String backendUrl, Tenant tenantInfo) { + this.username = tenantInfo.getContextUser().getUserName(); this.password = tenantInfo.getContextUser().getPassword(); @@ -79,10 +80,12 @@ public OAuth2RestClient(String backendUrl, Tenant tenantInfo) { } /** - * Create an Application + * Create an Application. * * @param application Application Model with application creation details. * @return Id of the created application. + * @throws IOException Exception. + * @throws JSONException JSON Exception. */ public String createApplication(ApplicationModel application) throws IOException, JSONException { String jsonRequest = toJSONString(application); @@ -99,8 +102,9 @@ public String createApplication(ApplicationModel application) throws IOException * * @param application Application Model with application creation details. * @return Application creation response. + * @throws IOException Exception. */ - public StatusLine createApplicationWithResponse(ApplicationModel application) throws IOException, JSONException { + public StatusLine createApplicationWithResponse(ApplicationModel application) throws IOException { String jsonRequest = toJSONString(application); try (CloseableHttpResponse response = getResponseOfHttpPost(applicationManagementApiBasePath, jsonRequest, @@ -110,12 +114,14 @@ public StatusLine createApplicationWithResponse(ApplicationModel application) th } /** - * Get Application details + * Get Application details. * * @param appId Application id. * @return ApplicationResponseModel object. + * @throws IOException Exception. */ public ApplicationResponseModel getApplication(String appId) throws IOException { + String endPointUrl = applicationManagementApiBasePath + PATH_SEPARATOR + appId; try (CloseableHttpResponse response = getResponseOfHttpGet(endPointUrl, getHeaders())) { @@ -148,12 +154,14 @@ public List getApplicationsByClientId(String clientId) thro } /** - * Update an existing application + * Update an existing application. * * @param appId Application id. * @param application Updated application patch object. + * @throws IOException Exception. */ public void updateApplication(String appId, ApplicationPatchModel application) throws IOException { + String jsonRequest = toJSONString(application); String endPointUrl = applicationManagementApiBasePath + PATH_SEPARATOR + appId; @@ -164,11 +172,13 @@ public void updateApplication(String appId, ApplicationPatchModel application) t } /** - * Get all applications + * Get all applications. * * @return ApplicationListResponse object. + * @throws IOException Exception. */ public ApplicationListResponse getAllApplications() throws IOException { + try (CloseableHttpResponse response = getResponseOfHttpGet(applicationManagementApiBasePath, getHeaders())) { String responseBody = EntityUtils.toString(response.getEntity()); @@ -178,11 +188,13 @@ public ApplicationListResponse getAllApplications() throws IOException { } /** - * Delete an application + * Delete an application. * * @param appId Application id. + * @throws IOException Exception. */ public void deleteApplication(String appId) throws IOException { + String endpointUrl = applicationManagementApiBasePath + PATH_SEPARATOR + appId; try (CloseableHttpResponse response = getResponseOfHttpDelete(endpointUrl, getHeaders())) { @@ -192,24 +204,28 @@ public void deleteApplication(String appId) throws IOException { } /** - * Get OIDC inbound configuration details of an application + * Get OIDC inbound configuration details of an application. * * @param appId Application id. * @return OpenIDConnectConfiguration object with oidc configuration details. + * @throws Exception Exception. */ public OpenIDConnectConfiguration getOIDCInboundDetails(String appId) throws Exception { + String responseBody = getConfig(appId, OIDC); ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory()); return jsonWriter.readValue(responseBody, OpenIDConnectConfiguration.class); } /** - * Get SAML inbound configuration details of an application + * Get SAML inbound configuration details of an application. * * @param appId Application id. * @return SAML2ServiceProvider object with saml configuration details. + * @throws Exception Exception. */ public SAML2ServiceProvider getSAMLInboundDetails(String appId) throws Exception { + String responseBody = getConfig(appId, SAML); ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory()); @@ -217,6 +233,7 @@ public SAML2ServiceProvider getSAMLInboundDetails(String appId) throws Exception } private String getConfig(String appId, String inboundType) throws Exception { + String endPointUrl = applicationManagementApiBasePath + PATH_SEPARATOR + appId + INBOUND_PROTOCOLS_BASE_PATH + PATH_SEPARATOR + inboundType; @@ -226,14 +243,16 @@ private String getConfig(String appId, String inboundType) throws Exception { } /** - * Update inbound configuration details of an application + * Update inbound configuration details of an application. * * @param appId Application id. - * @param inboundConfig inbound configuration object to be updated. + * @param inboundConfig Inbound configuration object to be updated. * @param inboundType Type of the inbound configuration. + * @throws IOException Exception. */ public void updateInboundDetailsOfApplication(String appId, Object inboundConfig, String inboundType) throws IOException { + String jsonRequest = toJSONString(inboundConfig); String endPointUrl = applicationManagementApiBasePath + PATH_SEPARATOR + appId + INBOUND_PROTOCOLS_BASE_PATH + PATH_SEPARATOR + inboundType; @@ -245,12 +264,14 @@ public void updateInboundDetailsOfApplication(String appId, Object inboundConfig } /** - * Delete an Inbound Configuration + * Delete an Inbound Configuration. * * @param appId Application id. * @param inboundType Inbound Type to be deleted. + * @throws IOException Exception. */ public Boolean deleteInboundConfiguration(String appId, String inboundType) throws IOException { + String endpointUrl = applicationManagementApiBasePath + PATH_SEPARATOR + appId + INBOUND_PROTOCOLS_BASE_PATH + PATH_SEPARATOR + inboundType; @@ -260,6 +281,7 @@ public Boolean deleteInboundConfiguration(String appId, String inboundType) thro } private String getApplicationsPath(String serverUrl, String tenantDomain) { + if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { return serverUrl + API_SERVER_BASE_PATH + APPLICATION_MANAGEMENT_PATH; } else { @@ -287,6 +309,7 @@ private String getSCIM2RoleV2Path(String serverUrl, String tenantDomain) { } private Header[] getHeaders() { + Header[] headerList = new Header[3]; headerList[0] = new BasicHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); headerList[1] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + @@ -297,7 +320,7 @@ private Header[] getHeaders() { } /** - * Add API authorization to an application + * Add API authorization to an application. * * @param appId Application id. * @param authorizedAPICreationModel AuthorizedAPICreationModel object with api authorization details. @@ -426,9 +449,12 @@ public void shareApplication(String appId, ApplicationSharePOSTRequest applicati } /** - * Close the HTTP client + * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java index 476a46e047a..573cb7e0d64 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java @@ -60,6 +60,7 @@ public RestBaseClient() { * @return Relevant json string. */ public String toJSONString(java.lang.Object object) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); return gson.toJson(object); } @@ -69,8 +70,10 @@ public String toJSONString(java.lang.Object object) { * * @param responseString Respective Http response. * @return Relevant json object. + * @throws Exception Exception. */ public JSONObject getJSONObject(String responseString) throws Exception { + JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(responseString); if (json == null) { @@ -85,8 +88,10 @@ public JSONObject getJSONObject(String responseString) throws Exception { * * @param responseString Respective Http response. * @return Relevant JSONArray object. + * @throws Exception Exception. */ public JSONArray getJSONArray(String responseString) throws Exception { + JSONParser parser = new JSONParser(); JSONArray jsonArray = (JSONArray) parser.parse(responseString); if (jsonArray == null) { @@ -97,15 +102,17 @@ public JSONArray getJSONArray(String responseString) throws Exception { } /** - * Execute and get the response of HTTP POST + * Execute and get the response of HTTP POST. * * @param endPointUrl REST endpoint. - * @param jsonRequest json body. - * @param headers header list of the request. + * @param jsonRequest Json body. + * @param headers Header list of the request. * @return Response of the Http request. + * @throws IOException Exception. */ public CloseableHttpResponse getResponseOfHttpPost(String endPointUrl, String jsonRequest, Header[] headers) throws IOException { + HttpPost request = new HttpPost(endPointUrl); request.setHeaders(headers); request.setEntity(new StringEntity(jsonRequest)); @@ -114,14 +121,16 @@ public CloseableHttpResponse getResponseOfHttpPost(String endPointUrl, String js } /** - * Execute and get the response of HTTP GET + * Execute and get the response of HTTP GET. * * @param endPointUrl REST endpoint. * @param headers header list of the request. * @return Response of the Http request. + * @throws IOException Exception. */ public CloseableHttpResponse getResponseOfHttpGet(String endPointUrl, Header[] headers) throws IOException { + HttpGet request = new HttpGet(endPointUrl); request.setHeaders(headers); @@ -129,14 +138,16 @@ public CloseableHttpResponse getResponseOfHttpGet(String endPointUrl, Header[] h } /** - * Execute and get the response of HTTP PATCH + * Execute and get the response of HTTP PATCH. * * @param endPointUrl REST endpoint. * @param jsonRequest json body. * @param headers header list of the request. * @return Response of the Http request. + * @throws IOException Exception. */ public CloseableHttpResponse getResponseOfHttpPatch(String endPointUrl, String jsonRequest, Header[] headers) throws IOException { + HttpPatch request = new HttpPatch(endPointUrl); request.setHeaders(headers); request.setEntity(new StringEntity(jsonRequest)); @@ -145,13 +156,15 @@ public CloseableHttpResponse getResponseOfHttpPatch(String endPointUrl, String j } /** - * Execute and get the response of HTTP DELETE + * Execute and get the response of HTTP DELETE. * * @param endPointUrl REST endpoint. * @param headers header list of the request. * @return Response of the Http request. + * @throws IOException Exception. */ public CloseableHttpResponse getResponseOfHttpDelete(String endPointUrl, Header[] headers) throws IOException { + HttpDelete request = new HttpDelete(endPointUrl); request.setHeaders(headers); @@ -159,20 +172,21 @@ public CloseableHttpResponse getResponseOfHttpDelete(String endPointUrl, Header[ } /** - * Execute and get the response of HTTP PUT + * Execute and get the response of HTTP PUT. * * @param endPointUrl REST endpoint. * @param jsonRequest json body. * @param headers header list of the request. * @return Response of the Http request. + * @throws IOException Exception. */ public CloseableHttpResponse getResponseOfHttpPut(String endPointUrl, String jsonRequest, Header[] headers) throws IOException { + HttpPut request = new HttpPut(endPointUrl); request.setHeaders(headers); request.setEntity(new StringEntity(jsonRequest)); return client.execute(request); } - } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java index 019e6136ce3..f0fb6afb95f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java @@ -55,6 +55,7 @@ public class SCIM2RestClient extends RestBaseClient { private final String password; public SCIM2RestClient(String serverUrl, Tenant tenantInfo){ + this.serverUrl = serverUrl; this.tenantDomain = tenantInfo.getContextUser().getUserDomain(); this.username = tenantInfo.getContextUser().getUserName(); @@ -62,12 +63,14 @@ public SCIM2RestClient(String serverUrl, Tenant tenantInfo){ } /** - * Create a user + * Create a user. * * @param userInfo object with user creation details. * @return Id of the created user. + * @throws Exception Exception. */ public String createUser(UserObject userInfo) throws Exception { + String jsonRequest = toJSONString(userInfo); if (userInfo.getScimSchemaExtensionEnterprise() != null) { jsonRequest = jsonRequest.replace("scimSchemaExtensionEnterprise", @@ -83,13 +86,15 @@ public String createUser(UserObject userInfo) throws Exception { } /** - * Get the details of a user + * Get the details of a user. * * @param userId id of the user. * @param attribute requested user attributes * @return JSONObject of the HTTP response. + * @throws Exception Exception. */ public JSONObject getUser(String userId, String attribute) throws Exception { + String endPointUrl; if (StringUtils.isEmpty(attribute)) { endPointUrl = getUsersPath() + PATH_SEPARATOR + userId; @@ -103,12 +108,14 @@ public JSONObject getUser(String userId, String attribute) throws Exception { } /** - * Update the details of an existing user + * Update the details of an existing user. * * @param patchUserInfo user patch request object. * @param userId id of the user. + * @throws IOException Exception. */ public void updateUser(PatchOperationRequestObject patchUserInfo, String userId) throws IOException { + String jsonRequest = toJSONString(patchUserInfo); String endPointUrl = getUsersPath() + PATH_SEPARATOR + userId; @@ -119,12 +126,14 @@ public void updateUser(PatchOperationRequestObject patchUserInfo, String userId) } /** - * Search a user and get requested attributes + * Search a user and get requested attributes. * * @param userSearchReq json String of user search request. * @return JSONObject of the user search response. + * @throws Exception Exception. */ public JSONObject searchUser(String userSearchReq) throws Exception { + String endPointUrl = getUsersPath() + SCIM2_SEARCH_PATH; try (CloseableHttpResponse response = getResponseOfHttpPost(endPointUrl, userSearchReq, getHeaders())) { @@ -135,11 +144,13 @@ public JSONObject searchUser(String userSearchReq) throws Exception { } /** - * Delete an existing user + * Delete an existing user. * * @param userId id of the user. + * @throws IOException Exception. */ public void deleteUser(String userId) throws IOException { + String endPointUrl = getUsersPath() + PATH_SEPARATOR + userId; try (CloseableHttpResponse response = getResponseOfHttpDelete(endPointUrl, getHeaders())) { @@ -149,12 +160,14 @@ public void deleteUser(String userId) throws IOException { } /** - * Add a new role + * Add a new role. * * @param roleInfo Role request object. * @return Role id. + * @throws Exception Exception. */ public String addRole(RoleRequestObject roleInfo) throws Exception { + String jsonRequest = toJSONString(roleInfo); try (CloseableHttpResponse response = getResponseOfHttpPost(getRolesPath(), jsonRequest, getHeaders())) { @@ -166,12 +179,14 @@ public String addRole(RoleRequestObject roleInfo) throws Exception { } /** - * Update an existing role + * Update an existing role. * * @param patchRoleInfo Role patch request object. * @param roleId Role id. + * @throws IOException Exception. */ public void updateUserRole(PatchOperationRequestObject patchRoleInfo, String roleId) throws IOException { + String jsonRequest = toJSONString(patchRoleInfo); String endPointUrl = getRolesPath() + PATH_SEPARATOR + roleId; @@ -182,10 +197,11 @@ public void updateUserRole(PatchOperationRequestObject patchRoleInfo, String rol } /** - * Search and get the id of a role by the name + * Search and get the id of a role by the name. * * @param roleName Role name. * @return Role id. + * @throws Exception Exception. */ public String getRoleIdByName(String roleName) throws Exception { @@ -209,11 +225,13 @@ jsonRequest, getHeaders())) { } /** - * Delete an existing role + * Delete an existing role. * * @param roleId Role id. + * @throws IOException Exception. */ public void deleteRole(String roleId) throws IOException { + String endPointUrl = getRolesPath() + PATH_SEPARATOR + roleId; try (CloseableHttpResponse response = getResponseOfHttpDelete(endPointUrl, getHeaders())) { @@ -223,10 +241,11 @@ public void deleteRole(String roleId) throws IOException { } /** - * Add a new group + * Add a new group. * * @param groupInfo Group request object. * @return Group id. + * @throws Exception Exception. */ public String createGroup(GroupRequestObject groupInfo) throws Exception { String jsonRequest = toJSONString(groupInfo); @@ -240,11 +259,13 @@ public String createGroup(GroupRequestObject groupInfo) throws Exception { } /** - * Delete an existing group + * Delete an existing group. * * @param groupId Group id. + * @throws IOException Exception. */ public void deleteGroup(String groupId) throws IOException { + String endPointUrl = getGroupsPath() + PATH_SEPARATOR + groupId; try (CloseableHttpResponse response = getResponseOfHttpDelete(endPointUrl, getHeaders())) { @@ -265,6 +286,7 @@ private Header[] getHeaders() { } private String getUsersPath() { + if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { return serverUrl + SCIM2_USERS_ENDPOINT; } else { @@ -273,6 +295,7 @@ private String getUsersPath() { } private String getRolesPath() { + if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { return serverUrl + SCIM2_ROLES_ENDPOINT; } else { @@ -281,6 +304,7 @@ private String getRolesPath() { } private String getGroupsPath() { + if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { return serverUrl + SCIM2_GROUPS_ENDPOINT; } else { @@ -290,8 +314,11 @@ private String getGroupsPath() { /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } From c8511cbf17ebb318dd42e88f94df0a7d503e144f Mon Sep 17 00:00:00 2001 From: Ashan Thamara Palihakkara <75057725+ashanthamara@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:19:01 +0530 Subject: [PATCH 2/7] Fixed minor formatting issues in integration tests --- ...thCodeGrantOpenIdRequestObjectTestCase.java | 12 ++++++++++++ ...uth2ServiceAuthCodeGrantOpenIdTestCase.java | 11 +++++++++++ .../oauth2/OAuth2ServiceJWTGrantTestCase.java | 13 ++++++++----- ...vocationWithSessionTerminationTestCase.java | 18 ++++++++++-------- .../test/oauth2/OIDCCustomScopesLoginTest.java | 1 + .../ChallengeQuestionsRestClient.java | 5 +++++ .../restclients/ClaimManagementRestClient.java | 11 ++++++++++- .../test/restclients/IdpMgtRestClient.java | 16 ++++++++++++++-- .../restclients/OIDCScopeMgtRestClient.java | 8 ++++++++ 9 files changed, 79 insertions(+), 16 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdRequestObjectTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdRequestObjectTestCase.java index 37515999ece..c894ca09117 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdRequestObjectTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdRequestObjectTestCase.java @@ -140,6 +140,7 @@ public void restoreConfiguration() throws Exception { @BeforeClass(alwaysRun = true) public void testInit() throws Exception { + super.init(TestUserMode.SUPER_TENANT_USER); adminUsername = userInfo.getUserName(); @@ -166,6 +167,7 @@ public void testInit() throws Exception { } private String addOIDCClaims(String externalClaim, String localClaim) throws Exception { + ExternalClaimReq externalClaimReq = new ExternalClaimReq(); externalClaimReq.setClaimURI(externalClaim); externalClaimReq.setMappedLocalClaimURI(localClaim); @@ -205,6 +207,7 @@ public void testRegisterApplication() throws Exception { @Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testRegisterApplication") public void testSendAuthorozedPost() throws Exception { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); urlParameters.add(new BasicNameValuePair("consumerKey", consumerKey)); @@ -242,6 +245,7 @@ public void testSendAuthorozedPost() throws Exception { @Test(groups = "wso2.is", description = "Send login post request", dependsOnMethods = "testSendAuthorozedPost") public void testSendLoginPost() throws Exception { + HttpResponse response = sendLoginPost(client, sessionDataKey); Assert.assertNotNull(response, "Login request failed. response is null."); @@ -292,6 +296,7 @@ public void testSendApprovalPost() throws Exception { @Test(groups = "wso2.is", description = "Get access token", dependsOnMethods = "testSendApprovalPost") public void testGetAccessToken() throws Exception { + HttpResponse response = sendGetAccessTokenPost(client, consumerSecret); Assert.assertNotNull(response, "Approval response is invalid."); EntityUtils.consume(response.getEntity()); @@ -325,6 +330,7 @@ public void testGetAccessToken() throws Exception { @Test(groups = "wso2.is", description = "Validate access token", dependsOnMethods = "testGetAccessToken") public void testValidateAccessToken() throws Exception { + HttpResponse response = sendValidateAccessTokenPost(client, accessToken); Assert.assertNotNull(response, "Validate access token response is invalid."); @@ -342,6 +348,7 @@ public void testValidateAccessToken() throws Exception { @Test(groups = "wso2.is", description = "Validate the user claim values", dependsOnMethods = "testGetAccessToken") public void testClaims() throws Exception { + HttpGet request = new HttpGet(OAuth2Constant.USER_INFO_ENDPOINT); request.setHeader("User-Agent", OAuth2Constant.USER_AGENT); @@ -367,6 +374,7 @@ public void testClaims() throws Exception { @Test(groups = "wso2.is", description = "Validate Token Expiration Time", dependsOnMethods = "testValidateAccessToken") public void testValidateTokenExpirationTime() throws Exception { + JSONObject tokenResponse = introspectToken(); Assert.assertNotNull(tokenResponse.get("exp"), "'exp' value is not included"); @@ -379,6 +387,7 @@ public void testValidateTokenExpirationTime() throws Exception { @Test(groups = "wso2.is", description = "Validate Authorization Context of jwt Token", dependsOnMethods = "testValidateAccessToken") public void testValidateTokenScope() throws Exception { + JSONObject tokenResponse = introspectToken(); Assert.assertTrue(tokenResponse.size() > 1, "Invalid JWT token received"); Assert.assertNotNull(tokenResponse.get("scope"), "'scope' is not included"); @@ -406,6 +415,7 @@ private void resetISConfiguration() throws Exception { } public HttpResponse sendLoginPost(HttpClient client, String sessionDataKey) throws IOException { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("username", USERNAME)); urlParameters.add(new BasicNameValuePair("password", PASSWORD)); @@ -415,12 +425,14 @@ public HttpResponse sendLoginPost(HttpClient client, String sessionDataKey) thro } private JSONObject introspectToken() throws Exception { + String introspectionUrl = tenantInfo.getDomain().equalsIgnoreCase("carbon.super") ? OAuth2Constant.INTRO_SPEC_ENDPOINT : OAuth2Constant.TENANT_INTRO_SPEC_ENDPOINT; return introspectTokenWithTenant(client, accessToken, introspectionUrl, adminUsername, adminPassword); } private void addAdminUser() throws Exception { + UserObject userInfo = new UserObject(); userInfo.setUserName(USERNAME); userInfo.setPassword(PASSWORD); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdTestCase.java index 9547007091d..8a0b4ebbde2 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAuthCodeGrantOpenIdTestCase.java @@ -97,6 +97,7 @@ public class OAuth2ServiceAuthCodeGrantOpenIdTestCase extends OAuth2ServiceAbstr @DataProvider(name = "configProvider") public static Object[][] configProvider() { + return new Object[][]{{TestUserMode.SUPER_TENANT_ADMIN}, {TestUserMode.TENANT_ADMIN}}; } @@ -131,6 +132,7 @@ public void testInit() throws Exception { @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + deleteApp(applicationId); scim2RestClient.deleteUser(userId); @@ -144,6 +146,7 @@ public void atEnd() throws Exception { @Test(groups = "wso2.is", description = "Check Oauth2 application registration") public void testRegisterApplication() throws Exception { + ApplicationResponseModel application = addApplication(); Assert.assertNotNull(application, "OAuth App creation failed."); applicationId = application.getId(); @@ -156,6 +159,7 @@ public void testRegisterApplication() throws Exception { @Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testRegisterApplication") public void testSendAuthorizedPost() throws Exception { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); urlParameters.add(new BasicNameValuePair("consumerKey", consumerKey)); @@ -194,6 +198,7 @@ public void testSendAuthorizedPost() throws Exception { @Test(groups = "wso2.is", description = "Send login post request", dependsOnMethods = "testSendAuthorizedPost") public void testSendLoginPost() throws Exception { + HttpResponse response = sendLoginPost(client, sessionDataKey); Assert.assertNotNull(response, "Login request failed. response is null."); @@ -244,6 +249,7 @@ public void testSendApprovalPost() throws Exception { @Test(groups = "wso2.is", description = "Get access token", dependsOnMethods = "testSendApprovalPost") public void testGetAccessToken() throws Exception { + HttpResponse response = sendGetAccessTokenPost(client, consumerSecret); Assert.assertNotNull(response, "Approval response is invalid."); EntityUtils.consume(response.getEntity()); @@ -307,6 +313,7 @@ public void testClaims() throws Exception { @Test(groups = "wso2.is", description = "Validate Token Expiration Time", dependsOnMethods = "testValidateAccessToken") public void testValidateTokenExpirationTime() throws Exception { + JSONObject tokenResponse = introspectToken(); Assert.assertNotNull(tokenResponse.get("exp"), "'exp' value is not included"); @@ -318,6 +325,7 @@ public void testValidateTokenExpirationTime() throws Exception { @Test(groups = "wso2.is", description = "Validate Authorization Context of jwt Token", dependsOnMethods = "testValidateAccessToken") public void testValidateTokenScope() throws Exception { + JSONObject tokenResponse = introspectToken(); Assert.assertTrue(tokenResponse.size() > 1, "Invalid JWT token received"); @@ -329,6 +337,7 @@ public void testValidateTokenScope() throws Exception { } public HttpResponse sendLoginPost(HttpClient client, String sessionDataKey) throws IOException { + List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("username", USERNAME)); urlParameters.add(new BasicNameValuePair("password", PASSWORD)); @@ -339,6 +348,7 @@ public HttpResponse sendLoginPost(HttpClient client, String sessionDataKey) thro } private JSONObject introspectToken() throws Exception { + String introspectionUrl = tenantInfo.getDomain().equalsIgnoreCase("carbon.super") ? OAuth2Constant.INTRO_SPEC_ENDPOINT : OAuth2Constant.TENANT_INTRO_SPEC_ENDPOINT; return introspectTokenWithTenant(client, accessToken, introspectionUrl, @@ -346,6 +356,7 @@ private JSONObject introspectToken() throws Exception { } private void addAdminUser() throws Exception { + UserObject userInfo = new UserObject(); userInfo.setUserName(USERNAME); userInfo.setPassword(PASSWORD); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceJWTGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceJWTGrantTestCase.java index c614f0ae1f6..4c1e79df0bd 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceJWTGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceJWTGrantTestCase.java @@ -151,6 +151,7 @@ public void setup() throws Exception { @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + deleteApp(applicationId); scim2RestClient.deleteUser(userId); idpMgtRestClient.deleteIdp(idpId); @@ -452,7 +453,7 @@ private void makeTokenRevokeRequest(Token token) throws URISyntaxException, IOEx /** * To reset configurations to default configurations after the change needed for * - * @throws Exception Exception + * @throws Exception Exception. */ private void resetISConfiguration() throws Exception { @@ -463,7 +464,8 @@ private void resetISConfiguration() throws Exception { /** * To create consumer application that supports JWT bearer grant type * - * @return ApplicationResponseModel + * @return ApplicationResponseModel. + * @throws Exception Exception. */ private ApplicationResponseModel createApplicationWithJWTGrantType() throws Exception { @@ -511,10 +513,11 @@ private void addFederatedIdentityProvider() throws Exception { /** * Get public certificate. * - * @return Encoded certificate string + * @return Encoded certificate string. * @throws Exception Exception. */ private String getEncodedCertificate() throws Exception { + CloseableHttpClient client = HttpClients.createDefault(); String jwksEndpoint = serverURL + getTenantedRelativePath(JWKS_BASE_PATH, tenantInfo.getDomain()); String certificate = BEGIN_CERTIFICATE + getPublicCertificate(client, jwksEndpoint) + END_CERTIFICATE; @@ -541,8 +544,8 @@ private void updateIdentityProviderWithClaimMappings() throws Exception { /** * To change the identity.xml with the configurations needed. * - * @param fileName the name of the file. - * @throws Exception Exception + * @param fileName The name of the file. + * @throws Exception Exception. */ private void changeISConfiguration(String fileName) throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java index 4ef9e9dd5de..4543413dbb1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java @@ -207,7 +207,7 @@ public void testTokenRevocationWhenSessionIsTerminated() throws Exception { /** * Playground app will initiate authorization request to IS and obtain session data key. * - * @throws IOException IOException + * @throws IOException IOException. */ private void initiateAuthorizationRequest() throws IOException { @@ -228,7 +228,7 @@ private void initiateAuthorizationRequest() throws IOException { /** * Provide user credentials and authenticate to the system. * - * @throws IOException IOException + * @throws IOException IOException. */ private void authenticateUser() throws Exception { @@ -253,7 +253,7 @@ private void authenticateUser() throws Exception { /** * Approve the consent. * - * @throws IOException IOException + * @throws IOException IOException. */ private void performConsentApproval() throws IOException { @@ -277,7 +277,7 @@ private void performConsentApproval() throws IOException { /** * Exchange authorization code and get accesstoken. * - * @throws Exception IOException + * @throws Exception IOException. */ private void generateAuthzCodeAccessToken() throws Exception { @@ -309,7 +309,7 @@ private List getOIDCInitiationRequestParams() { /** * Introspect the obtained accesstoken and it should be an active token. * - * @throws Exception Exception + * @throws Exception Exception. */ private void introspectActiveAccessToken() throws Exception { @@ -353,8 +353,8 @@ private Response getResponseOfDelete(String endpointURI) { /** * Get introspection endpoint response by callling introspection endpoint. * - * @return JSONObject - * @throws Exception Exception + * @return JSONObject. + * @throws Exception Exception. */ private JSONObject testIntrospectionEndpoint() throws Exception { @@ -371,7 +371,7 @@ private JSONObject testIntrospectionEndpoint() throws Exception { * @param key Basic authentication key. * @param secret Basic authentication secret. * @return JSON object of the response. - * @throws Exception Exception + * @throws Exception Exception. */ private JSONObject responseObject(String endpoint, List postParameters, String key, String secret) throws Exception { @@ -394,8 +394,10 @@ private JSONObject responseObject(String endpoint, List postParam /** * Create a user with admin role assigned. * + * @throws Exception Exception. */ private void addAdminUser() throws Exception { + UserObject userInfo = new UserObject(); userInfo.setUserName(USERNAME); userInfo.setPassword(PASSWORD); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java index 38544187ae6..e6014a5bca4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java @@ -646,6 +646,7 @@ private String getLoginUserId() throws Exception { } private void updateUserAttribute(String loginUserId, String attributePath, String attributeValue) throws IOException { + UserItemAddGroupobj updateUserPatchOp = new UserItemAddGroupobj().op(OpEnum.ADD); updateUserPatchOp.setPath(attributePath); updateUserPatchOp.setValue(attributeValue); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java index eccfefb2875..a57dcc9c437 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java @@ -53,6 +53,7 @@ public ChallengeQuestionsRestClient(String serverUrl, Tenant tenantInfo) { * @param userId userId. * @param questionSetId Challenge Question Set id. * @param challengeAsnwerObj Challenge Question request object. + * @throws Exception Exception. */ public void setChallengeQuestionAnswer(String userId, String questionSetId, UserChallengeAnswer challengeAsnwerObj) throws Exception { @@ -68,6 +69,7 @@ public void setChallengeQuestionAnswer(String userId, String questionSetId, } private Header[] getHeaders() { + Header[] headerList = new Header[3]; headerList[0] = new BasicHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); headerList[1] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + @@ -79,8 +81,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java index 86886281df8..d924aeab6df 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java @@ -47,6 +47,7 @@ public class ClaimManagementRestClient extends RestBaseClient { private final String serverBasePath; public ClaimManagementRestClient(String backendURL, Tenant tenantInfo) { + client = HttpClients.createDefault(); this.username = tenantInfo.getContextUser().getUserName(); @@ -58,12 +59,14 @@ public ClaimManagementRestClient(String backendURL, Tenant tenantInfo) { } /** - * Add External Claim + * Add External Claim. * * @param dialectId Claim dialect id. * @param claimRequest External Claim request object. + * @throws Exception Exception. */ public String addExternalClaim(String dialectId, ExternalClaimReq claimRequest) throws Exception { + String endPointUrl = serverBasePath + CLAIM_DIALECTS_ENDPOINT_URI + PATH_SEPARATOR + dialectId + CLAIMS_ENDPOINT_URI; String jsonRequest = toJSONString(claimRequest); @@ -82,6 +85,7 @@ public String addExternalClaim(String dialectId, ExternalClaimReq claimRequest) * @throws Exception Exception. */ public JSONObject getExternalClaim(String dialectId, String claimId) throws Exception { + String endPointUrl = serverBasePath + CLAIM_DIALECTS_ENDPOINT_URI + PATH_SEPARATOR + dialectId + CLAIMS_ENDPOINT_URI + PATH_SEPARATOR + claimId; @@ -98,6 +102,7 @@ public JSONObject getExternalClaim(String dialectId, String claimId) throws Exce * @throws IOException IOException. */ public void deleteExternalClaim(String dialectId, String claimId) throws IOException { + String endPointUrl = serverBasePath + CLAIM_DIALECTS_ENDPOINT_URI + PATH_SEPARATOR + dialectId + CLAIMS_ENDPOINT_URI + PATH_SEPARATOR + claimId; try (CloseableHttpResponse response = getResponseOfHttpDelete(endPointUrl, getHeaders())) { @@ -107,6 +112,7 @@ public void deleteExternalClaim(String dialectId, String claimId) throws IOExcep } private Header[] getHeaders() { + Header[] headerList = new Header[2]; headerList[0] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + Base64.encodeBase64String((username + ":" + password).getBytes()).trim()); @@ -117,8 +123,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java index 2816ae60c64..1486bd5eef8 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java @@ -36,6 +36,7 @@ import java.io.IOException; public class IdpMgtRestClient extends RestBaseClient { + private static final String CLAIMS_PATH = "/claims"; private static final String FEDERATED_AUTHENTICATORS_PATH = "/federated-authenticators/"; private final String serverUrl; @@ -56,6 +57,7 @@ public IdpMgtRestClient(String serverUrl, Tenant tenantInfo) { * Create an Identity Provider. * * @param idpCreateReqObj Identity Provider request object. + * @throws Exception Exception. */ public String createIdentityProvider(IdentityProviderPOSTRequest idpCreateReqObj) throws Exception { String jsonRequest = toJSONString(idpCreateReqObj); @@ -75,8 +77,10 @@ public String createIdentityProvider(IdentityProviderPOSTRequest idpCreateReqObj * @param idpId identity provider id. * @param federatedAuthenticatorId Federated Authenticator id. * @return JSONObject with Federated Authenticator details. + * @throws Exception Exception. */ public JSONObject getIdpFederatedAuthenticator(String idpId, String federatedAuthenticatorId) throws Exception { + String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(IDENTITY_PROVIDER_BASE_PATH, tenantDomain) + PATH_SEPARATOR + idpId + FEDERATED_AUTHENTICATORS_PATH + federatedAuthenticatorId; @@ -89,10 +93,12 @@ public JSONObject getIdpFederatedAuthenticator(String idpId, String federatedAut /** * Update an Identity Provider claim configurations. * - * @param idpId Identity Provider Id + * @param idpId Identity Provider Id. * @param idpClaims Identity Provider claim request object. + * @throws IOException Exception. */ public void updateIdpClaimConfig(String idpId, Claims idpClaims) throws IOException { + String jsonRequest = toJSONString(idpClaims); String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(IDENTITY_PROVIDER_BASE_PATH, tenantDomain) + PATH_SEPARATOR + idpId + CLAIMS_PATH; @@ -106,9 +112,11 @@ public void updateIdpClaimConfig(String idpId, Claims idpClaims) throws IOExcept /** * Delete an Identity Provider. * - * @param idpId Identity Provider Id + * @param idpId Identity Provider Id. + * @throws IOException Exception. */ public void deleteIdp(String idpId) throws IOException { + String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(IDENTITY_PROVIDER_BASE_PATH, tenantDomain) + PATH_SEPARATOR + idpId; @@ -119,6 +127,7 @@ public void deleteIdp(String idpId) throws IOException { } private Header[] getHeaders() { + Header[] headerList = new Header[3]; headerList[0] = new BasicHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); headerList[1] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + @@ -130,8 +139,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java index 7cb33c692d8..aa71604d49e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java @@ -56,8 +56,10 @@ public OIDCScopeMgtRestClient(String serverUrl, Tenant tenantInfo) { * * @param scopeId userId. * @return Scope object. + * @throws Exception Exception. */ public JSONObject getScope(String scopeId) throws Exception { + String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(OIDC_SCOPE_MGT_BASE_PATH, tenantDomain) + PATH_SEPARATOR + scopeId; @@ -71,8 +73,10 @@ public JSONObject getScope(String scopeId) throws Exception { * * @param scopeId userId. * @param scopeUpdateObj Scope update request object. + * @throws Exception Exception. */ public void updateScope(String scopeId, ScopeUpdateRequest scopeUpdateObj) throws Exception { + String jsonRequest = toJSONString(scopeUpdateObj); String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(OIDC_SCOPE_MGT_BASE_PATH, tenantDomain) + PATH_SEPARATOR + scopeId; @@ -84,6 +88,7 @@ public void updateScope(String scopeId, ScopeUpdateRequest scopeUpdateObj) throw } private Header[] getHeaders() { + Header[] headerList = new Header[3]; headerList[0] = new BasicHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); headerList[1] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + @@ -95,8 +100,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException Exception. */ public void closeHttpClient() throws IOException { + client.close(); } } From 8e9e84c2c24e0c86c9b70588a92b3da115ff383e Mon Sep 17 00:00:00 2001 From: Ashan Thamara Palihakkara <75057725+ashanthamara@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:30:47 +0530 Subject: [PATCH 3/7] Improved method description --- .../test/oauth2/OAuth2DeviceFlowTestCase.java | 2 +- .../OAuth2IDTokenEncryptionTestCase.java | 10 +-- .../OAuth2ServiceAbstractIntegrationTest.java | 78 ++++++++++--------- .../oauth2/OAuth2ServiceJWTGrantTestCase.java | 16 ++-- ...OAuth2ServiceSAML2BearerGrantTestCase.java | 12 +-- ...ithMultipleSessionTerminationTestCase.java | 6 +- ...ocationWithSessionTerminationTestCase.java | 16 ++-- .../restclients/AuthenticatorRestClient.java | 2 +- .../ChallengeQuestionsRestClient.java | 6 +- .../ClaimManagementRestClient.java | 8 +- .../restclients/EmailTemplatesRestClient.java | 2 +- .../IdentityGovernanceRestClient.java | 2 +- .../test/restclients/IdpMgtRestClient.java | 10 +-- .../restclients/KeystoreMgtRestClient.java | 12 ++- .../test/restclients/OAuth2RestClient.java | 26 +++---- .../restclients/OIDCScopeMgtRestClient.java | 8 +- .../test/restclients/RestBaseClient.java | 14 ++-- .../test/restclients/SCIM2RestClient.java | 24 +++--- .../test/restclients/TenantMgtRestClient.java | 4 + .../restclients/UserStoreMgtRestClient.java | 13 +++- 20 files changed, 150 insertions(+), 121 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java index b85c7d39064..cc7eeae26eb 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2DeviceFlowTestCase.java @@ -329,7 +329,7 @@ public HttpResponse sendGetRequest(HttpClient client, String locationURL) throws * Create Application with the given app configurations. * * @return ApplicationResponseModel. - * @throws Exception exception. + * @throws Exception If an error occurred while creating the application. */ private ApplicationResponseModel createApp() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java index 088e34c72a2..115530223b4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java @@ -438,7 +438,7 @@ private String getLocationHeaderValue(HttpResponse response) { /** * Initiate service provider keys required for the tests. * - * @throws Exception error. + * @throws Exception If an error occurred while getting certificate. */ private void initServiceProviderKeys() throws Exception { @@ -465,8 +465,8 @@ private void initServiceProviderKeys() throws Exception { * @param client CloseableHttpClient object to send the login post. * @param sessionDataKey String sessionDataKey obtained. * @return Extracted sessionDataKeyConsent. - * @throws IOException Error. - * @throws URISyntaxException Error. + * @throws IOException If an error occurred while getting Session Data key Consent. + * @throws URISyntaxException If an error occurred while extracting Session Data key parameter. */ private String getSessionDataKeyConsent(CloseableHttpClient client, String sessionDataKey) throws IOException, URISyntaxException { @@ -498,8 +498,8 @@ private String getSessionDataKeyConsent(CloseableHttpClient client, String sessi * @param idToken Encrypted ID token to be decrypted and checked. * @param audience Audience value that should be appeared in the token. * @return Boolean True if audience matches, False otherwise. - * @throws ParseException Error. - * @throws JOSEException Error. + * @throws ParseException If an error occurred while getting jwt. + * @throws JOSEException If an error occurred while decrypting jwt. */ private boolean decryptAndCheckIDToken(String idToken, String audience) throws ParseException, JOSEException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java index dfd2843970c..6cd72d9ec2b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java @@ -111,7 +111,7 @@ public class OAuth2ServiceAbstractIntegrationTest extends ISIntegrationTest { * Initialize. * * @param userMode - User Id. - * @throws Exception Exception. + * @throws Exception If an error occurred while initializing the clients. */ protected void init(TestUserMode userMode) throws Exception { @@ -126,7 +126,7 @@ protected void init(TestUserMode userMode) throws Exception { * Create Application with the given app configurations. * * @return OAuthConsumerAppDTO. - * @throws Exception Exception. + * @throws Exception If an error occurred while creating an application. */ public OAuthConsumerAppDTO createApplication() throws Exception { @@ -225,7 +225,7 @@ ServiceProvider setServiceProviderClaimConfig(ServiceProvider serviceProvider) { * * @param application Application creation object. * @return Application id. - * @throws Exception Exception. + * @throws Exception If an error occurred while creating an application. */ public String addApplication(ApplicationModel application) throws Exception { @@ -237,7 +237,7 @@ public String addApplication(ApplicationModel application) throws Exception { * * @param appId Application Id. * @return ApplicationResponseModel. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting an application. */ public ApplicationResponseModel getApplication(String appId) throws Exception { @@ -249,7 +249,7 @@ public ApplicationResponseModel getApplication(String appId) throws Exception { * * @param appId Application Id. * @param application Application update patch object. - * @throws Exception Exception. + * @throws Exception If an error occurred while updating an application. */ public void updateApplication(String appId, ApplicationPatchModel application) throws Exception { @@ -261,7 +261,7 @@ public void updateApplication(String appId, ApplicationPatchModel application) t * * @param appId Application Id. * @return OpenIDConnectConfiguration. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting OIDC Inbound configurations of an application. */ public OpenIDConnectConfiguration getOIDCInboundDetailsOfApplication(String appId) throws Exception { @@ -273,7 +273,7 @@ public OpenIDConnectConfiguration getOIDCInboundDetailsOfApplication(String appI * * @param appId Application Id. * @return SAML2ServiceProvider. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting SAML Inbound configurations of an application. */ public SAML2ServiceProvider getSAMLInboundDetailsOfApplication(String appId) throws Exception { @@ -286,6 +286,7 @@ public SAML2ServiceProvider getSAMLInboundDetailsOfApplication(String appId) thr * @param appId Application Id. * @param InboundConfig InboundConfig object. * @param inboundType inbound configuration type. + * @throws IOException If an error occurred while updating Inbound configurations of an application. */ public void updateApplicationInboundConfig(String appId, Object InboundConfig, String inboundType) throws IOException { @@ -405,8 +406,8 @@ private RequestedClaimConfiguration getRequestedClaim(String claimUri) { * @param urlParameters Url parameters. * @param url Endpoint. * @return HttpResponse. - * @throws ClientProtocolException ClientProtocolException. - * @throws java.io.IOException java.io.IOException. + * @throws ClientProtocolException If an error occurred while executing http POST request. + * @throws java.io.IOException If an error occurred while executing http POST request. */ public HttpResponse sendPostRequestWithParameters(HttpClient client, List urlParameters, String url) throws ClientProtocolException, IOException { @@ -424,8 +425,8 @@ public HttpResponse sendPostRequestWithParameters(HttpClient client, List consentClaims) throws IOException { @@ -598,7 +599,7 @@ public HttpResponse sendApprovalPostWithConsent(HttpClient client, String sessio * @param consentClaims Claims requiring user consent. * @param tenantDomain Tenant domain. * @return Http response. - * @throws java.io.IOException IOException. + * @throws java.io.IOException If an error occurred while executing approval post request for a tenant. */ public HttpResponse sendApprovalPostWithConsent(HttpClient client, String sessionDataKeyConsent, List consentClaims, String tenantDomain) @@ -618,13 +619,13 @@ public HttpResponse sendApprovalPostWithConsent(HttpClient client, String sessio } /** - * Send approval post request. + * Send access token post request. * * @param client - Http client. * @param consumerSecret - Consumer secret. * @return Http response. - * @throws ClientProtocolException ClientProtocolException. - * @throws java.io.IOException java.io.IOException. + * @throws ClientProtocolException If an error occurred while executing access token post request. + * @throws java.io.IOException If an error occurred while executing access token post request. */ public HttpResponse sendGetAccessTokenPost(HttpClient client, String consumerSecret) throws ClientProtocolException, IOException { @@ -641,8 +642,8 @@ public HttpResponse sendGetAccessTokenPost(HttpClient client, String consumerSec * @param client - Http client. * @param accessToken - Access token. * @return Http response. - * @throws ClientProtocolException ClientProtocolException. - * @throws java.io.IOException java.io.IOException. + * @throws ClientProtocolException If an error occurred while executing validate access token post request. + * @throws java.io.IOException If an error occurred while executing validate access token post request. */ public HttpResponse sendValidateAccessTokenPost(HttpClient client, String accessToken) throws ClientProtocolException, @@ -659,7 +660,7 @@ public HttpResponse sendValidateAccessTokenPost(HttpClient client, String access * @param accessToken - Access token. * @param endpoint - Introspection URL of the tenant domain. * @return JSON object of the response. - * @throws Exception Exception. + * @throws Exception If an error occurred while executing token introspection post request. */ public JSONObject introspectTokenWithTenant(HttpClient client, String accessToken, String endpoint, String key, String secret) throws Exception { @@ -670,15 +671,20 @@ public JSONObject introspectTokenWithTenant(HttpClient client, String accessToke } /** - * Delete Application. + * Delete Application using SOAP client. * - * @throws Exception Exception. + * @throws Exception If an error occurred while deleting an application. */ public void deleteApplication() throws Exception { appMgtclient.deleteApplication(SERVICE_PROVIDER_NAME); } + /** + * Delete Application using REST client. + * + * @throws Exception If an error occurred while deleting an application. + */ public void deleteApp(String appId) throws Exception { restClient.deleteApplication(appId); @@ -687,7 +693,7 @@ public void deleteApp(String appId) throws Exception { /** * Remove OAuth Application. * - * @throws Exception Exception. + * @throws Exception If an error occurred while removing oauth application data. */ public void removeOAuthApplicationData() throws Exception { @@ -768,7 +774,7 @@ public void updateApplicationCertificate(String appId, X509Certificate sp1X509Pu * * @param x509Certificate Certificate in x509 format. * @return Certificate in pem format. - * @throws CertificateEncodingException CertificateEncodingException. + * @throws CertificateEncodingException If an error occurred while converting the certificate to pem. */ public String convertToPem(X509Certificate x509Certificate) throws CertificateEncodingException { @@ -833,7 +839,7 @@ public ApplicationResponseModel getBasicOAuthApplication(String callBackURL) thr * * @param appDTO OAuthConsumerAppDTO of the service provider. * @return Registered service provider. - * @throws Exception Exception. + * @throws Exception If an error occurred while creating a service provider with oauth configurations. */ public ServiceProvider registerServiceProviderWithOAuthInboundConfigs(OAuthConsumerAppDTO appDTO) throws Exception { @@ -905,7 +911,7 @@ private void setInboundOAuthConfig(List auth * @param client httpclient. * @param authorizationHeader Authentication header. * @return JSON object of the response. - * @throws Exception Exception. + * @throws Exception If an error occurred while executing http POST request and generating response object. */ private JSONObject responseObject(HttpClient client, String endpoint, List postParameters, String authorizationHeader) throws Exception { @@ -931,7 +937,7 @@ private JSONObject responseObject(HttpClient client, String endpoint, List postParameters, String key, String secret) throws Exception { @@ -362,8 +362,8 @@ private Response getResponseOfDelete(String endpointURI) { /** * Get introspection endpoint response by callling introspection endpoint. * - * @return JSONObject - * @throws Exception Exception + * @return JSONObject. + * @throws Exception If an error occurred while getting introspection endpoint response. */ private JSONObject testIntrospectionEndpoint(String accessToken, HttpClient client) throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java index 4543413dbb1..9720df1e0d1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenRevocationWithSessionTerminationTestCase.java @@ -207,7 +207,7 @@ public void testTokenRevocationWhenSessionIsTerminated() throws Exception { /** * Playground app will initiate authorization request to IS and obtain session data key. * - * @throws IOException IOException. + * @throws IOException If an error occurred while initiating authorization request. */ private void initiateAuthorizationRequest() throws IOException { @@ -228,7 +228,7 @@ private void initiateAuthorizationRequest() throws IOException { /** * Provide user credentials and authenticate to the system. * - * @throws IOException IOException. + * @throws IOException If an error occurred while authenticating the user. */ private void authenticateUser() throws Exception { @@ -253,7 +253,7 @@ private void authenticateUser() throws Exception { /** * Approve the consent. * - * @throws IOException IOException. + * @throws IOException If an error occurred while approving the consent. */ private void performConsentApproval() throws IOException { @@ -277,7 +277,7 @@ private void performConsentApproval() throws IOException { /** * Exchange authorization code and get accesstoken. * - * @throws Exception IOException. + * @throws Exception If an error occurred while exchanging authorization code and getting access token. */ private void generateAuthzCodeAccessToken() throws Exception { @@ -309,7 +309,7 @@ private List getOIDCInitiationRequestParams() { /** * Introspect the obtained accesstoken and it should be an active token. * - * @throws Exception Exception. + * @throws Exception If an error occurred while introspecting the active access token. */ private void introspectActiveAccessToken() throws Exception { @@ -354,7 +354,7 @@ private Response getResponseOfDelete(String endpointURI) { * Get introspection endpoint response by callling introspection endpoint. * * @return JSONObject. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting introspection endpoint response. */ private JSONObject testIntrospectionEndpoint() throws Exception { @@ -371,7 +371,7 @@ private JSONObject testIntrospectionEndpoint() throws Exception { * @param key Basic authentication key. * @param secret Basic authentication secret. * @return JSON object of the response. - * @throws Exception Exception. + * @throws Exception If an error occurred while executing http POST request and getting response object. */ private JSONObject responseObject(String endpoint, List postParameters, String key, String secret) throws Exception { @@ -394,7 +394,7 @@ private JSONObject responseObject(String endpoint, List postParam /** * Create a user with admin role assigned. * - * @throws Exception Exception. + * @throws Exception If an error occurred while adding a user with admin role. */ private void addAdminUser() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java index 6ad22854eda..6ff6a10a18f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/AuthenticatorRestClient.java @@ -68,7 +68,7 @@ private Header[] getHeaders() { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java index a57dcc9c437..0c51b506378 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java @@ -53,10 +53,10 @@ public ChallengeQuestionsRestClient(String serverUrl, Tenant tenantInfo) { * @param userId userId. * @param questionSetId Challenge Question Set id. * @param challengeAsnwerObj Challenge Question request object. - * @throws Exception Exception. + * @throws IOException If an error occurred while setting the challenge question answer. */ public void setChallengeQuestionAnswer(String userId, String questionSetId, - UserChallengeAnswer challengeAsnwerObj) throws Exception { + UserChallengeAnswer challengeAsnwerObj) throws IOException { String jsonRequest = toJSONString(challengeAsnwerObj); String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(String.format( @@ -82,7 +82,7 @@ private Header[] getHeaders() { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java index d924aeab6df..372d049b6b1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java @@ -63,7 +63,7 @@ public ClaimManagementRestClient(String backendURL, Tenant tenantInfo) { * * @param dialectId Claim dialect id. * @param claimRequest External Claim request object. - * @throws Exception Exception. + * @throws Exception If an error occurred while adding an external claim. */ public String addExternalClaim(String dialectId, ExternalClaimReq claimRequest) throws Exception { @@ -82,7 +82,7 @@ public String addExternalClaim(String dialectId, ExternalClaimReq claimRequest) * @param dialectId Claim dialect id. * @param claimId claim id. * @return JSONObject JSON object of the response. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting an external claim. */ public JSONObject getExternalClaim(String dialectId, String claimId) throws Exception { @@ -99,7 +99,7 @@ public JSONObject getExternalClaim(String dialectId, String claimId) throws Exce * * @param dialectId Claim dialect id. * @param claimId claim id. - * @throws IOException IOException. + * @throws IOException If an error occurred while deleting an external claim. */ public void deleteExternalClaim(String dialectId, String claimId) throws IOException { @@ -124,7 +124,7 @@ private Header[] getHeaders() { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java index 698532635b4..320515c9bd0 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java @@ -94,7 +94,7 @@ private String getEncodedEmailTemplateTypeId(String emailTemplateTypeId) { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java index bbfeb3922a9..0479859b9a8 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java @@ -93,7 +93,7 @@ private Header[] getHeaders() { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java index 1486bd5eef8..33ba21ffe5c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java @@ -57,7 +57,7 @@ public IdpMgtRestClient(String serverUrl, Tenant tenantInfo) { * Create an Identity Provider. * * @param idpCreateReqObj Identity Provider request object. - * @throws Exception Exception. + * @throws Exception If an error occurred while creating an idp. */ public String createIdentityProvider(IdentityProviderPOSTRequest idpCreateReqObj) throws Exception { String jsonRequest = toJSONString(idpCreateReqObj); @@ -77,7 +77,7 @@ public String createIdentityProvider(IdentityProviderPOSTRequest idpCreateReqObj * @param idpId identity provider id. * @param federatedAuthenticatorId Federated Authenticator id. * @return JSONObject with Federated Authenticator details. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting idp's federated authenticator. */ public JSONObject getIdpFederatedAuthenticator(String idpId, String federatedAuthenticatorId) throws Exception { @@ -95,7 +95,7 @@ public JSONObject getIdpFederatedAuthenticator(String idpId, String federatedAut * * @param idpId Identity Provider Id. * @param idpClaims Identity Provider claim request object. - * @throws IOException Exception. + * @throws IOException If an error occurred while updating idp claim configurations. */ public void updateIdpClaimConfig(String idpId, Claims idpClaims) throws IOException { @@ -113,7 +113,7 @@ public void updateIdpClaimConfig(String idpId, Claims idpClaims) throws IOExcept * Delete an Identity Provider. * * @param idpId Identity Provider Id. - * @throws IOException Exception. + * @throws IOException If an error occurred while deleting an idp. */ public void deleteIdp(String idpId) throws IOException { @@ -140,7 +140,7 @@ private Header[] getHeaders() { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/KeystoreMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/KeystoreMgtRestClient.java index f53eb179674..b19e7cb2a95 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/KeystoreMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/KeystoreMgtRestClient.java @@ -51,8 +51,10 @@ public KeystoreMgtRestClient(String serverUrl, Tenant tenantInfo) { * Upload the certificate to the tenant keystore. This API is not supported for super tenant. * * @param certificateRequest Certificate request object. + * @throws IOException If an error occurred while uploading the certificate. */ - public void importCertToStore(CertificateRequest certificateRequest) throws Exception { + public void importCertToStore(CertificateRequest certificateRequest) throws IOException { + String jsonRequest = toJSONString(certificateRequest); String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(KEYSTORE_BASE_PATH, tenantDomain); @@ -67,8 +69,10 @@ public void importCertToStore(CertificateRequest certificateRequest) throws Exce * * @param alias alias. * @return Boolean status of certificate availability in tenant keystore. + * @throws IOException If an error occurred while checking the certificate. */ - public Boolean checkCertInStore(String alias) throws Exception { + public Boolean checkCertInStore(String alias) throws IOException { + String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(KEYSTORE_BASE_PATH, tenantDomain) + PATH_SEPARATOR + alias; @@ -78,6 +82,7 @@ public Boolean checkCertInStore(String alias) throws Exception { } private Header[] getHeaders() { + Header[] headerList = new Header[2]; headerList[0] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + Base64.encodeBase64String((username + ":" + password).getBytes()).trim()); @@ -88,8 +93,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java index 6a3250e54b1..1477055996d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java @@ -84,8 +84,8 @@ public OAuth2RestClient(String backendUrl, Tenant tenantInfo) { * * @param application Application Model with application creation details. * @return Id of the created application. - * @throws IOException Exception. - * @throws JSONException JSON Exception. + * @throws IOException If an error occurred while creating an application. + * @throws JSONException If an error occurred while creating the json string. */ public String createApplication(ApplicationModel application) throws IOException, JSONException { String jsonRequest = toJSONString(application); @@ -102,7 +102,7 @@ public String createApplication(ApplicationModel application) throws IOException * * @param application Application Model with application creation details. * @return Application creation response. - * @throws IOException Exception. + * @throws IOException If an error occurred while creating an application. */ public StatusLine createApplicationWithResponse(ApplicationModel application) throws IOException { @@ -118,7 +118,7 @@ public StatusLine createApplicationWithResponse(ApplicationModel application) th * * @param appId Application id. * @return ApplicationResponseModel object. - * @throws IOException Exception. + * @throws IOException If an error occurred while getting an application. */ public ApplicationResponseModel getApplication(String appId) throws IOException { @@ -137,7 +137,7 @@ public ApplicationResponseModel getApplication(String appId) throws IOException * * @param clientId Client id of the application. * @return Application list. - * @throws IOException Error when getting the response. + * @throws IOException If an error occurred while filtering an application using client id. */ public List getApplicationsByClientId(String clientId) throws IOException { @@ -158,7 +158,7 @@ public List getApplicationsByClientId(String clientId) thro * * @param appId Application id. * @param application Updated application patch object. - * @throws IOException Exception. + * @throws IOException If an error occurred while updating an application. */ public void updateApplication(String appId, ApplicationPatchModel application) throws IOException { @@ -175,7 +175,7 @@ public void updateApplication(String appId, ApplicationPatchModel application) t * Get all applications. * * @return ApplicationListResponse object. - * @throws IOException Exception. + * @throws IOException If an error occurred while getting all applications. */ public ApplicationListResponse getAllApplications() throws IOException { @@ -191,7 +191,7 @@ public ApplicationListResponse getAllApplications() throws IOException { * Delete an application. * * @param appId Application id. - * @throws IOException Exception. + * @throws IOException If an error occurred while deleting an application. */ public void deleteApplication(String appId) throws IOException { @@ -208,7 +208,7 @@ public void deleteApplication(String appId) throws IOException { * * @param appId Application id. * @return OpenIDConnectConfiguration object with oidc configuration details. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting OIDC inbound configuration details. */ public OpenIDConnectConfiguration getOIDCInboundDetails(String appId) throws Exception { @@ -222,7 +222,7 @@ public OpenIDConnectConfiguration getOIDCInboundDetails(String appId) throws Exc * * @param appId Application id. * @return SAML2ServiceProvider object with saml configuration details. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting SAML inbound configuration details. */ public SAML2ServiceProvider getSAMLInboundDetails(String appId) throws Exception { @@ -248,7 +248,7 @@ private String getConfig(String appId, String inboundType) throws Exception { * @param appId Application id. * @param inboundConfig Inbound configuration object to be updated. * @param inboundType Type of the inbound configuration. - * @throws IOException Exception. + * @throws IOException If an error occurred while updating an inbound configuration. */ public void updateInboundDetailsOfApplication(String appId, Object inboundConfig, String inboundType) throws IOException { @@ -268,7 +268,7 @@ public void updateInboundDetailsOfApplication(String appId, Object inboundConfig * * @param appId Application id. * @param inboundType Inbound Type to be deleted. - * @throws IOException Exception. + * @throws IOException If an error occurred while deleting an inbound configuration. */ public Boolean deleteInboundConfiguration(String appId, String inboundType) throws IOException { @@ -451,7 +451,7 @@ public void shareApplication(String appId, ApplicationSharePOSTRequest applicati /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java index aa71604d49e..3015069b6b9 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OIDCScopeMgtRestClient.java @@ -56,7 +56,7 @@ public OIDCScopeMgtRestClient(String serverUrl, Tenant tenantInfo) { * * @param scopeId userId. * @return Scope object. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting an OIDC scope. */ public JSONObject getScope(String scopeId) throws Exception { @@ -73,9 +73,9 @@ public JSONObject getScope(String scopeId) throws Exception { * * @param scopeId userId. * @param scopeUpdateObj Scope update request object. - * @throws Exception Exception. + * @throws IOException If an error occurred while updating the scope. */ - public void updateScope(String scopeId, ScopeUpdateRequest scopeUpdateObj) throws Exception { + public void updateScope(String scopeId, ScopeUpdateRequest scopeUpdateObj) throws IOException { String jsonRequest = toJSONString(scopeUpdateObj); String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(OIDC_SCOPE_MGT_BASE_PATH, @@ -101,7 +101,7 @@ private Header[] getHeaders() { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java index 573cb7e0d64..e1adcdde07f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java @@ -70,7 +70,7 @@ public String toJSONString(java.lang.Object object) { * * @param responseString Respective Http response. * @return Relevant json object. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting a JSON object from a json string. */ public JSONObject getJSONObject(String responseString) throws Exception { @@ -88,7 +88,7 @@ public JSONObject getJSONObject(String responseString) throws Exception { * * @param responseString Respective Http response. * @return Relevant JSONArray object. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting a JSON array from a JSON string. */ public JSONArray getJSONArray(String responseString) throws Exception { @@ -108,7 +108,7 @@ public JSONArray getJSONArray(String responseString) throws Exception { * @param jsonRequest Json body. * @param headers Header list of the request. * @return Response of the Http request. - * @throws IOException Exception. + * @throws IOException If an error occurred while executing http POST request. */ public CloseableHttpResponse getResponseOfHttpPost(String endPointUrl, String jsonRequest, Header[] headers) throws IOException { @@ -126,7 +126,7 @@ public CloseableHttpResponse getResponseOfHttpPost(String endPointUrl, String js * @param endPointUrl REST endpoint. * @param headers header list of the request. * @return Response of the Http request. - * @throws IOException Exception. + * @throws IOException If an error occurred while executing http GET request. */ public CloseableHttpResponse getResponseOfHttpGet(String endPointUrl, Header[] headers) throws IOException { @@ -144,7 +144,7 @@ public CloseableHttpResponse getResponseOfHttpGet(String endPointUrl, Header[] h * @param jsonRequest json body. * @param headers header list of the request. * @return Response of the Http request. - * @throws IOException Exception. + * @throws IOException If an error occurred while executing http PATCH request. */ public CloseableHttpResponse getResponseOfHttpPatch(String endPointUrl, String jsonRequest, Header[] headers) throws IOException { @@ -161,7 +161,7 @@ public CloseableHttpResponse getResponseOfHttpPatch(String endPointUrl, String j * @param endPointUrl REST endpoint. * @param headers header list of the request. * @return Response of the Http request. - * @throws IOException Exception. + * @throws IOException If an error occurred while executing http DELETE request. */ public CloseableHttpResponse getResponseOfHttpDelete(String endPointUrl, Header[] headers) throws IOException { @@ -178,7 +178,7 @@ public CloseableHttpResponse getResponseOfHttpDelete(String endPointUrl, Header[ * @param jsonRequest json body. * @param headers header list of the request. * @return Response of the Http request. - * @throws IOException Exception. + * @throws IOException If an error occurred while executing http PUT request. */ public CloseableHttpResponse getResponseOfHttpPut(String endPointUrl, String jsonRequest, Header[] headers) throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java index f0fb6afb95f..e748d4f9f60 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java @@ -67,7 +67,7 @@ public SCIM2RestClient(String serverUrl, Tenant tenantInfo){ * * @param userInfo object with user creation details. * @return Id of the created user. - * @throws Exception Exception. + * @throws Exception If an error occurred while creating a group. */ public String createUser(UserObject userInfo) throws Exception { @@ -91,7 +91,7 @@ public String createUser(UserObject userInfo) throws Exception { * @param userId id of the user. * @param attribute requested user attributes * @return JSONObject of the HTTP response. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting a user. */ public JSONObject getUser(String userId, String attribute) throws Exception { @@ -112,7 +112,7 @@ public JSONObject getUser(String userId, String attribute) throws Exception { * * @param patchUserInfo user patch request object. * @param userId id of the user. - * @throws IOException Exception. + * @throws IOException If an error occurred while updating a user. */ public void updateUser(PatchOperationRequestObject patchUserInfo, String userId) throws IOException { @@ -130,7 +130,7 @@ public void updateUser(PatchOperationRequestObject patchUserInfo, String userId) * * @param userSearchReq json String of user search request. * @return JSONObject of the user search response. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting a user. */ public JSONObject searchUser(String userSearchReq) throws Exception { @@ -147,7 +147,7 @@ public JSONObject searchUser(String userSearchReq) throws Exception { * Delete an existing user. * * @param userId id of the user. - * @throws IOException Exception. + * @throws IOException If an error occurred while deleting a user. */ public void deleteUser(String userId) throws IOException { @@ -164,7 +164,7 @@ public void deleteUser(String userId) throws IOException { * * @param roleInfo Role request object. * @return Role id. - * @throws Exception Exception. + * @throws Exception If an error occurred while adding a role. */ public String addRole(RoleRequestObject roleInfo) throws Exception { @@ -183,7 +183,7 @@ public String addRole(RoleRequestObject roleInfo) throws Exception { * * @param patchRoleInfo Role patch request object. * @param roleId Role id. - * @throws IOException Exception. + * @throws IOException If an error occurred while updating a role. */ public void updateUserRole(PatchOperationRequestObject patchRoleInfo, String roleId) throws IOException { @@ -201,7 +201,7 @@ public void updateUserRole(PatchOperationRequestObject patchRoleInfo, String rol * * @param roleName Role name. * @return Role id. - * @throws Exception Exception. + * @throws Exception If an error occurred while getting a role by name. */ public String getRoleIdByName(String roleName) throws Exception { @@ -228,7 +228,7 @@ jsonRequest, getHeaders())) { * Delete an existing role. * * @param roleId Role id. - * @throws IOException Exception. + * @throws IOException If an error occurred while deleting a role. */ public void deleteRole(String roleId) throws IOException { @@ -245,7 +245,7 @@ public void deleteRole(String roleId) throws IOException { * * @param groupInfo Group request object. * @return Group id. - * @throws Exception Exception. + * @throws Exception If an error occurred while adding a group. */ public String createGroup(GroupRequestObject groupInfo) throws Exception { String jsonRequest = toJSONString(groupInfo); @@ -262,7 +262,7 @@ public String createGroup(GroupRequestObject groupInfo) throws Exception { * Delete an existing group. * * @param groupId Group id. - * @throws IOException Exception. + * @throws IOException If an error occurred while deleting a group. */ public void deleteGroup(String groupId) throws IOException { @@ -315,7 +315,7 @@ private String getGroupsPath() { /** * Close the HTTP client. * - * @throws IOException Exception. + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/TenantMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/TenantMgtRestClient.java index 6ea7162ca7f..ba13ad86c16 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/TenantMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/TenantMgtRestClient.java @@ -55,6 +55,7 @@ public TenantMgtRestClient(String serverUrl, Tenant tenantInfo) { * * @param TenantReqModel object with tenant creation details. * @return Id of the created tenant. + * @throws Exception If an error occurred while adding a tenant. */ public String addTenant(TenantModel TenantReqModel) throws Exception { String endPoint = serverUrl + TENANT_MGT_BASE_PATH; @@ -79,8 +80,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { + client.close(); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java index 16a2d64323d..bb3ce91e179 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java @@ -47,6 +47,7 @@ public class UserStoreMgtRestClient extends RestBaseClient { private final String userStoreBasePath; public UserStoreMgtRestClient(String backendURL, Tenant tenantInfo) { + client = HttpClients.createDefault(); this.username = tenantInfo.getContextUser().getUserName(); @@ -61,8 +62,10 @@ public UserStoreMgtRestClient(String backendURL, Tenant tenantInfo) { * Add a secondary user store. * * @param UserStoreReq Secondary user store request object. + * @throws IOException If an error occurred while adding a user store. */ - public String addUserStore(UserStoreReq UserStoreReq) throws Exception { + public String addUserStore(UserStoreReq UserStoreReq) throws IOException { + String jsonRequest = toJSONString(UserStoreReq); try (CloseableHttpResponse response = getResponseOfHttpPost(userStoreBasePath, jsonRequest, getHeaders())) { String[] locationElements = response.getHeaders(LOCATION_HEADER)[0].toString().split(PATH_SEPARATOR); @@ -74,6 +77,7 @@ public String addUserStore(UserStoreReq UserStoreReq) throws Exception { * Get secondary user stores. * * @return JSONArray element of the user stores. + * @throws Exception If an error occurred while getting a user store. */ public JSONArray getUserStores() throws Exception { @@ -86,8 +90,10 @@ public JSONArray getUserStores() throws Exception { * Delete a user store * * @param domain User store domain(id). + * @throws IOException If an error occurred while deleting a user store. */ public void deleteUserStore(String domain) throws IOException { + String endpointUrl = userStoreBasePath + PATH_SEPARATOR + domain; try (CloseableHttpResponse response = getResponseOfHttpDelete(endpointUrl, getHeaders())) { @@ -101,6 +107,7 @@ public void deleteUserStore(String domain) throws IOException { * * @param domain User Store name * @return boolean response of the user store deployment. + * @throws Exception If an error occurred while checking the user store creation. */ public boolean waitForUserStoreDeployment(String domain) throws Exception { @@ -119,6 +126,7 @@ public boolean waitForUserStoreDeployment(String domain) throws Exception { } private Header[] getHeaders() { + Header[] headerList = new Header[2]; headerList[0] = new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE + Base64.encodeBase64String((username + ":" + password).getBytes()).trim()); @@ -129,8 +137,11 @@ private Header[] getHeaders() { /** * Close the HTTP client. + * + * @throws IOException If an error occurred while closing the Http Client. */ public void closeHttpClient() throws IOException { + client.close(); } } From d6c9a2e113477b81c8273eb9caf6b2928300478e Mon Sep 17 00:00:00 2001 From: Ashan Thamara Palihakkara <75057725+ashanthamara@users.noreply.github.com> Date: Thu, 28 Mar 2024 02:01:20 +0530 Subject: [PATCH 4/7] Modified punctuation in method description --- .../mgt/AccountLockEnabledTestCase.java | 6 ++++ .../oauth2/OIDCCustomScopesLoginTest.java | 1 + ...tedTokenColumnAbstractIntegrationTest.java | 1 + .../oidc/OIDCAbstractIntegrationTest.java | 33 ++++++++++--------- ...odeGrantSSODifferentSubjectIDTestCase.java | 5 +-- .../oidc/OIDCAuthCodeGrantSSOTestCase.java | 4 +-- ...IDCAuthzCodeIdTokenValidationTestCase.java | 1 + .../oidc/OIDCFederatedIdpInitLogoutTest.java | 1 + .../oidc/OIDCIdentityFederationTestCase.java | 1 + .../test/oidc/OIDCPasswordGrantTest.java | 24 +++++++------- .../integration/test/oidc/OIDCUtilTest.java | 6 ++-- .../test/saml/ChangeACSUrlTestCase.java | 2 ++ .../test/saml/IDPMetadataTestCase.java | 5 +-- .../test/saml/RegistryMountTestCase.java | 12 +++++++ ...derationWithFileBasedSPAndIDPTestCase.java | 6 ++++ 15 files changed, 70 insertions(+), 38 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockEnabledTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockEnabledTestCase.java index 3b2daafc74b..60cef405de2 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockEnabledTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockEnabledTestCase.java @@ -81,6 +81,7 @@ public class AccountLockEnabledTestCase extends ISIntegrationTest { @SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL}) @BeforeClass(alwaysRun = true) public void testInit() throws Exception { + super.init(); authenticatorRestClient = new AuthenticatorRestClient(serverURL); enableAccountLocking(); @@ -91,6 +92,7 @@ public void testInit() throws Exception { @SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL}) @Test(groups = "wso2.is", description = "Check whether the user account lock successfully") public void testSuccessfulLockedInitially() { + try { testLockUserId = addAdminUser(TEST_LOCK_USER_1, TEST_LOCK_USER_1_PASSWORD, null); @@ -156,6 +158,7 @@ public void testSuccessfulEmailTemplateRetrievalAccountUnLock() throws Exception @SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL}) @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + scim2RestClient.deleteUser(testLockUserId); scim2RestClient.deleteUser(testLockUser2Id); scim2RestClient.deleteUser(testLockUser3Id); @@ -171,6 +174,7 @@ protected String getISResourceLocation() { } protected void enableAccountLocking() throws Exception { + identityGovernanceRestClient = new IdentityGovernanceRestClient(serverURL, tenantInfo); PropertyReq property = new PropertyReq(); @@ -186,12 +190,14 @@ protected void enableAccountLocking() throws Exception { } protected void disableAccountLocking() throws Exception { + connectorPatchRequest.getProperties().get(0).setValue("false"); identityGovernanceRestClient.updateConnectors(CATEGORY_LOGIN_ATTEMPTS_SECURITY , CONNECTOR_ACCOUNT_LOCK_HANDLER, connectorPatchRequest); } protected String addAdminUser(String username, String password, String locale) throws Exception { + UserObject userInfo = new UserObject(); userInfo.setUserName(username); userInfo.setPassword(password); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java index e6014a5bca4..10dd5313434 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OIDCCustomScopesLoginTest.java @@ -634,6 +634,7 @@ private void deleteCustomOIDCScope() throws Exception { } private String getLoginUserId() throws Exception { + String userSearchReq = new JSONObject() .put("schemas", new JSONArray().put("urn:ietf:params:scim:api:messages:2.0:SearchRequest")) .put("attributes", new JSONArray().put("id")) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceWithConsentedTokenColumnAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceWithConsentedTokenColumnAbstractIntegrationTest.java index ab2b12d20fc..4c7772a5258 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceWithConsentedTokenColumnAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceWithConsentedTokenColumnAbstractIntegrationTest.java @@ -135,6 +135,7 @@ protected void createUser() throws Exception { } protected void removeUser() throws Exception { + scim2RestClient.deleteUser(userId); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java index 14f5c8a2c63..21d15dca485 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java @@ -54,7 +54,7 @@ import java.util.Map; /** - * This class defines basic functionality needed to initiate an OIDC test + * This class defines basic functionality needed to initiate an OIDC test. */ public class OIDCAbstractIntegrationTest extends OAuth2ServiceAbstractIntegrationTest { @@ -84,12 +84,13 @@ public void clear() { } /** - * Creates a user + * Creates a user. * - * @param user user instance - * @throws Exception Exception + * @param user user instance. + * @throws Exception If an error occurred while creating a user. */ public void createUser(UserObject user) throws Exception { + scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); userId = scim2RestClient.createUser(user); @@ -103,10 +104,10 @@ public void createUser(UserObject user) throws Exception { } /** - * Deletes a user + * Deletes a user. * - * @param user user instance - * @throws Exception Exception + * @param user user instance. + * @throws Exception If an error occurred while deleting a user. */ public void deleteUser(UserObject user) throws Exception { @@ -115,10 +116,10 @@ public void deleteUser(UserObject user) throws Exception { } /** - * Create an OIDC application + * Create an OIDC application. * - * @param application application instance - * @throws Exception Exception + * @param application application instance. + * @throws Exception If an error creating an application. */ public void createApplication(OIDCApplication application) throws Exception { @@ -163,10 +164,10 @@ private void createApplication(ApplicationModel applicationModel, OIDCApplicatio } /** - * Deletes the registered OIDC application in OP + * Deletes the registered OIDC application in OP. * - * @param application application instance - * @throws Exception Exception + * @param application application instance. + * @throws Exception If an error deleting an application. */ public void deleteApplication(OIDCApplication application) throws Exception { @@ -176,10 +177,10 @@ public void deleteApplication(OIDCApplication application) throws Exception { /** * Sends Authentication Request for an OIDC Flow. - * @param application application + * @param application application. * @param isFirstAuthenticationRequest true if the request is the first authentication request. - * @param client http client - * @param cookieStore cookie store + * @param client http client. + * @param cookieStore cookie store. * @throws Exception throws if an error occurs when sending the authentication request. */ public void testSendAuthenticationRequest(OIDCApplication application, boolean isFirstAuthenticationRequest, diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSODifferentSubjectIDTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSODifferentSubjectIDTestCase.java index a61ae784fe9..947d7d19495 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSODifferentSubjectIDTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSODifferentSubjectIDTestCase.java @@ -25,19 +25,20 @@ import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.SubjectConfig; /** - * This test class tests OIDC SSO functionality for two relying party applications with different subject identifiers + * This test class tests OIDC SSO functionality for two relying party applications with different subject identifiers. */ public class OIDCAuthCodeGrantSSODifferentSubjectIDTestCase extends OIDCAuthCodeGrantSSOTestCase { - @Override protected void initUser() throws Exception { + super.initUser(); user.setUserName("oidcsessiontestuser1"); } @Override protected void initApplications() throws Exception { + super.initApplications(); applications.get(OIDCUtilTest.playgroundAppOneAppName).setSubjectClaimURI(OIDCUtilTest.emailClaimUri); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java index fe20b6dba37..730c5aed824 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java @@ -58,7 +58,7 @@ import java.util.Map; /** - * This test class tests OIDC SSO functionality for two replying party applications + * This test class tests OIDC SSO functionality for two replying party applications. */ public class OIDCAuthCodeGrantSSOTestCase extends OIDCAbstractIntegrationTest { @@ -77,7 +77,6 @@ public class OIDCAuthCodeGrantSSOTestCase extends OIDCAbstractIntegrationTest { protected HttpClient client; protected List consentParameters = new ArrayList<>(); - @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -109,7 +108,6 @@ public void testClear() throws Exception { deleteUser(user); deleteApplications(); clear(); - } @Test(groups = "wso2.is", description = "Test authz endpoint before creating a valid session") diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java index 30d97dc4ccd..288b836527e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java @@ -109,6 +109,7 @@ public void testInit() throws Exception { @AfterClass(alwaysRun = true) public void atEnd() throws Exception { + deleteApp(applicationId); consumerKey = null; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCFederatedIdpInitLogoutTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCFederatedIdpInitLogoutTest.java index 5e710f95854..9647c1988bb 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCFederatedIdpInitLogoutTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCFederatedIdpInitLogoutTest.java @@ -514,6 +514,7 @@ private void createIdpInPrimaryIS() throws Exception { } private OpenIDConnectConfiguration getOIDCConfigurations() { + List grantTypes = new ArrayList<>(); Collections.addAll(grantTypes, "authorization_code", "implicit", "password", "client_credentials", "refresh_token", "urn:ietf:params:oauth:grant-type:saml2-bearer", "iwa:ntlm"); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCIdentityFederationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCIdentityFederationTestCase.java index 36f6618ef83..9a9ead40a1e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCIdentityFederationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCIdentityFederationTestCase.java @@ -383,6 +383,7 @@ private void createIDPInPrimaryIS() throws Exception { } private OpenIDConnectConfiguration getOIDCConfigurations() { + List grantTypes = new ArrayList<>(); Collections.addAll(grantTypes, "authorization_code", "implicit", "password", "client_credentials", "refresh_token", "urn:ietf:params:oauth:grant-type:saml2-bearer", "iwa:ntlm"); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCPasswordGrantTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCPasswordGrantTest.java index 823c2a0bb52..3e7258b6312 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCPasswordGrantTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCPasswordGrantTest.java @@ -182,12 +182,12 @@ public void testGetAccessTokenForPasswordGrantJsonRequest() throws Exception { /** * Invoke given endpointUri for Form POST request with given body, headers and Basic authentication credentials. * - * @param endpointUri endpoint to be invoked - * @param params map of parameters to be added to the request - * @param headers map of headers to be added to the request - * @param username basic auth username - * @param password basic auth password - * @return response + * @param endpointUri endpoint to be invoked. + * @param params map of parameters to be added to the request. + * @param headers map of headers to be added to the request. + * @param username basic auth username. + * @param password basic auth password. + * @return response. */ protected Response getResponseOfFormPostWithAuth(String endpointUri, Map params, Map headers, String username, String password) { @@ -202,12 +202,12 @@ protected Response getResponseOfFormPostWithAuth(String endpointUri, Map headers, String username, String password) { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java index dcc7995a0b0..9df3e94b2c8 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java @@ -104,7 +104,7 @@ public static void initApplications() { /** * To set and get name-value pairs. - * @param application application + * @param application application. * @return name-value pairs. */ public static List getNameValuePairs(OIDCApplication application) { @@ -126,9 +126,9 @@ public static List getNameValuePairs(OIDCApplication application, } /** - * Set sessionDataKey + * Set sessionDataKey. * @param response response - * @param keyPositionMap map to preserve the sessionDataKey + * @param keyPositionMap map to preserve the sessionDataKey. * @throws IOException if an error occurs when extracting data from the response. */ public static void setSessionDataKey(HttpResponse response, Map keyPositionMap) throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/ChangeACSUrlTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/ChangeACSUrlTestCase.java index 8dba333d127..0b24706f0c2 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/ChangeACSUrlTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/ChangeACSUrlTestCase.java @@ -318,6 +318,7 @@ private String authenticateWithSecondaryIS(HttpClient client, String sessionId) } private Map getSAMLResponseFromSecondaryIS(HttpClient client, String redirectURL) throws Exception { + HttpPost request = new HttpPost(redirectURL); request.addHeader("User-Agent", USER_AGENT); request.addHeader("Referer", PRIMARY_IS_SAML_ACS_URL); @@ -379,6 +380,7 @@ private boolean sendSAMLResponseToWebApp(HttpClient client, String samlResponse) } public boolean validateSAMLResponse(HttpResponse response, String userName) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer buffer = new StringBuffer(); String line = ""; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/IDPMetadataTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/IDPMetadataTestCase.java index d2681087eac..9363ef61180 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/IDPMetadataTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/IDPMetadataTestCase.java @@ -42,7 +42,7 @@ import java.rmi.RemoteException; /** - * This tests adds an Identity Provider using metadata file, checks for the validity of properties + * This tests adds an Identity Provider using metadata file, checks for the validity of properties. */ public class IDPMetadataTestCase extends ISIntegrationTest { @@ -59,9 +59,9 @@ public class IDPMetadataTestCase extends ISIntegrationTest { private IdpMgtRestClient identityProviderMgtRestClient; private String idpId; - @BeforeClass(alwaysRun = true) public void init() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); identityProviderMgtRestClient = new IdpMgtRestClient(serverURL, tenantInfo); } @@ -128,6 +128,7 @@ public void addIDPMetadata() throws Exception { @AfterClass(alwaysRun = true) public void endTest() throws RemoteException, IdentitySAMLSSOConfigServiceIdentityException { + try { identityProviderMgtRestClient.deleteIdp(idpId); } catch (Exception ex) { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/RegistryMountTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/RegistryMountTestCase.java index f3cd13bcbb5..ca191bc7c98 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/RegistryMountTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/RegistryMountTestCase.java @@ -107,6 +107,7 @@ public class RegistryMountTestCase extends ISIntegrationTest { @BeforeClass(alwaysRun = true) public void testInit() throws Exception { + super.init(); serverConfigurationManager = new ServerConfigurationManager(isServer); @@ -133,6 +134,7 @@ public void testInit() throws Exception { @AfterClass(alwaysRun = true) public void testClear() throws Exception{ + deleteApplication(); serverConfigurationManager.restoreToLastConfiguration(false); tenantMgtRestClient.closeHttpClient(); @@ -143,6 +145,7 @@ public void testClear() throws Exception{ @Test(alwaysRun = true, description = "Testing SAML SSO login", groups = "wso2.is") public void testSAMLSSOLogin() { + try { HttpResponse response; @@ -178,6 +181,7 @@ public void testSAMLSSOLogin() { private String extractDataFromResponse(HttpResponse response, String key, int token) throws IOException { + BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); String line; @@ -194,6 +198,7 @@ private String extractDataFromResponse(HttpResponse response, String key, int to } private HttpResponse sendPOSTMessage(String sessionKey) throws Exception { + HttpPost post = new HttpPost(COMMON_AUTH_URL); post.setHeader("User-Agent", USER_AGENT); post.addHeader("Referer", String.format(ACS_URL, artifact)); @@ -206,12 +211,14 @@ private HttpResponse sendPOSTMessage(String sessionKey) throws Exception { } private HttpResponse sendGetRequest(String url) throws Exception { + HttpGet request = new HttpGet(url); request.addHeader("User-Agent", USER_AGENT); return httpClient.execute(request); } private HttpResponse sendSAMLMessage(String url, String samlMsgKey, String samlMsgValue) throws IOException { + List urlParameters = new ArrayList<>(); HttpPost post = new HttpPost(getTenantQualifiedURL(url, tenantInfo.getDomain())); post.setHeader("User-Agent", USER_AGENT); @@ -222,6 +229,7 @@ private HttpResponse sendSAMLMessage(String url, String samlMsgKey, String samlM } private HttpResponse sendRedirectRequest(HttpResponse response) throws IOException { + Header[] headers = response.getAllHeaders(); String url = ""; for (Header header : headers) { @@ -237,6 +245,7 @@ private HttpResponse sendRedirectRequest(HttpResponse response) throws IOExcepti } private String extractDataFromResponse(HttpResponse response) throws IOException { + BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuilder result = new StringBuilder(); @@ -249,6 +258,7 @@ private String extractDataFromResponse(HttpResponse response) throws IOException } private void addRegistryMountTenant() throws Exception { + Owner tenantAdminUser = new Owner(); tenantAdminUser.setUsername(TENANT_ADMIN_TENANT_AWARE_USERNAME); tenantAdminUser.setPassword(TENANT_ADMIN_PASSWORD); @@ -265,6 +275,7 @@ private void addRegistryMountTenant() throws Exception { } private Tenant getRegistryMountTenantInfo() { + User registryMountTenantAdmin = new User(); registryMountTenantAdmin.setUserName(TENANT_ADMIN_USERNAME); registryMountTenantAdmin.setPassword(TENANT_ADMIN_PASSWORD); @@ -287,6 +298,7 @@ private void createApplication() throws Exception{ } private void deleteApplication() throws Exception{ + applicationMgtRestClient.deleteApplication(appId); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLFederationWithFileBasedSPAndIDPTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLFederationWithFileBasedSPAndIDPTestCase.java index 63a8a8b9573..168d6fd1fb4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLFederationWithFileBasedSPAndIDPTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLFederationWithFileBasedSPAndIDPTestCase.java @@ -288,6 +288,7 @@ protected boolean sendSAMLResponseToWebApp(HttpClient client, String samlRespons } public boolean validateSAMLResponse(HttpResponse response, String userName) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer buffer = new StringBuffer(); String line = ""; @@ -301,6 +302,7 @@ public boolean validateSAMLResponse(HttpResponse response, String userName) thro } protected void assertLocalClaims(String resultPage) { + String claimString = resultPage.substring(resultPage.lastIndexOf("")); Map attributeMap = extractClaims(claimString); Assert.assertTrue(attributeMap.containsKey(firstNameLocalClaimURI), "Claim firstname is expected"); @@ -311,6 +313,7 @@ protected void assertLocalClaims(String resultPage) { } private Map extractClaims(String claimString) { + String[] dataArray = StringUtils.substringsBetween(claimString, ""); Map attributeMap = new HashMap<>(); String key = null; @@ -387,6 +390,7 @@ protected void removeFromIdentity(String fileName, String targetDirectory) { } protected void createUserInSecondaryIS() { + log.info("Creating User " + userName); try { UserObject user = new UserObject() @@ -402,6 +406,7 @@ protected void createUserInSecondaryIS() { } protected void deleteUserInSecondaryIS() { + log.info("Deleting User " + userName); try { scim2RestClient.deleteUser(userId); @@ -446,6 +451,7 @@ private ClaimConfiguration getClaimConfigsForSPInSecondaryIS() { } protected String getSecondaryISURI() { + return String.format("https://localhost:%s/", DEFAULT_PORT + PORT_OFFSET_1); } From 9c1031ea3e486f701c9a163c8f29a8e750794698 Mon Sep 17 00:00:00 2001 From: Ashan Thamara Palihakkara <75057725+ashanthamara@users.noreply.github.com> Date: Thu, 28 Mar 2024 02:07:20 +0530 Subject: [PATCH 5/7] Updated minor formatting issues --- .../integration/test/saml/AbstractSAMLSSOTestCase.java | 3 ++- .../integration/test/saml/SAMLInvalidIssuerTestCase.java | 1 + .../integration/test/saml/SAMLQueryProfileTestCase.java | 4 +++- .../integration/test/saml/SAMLSSOConsentTestCase.java | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/AbstractSAMLSSOTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/AbstractSAMLSSOTestCase.java index 76384cd5d47..fdb61d47dc6 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/AbstractSAMLSSOTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/AbstractSAMLSSOTestCase.java @@ -113,7 +113,6 @@ public abstract class AbstractSAMLSSOTestCase extends ISIntegrationTest { protected Lookup cookieSpecRegistry; protected RequestConfig requestConfig; - protected enum HttpBinding { HTTP_REDIRECT("HTTP-Redirect"), @@ -556,6 +555,7 @@ public ClaimConfiguration getClaimConfigurations() { * @return the created SAMLSSOServiceProviderDTO. */ public SAML2Configuration getSAMLConfigurationsForIdPInit(SAMLConfig config){ + SAML2Configuration idpInitSamlConfig = getSAMLConfigurations(config); idpInitSamlConfig.getManualConfiguration().getSingleSignOnProfile().setEnableIdpInitiatedSingleSignOn(true); return idpInitSamlConfig; @@ -568,6 +568,7 @@ public SAML2Configuration getSAMLConfigurationsForIdPInit(SAMLConfig config){ * @return the created SAMLSSOServiceProviderDTO. */ public SAMLSSOServiceProviderDTO createSsoSPDTOForSAMLartifactBinding(SAMLConfig config){ + SAMLSSOServiceProviderDTO idpInitSpDTO = createSsoSPDTO(config); idpInitSpDTO.setEnableSAML2ArtifactBinding(true); return idpInitSpDTO; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLInvalidIssuerTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLInvalidIssuerTestCase.java index 1b66a9e1b7a..9badc316fe2 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLInvalidIssuerTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLInvalidIssuerTestCase.java @@ -160,6 +160,7 @@ public void testSAMLSSOLogin() { @DataProvider(name = "samlConfigProvider") public static Object[][] samlConfigProvider(){ + return new SAMLConfig[][]{ {new SAMLConfig(TestUserMode.SUPER_TENANT_ADMIN, User.SUPER_TENANT_USER, HttpBinding.HTTP_REDIRECT, ClaimType.NONE, App.SUPER_TENANT_APP_WITH_SIGNING)}, diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLQueryProfileTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLQueryProfileTestCase.java index f27e0ddbae7..dd9849a6660 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLQueryProfileTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLQueryProfileTestCase.java @@ -60,7 +60,7 @@ import static org.wso2.identity.integration.test.util.Utils.requestMissingClaims; /** - * Test case of SAMLQuery service + * Test case of SAMLQuery service. */ public class SAMLQueryProfileTestCase extends AbstractSAMLSSOTestCase { @@ -97,6 +97,7 @@ public SAMLQueryProfileTestCase(SAMLConfig config) { @BeforeTest public void initiateTenant() throws Exception { + // Since all the requests sign with default wso2 key, upload that public key to tenants super.init(TestUserMode.TENANT_ADMIN); tenantedSamlSSOUrl = getTenantQualifiedURL(WSO2IS_URL + "samlsso", config.getUser().getTenantDomain()); @@ -350,6 +351,7 @@ private Map extractClaims(String claimString) { } public SAML2Configuration getSAMLConfigurations(SAMLConfig config) { + SAML2Configuration samlConfig = super.getSAMLConfigurations(config); samlConfig.getManualConfiguration().setRequestValidation(new SAMLRequestValidation() .enableSignatureValidation(false) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOConsentTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOConsentTestCase.java index cf3b46e9a8f..deb56e693aa 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOConsentTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOConsentTestCase.java @@ -175,6 +175,7 @@ private void testUpdatedClaims () { } private void testSAMLSSOLogout() { + try { HttpResponse response; @@ -208,6 +209,7 @@ private void updateSPClaimConfiguration() throws Exception { } private String extractDataFromResponse(HttpResponse response) throws IOException { + BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuilder result = new StringBuilder(); @@ -220,6 +222,7 @@ private String extractDataFromResponse(HttpResponse response) throws IOException } private Map extractClaims(String claimString){ + String[] dataArray = StringUtils.substringsBetween(claimString, ""); Map attributeMap = new HashMap<>(); String key = null; From 071f91002f622382dacd81cfd91c4b551349343d Mon Sep 17 00:00:00 2001 From: Ashan Thamara Palihakkara <75057725+ashanthamara@users.noreply.github.com> Date: Thu, 28 Mar 2024 20:11:52 +0530 Subject: [PATCH 6/7] Fixed minor alignment issues in method description --- .../OAuth2IDTokenEncryptionTestCase.java | 4 +- .../OAuth2ServiceAbstractIntegrationTest.java | 109 +++++++++--------- ...OAuth2ServiceSAML2BearerGrantTestCase.java | 6 +- .../oidc/OIDCAbstractIntegrationTest.java | 9 +- .../integration/test/oidc/OIDCUtilTest.java | 4 +- .../ChallengeQuestionsRestClient.java | 4 +- .../ClaimManagementRestClient.java | 6 +- .../restclients/EmailTemplatesRestClient.java | 2 +- .../IdentityGovernanceRestClient.java | 4 +- .../test/restclients/IdpMgtRestClient.java | 4 +- .../test/restclients/OAuth2RestClient.java | 10 +- .../test/restclients/RestBaseClient.java | 12 +- .../test/restclients/SCIM2RestClient.java | 14 +-- .../restclients/UserStoreMgtRestClient.java | 12 +- 14 files changed, 103 insertions(+), 97 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java index 115530223b4..2a9d4bf9592 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java @@ -465,7 +465,7 @@ private void initServiceProviderKeys() throws Exception { * @param client CloseableHttpClient object to send the login post. * @param sessionDataKey String sessionDataKey obtained. * @return Extracted sessionDataKeyConsent. - * @throws IOException If an error occurred while getting Session Data key Consent. + * @throws IOException If an error occurred while getting Session Data key Consent. * @throws URISyntaxException If an error occurred while extracting Session Data key parameter. */ private String getSessionDataKeyConsent(CloseableHttpClient client, String sessionDataKey) @@ -499,7 +499,7 @@ private String getSessionDataKeyConsent(CloseableHttpClient client, String sessi * @param audience Audience value that should be appeared in the token. * @return Boolean True if audience matches, False otherwise. * @throws ParseException If an error occurred while getting jwt. - * @throws JOSEException If an error occurred while decrypting jwt. + * @throws JOSEException If an error occurred while decrypting jwt. */ private boolean decryptAndCheckIDToken(String idToken, String audience) throws ParseException, JOSEException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java index 6cd72d9ec2b..4149c4f2d32 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java @@ -247,7 +247,7 @@ public ApplicationResponseModel getApplication(String appId) throws Exception { /** * Get Application details with a given id. * - * @param appId Application Id. + * @param appId Application Id. * @param application Application update patch object. * @throws Exception If an error occurred while updating an application. */ @@ -283,9 +283,9 @@ public SAML2ServiceProvider getSAMLInboundDetailsOfApplication(String appId) thr /** * Update Application inbound configuration details with a given id and the inbound Type. * - * @param appId Application Id. + * @param appId Application Id. * @param InboundConfig InboundConfig object. - * @param inboundType inbound configuration type. + * @param inboundType inbound configuration type. * @throws IOException If an error occurred while updating Inbound configurations of an application. */ public void updateApplicationInboundConfig(String appId, Object InboundConfig, String inboundType) @@ -402,12 +402,13 @@ private RequestedClaimConfiguration getRequestedClaim(String claimUri) { /** * Send post request with parameters. - * @param client HttpClient. + * + * @param client HttpClient. * @param urlParameters Url parameters. - * @param url Endpoint. + * @param url Endpoint. * @return HttpResponse. * @throws ClientProtocolException If an error occurred while executing http POST request. - * @throws java.io.IOException If an error occurred while executing http POST request. + * @throws java.io.IOException If an error occurred while executing http POST request. */ public HttpResponse sendPostRequestWithParameters(HttpClient client, List urlParameters, String url) throws ClientProtocolException, IOException { @@ -422,11 +423,11 @@ public HttpResponse sendPostRequestWithParameters(HttpClient client, List auth /** * Build post request and return json response object. * - * @param endpoint Endpoint. - * @param postParameters postParameters. - * @param client httpclient. - * @param authorizationHeader Authentication header. + * @param endpoint Endpoint. + * @param postParameters postParameters. + * @param client httpclient. + * @param authorizationHeader Authentication header. * @return JSON object of the response. * @throws Exception If an error occurred while executing http POST request and generating response object. */ @@ -934,7 +937,7 @@ private JSONObject responseObject(HttpClient client, String endpoint, List getNameValuePairs(OIDCApplication application, /** * Set sessionDataKey. - * @param response response + * + * @param response response * @param keyPositionMap map to preserve the sessionDataKey. * @throws IOException if an error occurs when extracting data from the response. */ diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java index 0c51b506378..3f293197e09 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ChallengeQuestionsRestClient.java @@ -50,8 +50,8 @@ public ChallengeQuestionsRestClient(String serverUrl, Tenant tenantInfo) { /** * Set Answers for the user challenge questions * - * @param userId userId. - * @param questionSetId Challenge Question Set id. + * @param userId userId. + * @param questionSetId Challenge Question Set id. * @param challengeAsnwerObj Challenge Question request object. * @throws IOException If an error occurred while setting the challenge question answer. */ diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java index 372d049b6b1..b48eb0dbe98 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ClaimManagementRestClient.java @@ -61,7 +61,7 @@ public ClaimManagementRestClient(String backendURL, Tenant tenantInfo) { /** * Add External Claim. * - * @param dialectId Claim dialect id. + * @param dialectId Claim dialect id. * @param claimRequest External Claim request object. * @throws Exception If an error occurred while adding an external claim. */ @@ -80,7 +80,7 @@ public String addExternalClaim(String dialectId, ExternalClaimReq claimRequest) * Get an External Claim. * * @param dialectId Claim dialect id. - * @param claimId claim id. + * @param claimId Claim id. * @return JSONObject JSON object of the response. * @throws Exception If an error occurred while getting an external claim. */ @@ -98,7 +98,7 @@ public JSONObject getExternalClaim(String dialectId, String claimId) throws Exce * Delete an External Claim. * * @param dialectId Claim dialect id. - * @param claimId claim id. + * @param claimId Claim id. * @throws IOException If an error occurred while deleting an external claim. */ public void deleteExternalClaim(String dialectId, String claimId) throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java index 320515c9bd0..7c261f1cb9a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/EmailTemplatesRestClient.java @@ -61,7 +61,7 @@ public EmailTemplatesRestClient(String backendURL, Tenant tenantInfo) { * Get Email template. * * @param templateTypeId Template type id. - * @param templateId Template id. + * @param templateId Template id. * @return JSONObject with email template details. * @throws Exception If an error occurred while getting Email Template. */ diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java index 0479859b9a8..58f0b9d732d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdentityGovernanceRestClient.java @@ -62,8 +62,8 @@ public IdentityGovernanceRestClient(String backendURL, Tenant tenantInfo) { /** * Update connector properties. * - * @param categoryId Connector category id. - * @param connectorId Connector id. + * @param categoryId Connector category id. + * @param connectorId Connector id. * @param connectorPatch Connector patch request object. * @throws IOException If an error occurred while updating the governance connectors. */ diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java index 33ba21ffe5c..3ede99d378c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/IdpMgtRestClient.java @@ -74,7 +74,7 @@ public String createIdentityProvider(IdentityProviderPOSTRequest idpCreateReqObj /** * Get an Identity Provider's federated authenticator * - * @param idpId identity provider id. + * @param idpId identity provider id. * @param federatedAuthenticatorId Federated Authenticator id. * @return JSONObject with Federated Authenticator details. * @throws Exception If an error occurred while getting idp's federated authenticator. @@ -93,7 +93,7 @@ public JSONObject getIdpFederatedAuthenticator(String idpId, String federatedAut /** * Update an Identity Provider claim configurations. * - * @param idpId Identity Provider Id. + * @param idpId Identity Provider Id. * @param idpClaims Identity Provider claim request object. * @throws IOException If an error occurred while updating idp claim configurations. */ diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java index 1477055996d..4e7c0d50a3e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java @@ -84,7 +84,7 @@ public OAuth2RestClient(String backendUrl, Tenant tenantInfo) { * * @param application Application Model with application creation details. * @return Id of the created application. - * @throws IOException If an error occurred while creating an application. + * @throws IOException If an error occurred while creating an application. * @throws JSONException If an error occurred while creating the json string. */ public String createApplication(ApplicationModel application) throws IOException, JSONException { @@ -156,7 +156,7 @@ public List getApplicationsByClientId(String clientId) thro /** * Update an existing application. * - * @param appId Application id. + * @param appId Application id. * @param application Updated application patch object. * @throws IOException If an error occurred while updating an application. */ @@ -245,9 +245,9 @@ private String getConfig(String appId, String inboundType) throws Exception { /** * Update inbound configuration details of an application. * - * @param appId Application id. + * @param appId Application id. * @param inboundConfig Inbound configuration object to be updated. - * @param inboundType Type of the inbound configuration. + * @param inboundType Type of the inbound configuration. * @throws IOException If an error occurred while updating an inbound configuration. */ public void updateInboundDetailsOfApplication(String appId, Object inboundConfig, String inboundType) @@ -266,7 +266,7 @@ public void updateInboundDetailsOfApplication(String appId, Object inboundConfig /** * Delete an Inbound Configuration. * - * @param appId Application id. + * @param appId Application id. * @param inboundType Inbound Type to be deleted. * @throws IOException If an error occurred while deleting an inbound configuration. */ diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java index e1adcdde07f..55a4f34e813 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java @@ -124,7 +124,7 @@ public CloseableHttpResponse getResponseOfHttpPost(String endPointUrl, String js * Execute and get the response of HTTP GET. * * @param endPointUrl REST endpoint. - * @param headers header list of the request. + * @param headers Header list of the request. * @return Response of the Http request. * @throws IOException If an error occurred while executing http GET request. */ @@ -141,8 +141,8 @@ public CloseableHttpResponse getResponseOfHttpGet(String endPointUrl, Header[] h * Execute and get the response of HTTP PATCH. * * @param endPointUrl REST endpoint. - * @param jsonRequest json body. - * @param headers header list of the request. + * @param jsonRequest Json body. + * @param headers Header list of the request. * @return Response of the Http request. * @throws IOException If an error occurred while executing http PATCH request. */ @@ -159,7 +159,7 @@ public CloseableHttpResponse getResponseOfHttpPatch(String endPointUrl, String j * Execute and get the response of HTTP DELETE. * * @param endPointUrl REST endpoint. - * @param headers header list of the request. + * @param headers Header list of the request. * @return Response of the Http request. * @throws IOException If an error occurred while executing http DELETE request. */ @@ -175,8 +175,8 @@ public CloseableHttpResponse getResponseOfHttpDelete(String endPointUrl, Header[ * Execute and get the response of HTTP PUT. * * @param endPointUrl REST endpoint. - * @param jsonRequest json body. - * @param headers header list of the request. + * @param jsonRequest Json body. + * @param headers Header list of the request. * @return Response of the Http request. * @throws IOException If an error occurred while executing http PUT request. */ diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java index e748d4f9f60..a81654c4259 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/SCIM2RestClient.java @@ -88,8 +88,8 @@ public String createUser(UserObject userInfo) throws Exception { /** * Get the details of a user. * - * @param userId id of the user. - * @param attribute requested user attributes + * @param userId Id of the user. + * @param attribute Requested user attributes. * @return JSONObject of the HTTP response. * @throws Exception If an error occurred while getting a user. */ @@ -110,8 +110,8 @@ public JSONObject getUser(String userId, String attribute) throws Exception { /** * Update the details of an existing user. * - * @param patchUserInfo user patch request object. - * @param userId id of the user. + * @param patchUserInfo User patch request object. + * @param userId Id of the user. * @throws IOException If an error occurred while updating a user. */ public void updateUser(PatchOperationRequestObject patchUserInfo, String userId) throws IOException { @@ -128,7 +128,7 @@ public void updateUser(PatchOperationRequestObject patchUserInfo, String userId) /** * Search a user and get requested attributes. * - * @param userSearchReq json String of user search request. + * @param userSearchReq Json String of user search request. * @return JSONObject of the user search response. * @throws Exception If an error occurred while getting a user. */ @@ -146,7 +146,7 @@ public JSONObject searchUser(String userSearchReq) throws Exception { /** * Delete an existing user. * - * @param userId id of the user. + * @param userId Id of the user. * @throws IOException If an error occurred while deleting a user. */ public void deleteUser(String userId) throws IOException { @@ -182,7 +182,7 @@ public String addRole(RoleRequestObject roleInfo) throws Exception { * Update an existing role. * * @param patchRoleInfo Role patch request object. - * @param roleId Role id. + * @param roleId Role id. * @throws IOException If an error occurred while updating a role. */ public void updateUserRole(PatchOperationRequestObject patchRoleInfo, String roleId) throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java index bb3ce91e179..a2e5e105a80 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserStoreMgtRestClient.java @@ -61,12 +61,12 @@ public UserStoreMgtRestClient(String backendURL, Tenant tenantInfo) { /** * Add a secondary user store. * - * @param UserStoreReq Secondary user store request object. + * @param userStoreReq Secondary user store request object. * @throws IOException If an error occurred while adding a user store. */ - public String addUserStore(UserStoreReq UserStoreReq) throws IOException { + public String addUserStore(UserStoreReq userStoreReq) throws IOException { - String jsonRequest = toJSONString(UserStoreReq); + String jsonRequest = toJSONString(userStoreReq); try (CloseableHttpResponse response = getResponseOfHttpPost(userStoreBasePath, jsonRequest, getHeaders())) { String[] locationElements = response.getHeaders(LOCATION_HEADER)[0].toString().split(PATH_SEPARATOR); return locationElements[locationElements.length - 1]; @@ -87,7 +87,7 @@ public JSONArray getUserStores() throws Exception { } /** - * Delete a user store + * Delete a user store. * * @param domain User store domain(id). * @throws IOException If an error occurred while deleting a user store. @@ -103,9 +103,9 @@ public void deleteUserStore(String domain) throws IOException { } /** - * Check user store deployment + * Check user store deployment. * - * @param domain User Store name + * @param domain User Store name. * @return boolean response of the user store deployment. * @throws Exception If an error occurred while checking the user store creation. */ From ac6369aec5b694c1a0096781b4a722468a48f250 Mon Sep 17 00:00:00 2001 From: Ashan Thamara Palihakkara <75057725+ashanthamara@users.noreply.github.com> Date: Thu, 28 Mar 2024 20:21:33 +0530 Subject: [PATCH 7/7] Fixed minor formatting issue --- .../test/auth/SecondaryStoreUserLoginTestCase.java | 14 +++++++------- ...ccessTokenWithConsentedTokenColumnTestCase.java | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java index 03a7259a9a8..598c449f16a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java @@ -120,7 +120,7 @@ public void testInit() throws Exception { addUserIntoJDBCUserStore(PRIMARY_USERNAME, PRIMARY_PASSWORD, false); addUserIntoJDBCUserStore(SECONDARY_USERNAME, SECONDARY_PASSWORD, true); - // Creating, registering and starting application on tomcat + // Creating, registering and starting application on tomcat. createAndRegisterPlaygroundApplication(); startTomcat(); } @@ -131,9 +131,9 @@ public void testUserLogin(String username, String password) throws Exception { CookieStore cookieStore = new BasicCookieStore(); client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); - // Sending authorization request to IS + // Sending authorization request to IS. sendAuthorizedPost(); - // User (resource owner) authentication + // User (resource owner) authentication. HttpResponse response = sendLoginPostForCustomUsers(client, sessionDataKey, username, password); Assert.assertNotNull(response, "Login request failed. Login response is null."); Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION); @@ -148,7 +148,7 @@ public void testUserLogin(String username, String password) throws Exception { Assert.assertNotNull(keyValues, "SessionDataKeyConsent key value is null"); String sessionDataKeyConsent = keyValues.get(0).getValue(); EntityUtils.consume(response.getEntity()); - // Authorization + // Authorization. checkAuthorizationCode(sessionDataKeyConsent); } @@ -201,7 +201,7 @@ private void checkAuthorizationCode(String sessionDataKeyConsent) throws Excepti String locationHeaderValue = locationHeader.getValue(); Assert.assertNotNull(locationHeader, "Approval Location header is null."); String authorizationCodeString = StringUtils.substringAfterLast(locationHeaderValue, "?code="); - // Assuring that the authorization code is received, which confirms that the login is successful + // Assuring that the authorization code is received, which confirms that the login is successful. Assert.assertNotNull(authorizationCodeString, "Authorization code not present, hence login unsuccessful."); EntityUtils.consume(response.getEntity()); } @@ -276,13 +276,13 @@ private void stopTomcat() throws LifecycleException { private void addSecondaryJDBCUserStore() throws Exception { - //creating database + // Creating database. H2DataBaseManager dbmanager = new H2DataBaseManager("jdbc:h2:" + ServerConfigurationManager.getCarbonHome() + "/repository/database/" + USER_STORE_DB_NAME, DB_USER_NAME, DB_USER_PASSWORD); dbmanager.executeUpdate(new File(ServerConfigurationManager.getCarbonHome() + "/dbscripts/h2.sql")); dbmanager.disconnect(); - // Register a secondary user store + // Register a secondary user store. UserStoreReq userStore = new UserStoreReq() .typeId(USER_STORE_TYPE) .name(DOMAIN_ID) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceAuthCodeGrantJWTAccessTokenWithConsentedTokenColumnTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceAuthCodeGrantJWTAccessTokenWithConsentedTokenColumnTestCase.java index 6c4f32f5d5f..3716f8ec2bc 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceAuthCodeGrantJWTAccessTokenWithConsentedTokenColumnTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/consented/token/OAuth2ServiceAuthCodeGrantJWTAccessTokenWithConsentedTokenColumnTestCase.java @@ -110,8 +110,8 @@ public void testSendAuthorizedPost() throws Exception { urlParameters.add(new BasicNameValuePair("callbackurl", OAuth2Constant.CALLBACK_URL)); urlParameters.add(new BasicNameValuePair("authorizeEndpoint", OAuth2Constant.APPROVAL_URL)); urlParameters.add(new BasicNameValuePair("authorize", OAuth2Constant.AUTHORIZE_PARAM)); - // email scope is to retrieve the email address of the user. - // address scope is to retrieve the country number of the user. + // Email scope is to retrieve the email address of the user. + // Address scope is to retrieve the country of the user. urlParameters.add(new BasicNameValuePair("scope", OAuth2Constant.OAUTH2_SCOPE_OPENID + " " + OAuth2Constant.OAUTH2_SCOPE_EMAIL + " " + OAuth2Constant.OAUTH2_SCOPE_ADDRESS)); @@ -194,8 +194,8 @@ public void testGetAccessToken() throws Exception { Secret clientSecret = new Secret(consumerSecret); ClientAuthentication clientAuth = new ClientSecretBasic(clientID, clientSecret); URI tokenEndpoint = new URI(OAuth2Constant.ACCESS_TOKEN_ENDPOINT); - // email scope is to retrieve the email address of the user. - // address scope is to retrieve the country of the user. + // Email scope is to retrieve the email address of the user. + // Address scope is to retrieve the country of the user. TokenRequest request = new TokenRequest(tokenEndpoint, clientAuth, authorizationCodeGrant, new Scope(OAuth2Constant.OAUTH2_SCOPE_OPENID, OAuth2Constant.OAUTH2_SCOPE_EMAIL, OAuth2Constant.OAUTH2_SCOPE_ADDRESS));
", "", "