Skip to content

Commit

Permalink
Merge pull request #20706 from ashanthamara/actions
Browse files Browse the repository at this point in the history
Update integration tests of action-mgt rest api.
  • Loading branch information
ashanthamara authored Jul 17, 2024
2 parents 325bd1a + f2cdce4 commit 7f67e8f
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.ActionModel;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.ActionUpdateModel;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.AuthenticationType;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.AuthenticationTypeProperties;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.Endpoint;

import java.io.IOException;
Expand All @@ -43,7 +45,6 @@
*/
public class ActionsFailureTest extends ActionsTestBase {

private static final String PRE_ISSUE_ACCESS_TOKEN_INVALID_PATH = "/preissueaccesstoken";
private static final String TEST_USERNAME_INVALID_AUTH_PROPERTY = "invalidUsername";
private static final String TEST_ACTION_INVALID_ID = "invalid_id";
private static ActionModel action1;
Expand Down Expand Up @@ -88,34 +89,35 @@ public void testFinish() {
}

@Test
public void testCreateActionWithInvalidActionType() {
public void testCreateActionWithInvalidEndpointAuthProperties(){

action1 = new ActionModel()
.name(TEST_ACTION_NAME)
.description(TEST_ACTION_DESCRIPTION)
.endpoint(new Endpoint()
.uri(TEST_ENDPOINT_URI)
.authentication(new AuthenticationType()
.type(AuthenticationType.TypeEnum.BASIC)
.properties(new HashMap<String, Object>() {{
put(TEST_USERNAME_AUTH_PROPERTY, TEST_USERNAME_AUTH_PROPERTY_VALUE);
put(TEST_PASSWORD_AUTH_PROPERTY, TEST_PASSWORD_AUTH_PROPERTY_VALUE);
}})));
.name(TEST_ACTION_NAME)
.description(TEST_ACTION_DESCRIPTION)
.endpoint(new Endpoint()
.uri(TEST_ENDPOINT_URI)
.authentication(new AuthenticationType()
.type(AuthenticationType.TypeEnum.BASIC)
.properties(new HashMap<String, Object>() {{
put(TEST_USERNAME_INVALID_AUTH_PROPERTY, TEST_USERNAME_AUTH_PROPERTY_VALUE);
put(TEST_PASSWORD_AUTH_PROPERTY, TEST_PASSWORD_AUTH_PROPERTY_VALUE);
}})));

String body = toJSONString(action1);
Response responseOfPost = getResponseOfPost(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_INVALID_PATH, body);
PRE_ISSUE_ACCESS_TOKEN_PATH, body);
responseOfPost.then()
.log().ifValidationFails()
.assertThat().statusCode(HttpStatus.SC_BAD_REQUEST)
.body("description", equalTo("Invalid action type used for path parameter."));
.body("description", equalTo("Required authentication properties are not " +
"provided or invalid."));
}

@Test(dependsOnMethods = {"testCreateActionWithInvalidActionType"})
public void testCreateActionWithInvalidEndpointAuthProperties(){
@Test(dependsOnMethods = {"testCreateActionWithInvalidEndpointAuthProperties"})
public void testCreateActionWithEmptyEndpointAuthPropertyValues(){

action1.getEndpoint().getAuthentication().setProperties(new HashMap<String, Object>() {{
put(TEST_USERNAME_INVALID_AUTH_PROPERTY, TEST_USERNAME_AUTH_PROPERTY_VALUE);
put(TEST_USERNAME_AUTH_PROPERTY, "");
put(TEST_PASSWORD_AUTH_PROPERTY, TEST_PASSWORD_AUTH_PROPERTY_VALUE);
}});

Expand All @@ -125,11 +127,10 @@ public void testCreateActionWithInvalidEndpointAuthProperties(){
responseOfPost.then()
.log().ifValidationFails()
.assertThat().statusCode(HttpStatus.SC_BAD_REQUEST)
.body("description", equalTo("Required authentication properties are not " +
"provided or invalid."));
.body("description", equalTo("Authentication property values cannot be empty."));
}

@Test(dependsOnMethods = {"testCreateActionWithInvalidEndpointAuthProperties"})
@Test(dependsOnMethods = {"testCreateActionWithEmptyEndpointAuthPropertyValues"})
public void testCreateActionAfterReachingMaxActionCount(){

// Create an action.
Expand Down Expand Up @@ -160,11 +161,27 @@ public void testCreateActionAfterReachingMaxActionCount(){
@Test(dependsOnMethods = {"testCreateActionAfterReachingMaxActionCount"})
public void testUpdateActionWithInvalidID(){

action2.setName(TEST_ACTION_UPDATED_NAME);
// Update Action basic information with an invalid action id.
ActionUpdateModel actionUpdateModel = new ActionUpdateModel()
.name(TEST_ACTION_UPDATED_NAME);

String body = toJSONString(action2);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
String body = toJSONString(actionUpdateModel);
Response responseOfPatch = getResponseOfPatch(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + TEST_ACTION_INVALID_ID, body);
responseOfPatch.then()
.log().ifValidationFails()
.assertThat().statusCode(HttpStatus.SC_NOT_FOUND)
.body("description", equalTo("No Action is configured on the given action Id."));

// Update Action Endpoint Authentication Properties with an invalid action id.
AuthenticationTypeProperties authenticationType = new AuthenticationTypeProperties()
.properties(new HashMap<String, Object>() {{
put(TEST_ACCESS_TOKEN_AUTH_PROPERTY, TEST_ACCESS_TOKEN_AUTH_PROPERTY_VALUE);
}});

body = toJSONString(authenticationType);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + TEST_ACTION_INVALID_ID + ACTION_BEARER_AUTH_PATH, body);
responseOfPut.then()
.log().ifValidationFails()
.assertThat().statusCode(HttpStatus.SC_NOT_FOUND)
Expand All @@ -174,14 +191,15 @@ public void testUpdateActionWithInvalidID(){
@Test(dependsOnMethods = {"testUpdateActionWithInvalidID"})
public void testUpdateActionWithInvalidEndpointAuthProperties(){

action2.getEndpoint().getAuthentication().setProperties(new HashMap<String, Object>() {{
put(TEST_USERNAME_INVALID_AUTH_PROPERTY, TEST_USERNAME_AUTH_PROPERTY_VALUE);
put(TEST_PASSWORD_AUTH_PROPERTY, TEST_PASSWORD_AUTH_PROPERTY_VALUE);
}});
AuthenticationTypeProperties authenticationType = new AuthenticationTypeProperties()
.properties(new HashMap<String, Object>() {{
put(TEST_USERNAME_INVALID_AUTH_PROPERTY, TEST_USERNAME_AUTH_PROPERTY_VALUE);
put(TEST_PASSWORD_AUTH_PROPERTY, TEST_PASSWORD_AUTH_PROPERTY_VALUE);
}});

String body = toJSONString(action2);
String body = toJSONString(authenticationType);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId2, body);
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId2 + ACTION_BASIC_AUTH_PATH, body);
responseOfPut.then()
.log().ifValidationFails()
.assertThat().statusCode(HttpStatus.SC_BAD_REQUEST)
Expand All @@ -190,6 +208,24 @@ public void testUpdateActionWithInvalidEndpointAuthProperties(){
}

@Test(dependsOnMethods = {"testUpdateActionWithInvalidEndpointAuthProperties"})
public void testUpdateActionWithEmptyEndpointAuthPropertyValues(){

AuthenticationTypeProperties authenticationType = new AuthenticationTypeProperties()
.properties(new HashMap<String, Object>() {{
put(TEST_USERNAME_AUTH_PROPERTY, "");
put(TEST_PASSWORD_AUTH_PROPERTY, TEST_PASSWORD_AUTH_PROPERTY_VALUE);
}});

String body = toJSONString(authenticationType);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId2 + ACTION_BASIC_AUTH_PATH, body);
responseOfPut.then()
.log().ifValidationFails()
.assertThat().statusCode(HttpStatus.SC_BAD_REQUEST)
.body("description", equalTo("Authentication property values cannot be empty."));
}

@Test(dependsOnMethods = {"testUpdateActionWithEmptyEndpointAuthPropertyValues"})
public void testActivateActionWithInvalidID(){

getResponseOfPost(ACTION_MANAGEMENT_API_BASE_PATH + PRE_ISSUE_ACCESS_TOKEN_PATH +
Expand All @@ -211,6 +247,18 @@ public void testDeactivateActionWithInvalidID(){
.assertThat()
.statusCode(HttpStatus.SC_NOT_FOUND)
.body("description", equalTo("No Action is configured on the given action Id."));
}

@Test(dependsOnMethods = {"testDeactivateActionWithInvalidID"})
public void testDeleteActionWithInvalidID(){

getResponseOfDelete(ACTION_MANAGEMENT_API_BASE_PATH + PRE_ISSUE_ACCESS_TOKEN_PATH +
"/" + TEST_ACTION_INVALID_ID)
.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NOT_FOUND)
.body("description", equalTo("No Action is configured on the given action Id."));

// Delete, created action.
deleteAction(PRE_ISSUE_ACCESS_TOKEN_PATH , testActionId2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.ActionModel;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.ActionUpdateModel;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.AuthenticationType;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.AuthenticationTypeProperties;
import org.wso2.identity.integration.test.rest.api.server.action.management.v1.model.Endpoint;

import java.io.IOException;
Expand Down Expand Up @@ -104,8 +106,7 @@ public void testCreateAction() {
.body("description", equalTo(TEST_ACTION_DESCRIPTION))
.body("endpoint.uri", equalTo(TEST_ENDPOINT_URI))
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BASIC.toString()))
.body("endpoint.authentication.properties.username", equalTo(TEST_USERNAME_AUTH_PROPERTY_VALUE))
.body("endpoint.authentication.properties.password", equalTo(TEST_PASSWORD_AUTH_PROPERTY_VALUE));
.body("endpoint.authentication", not(hasKey(TEST_PROPERTIES_AUTH_ATTRIBUTE)));

testActionId = responseOfPost.getBody().jsonPath().getString("id");
}
Expand All @@ -125,13 +126,11 @@ public void testGetActionByActionType() {
.body( "find { it.id == '" + testActionId + "' }.endpoint.uri", equalTo(TEST_ENDPOINT_URI))
.body( "find { it.id == '" + testActionId + "' }.endpoint.authentication.type",
equalTo(AuthenticationType.TypeEnum.BASIC.toString()))
.body( "find { it.id == '" + testActionId + "' }.endpoint.authentication.properties.username",
equalTo(TEST_USERNAME_AUTH_PROPERTY_VALUE))
.body( "find { it.id == '" + testActionId + "' }.endpoint.authentication.properties.password",
equalTo(TEST_PASSWORD_AUTH_PROPERTY_VALUE));
.body( "find { it.id == '" + testActionId + "' }.endpoint.authentication",
not(hasKey(TEST_PROPERTIES_AUTH_ATTRIBUTE)));
}

@Test(dependsOnMethods = {"testCreateAction"})
@Test(dependsOnMethods = {"testGetActionByActionType"})
public void testGetActions() {

Response responseOfGet = getResponseOfGet(ACTION_MANAGEMENT_API_BASE_PATH + TYPES_API_PATH);
Expand All @@ -155,35 +154,70 @@ public void testGetActions() {
.body( "find { it.type == '" + PRE_UPDATE_PASSWORD_ACTION_TYPE + "' }.self", notNullValue());
}

@Test(dependsOnMethods = {"testGetActionByActionType"})
public void testUpdateAction() {
@Test(dependsOnMethods = {"testGetActions"})
public void testUpdateActionBasicInfo() {

action.setName(TEST_ACTION_UPDATED_NAME);
action.getEndpoint().setAuthentication(new AuthenticationType()
.type(AuthenticationType.TypeEnum.BEARER)
.properties(new HashMap<String, Object>() {{
put(TEST_ACCESS_TOKEN_AUTH_PROPERTY, TEST_ACCESS_TOKEN_AUTH_PROPERTY_VALUE);
}}));
ActionUpdateModel actionUpdateModel = new ActionUpdateModel()
.name(TEST_ACTION_UPDATED_NAME)
.endpointUri(TEST_UPDATED_ENDPOINT_URI);

String body = toJSONString(action);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
String body = toJSONString(actionUpdateModel);
Response responseOfPatch = getResponseOfPatch(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId, body);

responseOfPut.then()
responseOfPatch.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("id", equalTo(testActionId))
.body("name", equalTo(TEST_ACTION_UPDATED_NAME))
.body("description", equalTo(TEST_ACTION_DESCRIPTION))
.body("status", equalTo(TEST_ACTION_ACTIVE_STATUS))
.body("endpoint.uri", equalTo(TEST_ENDPOINT_URI))
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.toString()))
.body("endpoint.authentication.properties.accessToken",
equalTo(TEST_ACCESS_TOKEN_AUTH_PROPERTY_VALUE));
.body("endpoint.uri", equalTo(TEST_UPDATED_ENDPOINT_URI))
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BASIC.toString()))
.body("endpoint.authentication", not(hasKey(TEST_PROPERTIES_AUTH_ATTRIBUTE)));
}

@Test(dependsOnMethods = {"testUpdateAction"})
@Test(dependsOnMethods = {"testUpdateActionBasicInfo"})
public void testUpdateEndpointAuthentication() {

AuthenticationTypeProperties newAuthProperties = new AuthenticationTypeProperties()
.properties(new HashMap<String, Object>() {{
put(TEST_ACCESS_TOKEN_AUTH_PROPERTY, TEST_ACCESS_TOKEN_AUTH_PROPERTY_VALUE);
}});

String body = toJSONString(newAuthProperties);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId + ACTION_BEARER_AUTH_PATH, body);

responseOfPut.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("endpoint.uri", equalTo(TEST_UPDATED_ENDPOINT_URI))
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.toString()));
}

@Test(dependsOnMethods = {"testUpdateEndpointAuthentication"})
public void testUpdateEndpointAuthProperties() {

AuthenticationTypeProperties newAuthProperties = new AuthenticationTypeProperties()
.properties(new HashMap<String, Object>() {{
put(TEST_ACCESS_TOKEN_AUTH_PROPERTY, TEST_UPDATED_ACCESS_TOKEN_AUTH_PROPERTY_VALUE);
}});

String body = toJSONString(newAuthProperties);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId + ACTION_BEARER_AUTH_PATH, body);

responseOfPut.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.toString()));
}

@Test(dependsOnMethods = {"testUpdateEndpointAuthProperties"})
public void testDeactivateAction() {

getResponseOfPost(ACTION_MANAGEMENT_API_BASE_PATH + PRE_ISSUE_ACCESS_TOKEN_PATH +
Expand Down Expand Up @@ -253,38 +287,29 @@ public void testCreateActionWithExtraEndpointAuthProperties() {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BASIC.toString()))
.body("endpoint.authentication.properties.username", equalTo(TEST_USERNAME_AUTH_PROPERTY_VALUE))
.body("endpoint.authentication.properties.password", equalTo(TEST_PASSWORD_AUTH_PROPERTY_VALUE))
.body("endpoint.authentication.properties", not(hasKey(TEST_ACCESS_TOKEN_AUTH_PROPERTY)));
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BASIC.toString()));

testActionId = responseOfPost.getBody().jsonPath().getString("id");
}

@Test(dependsOnMethods = {"testCreateActionWithExtraEndpointAuthProperties"})
public void testUpdateActionWithExtraEndpointAuthProperties() {

action.setName(TEST_ACTION_UPDATED_NAME);
action.getEndpoint().setAuthentication(new AuthenticationType()
.type(AuthenticationType.TypeEnum.BEARER)
AuthenticationTypeProperties newAuthProperties = new AuthenticationTypeProperties()
.properties(new HashMap<String, Object>() {{
put(TEST_ACCESS_TOKEN_AUTH_PROPERTY, TEST_ACCESS_TOKEN_AUTH_PROPERTY_VALUE);
put(TEST_USERNAME_AUTH_PROPERTY, TEST_USERNAME_AUTH_PROPERTY_VALUE);
}}));
}});

String body = toJSONString(action);
String body = toJSONString(newAuthProperties);
Response responseOfPut = getResponseOfPut(ACTION_MANAGEMENT_API_BASE_PATH +
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId, body);
PRE_ISSUE_ACCESS_TOKEN_PATH + "/" + testActionId + ACTION_BEARER_AUTH_PATH, body);

responseOfPut.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("name", equalTo(TEST_ACTION_UPDATED_NAME))
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.toString()))
.body("endpoint.authentication.properties.accessToken",
equalTo(TEST_ACCESS_TOKEN_AUTH_PROPERTY_VALUE))
.body("endpoint.authentication.properties", not(hasKey(TEST_USERNAME_AUTH_PROPERTY)));
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.toString()));

// Delete, created action.
deleteAction(PRE_ISSUE_ACCESS_TOKEN_PATH , testActionId);
Expand Down
Loading

0 comments on commit 7f67e8f

Please sign in to comment.