-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21315 from Thisara-Welmilla/improve-authenticatio…
…n-api-integration-test Improve integration tests on the definedBy authentication property
- Loading branch information
Showing
6 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...ntegration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.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,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"); | ||
} | ||
} | ||
|
||
} | ||
|
67 changes: 67 additions & 0 deletions
67
...y/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.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,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; | ||
} | ||
} |
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
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
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
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