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

Set the default action status to INACTIVE #6556

Merged
merged 2 commits into from
Feb 22, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ private void addBasicInfo(ActionDTO actionDTO, Integer tenantId) throws ActionMg
statement.setString(ActionMgtSQLConstants.Column.ACTION_NAME, actionDTO.getName());
statement.setString(ActionMgtSQLConstants.Column.ACTION_DESCRIPTION,
actionDTO.getDescription());
statement.setString(ActionMgtSQLConstants.Column.ACTION_STATUS,
String.valueOf(Action.Status.ACTIVE));
statement.setString(ActionMgtSQLConstants.Column.ACTION_STATUS, actionDTO.getStatus().name());
statement.setInt(ActionMgtSQLConstants.Column.TENANT_ID, tenantId);
statement.setString(ActionMgtSQLConstants.Column.SCHEMA_VERSION, V1);
}, actionDTO, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,26 @@ private void doEndpointAuthenticationValidation(Authentication authentication) t

private ActionDTO buildActionDTO(String actionType, String actionId, Action action) {

Action.ActionTypes resolvedActionType = Action.ActionTypes.valueOf(actionType);
Action.Status resolvedStatus = resolvedActionType.getCategory() == Action.ActionTypes.Category.IN_FLOW ?
Action.Status.ACTIVE : Action.Status.INACTIVE;

ActionConverter actionConverter =
ActionConverterFactory.getActionConverter(Action.ActionTypes.valueOf(actionType));
if (actionConverter != null) {
ActionDTO actionDTO = actionConverter.buildActionDTO(action);

return new ActionDTOBuilder(actionDTO)
.id(actionId)
.type(Action.ActionTypes.valueOf(actionType))
.type(resolvedActionType)
.status(resolvedStatus)
.build();
}

return new ActionDTOBuilder(action)
.id(actionId)
.type(Action.ActionTypes.valueOf(actionType))
.type(resolvedActionType)
.status(resolvedStatus)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ public void testUpdateCompleteAction() throws ActionMgtException {
}

@Test(priority = 8)
public void testActivateAction() throws ActionMgtException {

Assert.assertEquals(actionDTORetrieved.getStatus(), Action.Status.INACTIVE);
ActionDTO activatedActionDTO = daoFacade.activateAction(PRE_UPDATE_PASSWORD_TYPE, actionDTORetrieved.getId(),
TENANT_ID);
Assert.assertEquals(activatedActionDTO.getStatus(), Action.Status.ACTIVE);
actionDTORetrieved = activatedActionDTO;
}

@Test(priority = 9)
public void testDeactivateAction() throws ActionMgtException {

Assert.assertEquals(actionDTORetrieved.getStatus(), Action.Status.ACTIVE);
Expand All @@ -311,14 +321,6 @@ public void testDeactivateAction() throws ActionMgtException {
Assert.assertEquals(deactivatedActionDTO.getStatus(), Action.Status.INACTIVE);
}

@Test(priority = 9)
public void testActivateAction() throws ActionMgtException {

ActionDTO activatedActionDTO = daoFacade.activateAction(PRE_UPDATE_PASSWORD_TYPE, actionDTORetrieved.getId(),
TENANT_ID);
Assert.assertEquals(activatedActionDTO.getStatus(), Action.Status.ACTIVE);
}

@Test(priority = 10)
public void testGetActionsCountPerType() throws ActionMgtException {

Expand All @@ -330,6 +332,9 @@ public void testGetActionsCountPerType() throws ActionMgtException {
@Test(priority = 11)
public void testDeleteAction() throws ActionMgtException {

actionDTORetrieved = daoFacade.getActionByActionId(PRE_UPDATE_PASSWORD_TYPE, actionDTORetrieved.getId(),
TENANT_ID);

mockActionPropertyResolver(testActionPropertyResolver);
try {
daoFacade.deleteAction(actionDTORetrieved, TENANT_ID);
Expand Down Expand Up @@ -579,6 +584,7 @@ private ActionDTOBuilder createActionDTOBuilderForPasswordUpdateAction() {
.type(Action.ActionTypes.PRE_UPDATE_PASSWORD)
.name(TEST_ACTION_NAME)
.description(TEST_ACTION_DESCRIPTION)
.status(Action.Status.INACTIVE)
.endpoint(new EndpointConfig.EndpointConfigBuilder()
.uri(TEST_ACTION_URI)
.authentication(TestUtil.buildMockBasicAuthentication(TEST_USERNAME, TEST_PASSWORD))
Expand All @@ -594,7 +600,7 @@ private void verifyActionDTO(ActionDTO actualActionDTO, ActionDTO expectedAction
Assert.assertEquals(actualActionDTO.getType(), expectedActionDTO.getType());
Assert.assertEquals(actualActionDTO.getName(), expectedActionDTO.getName());
Assert.assertEquals(actualActionDTO.getDescription(), expectedActionDTO.getDescription());
Assert.assertEquals(actualActionDTO.getStatus(), Action.Status.ACTIVE);
Assert.assertEquals(actualActionDTO.getStatus(), Action.Status.INACTIVE);
Assert.assertEquals(actualActionDTO.getEndpoint().getUri(), expectedActionDTO.getEndpoint().getUri());

Authentication createdAuthentication = actualActionDTO.getEndpoint().getAuthentication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void testAddAction() throws ActionMgtException {
.type(Action.ActionTypes.PRE_ISSUE_ACCESS_TOKEN)
.name(TestUtil.TEST_ACTION_NAME)
.description(TestUtil.TEST_ACTION_DESCRIPTION)
.status(Action.Status.INACTIVE)
.endpoint(new EndpointConfig.EndpointConfigBuilder()
.uri(TestUtil.TEST_ACTION_URI)
.authentication(TestUtil.buildMockBasicAuthentication(TestUtil.TEST_USERNAME_SECRET_REFERENCE,
Expand All @@ -89,7 +90,7 @@ public void testAddAction() throws ActionMgtException {
Assert.assertEquals(createdActionDTO.getType(), creatingActionDTO.getType());
Assert.assertEquals(createdActionDTO.getName(), creatingActionDTO.getName());
Assert.assertEquals(createdActionDTO.getDescription(), creatingActionDTO.getDescription());
Assert.assertEquals(createdActionDTO.getStatus(), Action.Status.ACTIVE);
Assert.assertEquals(createdActionDTO.getStatus(), Action.Status.INACTIVE);
Assert.assertEquals(createdActionDTO.getEndpoint().getUri(), creatingActionDTO.getEndpoint().getUri());

Authentication createdAuthentication = createdActionDTO.getEndpoint().getAuthentication();
Expand Down Expand Up @@ -178,6 +179,7 @@ public void testAddActionWithoutDescription() throws ActionMgtException {
.id(PRE_ISSUE_ACCESS_TOKEN_ACTION_ID)
.type(Action.ActionTypes.PRE_ISSUE_ACCESS_TOKEN)
.name(TestUtil.TEST_ACTION_NAME)
.status(Action.Status.INACTIVE)
.endpoint(new EndpointConfig.EndpointConfigBuilder()
.uri(TestUtil.TEST_ACTION_URI)
.authentication(TestUtil.buildMockBasicAuthentication(TestUtil.TEST_USERNAME_SECRET_REFERENCE,
Expand All @@ -197,7 +199,7 @@ public void testAddActionWithoutDescription() throws ActionMgtException {
Assert.assertEquals(createdActionDTO.getType(), creatingActionDTO.getType());
Assert.assertEquals(createdActionDTO.getName(), creatingActionDTO.getName());
Assert.assertNull(createdActionDTO.getDescription());
Assert.assertEquals(createdActionDTO.getStatus(), Action.Status.ACTIVE);
Assert.assertEquals(createdActionDTO.getStatus(), Action.Status.INACTIVE);
Assert.assertEquals(createdActionDTO.getEndpoint().getUri(), creatingActionDTO.getEndpoint().getUri());

Authentication createdAuthentication = createdActionDTO.getEndpoint().getAuthentication();
Expand Down Expand Up @@ -505,22 +507,23 @@ public void testUpdateActionProperties() throws ActionMgtException {
createdActionDTO = result;
}


@Test(priority = 14)
public void testDeactivateAction() throws ActionMgtException {
public void testActivateAction() throws ActionMgtException {

Assert.assertEquals(createdActionDTO.getStatus(), Action.Status.ACTIVE);
ActionDTO deactivatedActionDTO = daoImpl.deactivateAction(PRE_ISSUE_ACCESS_TOKEN_TYPE, createdActionDTO.getId(),
Assert.assertEquals(createdActionDTO.getStatus(), Action.Status.INACTIVE);
ActionDTO activatedActionDTO = daoImpl.activateAction(PRE_ISSUE_ACCESS_TOKEN_TYPE, createdActionDTO.getId(),
TENANT_ID);
Assert.assertEquals(deactivatedActionDTO.getStatus(), Action.Status.INACTIVE);
Assert.assertEquals(activatedActionDTO.getStatus(), Action.Status.ACTIVE);
createdActionDTO = activatedActionDTO;
}

@Test(priority = 15)
public void testActivateAction() throws ActionMgtException {
public void testDeactivateAction() throws ActionMgtException {

ActionDTO activatedActionDTO = daoImpl.activateAction(PRE_ISSUE_ACCESS_TOKEN_TYPE, createdActionDTO.getId(),
Assert.assertEquals(createdActionDTO.getStatus(), Action.Status.ACTIVE);
ActionDTO deactivatedActionDTO = daoImpl.deactivateAction(PRE_ISSUE_ACCESS_TOKEN_TYPE, createdActionDTO.getId(),
TENANT_ID);
Assert.assertEquals(activatedActionDTO.getStatus(), Action.Status.ACTIVE);
Assert.assertEquals(deactivatedActionDTO.getStatus(), Action.Status.INACTIVE);
}

@Test(priority = 16)
Expand All @@ -530,6 +533,7 @@ public void testGetActionsCountPerType() throws ActionMgtException {
.id(PRE_UPDATE_PASSWORD_ACTION_ID)
.type(Action.ActionTypes.PRE_UPDATE_PASSWORD)
.name(TestUtil.TEST_ACTION_NAME)
.status(Action.Status.INACTIVE)
.endpoint(new EndpointConfig.EndpointConfigBuilder()
.uri(TestUtil.TEST_ACTION_URI)
.authentication(new Authentication.NoneAuthBuilder().build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testAddAction() throws ActionMgtException, SecretManagementException
Assert.assertNotNull(sampleAction.getId());
Assert.assertEquals(sampleAction.getName(), creatingAction.getName());
Assert.assertEquals(sampleAction.getDescription(), creatingAction.getDescription());
Assert.assertEquals(sampleAction.getStatus(), Action.Status.ACTIVE);
Assert.assertEquals(sampleAction.getStatus(), Action.Status.INACTIVE);
Assert.assertEquals(sampleAction.getType(), Action.ActionTypes.PRE_ISSUE_ACCESS_TOKEN);
Assert.assertEquals(sampleAction.getEndpoint().getUri(), creatingAction.getEndpoint().getUri());

Expand Down Expand Up @@ -248,20 +248,13 @@ public void testUpdateAction() throws ActionMgtException, SecretManagementExcept
}

@Test(priority = 8)
public void testDeactivateAction() throws ActionMgtException {

Assert.assertEquals(sampleAction.getStatus(), Action.Status.ACTIVE);
Action deactivatedAction = actionManagementService.deactivateAction(PRE_ISSUE_ACCESS_TOKEN_PATH,
sampleAction.getId(), TENANT_DOMAIN);
Assert.assertEquals(deactivatedAction.getStatus(), Action.Status.INACTIVE);
}

@Test(priority = 9)
public void testActivateAction() throws ActionMgtException {

Assert.assertEquals(sampleAction.getStatus(), Action.Status.INACTIVE);
Action activatedAction = actionManagementService.activateAction(PRE_ISSUE_ACCESS_TOKEN_PATH,
sampleAction.getId(), TENANT_DOMAIN);
Assert.assertEquals(activatedAction.getStatus(), Action.Status.ACTIVE);
sampleAction = activatedAction;
}

@Test(priority = 10)
Expand All @@ -278,6 +271,15 @@ public void testGetActionsCountPerType() throws ActionMgtException {
}
}

@Test(priority = 11)
public void testDeactivateAction() throws ActionMgtException {

Assert.assertEquals(sampleAction.getStatus(), Action.Status.ACTIVE);
Action deactivatedAction = actionManagementService.deactivateAction(PRE_ISSUE_ACCESS_TOKEN_PATH,
sampleAction.getId(), TENANT_DOMAIN);
Assert.assertEquals(deactivatedAction.getStatus(), Action.Status.INACTIVE);
}

@Test(priority = 11)
public void testUpdateEndpointConfigWithSameAuthenticationType() throws ActionMgtException,
SecretManagementException {
Expand Down Expand Up @@ -347,7 +349,7 @@ public void testAddActionWithRule() throws ActionMgtException, SecretManagementE
Assert.assertNotNull(sampleAction.getId());
Assert.assertEquals(sampleAction.getName(), creatingAction.getName());
Assert.assertEquals(sampleAction.getDescription(), creatingAction.getDescription());
Assert.assertEquals(sampleAction.getStatus(), Action.Status.ACTIVE);
Assert.assertEquals(sampleAction.getStatus(), Action.Status.INACTIVE);
Assert.assertEquals(sampleAction.getType(), Action.ActionTypes.PRE_ISSUE_ACCESS_TOKEN);
Assert.assertEquals(sampleAction.getEndpoint().getUri(), creatingAction.getEndpoint().getUri());

Expand Down