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 #15906

Merged
merged 71 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
a558b9b
test
ashanthamara May 18, 2023
9edb2ae
Merge branch '7.x.x-ashan' into 7.x.x
ashanthamara May 18, 2023
57c0c94
Created AdditionalSpProperties object class
ashanthamara May 24, 2023
84312b6
Created ApplicationPatchModel object class
ashanthamara May 24, 2023
bdea09b
Created ApplicationResponseModel object class
ashanthamara May 24, 2023
bf6d005
Created InboundProtocolListItem object class
ashanthamara May 24, 2023
071a14d
Created InboundProtocolsListResponse object class
ashanthamara May 24, 2023
4e83436
Created Claim object class
ashanthamara May 24, 2023
681f334
Created OAuth2RestClient class f
ashanthamara May 24, 2023
6e393f6
Created object classes for scim2 rest api
ashanthamara May 24, 2023
fc380ab
Modified SubjectConfig class
ashanthamara May 24, 2023
b84cbd3
Modified RoleConfig class
ashanthamara May 24, 2023
c0b6c28
Modified AdvancedApplicationConfiguration class
ashanthamara May 24, 2023
0672a87
Modified AccessTokenConfiguration class
ashanthamara May 24, 2023
8186bac
Created SCIM2RestClient class
ashanthamara May 24, 2023
64b443f
Updated OAuth2RoleClaimTestCase
ashanthamara May 24, 2023
9cece9c
Modified OAuth2ServiceAbstractIntegrationTest
ashanthamara May 24, 2023
df9d509
Updated OAuth2DeviceFlowTestCase
ashanthamara May 24, 2023
b3df124
Updated OAuth2RequestObjectSignatureValidationTestCase
ashanthamara May 24, 2023
4f617f7
Moved OAuth2RestClient and SCIM2RestClient to a separate package
ashanthamara May 24, 2023
c32e11c
Updated OAuth2IDTokenEncryptionTestCase
ashanthamara May 24, 2023
4d4a1a2
Updated OAuth2ServiceErrorResponseTest
ashanthamara May 24, 2023
99896a9
Merge remote-tracking branch 'origin/7.x.x' into 7.x.x-soap_removal
ashanthamara May 25, 2023
38e6cdd
Fixed minor format errors
ashanthamara May 25, 2023
ec2a27f
Fixed changed wso2carbon.jks file
ashanthamara May 25, 2023
03cc833
Updated OAuth2ServiceRefreshTokenGrantTestCase
ashanthamara May 25, 2023
a3e44ec
Updated PermissionBasedScopeValidatorTestCase
ashanthamara May 25, 2023
ae4a59e
Created ResourceAdminServiceRestClient
ashanthamara May 29, 2023
dd4655c
Revert "Created ResourceAdminServiceRestClient"
ashanthamara May 31, 2023
838461e
Updated UserObject class to create a user with a given locale
ashanthamara May 31, 2023
b32345b
Created RestBaseClient for common restclient operations and constants
ashanthamara May 31, 2023
5bb9f37
Updated other OAuth2RestClient and SCIM2RestClient
ashanthamara May 31, 2023
fa3c384
Updated OAuth2RoleClaimTestCase
ashanthamara May 31, 2023
98efb3c
Updated license header
ashanthamara May 31, 2023
8917742
Merge branch '7.x.x' into 7.x.x-soap_removal
ashanthamara May 31, 2023
3a6105b
Revert "WIP on 7.x.x: 51a6854a3 Bump framework version (#15898)"
ashanthamara May 31, 2023
bb891d7
Updated OAuth2ServiceClientCredentialTestCase
ashanthamara May 31, 2023
9a9193c
Added/Modified License header
ashanthamara Jun 1, 2023
dc1aaa4
Created AuthenticatorRestClient
ashanthamara Jun 2, 2023
b2d0f83
Created AuthenticationRequest object class
ashanthamara Jun 2, 2023
bfc2a53
Created RoleSearchRequestObject object class
ashanthamara Jun 2, 2023
ba664da
Added getuser() and getRoleIdByName() functions to SCIM2RestClient
ashanthamara Jun 2, 2023
12a53c5
Updated AccountLockEnabledTestCase
ashanthamara Jun 2, 2023
4df9a54
Created AssertionEncryptionConfiguration object
ashanthamara Jun 7, 2023
fff0159
Created IdpInitiatedSingleLogout object
ashanthamara Jun 7, 2023
1390e7d
Created SAMLAssertionConfiguration object
ashanthamara Jun 7, 2023
aae3202
Created SAMLAttributeProfile object
ashanthamara Jun 7, 2023
610ff81
Created SAMLRequestValidation object
ashanthamara Jun 7, 2023
35832ea
Created SAMLResponseSigning object
ashanthamara Jun 7, 2023
d489fbd
Created SingleLogoutProfile object
ashanthamara Jun 7, 2023
3e2ea9a
Created SingleSignOnProfile object
ashanthamara Jun 7, 2023
fa80b04
Updated SAML2ServiceProvider object
ashanthamara Jun 7, 2023
8c5c281
Updated SAML2Configuration object
ashanthamara Jun 7, 2023
ead22d8
Updated OAuth2RestClient by adding generic method to update inbound c…
ashanthamara Jun 7, 2023
3cf67e4
Modified method signature change
ashanthamara Jun 7, 2023
cd7f8d4
Modified OAuth2ServiceSAML2BearerGrantTestCase
ashanthamara Jun 7, 2023
6856d80
Minor fix
ashanthamara Jun 7, 2023
f29616c
Updated OAuth2ServiceImplicitGrantTestCase
ashanthamara Jun 7, 2023
63cde8c
Updated OAuth2ServiceIntrospectionTestCase
ashanthamara Jun 7, 2023
53b99ee
Updated OAuth2ServiceRegexCallbackUrlTestCase
ashanthamara Jun 8, 2023
945201d
Updated OAuth2ServiceResourceOwnerTestCase
ashanthamara Jun 9, 2023
930ea81
Updated OAuth2TokenRevocationWithRevokedAccessToken
ashanthamara Jun 12, 2023
16d1ab2
Updated OAuth2BackChannelLogoutTestCase
ashanthamara Jun 13, 2023
a5afc99
Updated OAuth2TokenRevocationWithMultipleSessionTerminationTestCase
ashanthamara Jun 14, 2023
22f0da4
Merge branch '7.x.x' into 7.x.x-soap_removal
ashanthamara Jun 18, 2023
0daef8b
Updated OAuth2TokenRevocationAfterAccountDisablingTestCase
ashanthamara Jun 19, 2023
58e6cec
Addressed comments
ashanthamara Jun 19, 2023
88b91e2
Updated Oauth2OPIframeTestCase
ashanthamara Jun 19, 2023
77604e3
Minor fix to OAuth2ServiceResourceOwnerTestCase
ashanthamara Jun 20, 2023
385e6dd
Minor fix to OAuth2ServiceClientCredentialTestCase
ashanthamara Jun 20, 2023
000f146
Added method comments
ashanthamara Jun 20, 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 @@ -40,6 +40,7 @@ public class ISIntegrationTest {
protected Log log = LogFactory.getLog(getClass());
protected AutomationContext isServer;
protected String backendURL;
protected String serverURL;
protected String sessionCookie;
protected Tenant tenantInfo;
protected User userInfo;
Expand All @@ -54,6 +55,7 @@ protected void init() throws Exception {
protected void init(TestUserMode userMode) throws Exception {
isServer = new AutomationContext("IDENTITY", userMode);
backendURL = isServer.getContextUrls().getBackEndUrl();
serverURL = backendURL.replace("services/", "");
loginLogoutClient = new LoginLogoutClient(isServer);
sessionCookie = loginLogoutClient.login();
identityContextUrls = isServer.getContextUrls();
Expand All @@ -66,6 +68,7 @@ protected void init(String instance, String domainKey, String userKey) throws Ex
loginLogoutClient = new LoginLogoutClient(isServer);
sessionCookie = loginLogoutClient.login();
backendURL = isServer.getContextUrls().getBackEndUrl();
serverURL = backendURL.replace("services/", "");
}

protected String login() throws Exception{
Expand All @@ -86,6 +89,7 @@ protected void initPublisher(String productGroupName, String instanceName, TestU
throws XPathExpressionException {
isServer = new AutomationContext(productGroupName, instanceName, userMode);
backendURL = isServer.getContextUrls().getBackEndUrl();
serverURL = backendURL.replace("services/", "");
}

protected String getBackendURL() throws XPathExpressionException {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2020, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
Expand All @@ -18,7 +18,6 @@

package org.wso2.identity.integration.test.oauth2;

import org.apache.commons.lang.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
Expand All @@ -36,23 +35,26 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig;
import org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig;
import org.wso2.carbon.identity.application.common.model.xsd.Property;
import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider;
import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.um.ws.api.stub.ClaimValue;
import org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient;
import org.wso2.identity.integration.common.clients.oauth.OauthAdminClient;
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.InboundProtocols;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OIDCLogoutConfiguration;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration;
import org.wso2.identity.integration.test.rest.api.user.common.model.Email;
import org.wso2.identity.integration.test.rest.api.user.common.model.ListObject;
import org.wso2.identity.integration.test.rest.api.user.common.model.PatchOperationRequestObject;
import org.wso2.identity.integration.test.rest.api.user.common.model.RoleItemAddGroupobj;
import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject;
import org.wso2.identity.integration.test.restclients.SCIM2RestClient;
import org.wso2.identity.integration.test.util.Utils;
import org.wso2.identity.integration.test.utils.CommonConstants;
import org.wso2.identity.integration.test.utils.DataExtractUtil;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -66,23 +68,21 @@ public class OAuth2BackChannelLogoutTestCase extends OAuth2ServiceAbstractIntegr

private HttpClient client;
private final String OIDC_APP_NAME = "playground2";
private String oidcAppClientId = "";
private String oidcAppClientSecret = "";
private OauthAdminClient adminClient;
private ApplicationManagementServiceClient applicationManagementServiceClient;
private String oidcAppClientId;
private String sessionDataKeyConsent;
private String sessionDataKey;
private final String CONSENT = "consent";
private final String APPROVE = "approve";
private final String SCOPE_APPROVAL = "scope-approval";
private final String USER_AGENT = "User-Agent";
private final String username;
private final String userPassword;
private final String activeTenant;
private static final String CONSENT = "consent";
private static final String APPROVE = "approve";
private static final String SCOPE_APPROVAL = "scope-approval";
private static final String USER_AGENT = "User-Agent";
private static final String USERS_PATH = "users";

private static final String USER_EMAIL = "abc@wso2.com";
private static final String USERNAME = "testUser";
private static final String PASSWORD = "pass123";
private String applicationId;
private SCIM2RestClient scim2RestClient;
private String userId;

@DataProvider(name = "configProvider")
public static Object[][] configProvider() {
Expand All @@ -93,38 +93,23 @@ public static Object[][] configProvider() {
public OAuth2BackChannelLogoutTestCase(TestUserMode userMode) throws Exception {

super.init(userMode);
AutomationContext context = new AutomationContext("IDENTITY", userMode);
this.username = context.getContextTenant().getTenantAdmin().getUserName();
this.userPassword = context.getContextTenant().getTenantAdmin().getPassword();
this.activeTenant = context.getContextTenant().getDomain();
}

@BeforeClass(alwaysRun = true)
public void testInit() throws Exception {

init();
client = HttpClientBuilder.create().setDefaultCookieStore(new BasicCookieStore()).build();
createOIDCApplication();
createServiceProvider();

remoteUSMServiceClient.addUser(USERNAME, PASSWORD, new String[]{"admin"},
getUserClaims(), "default", true);
scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo);

createOIDCApplication();
addAdminUser();
}

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

removeApplications();

remoteUSMServiceClient.deleteUser(USERNAME);
}

protected void init() throws Exception {

super.init();
adminClient = new OauthAdminClient(backendURL, sessionCookie);
applicationManagementServiceClient = new ApplicationManagementServiceClient(sessionCookie, backendURL, null);
scim2RestClient.deleteUser(userId);
}

@Test(groups = "wso2.is", description = "Test back channel logout for OIDC.")
Expand All @@ -140,25 +125,38 @@ public void testOIDCLogout() throws IOException {
}

private void createOIDCApplication() throws Exception {
ApplicationModel application = new ApplicationModel();

List<String> grantTypes = new ArrayList<>();
Collections.addAll(grantTypes, OAuth2Constant.OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE);

List<String> callBackUrls = new ArrayList<>();
Collections.addAll(callBackUrls, OAuth2Constant.CALLBACK_URL);

OAuthConsumerAppDTO appDTO = new OAuthConsumerAppDTO();
appDTO.setApplicationName(OIDC_APP_NAME);
appDTO.setCallbackUrl(OAuth2Constant.CALLBACK_URL);
appDTO.setOAuthVersion(OAuth2Constant.OAUTH_VERSION_2);
appDTO.setGrantTypes(OAuth2Constant.OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE);
appDTO.setBackChannelLogoutUrl("http://localhost:" + DEFAULT_TOMCAT_PORT + "/playground2/bclogout");

adminClient.registerOAuthApplicationData(appDTO);
OAuthConsumerAppDTO createdApp = adminClient.getOAuthAppByName(OIDC_APP_NAME);
Assert.assertNotNull(createdApp, "Adding OIDC app failed.");
oidcAppClientId = createdApp.getOauthConsumerKey();
oidcAppClientSecret = createdApp.getOauthConsumerSecret();
OpenIDConnectConfiguration oidcConfig = new OpenIDConnectConfiguration();
oidcConfig.setGrantTypes(grantTypes);
oidcConfig.setCallbackURLs(callBackUrls);
oidcConfig.setLogout(new OIDCLogoutConfiguration().backChannelLogoutUrl("http://localhost:" +
DEFAULT_TOMCAT_PORT + "/playground2/bclogout"));

InboundProtocols inboundProtocolsConfig = new InboundProtocols();
inboundProtocolsConfig.setOidc(oidcConfig);

application.setInboundProtocolConfiguration(inboundProtocolsConfig);
application.setName(OIDC_APP_NAME);

String appId = addApplication(application);
ApplicationResponseModel createdApplication = getApplication(appId);

applicationId = createdApplication.getId();
oidcConfig = getOIDCInboundDetailsOfApplication(applicationId);

oidcAppClientId = oidcConfig.getClientId();
}

private void removeApplications() throws Exception {

adminClient.removeOAuthApplicationData(oidcAppClientId);
applicationManagementServiceClient.deleteApplication(OIDC_APP_NAME);
deleteApp(applicationId);
}

private void initiateOIDCRequest(boolean isCheckLogoutConfirmation) throws IOException {
Expand Down Expand Up @@ -281,7 +279,7 @@ public HttpResponse sendPostRequestWithParameters(List<NameValuePair> urlParamet

private List<NameValuePair> getOIDCInitiationRequestParams() {

List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE));
urlParameters.add(new BasicNameValuePair("consumerKey", oidcAppClientId));
urlParameters.add(new BasicNameValuePair("callbackurl", OAuth2Constant.CALLBACK_URL));
Expand All @@ -291,40 +289,20 @@ private List<NameValuePair> getOIDCInitiationRequestParams() {
return urlParameters;
}

private ServiceProvider createServiceProvider() throws Exception {

ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(OIDC_APP_NAME);
serviceProvider.setManagementApp(true);
applicationManagementServiceClient.createApplication(serviceProvider);
serviceProvider = applicationManagementServiceClient.getApplication(OIDC_APP_NAME);

InboundAuthenticationRequestConfig requestConfig = new InboundAuthenticationRequestConfig();
requestConfig.setInboundAuthKey(oidcAppClientId);
requestConfig.setInboundAuthType("oauth2");
if (StringUtils.isNotBlank(oidcAppClientSecret)) {
Property property = new Property();
property.setName("oauthConsumerSecret");
property.setValue(oidcAppClientSecret);
Property[] properties = {property};
requestConfig.setProperties(properties);
}
private void addAdminUser() throws Exception {
UserObject userInfo = new UserObject();
userInfo.setUserName(USERNAME);
userInfo.setPassword(PASSWORD);
userInfo.addEmail(new Email().value(USER_EMAIL));

InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
inboundAuthenticationConfig
.setInboundAuthenticationRequestConfigs(new InboundAuthenticationRequestConfig[]{requestConfig});
serviceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig);
applicationManagementServiceClient.updateApplicationData(serviceProvider);
return serviceProvider;
}
userId = scim2RestClient.createUser(userInfo);
String roleId = scim2RestClient.getRoleIdByName("admin");

protected ClaimValue[] getUserClaims() {
RoleItemAddGroupobj patchRoleItem = new RoleItemAddGroupobj();
patchRoleItem.setOp(RoleItemAddGroupobj.OpEnum.ADD);
patchRoleItem.setPath(USERS_PATH);
patchRoleItem.addValue(new ListObject().value(userId));

ClaimValue[] claimValues = new ClaimValue[1];
ClaimValue email = new ClaimValue();
email.setClaimURI(EMAIL_CLAIM_URI);
email.setValue(USER_EMAIL);
claimValues[0] = email;
return claimValues;
scim2RestClient.updateUserRole(new PatchOperationRequestObject().addOperations(patchRoleItem), roleId);
}
}
Loading