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

Bundle Rule Metadata REST API and add integration tests #21863

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions modules/api-resources/api-resources-full/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -500,5 +500,13 @@
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.action.management.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.rule.metadata.v1</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.rule.metadata.common</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<import resource="classpath:META-INF/cxf/user-organization-v1-cxf.xml"/>
<import resource="classpath:META-INF/cxf/api-resource-server-v1-cxf.xml"/>
<import resource="classpath:META-INF/cxf/action-server-v1-cxf.xml"/>
<import resource="classpath:META-INF/cxf/rule-metadata-server-v1-cxf.xml"/>

<context:property-placeholder/>
<context:annotation-config/>
Expand Down Expand Up @@ -147,6 +148,7 @@
<bean class="org.wso2.carbon.identity.api.server.organization.selfservice.v1.SelfServiceApi"/>
<bean class="org.wso2.carbon.identity.api.server.api.resource.v1.MetaApi"/>
<bean class="org.wso2.carbon.identity.api.server.action.management.v1.ActionsApi"/>
<bean class="org.wso2.carbon.identity.api.server.rule.metadata.v1.RulesApi"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider">
Expand Down
10 changes: 10 additions & 0 deletions modules/api-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,16 @@
<artifactId>org.wso2.carbon.identity.api.server.action.management.common</artifactId>
<version>${identity.server.api.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.rule.metadata.v1</artifactId>
<version>${identity.server.api.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.rule.metadata.common</artifactId>
<version>${identity.server.api.version}</version>
</dependency>

<!-- Legacy API dependencies -->
<dependency>
Expand Down
11 changes: 11 additions & 0 deletions modules/distribution/src/assembly/bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@
<include>**/</include>
</includes>
</fileSet>
<!--copy rule meta data files of rule metadata feature-->
<fileSet>
<directory>
../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/resources/identity/rulemeta
</directory>
<outputDirectory>wso2is-${pom.version}/repository/resources/identity/rulemeta</outputDirectory>
<includes>
<include>**/*.json</include>
</includes>
</fileSet>

<fileSet>
<directory>src/repository/resources/conf/templates</directory>
<outputDirectory>wso2is-${pom.version}/repository/resources/conf/templates</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* 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.rest.api.server.rules.metadata.v1;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;

import static org.hamcrest.CoreMatchers.equalTo;

public class RulesMetadataFailureTest extends RulesMetadataTestBase {

@DataProvider(name = "testExecutionContextProvider")
public static Object[][] getTestExecutionContext() {

return new Object[][]{
{TestUserMode.SUPER_TENANT_ADMIN},
{TestUserMode.TENANT_ADMIN}
};
}

@Factory(dataProvider = "testExecutionContextProvider")
public RulesMetadataFailureTest(TestUserMode userMode) throws Exception {

super.init(userMode);
this.context = isServer;
this.authenticatingUserName = context.getContextTenant().getTenantAdmin().getUserName();
this.authenticatingCredential = context.getContextTenant().getTenantAdmin().getPassword();
this.tenant = context.getContextTenant().getDomain();
}

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

super.initTestClass(tenant);
}

@AfterClass(alwaysRun = true)
public void conclude() {

super.conclude();
}

@BeforeMethod(alwaysRun = true)
public void testInit() {

RestAssured.basePath = basePath;
}

@Test
public void testGetRuleMetadataForNotImplementedFlow() throws Exception {

Response responseOfGet = getResponseOfGet(getAPIRequestForFlow("preLogin"));
responseOfGet.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_BAD_REQUEST)
.body("code", equalTo("RULEMETA-60001"))
.body("message", equalTo("Invalid flow."))
.body("description", equalTo("Provided flow type is invalid or not implemented."));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* 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.rest.api.server.rules.metadata.v1;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.hasItems;

public class RulesMetadataSuccessTest extends RulesMetadataTestBase {

@DataProvider(name = "testExecutionContextProvider")
public static Object[][] getTestExecutionContext() {

return new Object[][]{
{TestUserMode.SUPER_TENANT_ADMIN},
{TestUserMode.TENANT_ADMIN}
};
}

@Factory(dataProvider = "testExecutionContextProvider")
public RulesMetadataSuccessTest(TestUserMode userMode) throws Exception {

super.init(userMode);
this.context = isServer;
this.authenticatingUserName = context.getContextTenant().getTenantAdmin().getUserName();
this.authenticatingCredential = context.getContextTenant().getTenantAdmin().getPassword();
this.tenant = context.getContextTenant().getDomain();
}

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

super.initTestClass(tenant);
}

@AfterClass(alwaysRun = true)
public void conclude() {

super.conclude();
}

@BeforeMethod(alwaysRun = true)
public void testInit() {

RestAssured.basePath = basePath;
}

@DataProvider(name = "flowProvider")
public static Object[][] getFlows() {

return new Object[][]{
{"preIssueAccessToken"},
};
}

@Test(dataProvider = "flowProvider")
public void testGetRuleMetadata(String flow) throws Exception {

Response responseOfGet = getResponseOfGet(getAPIRequestForValidFlow(flow));
validateResponse(flow, responseOfGet);
}

private static void validateResponse(String flow, Response response) {

if (flow.equals("preIssueAccessToken")) {
validateResponseForPreIssueAccessTokenFlow(response);
} else {
throw new IllegalArgumentException("Invalid flow: " + flow);
}
}

private static void validateResponseForPreIssueAccessTokenFlow(Response response) {

response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("[0].field.name", equalTo("application"))
.body("[0].field.displayName", equalTo("application"))
.body("[0].operators.name", hasItems("equals", "notEquals"))
.body("[0].operators.displayName", hasItems("equals", "not equals"))
.body("[0].value.inputType", equalTo("options"))
.body("[0].value.valueType", equalTo("reference"))
.body("[0].value.valueReferenceAttribute", equalTo("id"))
.body("[0].value.valueDisplayAttribute", equalTo("name"))
.body("[0].value.links.href",
hasItems("/applications?offset=0&limit=10", "/applications?filter=&limit=10"))
.body("[0].value.links.method", hasItems("GET"))
.body("[0].value.links.rel", hasItems("values", "filter"))
.body("[1].field.name", equalTo("grantType"))
.body("[1].field.displayName", equalTo("grant type"))
.body("[1].operators.name", hasItems("equals", "notEquals"))
.body("[1].operators.displayName", hasItems("equals", "not equals"))
.body("[1].value.inputType", equalTo("options"))
.body("[1].value.valueType", equalTo("string"))
.body("[1].value.values.name",
hasItems("authorization_code", "password", "refresh_token", "client_credentials"))
.body("[1].value.values.displayName",
hasItems("authorization code", "password", "refresh token", "client credentials"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* 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.rest.api.server.rules.metadata.v1;

import org.testng.Assert;
import org.wso2.identity.integration.test.rest.api.server.common.RESTAPIServerTestBase;

import java.io.IOException;

public class RulesMetadataTestBase extends RESTAPIServerTestBase {

private static final String API_DEFINITION_NAME = "rule-metadata.yaml";
private static final String API_VERSION = "v1";

private static String swaggerDefinition;

static {
String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.rule.metadata.v1";
try {
swaggerDefinition = getAPISwaggerDefinition(API_PACKAGE_NAME, API_DEFINITION_NAME);
} catch (IOException e) {
Assert.fail(String.format("Unable to read the swagger definition %s from %s", API_DEFINITION_NAME,
API_PACKAGE_NAME), e);
}
}

protected void initTestClass(String tenantDomain) throws IOException {

super.testInit(API_VERSION, swaggerDefinition, tenantDomain);
}

protected String getAPIRequestForValidFlow(String flow) {

validateFlow(flow);
return getAPIEndpoint() + "?flow=" + flow;
}

protected String getAPIRequestForFlow(String flow) {

return getAPIEndpoint() + "?flow=" + flow;
}

protected String getAPIEndpoint() {

return "/rules/metadata";
}

private void validateFlow(String flow) {

if (!"preIssueAccessToken".equals(flow)) {
throw new IllegalArgumentException("Invalid flow: " + flow);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@
<class name="org.wso2.identity.integration.test.rest.api.server.action.management.v1.ActionsFailureTest"/>
<class name="org.wso2.identity.integration.test.rest.api.server.extension.management.v1.ExtensionManagementSuccessTest"/>
<class name="org.wso2.identity.integration.test.rest.api.server.authenticator.management.v1.AuthenticatorSuccessTest"/>
<class name="org.wso2.identity.integration.test.rest.api.server.rules.metadata.v1.RulesMetadataSuccessTest"/>
<class name="org.wso2.identity.integration.test.rest.api.server.rules.metadata.v1.RulesMetadataFailureTest"/>
</classes>
</test>

Expand Down
9 changes: 9 additions & 0 deletions modules/p2-profile-gen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@
org.wso2.carbon.identity.framework:org.wso2.carbon.identity.certificate.management.server.feature:${carbon.identity.framework.version}
</featureArtifactDef>

<!-- Rule Management Feature -->
<featureArtifactDef>
org.wso2.carbon.identity.framework:org.wso2.carbon.identity.rule.management.server.feature:${carbon.identity.framework.version}
</featureArtifactDef>

<!-- SAML Request/Response Validator Toolkit Feature -->
<featureArtifactDef>
org.wso2.carbon.identity.tool.validator.sso.saml2:org.wso2.carbon.identity.tools.saml.validator.feature:${identity.tool.samlsso.validator.version}
Expand Down Expand Up @@ -856,6 +861,10 @@
<id>org.wso2.carbon.identity.certificate.management.server.feature.group</id>
<version>${carbon.identity.framework.version}</version>
</feature>
<feature>
<id>org.wso2.carbon.identity.rule.management.server.feature.group</id>
<version>${carbon.identity.framework.version}</version>
</feature>
<feature>
<id>
org.wso2.carbon.identity.unique.claim.mgt.server.feature.group
Expand Down