Skip to content

Commit

Permalink
Merge pull request #20096 from ashanthamara/bug-fixing
Browse files Browse the repository at this point in the history
Fixed minor-formatting issues in integration test files
  • Loading branch information
UdeshAthukorala authored Mar 28, 2024
2 parents 537be0f + ac6369a commit d1bcc7f
Show file tree
Hide file tree
Showing 57 changed files with 611 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -171,6 +174,7 @@ protected String getISResourceLocation() {
}

protected void enableAccountLocking() throws Exception {

identityGovernanceRestClient = new IdentityGovernanceRestClient(serverURL, tenantInfo);

PropertyReq property = new PropertyReq();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void testOIDCLogout() throws IOException {
}

private void createOIDCApplication() throws Exception {

ApplicationModel application = new ApplicationModel();

List<String> grantTypes = new ArrayList<>();
Expand Down Expand Up @@ -310,6 +311,7 @@ private List<NameValuePair> getOIDCInitiationRequestParams() {
}

private void addAdminUser() throws Exception {

UserObject userInfo = new UserObject();
userInfo.setUserName(USERNAME);
userInfo.setPassword(PASSWORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 If an error occurred while creating the application.
*/
private ApplicationResponseModel createApp() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void testInit() throws Exception {

@AfterClass(alwaysRun = true)
public void atEnd() throws Exception {

deleteApp(application.getId());

consumerKey = null;
Expand Down Expand Up @@ -437,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 {

Expand All @@ -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 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 {
Expand Down Expand Up @@ -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 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -76,6 +77,7 @@ public void testInit() throws Exception {

@AfterClass(alwaysRun = true)
public void atEnd() throws Exception {

deleteApp(application.getId());

consumerKey = null;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -189,6 +190,7 @@ public void testSendAuthorizedPostAfterRoleUpdate() throws Exception {
}

private UserObject getUserCreationInfo() {

UserObject userInfo = new UserObject();

userInfo.setUserName(USER_USERNAME);
Expand Down Expand Up @@ -221,13 +223,15 @@ private UserObject getUserCreationInfo() {
}

private RoleRequestObject getRoleCreationInfo() {

RoleRequestObject roleInfo = new RoleRequestObject();
roleInfo.setDisplayName(OAUTH_ROLE);

return roleInfo;
}

private PatchOperationRequestObject getAddUserPatchRole(String userId) {

RoleItemAddGroupobj patchRoleItem = new RoleItemAddGroupobj();
patchRoleItem.setOp(RoleItemAddGroupobj.OpEnum.ADD);
patchRoleItem.setPath(USERS_PATH);
Expand Down
Loading

0 comments on commit d1bcc7f

Please sign in to comment.