<!--
============LICENSE_START=======================================================
- Copyright (C) 2019 Nordix Foundation.
+ Copyright (C) 2019,2023 Nordix Foundation.
Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
Modifications Copyright (C) 2020-2022 Bell Canada.
================================================================================
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.pap</groupId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.pap.main.config;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
+/**
+ * Configure how access to this module's REST end points is secured.
+ */
@Configuration
-@EnableWebSecurity
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests().antMatchers().authenticated().anyRequest().authenticated().and().httpBasic();
- // disable csrf as the endpoints are meant for non browser clients
- http.csrf().disable();
+public class WebSecurityConfig {
+ /**
+ * Return the configuration of how access to this module's REST end points is secured.
+ *
+ * @param http the HTTP security settings
+ * @return the HTTP security settings
+ */
+ @Bean
+ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
+ http
+ .httpBasic()
+ .and()
+ .authorizeHttpRequests().anyRequest().authenticated()
+ .and()
+ .csrf().disable();
+ return http.build();
}
-
-}
+}
\ No newline at end of file
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
List<PdpStatistics> pdpStatistics = new ArrayList<>(pdpStatisticsList.size());
for (PdpStatistics pdpStatisticsItem : pdpStatisticsList) {
+ @SuppressWarnings("deprecation")
var jpaPdpStatistics = pdpStatisticsRepository.getById(pdpStatisticsItem.getGeneratedId());
pdpStatistics.add(jpaPdpStatistics.toAuthorative());
}
* ONAP PAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021-2022 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.pap.main.comm;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
listener = mock(RequestListener.class);
PdpParameters pdpParams = mock(PdpParameters.class);
- doAnswer((Answer<Object>) invocation -> {
+ lenient().doAnswer((Answer<Object>) invocation -> {
queue.add(invocation.getArgument(0, QueueToken.class));
return null;
}).when(publisher).enqueue(any());
- when(timers.register(any(), any())).thenReturn(timer);
+ lenient().when(timers.register(any(), any())).thenReturn(timer);
PdpStateChangeParameters stateParams = mock(PdpStateChangeParameters.class);
- when(stateParams.getMaxRetryCount()).thenReturn(RETRIES);
- when(pdpParams.getStateChangeParameters()).thenReturn(stateParams);
+ lenient().when(stateParams.getMaxRetryCount()).thenReturn(RETRIES);
+ lenient().when(pdpParams.getStateChangeParameters()).thenReturn(stateParams);
PdpUpdateParameters updateParams = mock(PdpUpdateParameters.class);
- when(updateParams.getMaxRetryCount()).thenReturn(RETRIES);
- when(pdpParams.getUpdateParameters()).thenReturn(updateParams);
+ lenient().when(updateParams.getMaxRetryCount()).thenReturn(RETRIES);
+ lenient().when(pdpParams.getUpdateParameters()).thenReturn(updateParams);
reqParams = new RequestParams().setMaxRetryCount(RETRIES).setModifyLock(lock).setPdpPublisher(publisher)
.setResponseDispatcher(dispatcher).setTimers(timers);
* ONAP PAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams;
import org.onap.policy.pap.main.service.PdpGroupService;
import org.onap.policy.pap.main.service.PolicyStatusService;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
@RunWith(MockitoJUnitRunner.class)
public class PdpModifyRequestMapTest extends CommonRequestBase {
@Test
public void testPdpModifyRequestMap() {
- assertSame(mapParams, Whitebox.getInternalState(map, "params"));
- assertSame(lock, Whitebox.getInternalState(map, "modifyLock"));
+ assertSame(mapParams, ReflectionTestUtils.getField(map, "params"));
+ assertSame(lock, ReflectionTestUtils.getField(map, "modifyLock"));
}
@Test
* @return the request's listener
*/
private RequestListener getListener(Request request) {
- return Whitebox.getInternalState(request, "listener");
+ return (RequestListener) ReflectionTestUtils.getField(request, "listener");
}
private PdpGroup makeGroup(String name) {
* ONAP PAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021,2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.comm.CommonRequestBase;
+@RunWith(MockitoJUnitRunner.class)
public class UpdateReqTest extends CommonRequestBase {
private UpdateReq data;
*
* @throws Exception if an error occurs
*/
+ @Override
@Before
public void setUp() throws Exception {
super.setUp();
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019,2023 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* ================================================================================
import org.onap.policy.pap.main.PolicyPapApplication;
import org.onap.policy.pap.main.parameters.CommonTestData;
import org.onap.policy.pap.main.startstop.PapActivator;
-import org.powermock.reflect.Whitebox;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.util.ReflectionTestUtils;
/**
* Class to perform unit test of {@link PapRestControllerV1}.
}
private void markActivator(boolean wasAlive) {
- Object manager = Whitebox.getInternalState(papActivator, "serviceManager");
- AtomicBoolean running = Whitebox.getInternalState(manager, "running");
+ Object manager = ReflectionTestUtils.getField(papActivator, "serviceManager");
+ AtomicBoolean running = (AtomicBoolean) ReflectionTestUtils.getField(manager, "running");
running.set(wasAlive);
}
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.context.TestConfiguration;
-import org.springframework.core.annotation.Order;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
@Test
public void testMetricsEndpoint() throws Exception {
- mock.perform(get("/plain-metrics")).andDo(print())
+ mock.perform(get("/plain-metrics").with(SecurityMockMvcRequestPostProcessors.httpBasic(
+ "policyAdmin", "zb!XztG34")))
+ .andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$").isNotEmpty());
}
@Test
public void testPrometheusEndpoint() throws Exception {
- mock.perform(get("/metrics")).andDo(print())
+ mock.perform(get("/metrics").with(SecurityMockMvcRequestPostProcessors.httpBasic("policyAdmin", "zb!XztG34")))
+ .andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$").isNotEmpty());
}
-
- @TestConfiguration
- @Order(1)
- public static class TestSecurityConfig extends WebSecurityConfigurerAdapter {
- @Override
- protected void configure(HttpSecurity httpSecurity) throws Exception {
- httpSecurity.csrf().disable()
- .authorizeRequests().anyRequest().permitAll();
- }
- }
}
* ONAP PAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.PapConstants;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class TestProviderBase extends ProviderSuper {
private static final String EXPECTED_EXCEPTION = "expected exception";
@Test
public void testProviderBase() {
- assertSame(lockit, Whitebox.getInternalState(prov, "updateLock"));
- assertSame(reqmap, Whitebox.getInternalState(prov, "requestMap"));
+ assertSame(lockit, ReflectionTestUtils.getField(prov, "updateLock"));
+ assertSame(reqmap, ReflectionTestUtils.getField(prov, "requestMap"));
}
@Test