This required some changes due to not backwards compatible changes.
- The API to springboot WebClient is changed, which is wrapped in class AsyncRestClient.
- The validation of trusted certs is made more strict. The Owner field of the peer cert must contain the name ofthe using host.
The uniitest tests this, so the cert in config is updated (Owner is "localhost").
Change-Id: Ia954b0ee5942884cd4b9fd82769bc8089dc35c53
Issue-ID: CCSDK-3421
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
~ ============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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
+ <artifactId>spring-boot-25-starter-parent</artifactId>
<version>2.2.0-SNAPSHOT</version>
- <relativePath/>
+ <relativePath />
</parent>
<groupId>org.onap.ccsdk.oran</groupId>
<artifactId>a1-policy-management-service</artifactId>
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
-import reactor.netty.resources.ConnectionProvider;
-import reactor.netty.tcp.ProxyProvider.Proxy;
-import reactor.netty.tcp.TcpClient;
+import reactor.netty.transport.ProxyProvider;
/**
* Generic reactive REST client.
&& !httpProxyConfig.httpProxyHost().isEmpty();
}
- private TcpClient createTcpClient() {
- TcpClient client = TcpClient.create(ConnectionProvider.newConnection()) //
+ private HttpClient buildHttpClient() {
+ HttpClient httpClient = HttpClient.create() //
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) //
.doOnConnected(connection -> {
connection.addHandlerLast(new ReadTimeoutHandler(30));
connection.addHandlerLast(new WriteTimeoutHandler(30));
});
+
if (this.sslContext != null) {
- client = client.secure(c -> c.sslContext(sslContext));
+ httpClient = httpClient.secure(ssl -> ssl.sslContext(sslContext));
}
+
if (isHttpProxyConfigured()) {
- client = client.proxy(proxy -> proxy.type(Proxy.HTTP).host(httpProxyConfig.httpProxyHost())
- .port(httpProxyConfig.httpProxyPort()));
+ httpClient = httpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
+ .host(httpProxyConfig.httpProxyHost()).port(httpProxyConfig.httpProxyPort()));
}
- return client;
+ return httpClient;
}
- private WebClient createWebClient(String baseUrl, TcpClient tcpClient) {
- HttpClient httpClient = HttpClient.from(tcpClient);
-
- ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
+ private WebClient buildWebClient(String baseUrl) {
+ final HttpClient httpClient = buildHttpClient();
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() //
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)) //
.build();
return WebClient.builder() //
- .clientConnector(connector) //
+ .clientConnector(new ReactorClientHttpConnector(httpClient)) //
.baseUrl(baseUrl) //
.exchangeStrategies(exchangeStrategies) //
.build();
private Mono<WebClient> getWebClient() {
if (this.webClient == null) {
- try {
- TcpClient tcpClient = createTcpClient();
- this.webClient = createWebClient(this.baseUrl, tcpClient);
- } catch (Exception e) {
- logger.error("Could not create WebClient {}", e.getMessage());
- return Mono.error(e);
- }
+ this.webClient = buildWebClient(baseUrl);
}
- return Mono.just(this.webClient);
+ return Mono.just(buildWebClient(baseUrl));
}
}
return createRestClient(baseUrl, false);
}
- public AsyncRestClient createRestClient(String baseUrl) {
+ public AsyncRestClient createRestClientUseHttpProxy(String baseUrl) {
return createRestClient(baseUrl, true);
}
}
}
-
}
private final UriBuilder uri;
public OscA1Client(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(ricConfig, restClientFactory.createRestClient(""));
+ this(ricConfig, restClientFactory.createRestClientUseHttpProxy(""));
}
public OscA1Client(RicConfig ricConfig, AsyncRestClient restClient) {
private final UriBuilder uri;
public StdA1ClientVersion1(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(restClientFactory.createRestClient(""), ricConfig);
+ this(restClientFactory.createRestClientUseHttpProxy(""), ricConfig);
}
public StdA1ClientVersion1(AsyncRestClient restClient, RicConfig ricConfig) {
private final OranV2UriBuilder uriBuiler;
public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(ricConfig, restClientFactory.createRestClient(""));
+ this(ricConfig, restClientFactory.createRestClientUseHttpProxy(""));
}
public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClient restClient) {
public static final String TRANSIENT_PARAM = "transient";
public static final String MANAGED_ELEMENT_ID_PARAM = "managed_element_id";
- public static final String V2_API_ROOT = "a1-policy/v2";
+ public static final String V2_API_ROOT = "/a1-policy/v2";
public static final String V2_API_SERVICE_CALLBACKS_NAME = "Callbacks";
public static final String V2_API_SERVICE_CALLBACKS_DESCRIPTION = "";
this.addPolicyType("", "ric2");
url = "/rics?policyType=";
- // This tests also validation of trusted certs restClient(true)
- rsp = restClient(true).get(url).block();
+ rsp = restClient().get(url).block();
assertThat(rsp).contains("ric2") //
.doesNotContain("ric1") //
.contains("AVAILABLE");
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = { //
- "server.ssl.key-store=./config/keystore.jks", //
- "app.webclient.trust-store=./config/truststore.jks", //
+ "server.ssl.key-store=./src/test/resources/keystore.jks", //
+ "app.webclient.trust-store=./src/test/resources/truststore.jks", //
"app.vardata-directory=./target/testdata", //
"app.filepath=" //
})
assertThat(receivedCallbacks.getReceivedInfo().size()).isEqualTo(1);
}
+ @Test
+ void testTrustValidation() {
+ addRic("ric1");
+ String rsp = restClient(true).get("/rics").block(); // restClient(true) enables trust validation
+ assertThat(rsp).contains("ric1");
+ }
+
@Test
void testGetRics() throws Exception {
addRic("ric1");
addRic("ric2");
this.addPolicyType("", "ric2");
url = "/rics?policytype_id=";
-
- // This tests also validation of trusted certs restClient(true)
- rsp = restClient(true).get(url).block();
+ rsp = restClient().get(url).block();
assertThat(rsp).contains("ric2") //
.doesNotContain("ric1") //
.contains("AVAILABLE");
}
private AsyncRestClient restClient(boolean useTrustValidation) {
- String baseUrl = "https://localhost:" + port + Consts.V2_API_ROOT;
- return restClient(baseUrl, useTrustValidation);
+ return restClient(baseUrl() + Consts.V2_API_ROOT, useTrustValidation);
}
private AsyncRestClient restClient() {
.keyStorePassword(config.keyStorePassword()) //
.keyStore(config.keyStore()) //
.keyPassword(config.keyPassword()) //
- .isTrustStoreUsed(true) //
+ .isTrustStoreUsed(false) //
.trustStore(config.trustStore()) //
.trustStorePassword(config.trustStorePassword()) //
.httpProxyConfig(config.httpProxyConfig()) //
.build();
AsyncRestClientFactory f = new AsyncRestClientFactory(config);
- return f.createRestClient("https://localhost:" + port);
+ return f.createRestClientNoHttpProxy("https://localhost:" + port);
}
}
package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
.build();
private static final String RIC_1_NAME = "ric1";
+
private static final Ric RIC_1 = new Ric(ImmutableRicConfig.builder() //
.ricId(RIC_1_NAME) //
.baseUrl("baseUrl1") //
RicSynchronizationTask synchronizerUnderTest = spy(createTask());
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock, times(1)).getPolicyTypeIdentities();
verifyNoMoreInteractions(a1ClientMock);
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock).getPolicyTypeIdentities();
verifyNoMoreInteractions(a1ClientMock);
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
-
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock).deleteAllPolicies();
verify(a1ClientMock).putPolicy(POLICY_1);
verifyNoMoreInteractions(a1ClientMock);
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock, times(2)).deleteAllPolicies();
verifyNoMoreInteractions(a1ClientMock);
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock, times(2)).deleteAllPolicies();
verifyNoMoreInteractions(a1ClientMock);