Skip to content

Commit

Permalink
Merge pull request #21315 from Thisara-Welmilla/improve-authenticatio…
Browse files Browse the repository at this point in the history
…n-api-integration-test

Improve integration tests on the definedBy authentication property
  • Loading branch information
Thisara-Welmilla authored Oct 19, 2024
2 parents 1785ec1 + 2418eca commit 01587c3
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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.authenticator.management.v1;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
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 java.io.IOException;

/**
* Tests for happy paths of the authentication Management REST API.
*/
public class AuthenticatorSuccessTest extends AuthenticatorTestBase{


@Factory(dataProvider = "restAPIUserConfigProvider")
public AuthenticatorSuccessTest(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 IOException {

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

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

super.conclude();
}

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

RestAssured.basePath = basePath;
}

@AfterMethod(alwaysRun = true)
public void testFinish() {

RestAssured.basePath = StringUtils.EMPTY;
}

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

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

@Test
public void getAuthenticators() throws JSONException {

Response response = getResponseOfGet(AUTHENTICATOR_API_BASE_PATH);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK);

JSONArray jsonArray = new JSONArray(response.body().asString());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject authenticator = jsonArray.getJSONObject(i);
Assert.assertTrue(authenticator.has("id"));
Assert.assertTrue(authenticator.has("name"));
Assert.assertTrue(authenticator.has("displayName"));
Assert.assertTrue(authenticator.has("type"));
Assert.assertEquals(authenticator.getString("definedBy"), "SYSTEM");
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.authenticator.management.v1;

import io.restassured.RestAssured;
import org.apache.commons.lang.StringUtils;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.wso2.identity.integration.test.rest.api.server.common.RESTAPIServerTestBase;

import java.io.IOException;

public class AuthenticatorTestBase extends RESTAPIServerTestBase {

private static final String API_DEFINITION_NAME = "authenticators.yaml";
protected static final String API_VERSION = "v1";
protected static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.authenticators.v1";

protected static final String AUTHENTICATOR_API_BASE_PATH = "/authenticators";

protected static String swaggerDefinition;

static {
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);
}
}

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

super.conclude();
}

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

RestAssured.basePath = basePath;
}

@AfterMethod(alwaysRun = true)
public void testFinish() {

RestAssured.basePath = StringUtils.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void testGetAuthenticator() throws Exception {
.body("name", equalTo("BasicAuthenticator"))
.body("displayName", equalTo("Username & Password"))
.body("isEnabled", equalTo(true))
.body("properties", notNullValue());
.body("properties", notNullValue())
.body("definedBy", equalTo("SYSTEM"));
}

@Test(dependsOnMethods = {"testGetAuthenticator"})
Expand All @@ -118,7 +119,8 @@ public void testGetAuthenticators() throws Exception {
.statusCode(HttpStatus.SC_OK)
.body(baseIdentifier + "name", equalTo("BasicAuthenticator"))
.body(baseIdentifier + "displayName", equalTo("Username & Password"))
.body(baseIdentifier + "isEnabled", equalTo(true));
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo("SYSTEM"));
}

@Test(dependsOnMethods = {"testGetAuthenticators"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ public void testUpdateIdPFederatedAuthenticator() throws IOException {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK);
.statusCode(HttpStatus.SC_OK)
.body("definedBy", equalTo("SYSTEM"));
}

@Test(dependsOnMethods = {"testUpdateIdPFederatedAuthenticator"})
Expand All @@ -377,6 +378,7 @@ public void testGetIdPFederatedAuthenticator() throws IOException {
.body("isEnabled", equalTo(true))
.body("isDefault", equalTo(true))
.body("properties", notNullValue())
.body("definedBy", equalTo("SYSTEM"))
.body("properties.find{ it.key == 'ClientId' }.value", equalTo
("165474950684-7mvqd8m6hieb8mdnffcarnku2aua0tpl.apps.googleusercontent.com"))
.body("properties.find{ it.key == 'ClientSecret' }.value", equalTo("testclientsecret"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
<class name="org.wso2.identity.integration.test.rest.api.server.action.management.v1.ActionsSuccessTest"/>
<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"/>
</classes>
</test>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@

<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.17</identity.api.dispatcher.version>
<identity.server.api.version>1.2.239</identity.server.api.version>
<identity.server.api.version>1.2.240</identity.server.api.version>
<identity.user.api.version>1.3.43</identity.user.api.version>

<identity.agent.sso.version>5.5.9</identity.agent.sso.version>
Expand Down

0 comments on commit 01587c3

Please sign in to comment.