-
Notifications
You must be signed in to change notification settings - Fork 730
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
Add DCR integration tests #18491
Open
SachiniSiriwardene
wants to merge
33
commits into
wso2:master
Choose a base branch
from
SachiniSiriwardene:master_DCRTest_New
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add DCR integration tests #18491
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c7cb2e3
add test case for persisting newly added DCR attributes
SachiniSiriwardene 685d9ad
change test case priority
SachiniSiriwardene ddae1d9
Merge branch 'master' of https://github.com/wso2/product-is
SachiniSiriwardene eba231d
Merge branch 'master' of https://github.com/wso2/product-is
SachiniSiriwardene ea7c445
refactor tests
SachiniSiriwardene ca0088c
refactor tests
SachiniSiriwardene eb36ea4
add update test case
SachiniSiriwardene a4dba8f
refactored code
SachiniSiriwardene 4e95b8d
Merge branch 'master' of https://github.com/wso2/product-is into mast…
SachiniSiriwardene 63497ce
add fapi validations for dcr tests
SachiniSiriwardene dffd497
add eof lines
SachiniSiriwardene 1ebcbb0
refactor code
SachiniSiriwardene 61dfc21
add fapi dcr validation tests to a separate class
SachiniSiriwardene cc18af5
add config changes
SachiniSiriwardene 4b54440
address pr comments
SachiniSiriwardene 9e06af6
update dcr tests
SachiniSiriwardene cfcb0d5
update dcr tests
SachiniSiriwardene 9eb55f3
address pr comments
SachiniSiriwardene 6bc1d76
change error message
SachiniSiriwardene eedca72
change application name to be common
SachiniSiriwardene faf21c9
fix test failures
SachiniSiriwardene cd98f8d
change application name for error scenarios
SachiniSiriwardene 527e1e4
send tls_client_certificate_bound_access_tokens in dcr requests
SachiniSiriwardene 4f48eed
Merge branch 'master' of https://github.com/wso2/product-is into mast…
SachiniSiriwardene e1567be
address pr comments
SachiniSiriwardene facd12a
Merge branch 'master' of https://github.com/wso2/product-is into mast…
SachiniSiriwardene d0f6e26
address pr comments
SachiniSiriwardene 8eab0d7
change year in license header
SachiniSiriwardene 1d55269
Merge branch 'master' of https://github.com/wso2/product-is into mast…
SachiniSiriwardene 4be99dc
change year in license header
SachiniSiriwardene fe0b64d
fix failing tests
SachiniSiriwardene 7b214e1
Merge branch 'master' of https://github.com/wso2/product-is into mast…
SachiniSiriwardene a7bf6d8
Merge branch 'master' of https://github.com/wso2/product-is into mast…
SachiniSiriwardene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
...t/java/org/wso2/identity/integration/test/oauth2/dcrm/api/FAPIDCRValidationsTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.wso2.identity.integration.test.oauth2.dcrm.api; | ||
|
||
import org.apache.http.HttpHeaders; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpDelete; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.json.simple.JSONObject; | ||
import org.testng.annotations.BeforeClass; | ||
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.integration.common.utils.mgt.ServerConfigurationManager; | ||
import org.wso2.identity.integration.common.utils.ISIntegrationTest; | ||
import org.wso2.identity.integration.test.oauth2.dcrm.api.util.DCRUtils; | ||
import org.wso2.identity.integration.test.oauth2.dcrm.api.util.OAuthDCRMConstants; | ||
import org.wso2.identity.integration.test.util.Utils; | ||
|
||
import java.io.File; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
|
||
/** | ||
* FAPI validation test case for the DCR flow | ||
*/ | ||
public class FAPIDCRValidationsTestCase extends ISIntegrationTest { | ||
|
||
private HttpClient client; | ||
private String client_id; | ||
private String username; | ||
private String password; | ||
private String tenant; | ||
private ServerConfigurationManager serverConfigurationManager; | ||
|
||
@Factory(dataProvider = "dcrmConfigProvider") | ||
public FAPIDCRValidationsTestCase(TestUserMode userMode) throws Exception { | ||
|
||
AutomationContext context = new AutomationContext("IDENTITY", userMode); | ||
this.username = context.getContextTenant().getTenantAdmin().getUserName(); | ||
this.password = context.getContextTenant().getTenantAdmin().getPassword(); | ||
this.tenant = context.getContextTenant().getDomain(); | ||
|
||
} | ||
|
||
@DataProvider(name = "dcrmConfigProvider") | ||
public static Object[][] dcrmConfigProvider() { | ||
|
||
return new Object[][]{{TestUserMode.SUPER_TENANT_ADMIN}, {TestUserMode.TENANT_ADMIN}}; | ||
} | ||
|
||
@BeforeClass(alwaysRun = true) | ||
public void testInit() throws Exception { | ||
|
||
super.init(); | ||
client = HttpClients.createDefault(); | ||
changeISConfiguration(); | ||
} | ||
|
||
@DataProvider(name = "dcrConfigProvider") | ||
private static Object[][] dcrConfigProvider() throws Exception { | ||
|
||
String INVALID_CLIENT_METADATA = "invalid_client_metadata"; | ||
String INVALID_SOFTWARE_STATEMENT = "invalid_software_statement"; | ||
return new Object[][]{ | ||
{ | ||
DCRUtils.getRegisterRequestJSON("request1.json"), INVALID_CLIENT_METADATA, | ||
"Invalid token endpoint authentication method requested." | ||
}, | ||
{ | ||
DCRUtils.getRegisterRequestJSON("request2.json"), INVALID_CLIENT_METADATA, | ||
"Invalid signature algorithm requested" | ||
}, | ||
{ | ||
DCRUtils.getRegisterRequestJSON("request3.json"), INVALID_CLIENT_METADATA, | ||
"Invalid encryption algorithm requested" | ||
}, | ||
{ | ||
DCRUtils.getRegisterRequestJSON("request4.json"), INVALID_CLIENT_METADATA, | ||
"Sector identifier URI is needed for PPID calculation" | ||
}, | ||
{ | ||
DCRUtils.getRegisterRequestJSON("request5.json"), INVALID_CLIENT_METADATA, | ||
"Redirect URI missing in sector identifier URI set" | ||
}, | ||
{ | ||
DCRUtils.getRegisterRequestJSON("request8.json"), INVALID_SOFTWARE_STATEMENT, | ||
"Signature validation failed for the software statement" | ||
} | ||
}; | ||
} | ||
|
||
private void changeISConfiguration() throws Exception { | ||
|
||
log.info("Adding entity id of SSOService to deployment.toml file"); | ||
String carbonHome = Utils.getResidentCarbonHome(); | ||
File defaultConfigFile = getDeploymentTomlFile(carbonHome); | ||
File configuredIdentityXML = new File(getISResourceLocation() + File.separator + "oauth" | ||
+ File.separator + "dcr-fapi-validation-enabled.toml"); | ||
serverConfigurationManager = new ServerConfigurationManager(isServer); | ||
serverConfigurationManager.applyConfigurationWithoutRestart(configuredIdentityXML, | ||
defaultConfigFile, true); | ||
serverConfigurationManager.restartGracefully(); | ||
} | ||
|
||
@Test(alwaysRun = true, groups = "wso2.is", priority = 1, | ||
description = "Check FAPI validations, PPID and SSA during DCR", dataProvider = "dcrConfigProvider") | ||
public void validateErrorScenarios(JSONObject requestJSON, String errorCode, String errorMessage) throws Exception { | ||
|
||
HttpPost request = new HttpPost(DCRUtils.getPath(tenant)); | ||
request.addHeader(HttpHeaders.AUTHORIZATION, DCRUtils.getAuthzHeader(username, password)); | ||
request.addHeader(HttpHeaders.CONTENT_TYPE, OAuthDCRMConstants.CONTENT_TYPE); | ||
StringEntity entity = new StringEntity(requestJSON.toJSONString()); | ||
request.setEntity(entity); | ||
HttpResponse response = client.execute(request); | ||
|
||
assertEquals(response.getStatusLine().getStatusCode(), 400, "Service Provider " + | ||
"should not be created successfully"); | ||
JSONObject errorResponse = DCRUtils.getPayload(response); | ||
assertEquals(errorResponse.get("error"), errorCode); | ||
assertEquals(errorResponse.get("error_description"), errorMessage); | ||
} | ||
|
||
@Test(alwaysRun = true, groups = "wso2.is", priority = 2, | ||
description = "Check FAPI validations, PPID and SSA during DCR", dataProvider = "dcrConfigProvider") | ||
public void validateErrorScenariosForDCRUpdate(JSONObject requestJSON, String errorCode, String errorMessage) | ||
throws Exception { | ||
|
||
// Create application. | ||
HttpPost request = new HttpPost(DCRUtils.getPath(tenant)); | ||
JSONObject registerRequestJSON = DCRUtils.getRegisterRequestJSON("request6.json"); | ||
// Removing sending sector identifier uri to validate error message during update request. | ||
if (errorMessage.equals("Sector identifier URI is needed for PPID calculation")) { | ||
registerRequestJSON.remove("sector_identifier_uri"); | ||
} | ||
request.addHeader(HttpHeaders.AUTHORIZATION, DCRUtils.getAuthzHeader(username, password)); | ||
request.addHeader(HttpHeaders.CONTENT_TYPE, OAuthDCRMConstants.CONTENT_TYPE); | ||
StringEntity entity = new StringEntity(registerRequestJSON.toJSONString()); | ||
request.setEntity(entity); | ||
|
||
HttpResponse response = client.execute(request); | ||
assertEquals(response.getStatusLine().getStatusCode(), 201, "Service Provider " + | ||
"created successfully"); | ||
JSONObject createResponsePayload = DCRUtils.getPayload(response); | ||
client_id = ((JSONObject) createResponsePayload).get("client_id").toString(); | ||
assertNotNull(client_id, "client_id cannot be null"); | ||
|
||
// Check error scenarios for update request. | ||
HttpPut updateRequest = new HttpPut(DCRUtils.getPath(tenant) + client_id); | ||
updateRequest.addHeader(HttpHeaders.AUTHORIZATION, DCRUtils.getAuthzHeader(username, password)); | ||
updateRequest.addHeader(HttpHeaders.CONTENT_TYPE, OAuthDCRMConstants.CONTENT_TYPE); | ||
entity = new StringEntity(requestJSON.toJSONString()); | ||
updateRequest.setEntity(entity); | ||
|
||
HttpResponse updateResponse = client.execute(updateRequest); | ||
assertEquals(updateResponse.getStatusLine().getStatusCode(), 400, "Service Provider should " + | ||
"not be created successfully"); | ||
JSONObject errorResponse = DCRUtils.getPayload(updateResponse); | ||
assertEquals(errorResponse.get("error"), errorCode); | ||
assertEquals(errorResponse.get("error_description"), errorMessage); | ||
|
||
// Delete application. | ||
HttpDelete deleteRequest = new HttpDelete(DCRUtils.getPath(tenant) + client_id); | ||
deleteRequest.addHeader(HttpHeaders.AUTHORIZATION, DCRUtils.getAuthzHeader(username, password)); | ||
HttpResponse deleteResponse = client.execute(deleteRequest); | ||
assertEquals(deleteResponse.getStatusLine().getStatusCode(), 204, "Service provider " + | ||
"deletion failed"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the license header, I think latest one should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mail: License Header for WSO2 code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated