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 22 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 @@ -15,16 +15,15 @@
*/
package org.wso2.identity.integration.test.oauth2;

import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.simple.JSONObject;
Expand All @@ -36,8 +35,10 @@
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.oauth.stub.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.integration.common.admin.client.AuthenticatorClient;
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.OpenIDConnectConfiguration;
import org.wso2.identity.integration.test.util.Utils;
import org.wso2.identity.integration.test.utils.CommonConstants;
import org.wso2.identity.integration.test.utils.DataExtractUtil;
Expand All @@ -46,10 +47,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved

import static org.wso2.identity.integration.test.utils.OAuth2Constant.COMMON_AUTH_URL;
import static org.wso2.identity.integration.test.utils.OAuth2Constant.SCOPE_PLAYGROUND_NAME;
Expand All @@ -64,41 +62,45 @@ public class OAuth2DeviceFlowTestCase extends OAuth2ServiceAbstractIntegrationTe
private String sessionDataKey;
private String consumerKey;
private String consumerSecret;
private String appId;
private String userCode;
private String deviceCode;
private CloseableHttpClient client;

private DefaultHttpClient client;

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

super.init(TestUserMode.SUPER_TENANT_USER);
AuthenticatorClient logManger = new AuthenticatorClient(backendURL);
logManger.login(isServer.getSuperTenant().getTenantAdmin().getUserName(),
isServer.getSuperTenant().getTenantAdmin().getPassword(),
isServer.getInstance().getHosts().get("default"));
client = new DefaultHttpClient();
client = HttpClients.createDefault();

setSystemproperties();
}

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

deleteApplication();
removeOAuthApplicationData();
deleteApp(appId);
consumerKey = null;
consumerSecret = null;
appId = null;
client.close();
}

@Test(groups = "wso2.is", description = "Check Oauth2 application registration")
public void testRegisterApplication() throws Exception {

OAuthConsumerAppDTO appDto = createApp();
Assert.assertNotNull(appDto, "Application creation failed.");
ApplicationResponseModel application = createApp();
Assert.assertNotNull(application, "OAuth App creation failed.");

consumerKey = appDto.getOauthConsumerKey();
OpenIDConnectConfiguration oidcConfig = getOIDCInboundDetailsOfApplication(application.getId());

consumerKey = oidcConfig.getClientId();
Assert.assertNotNull(consumerKey, "Application creation failed.");

consumerSecret = appDto.getOauthConsumerSecret();
consumerSecret = oidcConfig.getClientSecret();
Assert.assertNotNull(consumerSecret, "Application creation failed.");
appId = application.getId();
}

@Test(groups = "wso2.is", description = "Send authorize user request without redirect_uri param", dependsOnMethods
Expand Down Expand Up @@ -129,7 +131,7 @@ public void testNonUsedDeviceTokenRequest() throws Exception {
@Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testSendDeviceAuthorize")
public void testSendDeviceAuthorozedPost() throws Exception {

List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair(USER_CODE, userCode));
AutomationContext automationContext = new AutomationContext("IDENTITY", TestUserMode.SUPER_TENANT_ADMIN);
String authenticationEndpoint = automationContext.getContextUrls().getBackEndUrl()
Expand All @@ -156,7 +158,7 @@ public void testDevicePost() throws Exception {
response = sendGetRequest(client, locationHeader.getValue());
Assert.assertNotNull(response, "Authorized user response is null.");

Map<String, Integer> keyPositionMap = new HashMap<String, Integer>(1);
Map<String, Integer> keyPositionMap = new HashMap<>(1);
keyPositionMap.put("name=\"sessionDataKey\"", 1);
List<DataExtractUtil.KeyValue> keyValues =
DataExtractUtil.extractDataFromResponse(response, keyPositionMap);
Expand Down Expand Up @@ -189,7 +191,7 @@ public void testSendLoginPost() throws Exception {
EntityUtils.consume(response.getEntity());

response = sendGetRequest(client, locationHeader.getValue());
Map<String, Integer> keyPositionMap = new HashMap<String, Integer>(1);
Map<String, Integer> keyPositionMap = new HashMap<>(1);
keyPositionMap.put("name=\"" + OAuth2Constant.SESSION_DATA_KEY_CONSENT + "\"", 1);
List<DataExtractUtil.KeyValue> keyValues =
DataExtractUtil.extractSessionConsentDataFromResponse(response,
Expand Down Expand Up @@ -297,19 +299,32 @@ public HttpResponse sendGetRequest(HttpClient client, String locationURL) throws
/**
* Create Application with the given app configurations
*
* @return OAuthConsumerAppDTO
* @throws Exception
* @return ApplicationResponseModel
* @throws Exception exception
*/
private OAuthConsumerAppDTO createApp() throws Exception {

OAuthConsumerAppDTO appDTO = new OAuthConsumerAppDTO();
appDTO.setApplicationName(OAuth2Constant.OAUTH_APPLICATION_NAME);
appDTO.setCallbackUrl(OAuth2Constant.CALLBACK_URL);
appDTO.setOAuthVersion(OAuth2Constant.OAUTH_VERSION_2);
appDTO.setGrantTypes("authorization_code implicit password client_credentials refresh_token " +
"urn:ietf:params:oauth:grant-type:saml2-bearer iwa:ntlm " +
"urn:ietf:params:oauth:grant-type:device_code");
appDTO.setBypassClientCredentials(true);
return createApplication(appDTO, SERVICE_PROVIDER_NAME);
private ApplicationResponseModel createApp() throws Exception {

ApplicationModel application = new ApplicationModel();

List<String> grantTypes = new ArrayList<>();
Collections.addAll(grantTypes, "authorization_code", "implicit", "password", "client_credentials", "refresh_token", "urn:ietf:params:oauth:grant-type:saml2-bearer", "iwa:ntlm", "urn:ietf:params:oauth:grant-type:device_code");
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved

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

OpenIDConnectConfiguration oidcConfig = new OpenIDConnectConfiguration();
oidcConfig.setGrantTypes(grantTypes);
oidcConfig.setCallbackURLs(callBackUrls);
oidcConfig.setPublicClient(true);

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

application.setInboundProtocolConfiguration(inboundProtocolsConfig);
application.setName(OAuth2Constant.OAUTH_APPLICATION_NAME);

String appId = addApplication(application);

return getApplication(appId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@
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.carbon.identity.application.common.model.xsd.ServiceProvider;
import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
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.DataExtractUtil;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -91,6 +92,10 @@ public class OAuth2IDTokenEncryptionTestCase extends OAuth2ServiceAbstractIntegr
private String sessionDataKeyConsent;
private AuthorizationCode authorizationCode;
private String idToken;
private String consumerKey;
private String consumerSecret;
private ApplicationResponseModel application;
private OpenIDConnectConfiguration oidcInboundConfig;

@BeforeClass(alwaysRun = true)
public void testInit() throws Exception {
Expand All @@ -101,13 +106,14 @@ public void testInit() throws Exception {

@AfterClass(alwaysRun = true)
public void atEnd() throws Exception {
deleteApplication();
removeOAuthApplicationData();
deleteApp(application.getId());

consumerKey = null;
consumerSecret = null;
spPrivateKey = null;
spX509PublicCert = null;
application = null;
oidcInboundConfig = null;

client.close();
}
Expand All @@ -124,43 +130,42 @@ public void testGenerateServiceProviderKeys() throws Exception {
dependsOnMethods = "testGenerateServiceProviderKeys")
public void testRegisterApplication() throws Exception {

OAuthConsumerAppDTO oAuthConsumerAppDTO = getBasicOAuthApp(CALLBACK_URL);
ServiceProvider serviceProvider = registerServiceProviderWithOAuthInboundConfigs(oAuthConsumerAppDTO);
Assert.assertNotNull(serviceProvider, "OAuth App creation failed.");
application = getBasicOAuthApplication(CALLBACK_URL);
Assert.assertNotNull(application, "OAuth App creation failed.");

oidcInboundConfig = getOIDCInboundDetailsOfApplication(application.getId());
consumerKey = oidcInboundConfig.getClientId();
Assert.assertNotNull(consumerKey, "Consumer Key is null.");
consumerSecret = oidcInboundConfig.getClientSecret();
Assert.assertNotNull(consumerSecret, "Consumer Secret is null.");
}

@Test(groups = "wso2.is", description = "Check Updating public cert of Service Provider.",
dependsOnMethods = "testRegisterApplication")
public void updateServiceProviderCert() throws Exception {

ServiceProvider application = appMgtclient.getApplication(SERVICE_PROVIDER_NAME);
Assert.assertNotNull(application, "Application: " + SERVICE_PROVIDER_NAME + " retrieval failed.");

application.setCertificateContent(convertToPem(spX509PublicCert));
appMgtclient.updateApplicationData(application);
updateApplicationCertificate(application.getId(), spX509PublicCert);

ServiceProvider updatedApp = appMgtclient.getApplication(SERVICE_PROVIDER_NAME);
Assert.assertNotNull(updatedApp, "Updated application: " + SERVICE_PROVIDER_NAME +
" retrieval failed.");
Assert.assertNotNull(updatedApp.getCertificateContent(), "Updating application certificate failed.");
ApplicationResponseModel updatedApplication = getApplication(application.getId());
Assert.assertNotNull(updatedApplication, "Application: " + application.getName() + " retrieval failed.");
Assert.assertNotNull(updatedApplication.getAdvancedConfigurations().getCertificate(), "Application Certificate update failed");
}

@Test(groups = "wso2.is", description = "Setup encryption algorithm and encryption method.",
dependsOnMethods = "updateServiceProviderCert")
public void testConfigureIDTokenEncryptionAlgorithms() throws Exception {

OAuthConsumerAppDTO consumerAppDTO = adminClient.getOAuthAppByConsumerKey(consumerKey);
consumerAppDTO.setIdTokenEncryptionEnabled(true);
consumerAppDTO.setIdTokenEncryptionAlgorithm(ENCRYPTION_ALGORITHM);
consumerAppDTO.setIdTokenEncryptionMethod(ENCRYPTION_METHOD);
adminClient.updateConsumerApp(consumerAppDTO);
OAuthConsumerAppDTO updateApp = adminClient.getOAuthAppByConsumerKey(consumerKey);
Assert.assertTrue(updateApp.getIdTokenEncryptionEnabled(), "Enforcing ID Token encryption failed.");
Assert.assertEquals(updateApp.getIdTokenEncryptionAlgorithm(),
oidcInboundConfig.getIdToken().getEncryption().setEnabled(true);
oidcInboundConfig.getIdToken().getEncryption().setAlgorithm(ENCRYPTION_ALGORITHM);
oidcInboundConfig.getIdToken().getEncryption().setMethod(ENCRYPTION_METHOD);
updateApplicationOidcInboundConfig(application.getId(), oidcInboundConfig);

OpenIDConnectConfiguration updatedOidcInboundConfig = getOIDCInboundDetailsOfApplication(application.getId());
Assert.assertTrue(updatedOidcInboundConfig.getIdToken().getEncryption().getEnabled(),
"Enforcing ID Token encryption failed.");
Assert.assertEquals(updatedOidcInboundConfig.getIdToken().getEncryption().getAlgorithm(),
ENCRYPTION_ALGORITHM, "Configuring encryption algorithm failed.");
Assert.assertEquals(updateApp.getIdTokenEncryptionMethod(),
Assert.assertEquals(updatedOidcInboundConfig.getIdToken().getEncryption().getMethod(),
ENCRYPTION_METHOD, "Configuring encryption method failed.");
}

Expand Down Expand Up @@ -407,7 +412,7 @@ private String getLocationHeaderValue(HttpResponse response) {
/**
* Initiate service provider keys required for the tests.
*
* @throws Exception
* @throws Exception error
*/
private void initServiceProviderKeys() throws Exception {

Expand All @@ -416,7 +421,7 @@ private void initServiceProviderKeys() throws Exception {
File.separator + "keystores" + File.separator + "sp1KeyStore.jks";
String jksPassword = "wso2carbon";

keyStore.load(new FileInputStream(jksPath), jksPassword.toCharArray());
keyStore.load(Files.newInputStream(Paths.get(jksPath)), jksPassword.toCharArray());

String alias = "wso2carbon";
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias,
Expand All @@ -434,8 +439,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
* @throws URISyntaxException
* @throws IOException Error
* @throws URISyntaxException Error
*/
private String getSessionDataKeyConsent(CloseableHttpClient client, String sessionDataKey)
throws IOException, URISyntaxException {
Expand Down Expand Up @@ -467,8 +472,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
* @throws JOSEException
* @throws ParseException Error
* @throws JOSEException Error
*/
private boolean decryptAndCheckIDToken(String idToken, String audience) throws ParseException, JOSEException {

Expand Down
Loading