Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update integration tests to use REST APIs in master branch (III) #16354

Merged
merged 42 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
30d609b
Updated OAuth2ServiceWithConsentedTokenColumnAbstractIntegrationTest
ashanthamara Jul 19, 2023
91aa872
Updated OAuth2ServiceAuthCodeGrantJWTAccessTokenWithConsentedTokenCol…
ashanthamara Jul 19, 2023
d9f374d
Updated OAuth2ServicePasswordGrantJWTAccessTokenWithConsentedTokenCol…
ashanthamara Jul 19, 2023
2c7838b
Updated AccountLockWhileCaseInsensitiveUserFalseTestCase
ashanthamara Jul 20, 2023
e3b8a0c
Updated OIDCAuthCodeGrantSSODifferentSubjectIDTestCase
ashanthamara Aug 1, 2023
59ebd73
Updated OIDCAuthCodeGrantSSOTestCase
ashanthamara Aug 1, 2023
0130586
Updated OIDCAuthzCodeIdTokenValidationTestCase
ashanthamara Aug 1, 2023
fe6d3cd
Updated OIDCFileBasedSkipLoginConsentTestCase
ashanthamara Aug 1, 2023
0d22f4b
Created UserStoreMgtRestClient
ashanthamara Aug 1, 2023
ad396f3
Updated OIDCPasswordGrantTest
ashanthamara Aug 1, 2023
37c300c
Updated OIDCSPWiseSkipLoginConsentTestCase
ashanthamara Aug 1, 2023
2e95c24
Updated OIDCSSOConsentTestCase
ashanthamara Aug 1, 2023
3a121db
Updated OIDCAbstractIntegrationTest
ashanthamara Aug 1, 2023
4fcaeab
Modified AbstractIdentityFederationTestCase
ashanthamara Aug 1, 2023
9cd33c4
Updated OIDCIdentityFederationTestCase
ashanthamara Aug 1, 2023
42c3581
Updated OIDCFederatedIdpInitLogoutTest
ashanthamara Aug 1, 2023
a245b43
Modified few files
ashanthamara Aug 1, 2023
2017332
Updated OIDCUtilTest
ashanthamara Aug 1, 2023
92bc05e
Modified AccountLockEnabledTestCase
ashanthamara Aug 1, 2023
9947d86
Merge branch 'master' into update_int_tests
ashanthamara Aug 1, 2023
a6caade
Updated ChangeACSUrlTestCase
ashanthamara Aug 2, 2023
7bd6659
Updated IDPMetadataTestCase
ashanthamara Aug 2, 2023
e8613ac
Created TenantMgtRestClient
ashanthamara Aug 3, 2023
33f74cf
Updated RegistryMountTestCase
ashanthamara Aug 3, 2023
ed161fd
Updated SAMLErrorResponseTestCase
ashanthamara Aug 3, 2023
0789f92
Updated SAMLFederationDynamicQueryParametersTestCase
ashanthamara Aug 3, 2023
51cc2eb
Created GroupRequestObject class
ashanthamara Aug 4, 2023
477026d
Updated SecondaryStoreUserLoginTestCase
ashanthamara Aug 4, 2023
4e6c3d1
Updated SAMLFederationWithFileBasedSPAndIDPTestCase
ashanthamara Aug 4, 2023
8796c76
Minor change
ashanthamara Aug 4, 2023
24845ab
Merge branch 'master' into update_int_tests
ashanthamara Aug 4, 2023
fb609ab
Merge branch 'master' into update_int_tests
ashanthamara Aug 6, 2023
8efbce9
Change tenant execution order in passive sts test
ashanthamara Aug 7, 2023
d5e3196
revert commit
ashanthamara Aug 7, 2023
faa8006
added debug logs
ashanthamara Aug 7, 2023
6000332
Merge branch 'master' into update_int_tests
ashanthamara Aug 7, 2023
8856763
Updated TestPassiveSTS and modified debug logs
ashanthamara Aug 8, 2023
cda3975
Revert "Updated TestPassiveSTS and modified debug logs"
ashanthamara Aug 8, 2023
aef7e13
Modified debug logs
ashanthamara Aug 8, 2023
1aaa8b7
Remove debug logs in TestPassiveSTS
ashanthamara Aug 8, 2023
2e2720d
Minor change in a comment
ashanthamara Aug 9, 2023
0152c09
Merge branch 'master' into update_int_tests
ashanthamara Aug 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.RFC6265CookieSpecProvider;
import org.json.JSONException;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.extensions.servers.carbonserver.MultipleServersManager;
import org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider;
Expand All @@ -46,6 +47,13 @@
import org.wso2.identity.integration.common.utils.CarbonTestServerManager;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.base.TestDataHolder;
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.ApplicationResponseModel;
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.SAML2ServiceProvider;
import org.wso2.identity.integration.test.rest.api.server.idp.v1.model.IdentityProviderPOSTRequest;
import org.wso2.identity.integration.test.restclients.IdpMgtRestClient;
import org.wso2.identity.integration.test.restclients.OAuth2RestClient;
import org.wso2.identity.integration.test.utils.CommonConstants;
import org.wso2.identity.integration.test.utils.IdentityConstants;

Expand All @@ -63,6 +71,8 @@ public abstract class AbstractIdentityFederationTestCase extends ISIntegrationTe
private Map<Integer, IdentityProviderMgtServiceClient> identityProviderMgtServiceClients;
private Map<Integer, SAMLSSOConfigServiceClient> samlSSOConfigServiceClients;
private Map<Integer, OauthAdminClient> oauthAdminClients;
private Map<Integer, OAuth2RestClient> applicationManagementRestClients;
private Map<Integer, IdpMgtRestClient> identityProviderMgtRestClients;
protected Map<Integer, AutomationContext> automationContextMap;
private MultipleServersManager manager;
protected static final int DEFAULT_PORT = CommonConstants.IS_DEFAULT_HTTPS_PORT;
Expand All @@ -71,6 +81,8 @@ public void initTest() throws Exception {

super.init();
TestDataHolder testDataHolder = TestDataHolder.getInstance();
applicationManagementRestClients = new HashMap<>();
identityProviderMgtRestClients = new HashMap<>();
applicationManagementServiceClients = new HashMap<>();
identityProviderMgtServiceClients = new HashMap<>();
samlSSOConfigServiceClients = new HashMap<>();
Expand Down Expand Up @@ -137,6 +149,26 @@ public void createServiceClients(int portOffset, String sessionCookie,
}
}

public void createServiceClients(int portOffset, IdentityConstants.ServiceClientType[] adminClients)
throws Exception {

if (adminClients == null) {
return;
}

serverURL = automationContextMap.get(portOffset).getContextUrls().getSecureServiceUrl()
.replace("/services", "");
String serviceUrl = getSecureServiceUrl(portOffset, serverURL);

for (IdentityConstants.ServiceClientType clientType : adminClients) {
if (IdentityConstants.ServiceClientType.APPLICATION_MANAGEMENT.equals(clientType)) {
applicationManagementRestClients.put(portOffset, new OAuth2RestClient(serviceUrl, tenantInfo));
} else if (IdentityConstants.ServiceClientType.IDENTITY_PROVIDER_MGT.equals(clientType)) {
identityProviderMgtRestClients.put(portOffset, new IdpMgtRestClient(serviceUrl, tenantInfo));
}
}
}

public void addServiceProvider(int portOffset, String applicationName) throws Exception {

ServiceProvider serviceProvider = new ServiceProvider();
Expand All @@ -146,6 +178,31 @@ public void addServiceProvider(int portOffset, String applicationName) throws Ex
applicationManagementServiceClients.get(portOffset).createApplication(serviceProvider);
}

public String addApplication(int portOffset, ApplicationModel applicationModel) throws JSONException, IOException {

return applicationManagementRestClients.get(portOffset).createApplication(applicationModel);
}

public ApplicationResponseModel getApplication(int portOffset, String appId) throws Exception {

return applicationManagementRestClients.get(portOffset).getApplication(appId);
}

public OpenIDConnectConfiguration getOIDCInboundDetailsOfApplication(int portOffset, String appId) throws Exception {

return applicationManagementRestClients.get(portOffset).getOIDCInboundDetails(appId);
}

public SAML2ServiceProvider getSAMLInboundDetailsOfApplication(int portOffset, String appId) throws Exception {

return applicationManagementRestClients.get(portOffset).getSAMLInboundDetails(appId);
}

public void deleteApplication(int portOffset, String appId) throws Exception {

applicationManagementRestClients.get(portOffset).deleteApplication(appId);
}

public ServiceProvider getServiceProvider(int portOffset, String applicationName)
throws Exception {

Expand All @@ -169,6 +226,16 @@ public void addIdentityProvider(int portOffset, IdentityProvider identityProvide
identityProviderMgtServiceClients.get(portOffset).addIdP(identityProvider);
}

public String addIdentityProvider(int portOffset, IdentityProviderPOSTRequest idp) throws Exception {

return identityProviderMgtRestClients.get(portOffset).createIdentityProvider(idp);
}

public void deleteIdp(int portOffset, String idpId) throws Exception {

identityProviderMgtRestClients.get(portOffset).deleteIdp(idpId);
}

public IdentityProvider getIdentityProvider(int portOffset, String idPName) throws Exception {

return identityProviderMgtServiceClients.get(portOffset).getIdPByName(idPName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider;
import org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO;
import org.wso2.identity.integration.common.clients.UserManagementClient;
import org.wso2.identity.integration.common.clients.user.store.config.UserStoreConfigAdminServiceClient;
import org.wso2.identity.integration.common.utils.UserStoreConfigUtils;
import org.wso2.carbon.automation.test.utils.dbutils.H2DataBaseManager;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.identity.integration.test.base.TomcatInitializerTestCase;
import org.wso2.identity.integration.test.oidc.OIDCAbstractIntegrationTest;
import org.wso2.identity.integration.test.oidc.OIDCUtilTest;
import org.wso2.identity.integration.test.oidc.bean.OIDCApplication;
import org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreReq;
import org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreReq.Property;
import org.wso2.identity.integration.test.rest.api.user.common.model.GroupRequestObject;
import org.wso2.identity.integration.test.rest.api.user.common.model.GroupRequestObject.MemberItem;
import org.wso2.identity.integration.test.rest.api.user.common.model.ListObject;
import org.wso2.identity.integration.test.rest.api.user.common.model.RoleRequestObject;
import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject;
import org.wso2.identity.integration.test.restclients.UserStoreMgtRestClient;
import org.wso2.identity.integration.test.util.Utils;
import org.wso2.identity.integration.test.utils.DataExtractUtil;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -73,21 +79,30 @@ public class SecondaryStoreUserLoginTestCase extends OIDCAbstractIntegrationTest
private static final String PRIMARY_PASSWORD = "primaryPassword";
private static final String SECONDARY_USERNAME = "secondaryUsername";
private static final String SECONDARY_PASSWORD = "secondaryPassword";
private static final UserStoreConfigUtils USER_STORE_CONFIG_UTILS = new UserStoreConfigUtils();
private static final String PERMISSION_LOGIN = "/permission/admin/login";
private static final String JDBC_CLASS = "org.wso2.carbon.user.core.jdbc.UniqueIDJDBCUserStoreManager";
private static final String DOMAIN_ID = "WSO2TEST.COM";
private static final String PRIMARY_USER_GROUP = "jdbcUserStoreGroup";
private static final String PRIMARY_USER_ROLE = "jdbcUserStoreRole";
private static final String SECONDARY_USER_ROLE = DOMAIN_ID + "/" + "jdbcUserStoreRole";
private static final String SECONDARY_USER_GROUP = DOMAIN_ID + "/" + "jdbcSecondaryUserStoreGroup";
private static final String SECONDARY_USER_ROLE = "jdbcSecondaryUserStoreRole";
private static final String USER_STORE_DB_NAME = "SECONDARY_USER_STORE_DB";
private static final String USER_STORE_TYPE = "VW5pcXVlSURKREJDVXNlclN0b3JlTWFuYWdlcg";
private static final Log LOG = LogFactory.getLog(TomcatInitializerTestCase.class);
private static final String DB_USER_NAME = "wso2automation";
private static final String DB_USER_PASSWORD = "wso2automation";
private OIDCApplication playgroundApp;
private HttpClient client;
private String sessionDataKey;
private UserStoreConfigAdminServiceClient userStoreConfigAdminServiceClient;
private UserManagementClient userMgtClient;
private Tomcat tomcat;
private String clientID;
private UserStoreMgtRestClient userStoreMgtRestClient;
private String userStoreId;
private String secondaryUserStoreRoleId;
private String secondaryUserStoreUserId;
private String primaryUserStoreUserId;
private String primaryUserStoreRoleId;
private String secondaryUserStoreGroupId;
private String primaryUserStoreGroupId;

@DataProvider(name = "userCredentialProvider")
public static Object[][] userCredentialProvider() {
Expand All @@ -99,20 +114,12 @@ public static Object[][] userCredentialProvider() {
public void testInit() throws Exception {

super.init();
userStoreMgtRestClient = new UserStoreMgtRestClient(serverURL, tenantInfo);
addSecondaryJDBCUserStore();

// Register a secondary user store
userStoreConfigAdminServiceClient = new UserStoreConfigAdminServiceClient(backendURL, sessionCookie);
userMgtClient = new UserManagementClient(backendURL, getSessionCookie());
UserStoreDTO userStoreDTO = userStoreConfigAdminServiceClient.createUserStoreDTO(JDBC_CLASS, DOMAIN_ID,
USER_STORE_CONFIG_UTILS.getJDBCUserStoreProperties(USER_STORE_DB_NAME));
userStoreConfigAdminServiceClient.addUserStore(userStoreDTO);
Thread.sleep(5000);
boolean isSecondaryUserStoreDeployed = USER_STORE_CONFIG_UTILS.waitForUserStoreDeployment(
userStoreConfigAdminServiceClient, DOMAIN_ID);
Assert.assertTrue(isSecondaryUserStoreDeployed);
// Creating users in the primary and secondary user stores
addUserIntoJDBCUserStore(PRIMARY_USERNAME, PRIMARY_PASSWORD, false);
addUserIntoJDBCUserStore(SECONDARY_USERNAME, SECONDARY_PASSWORD, true);

// Creating, registering and starting application on tomcat
createAndRegisterPlaygroundApplication();
startTomcat();
Expand Down Expand Up @@ -149,9 +156,13 @@ public void testUserLogin(String username, String password) throws Exception {
public void atEnd() throws Exception {

stopTomcat();
userStoreConfigAdminServiceClient.deleteUserStore(DOMAIN_ID);
userMgtClient.deleteUser(PRIMARY_USERNAME);
userMgtClient.deleteUser(DOMAIN_ID + "/" + SECONDARY_USERNAME);
scim2RestClient.deleteUser(primaryUserStoreUserId);
scim2RestClient.deleteUser(secondaryUserStoreUserId);
scim2RestClient.deleteGroup(primaryUserStoreGroupId);
scim2RestClient.deleteGroup(secondaryUserStoreGroupId);
scim2RestClient.deleteRole(primaryUserStoreRoleId);
scim2RestClient.deleteRole(secondaryUserStoreRoleId);
userStoreMgtRestClient.deleteUserStore(userStoreId);
deleteApplication(playgroundApp);
clear();
}
Expand Down Expand Up @@ -201,25 +212,42 @@ private void createAndRegisterPlaygroundApplication() throws Exception {
playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.lastNameClaimUri);
ServiceProvider serviceProvider = new ServiceProvider();
createApplication(serviceProvider, playgroundApp);

createApplication(playgroundApp);
clientID = playgroundApp.getClientId();
}

private void addUserIntoJDBCUserStore(String username, String password, boolean isSecondaryStoreUser)
throws Exception {

if (isSecondaryStoreUser) {
userMgtClient.addRole(SECONDARY_USER_ROLE, null, new String[]{PERMISSION_LOGIN});
Assert.assertTrue(userMgtClient.roleNameExists(SECONDARY_USER_ROLE), "Role name doesn't exist");
userMgtClient.addUser(DOMAIN_ID + "/" + username, password, new String[]{SECONDARY_USER_ROLE}, null);
Assert.assertTrue(userMgtClient.userNameExists(SECONDARY_USER_ROLE, DOMAIN_ID + "/" + username),
"User is not created.");
secondaryUserStoreUserId = scim2RestClient.createUser(new UserObject()
.userName(DOMAIN_ID + "/" + username)
.password(password));

secondaryUserStoreGroupId = scim2RestClient.createGroup(new GroupRequestObject()
.displayName(SECONDARY_USER_GROUP)
.addMember(new MemberItem().value(secondaryUserStoreUserId)));

secondaryUserStoreRoleId = scim2RestClient.addRole(new RoleRequestObject()
.displayName(SECONDARY_USER_ROLE)
.addPermissions(PERMISSION_LOGIN)
.addUsers(new ListObject().value(secondaryUserStoreUserId))
.addGroups(new ListObject().value(secondaryUserStoreGroupId)));
} else {
userMgtClient.addRole(PRIMARY_USER_ROLE, null, new String[]{PERMISSION_LOGIN});
Assert.assertTrue(userMgtClient.roleNameExists(PRIMARY_USER_ROLE), "Role name doesn't exist");
userMgtClient.addUser(username, password, new String[]{PRIMARY_USER_ROLE}, null);
Assert.assertTrue(userMgtClient.userNameExists(PRIMARY_USER_ROLE, username), "User is not created.");
primaryUserStoreUserId = scim2RestClient.createUser(new UserObject()
.userName(username)
.password(password));

primaryUserStoreGroupId = scim2RestClient.createGroup(new GroupRequestObject()
.displayName(PRIMARY_USER_GROUP)
.addMember(new MemberItem().value(primaryUserStoreUserId)));

primaryUserStoreRoleId = scim2RestClient.addRole(new RoleRequestObject()
.displayName(PRIMARY_USER_ROLE)
.addPermissions(PERMISSION_LOGIN)
.addUsers(new ListObject().value(primaryUserStoreUserId))
.addGroups(new ListObject().value(primaryUserStoreGroupId)));
}
}

Expand All @@ -245,4 +273,59 @@ private void stopTomcat() throws LifecycleException {
tomcat.destroy();
LOG.info("Tomcat server stopped.");
}

private void addSecondaryJDBCUserStore() throws Exception {

//creating database
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved
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
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved
UserStoreReq userStore = new UserStoreReq()
.typeId(USER_STORE_TYPE)
.name(DOMAIN_ID)
.addPropertiesItem(new Property()
.name("driverName")
.value("org.h2.Driver"))
.addPropertiesItem(new Property()
.name("url")
.value("jdbc:h2:./repository/database/" + USER_STORE_DB_NAME))
.addPropertiesItem(new Property()
.name("userName")
.value(DB_USER_NAME))
.addPropertiesItem(new Property()
.name("password")
.value(DB_USER_PASSWORD))
.addPropertiesItem(new Property()
.name("PasswordJavaRegEx")
.value("^[\\S]{5,30}$"))
.addPropertiesItem(new Property()
.name("UsernameJavaRegEx")
.value("^[\\S]{5,30}$"))
.addPropertiesItem(new Property()
.name("Disabled")
.value("false"))
.addPropertiesItem(new Property()
.name("PasswordDigest")
.value("SHA-256"))
.addPropertiesItem(new Property()
.name("StoreSaltedPassword")
.value("true"))
.addPropertiesItem(new Property()
.name("SCIMEnabled")
.value("true"))
.addPropertiesItem(new Property()
.name("CountRetrieverClass")
.value("org.wso2.carbon.identity.user.store.count.jdbc.JDBCUserStoreCountRetriever"))
.addPropertiesItem(new Property()
.name("UserIDEnabled")
.value("true"));

userStoreId = userStoreMgtRestClient.addUserStore(userStore);
Thread.sleep(5000);
boolean isSecondaryUserStoreDeployed = userStoreMgtRestClient.waitForUserStoreDeployment(DOMAIN_ID);
Assert.assertTrue(isSecondaryUserStoreDeployed);
}
}
Loading