Test that a service instance of another subscriber has no edit permission 40/100940/3
authorEinat Vinouze <einat.vinouze@intl.att.com>
Thu, 30 Jan 2020 14:11:29 +0000 (16:11 +0200)
committerIttay Stern <ittay.stern@att.com>
Thu, 30 Jan 2020 16:11:18 +0000 (18:11 +0200)
Issue-ID: VID-758
Change-Id: Ia394c7b04d78cf9fb5e187e8d2d9b7b3a62ef210
Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com>
Signed-off-by: Ittay Stern <ittay.stern@att.com>
vid-automation/src/main/java/vid/automation/test/infra/Features.java
vid-automation/src/test/java/org/onap/vid/api/AaiApiTest.java

index d981034..55b7b3f 100644 (file)
@@ -58,6 +58,7 @@ public enum Features implements Feature {
     FLAG_2002_UNLIMITED_MAX,
     FLAG_2004_INSTANTIATION_TEMPLATES_POPUP,
     FLAG_2006_VFM_SDNC_PRELOAD_FILES,
+    FLAG_2006_USER_PERMISSIONS_BY_OWNING_ENTITY,
     ;
 
     public boolean isActive() {
index 555c2ed..e170c45 100644 (file)
@@ -2,6 +2,7 @@ package org.onap.vid.api;
 
 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
 import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet.defaultPlacement;
 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet.ofL3Network;
@@ -13,12 +14,15 @@ import static org.onap.simulator.presetGenerator.presets.ecompportal_att.EcompPo
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 import static org.testng.AssertJUnit.assertEquals;
+import static vid.automation.test.Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_CRAIG_ROBERTS;
 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
 import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMultimap;
@@ -898,6 +902,35 @@ public class AaiApiTest extends BaseApiAaiTest {
         assertThat(response.getBody(), jsonEquals(getResourceAsString(AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS)));
     }
 
+    @Test
+    public void searchServiceInstances_serviceInstanceOfAnotherSubscriber_authIsFollwingFeatureToggle() {
+        String craigRobertsSubscriberId = "31739f3e-526b-11e6-beb8-9e71128cae77";
+        String aServiceInstanceId = "4ea864f2-b946-473a-b51c-51a7c10b8391";
+        String aServiceOwningEntityId = "f160c875-ddd1-4ef5-84d8-d098784daa3a";
+        String currentUserAuthorizedOwningEntityId = "SILVIA ROBBINS"; // this will need to change with translateOwningEntityNameToOwningEntityId
+
+        boolean expectedPermission = Features.FLAG_2006_USER_PERMISSIONS_BY_OWNING_ENTITY.isActive();
+
+        SimulatorApi.registerExpectation(GET_SUBSCRIBERS_FOR_CUSTOMER_CRAIG_ROBERTS,
+            ImmutableMap.of(aServiceOwningEntityId, currentUserAuthorizedOwningEntityId), CLEAR_THEN_SET);
+
+        JsonNode serviceInstancesResult = restTemplate
+            .getForObject(uri + "/search_service_instances?subscriberId=" + craigRobertsSubscriberId, JsonNode.class);
+
+        assertThat(serviceInstancesResult.path("service-instances").isArray(), is(true));
+
+        ArrayNode servicesArray = ((ArrayNode) serviceInstancesResult.path("service-instances"));
+
+        JsonNode aServiceResult = Streams.fromIterator(servicesArray.iterator())
+            .filter(it -> it.path("serviceInstanceId").asText().equals(aServiceInstanceId))
+            .findAny()
+            .orElseThrow(() -> new AssertionError("could not find serviceInstanceId=" + aServiceInstanceId));
+
+        assertThat(aServiceResult.toString(),
+            aServiceResult.path("isPermitted").booleanValue(), is(expectedPermission));
+
+    }
+
     private void assertResponse(Object expected, String response) {
         assertResponse(Configuration.empty(), expected, response);
     }