From 807c61281dda39440b8cba0e1fc83407d62aff05 Mon Sep 17 00:00:00 2001 From: Lathish Date: Thu, 24 Feb 2022 13:26:01 +0000 Subject: Accept only Whitelisted Repos from Tosca Template Issue-ID: POLICY-3894 Change-Id: Iaffaf3f1243f6070c600a58891899e9e1e326732 Signed-off-by: Lathish --- .../handler/AutomationCompositionElementHandlerTest.java | 3 ++- .../acm/participant/kubernetes/rest/ChartControllerTest.java | 3 ++- .../acm/participant/kubernetes/service/ChartServiceTest.java | 11 ++++++++++- .../src/test/resources/ChartList.json | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) (limited to 'participant/participant-impl/participant-impl-kubernetes/src/test') diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java index dc74afc1a..6124060cb 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -132,6 +132,7 @@ class AutomationCompositionElementHandlerTest { @Test void test_AutomationCompositionElementUpdate() throws PfModelException, IOException, ServiceException, ExecutionException, InterruptedException { + doReturn(true).when(chartService).installChart(any()); doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt()); UUID elementId1 = UUID.randomUUID(); AutomationCompositionElement element = new AutomationCompositionElement(); diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java index c59e7fb5d..7105c2327 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java @@ -24,6 +24,7 @@ package org.onap.policy.clamp.acm.participant.kubernetes.rest; import static org.hamcrest.CoreMatchers.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -130,7 +131,7 @@ class ChartControllerTest { RequestBuilder requestBuilder; //Mocking successful installation for void install method - doNothing().when(chartService).installChart(charts.get(0)); + doReturn(true).when(chartService).installChart(charts.get(0)); requestBuilder = MockMvcRequestBuilders.post(INSTALL_CHART_URL).accept(MediaType.APPLICATION_JSON_VALUE) .content(getInstallationJson(charts.get(0).getChartId().getName(), charts.get(0).getChartId().getVersion())) diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartServiceTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartServiceTest.java index f5b6093d3..4fc045d48 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartServiceTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartServiceTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ import static org.mockito.Mockito.doThrow; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.junit.jupiter.api.BeforeAll; @@ -42,10 +43,12 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; +import org.onap.policy.clamp.acm.participant.kubernetes.configurations.HelmRepositoryConfig; import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException; import org.onap.policy.clamp.acm.participant.kubernetes.helm.HelmClient; import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo; import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartList; +import org.onap.policy.clamp.acm.participant.kubernetes.models.HelmRepository; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -69,6 +72,9 @@ class ChartServiceTest { @Mock private HelmClient helmClient; + @Mock + private HelmRepositoryConfig helmRepositoryConfig; + @BeforeAll static void init() throws CoderException { charts = CODER.decode(new File(CHART_INFO_YAML), ChartList.class).getCharts(); @@ -114,6 +120,9 @@ class ChartServiceTest { @Test void test_installChart() throws IOException, ServiceException { + List helmRepositoryList = new ArrayList<>(); + helmRepositoryList.add(HelmRepository.builder().address("https://localhost:8080").build()); + doReturn(helmRepositoryList).when(helmRepositoryConfig).getRepos(); assertDoesNotThrow(() -> chartService.installChart(charts.get(0))); doThrow(ServiceException.class).when(helmClient).installChart(any()); assertThatThrownBy(() -> chartService.installChart(charts.get(0))).isInstanceOf(ServiceException.class); diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json b/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json index 9822846f3..d4cd5de47 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json @@ -7,7 +7,8 @@ }, "namespace" : "onap", "repository" : { - "repoName": "chartMuseum" + "repoName": "chartMuseum", + "address" : "https://localhost:8080" }, "releaseName" : "helloworld" }, -- cgit 1.2.3-korg