diff options
author | MichaelMorris <michael.morris@est.tech> | 2023-05-15 11:26:46 +0100 |
---|---|---|
committer | MichaelMorris <michael.morris@est.tech> | 2023-05-15 22:40:08 +0100 |
commit | 5768f2e5a056df6b23f7f8a87529d5ca00063c68 (patch) | |
tree | 20b5679279a5987913f91f69ad0fd6b0885ca065 /catalog-be | |
parent | f21f1b1b1f474e311409693f5a49780101cb5bc5 (diff) |
Fix error in userId handling
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-4468
Change-Id: Iccc61e54876fea732d82334d0bf21bc485b9e1bb
Diffstat (limited to 'catalog-be')
8 files changed, 30 insertions, 1 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index 8b18346bdd..de0f791eda 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -375,7 +375,7 @@ public abstract class BaseBusinessLogic { } // verify component last update user is the current user String lastUpdaterUserId = component.getLastUpdaterUserId(); - if (!userId.equals(lastUpdaterUserId)) { + if (!userValidations.isSameUser(userId, lastUpdaterUserId)) { log.debug("Current user is not last updater, last updater userId: {}, current user userId: {}", lastUpdaterUserId, userId); throw new ByActionStatusComponentException(actionStatus); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java index cf4f84884f..3d148f64c1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java @@ -82,4 +82,8 @@ public class UserValidations { public User validateUserExists(final User user) { return validateUserExists(user.getUserId()); } + + public boolean isSameUser(final String userId1, final String userId2) { + return validateUserExists(userId1).getUserId().equals(validateUserExists(userId2).getUserId()); + } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java index 54ccf2bee9..36d22bc453 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java @@ -2139,6 +2139,8 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock { when(userValidations.validateUserExists(Mockito.eq("userId"))) .thenReturn(user); + when(userValidations.isSameUser(Mockito.eq("userId"), Mockito.eq("userId"))) + .thenReturn(true); when(toscaOperationFacade.getToscaFullElement(any())) .thenReturn(Either.left(resource)); when(artifactToscaOperation.getArtifactById(any(), any(), any(), any())) @@ -2259,6 +2261,8 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock { when(userValidations.validateUserExists(eq(user.getUserId()))) .thenReturn(user); + when(userValidations.isSameUser(Mockito.eq("userId"), Mockito.eq("userId"))) + .thenReturn(true); when(toscaOperationFacade.getToscaFullElement(eq(componentId))) .thenReturn(Either.left(resource)); when(artifactToscaOperation.getArtifactById(anyString(), anyString(), any(ComponentTypeEnum.class), anyString())) diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index f6a86ac02f..e813924b4b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -715,6 +715,7 @@ class ComponentInstanceBusinessLogicTest { private void stubMethods() { Mockito.lenient().when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user); + Mockito.lenient().when(userValidations.isSameUser(eq(USER_ID),eq(USER_ID))).thenReturn(true); Mockito.lenient().when(componentsUtils .convertFromStorageResponse(eq(StorageOperationStatus.GENERAL_ERROR), any(ComponentTypeEnum.class))) .thenReturn(ActionStatus.GENERAL_ERROR); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java index 953cc3b801..5ecc488570 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java @@ -179,6 +179,7 @@ public class InputsBusinessLogicTest { instanceInputMap.put("someInputId", Collections.singletonList(new ComponentInstanceInput())); service.setComponentInstancesInputs(instanceInputMap); when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(new User()); + when(userValidations.isSameUser(eq(USER_ID),eq(USER_ID))).thenReturn(true); when(userAdminMock.getUser(USER_ID, false)).thenReturn(new User()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java index cfdd774f67..ddef267c8d 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java @@ -46,6 +46,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.components.attribute.AttributeDeclarationOrchestrator; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; @@ -159,6 +160,7 @@ class OutputsBusinessLogicTest { instanceOutputMap.put("someOutputId", Collections.singletonList(new ComponentInstanceOutput())); service.setComponentInstancesOutputs(instanceOutputMap); when(userValidations.validateUserExists(USER_ID)).thenReturn(new User()); + when(userValidations.isSameUser(eq(USER_ID),eq(USER_ID))).thenReturn(true); when(userAdminMock.getUser(USER_ID, false)).thenReturn(new User()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java index d0a91e312a..83e52674d7 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java @@ -502,6 +502,7 @@ class PolicyBusinessLogicTest { @Test void testDeclarePropertiesAsPoliciesSuccess() { + when(userValidations.isSameUser(eq(USER_ID),eq(USER_ID))).thenReturn(true); when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource)); when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK); when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK); @@ -603,6 +604,7 @@ class PolicyBusinessLogicTest { private void stubValidationSuccess() { when(userValidations.validateUserExists(USER_ID)).thenReturn(user); + Mockito.lenient().when(userValidations.isSameUser(eq(USER_ID),eq(USER_ID))).thenReturn(true); when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java index c19cf4679e..6a7bed9341 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java @@ -160,4 +160,19 @@ public class UserValidationsTest { }); Mockito.verify(userAdmin, Mockito.times(1)).getUser(Mockito.anyString()); } + + @Test + public void testValidateUserisSame() { + String userId = "cs0008"; + String encryptedSameUser = "eaGi1IQqP9kbgBHuG/pZm9frcXMQUvoQ59rKkiz6+ug="; + + User user = new User(); + user.setUserId(userId); + user.setStatus(UserStatusEnum.ACTIVE); + + Mockito.when(userAdmin.getUser(userId)).thenReturn(user); + Mockito.when(userAdmin.getUser(encryptedSameUser)).thenReturn(user); + + assertTrue(testSubject.isSameUser(userId, encryptedSameUser)); + } } |