Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit d1eb88ab authored by Jean Claude Correale's avatar Jean Claude Correale
Browse files

OkHttpAuthorityExchange

parent e3e23878
No related branches found
No related tags found
4 merge requests!130Release,!129Release,!128fix unit tests - add property,!109OkHttpAuthorityExchange
Pipeline #222320 passed with warnings
......@@ -14,8 +14,10 @@ import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
@Log4j2
@Component
public class MtlsClientFactory {
......@@ -43,6 +45,7 @@ public class MtlsClientFactory {
public AuthorityExchange buildAuthorityClient(String url, KeyStore keyStore, String password)
throws CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException {
log.info("Creating MTLS Client of type {}", clientProperties.type());
return switch (clientProperties.type()) {
case FEIGN -> buildClient(feignSimplClient.builder(), keyStore, password)
.target(AuthorityExchange.class, url);
......
......@@ -6,13 +6,16 @@ import static org.mockito.Mockito.*;
import com.aruba.simpl.client.SimplClient.Builder;
import com.aruba.simpl.client.adapters.EphemeralProofAdapter;
import com.aruba.simpl.client.feign.FeignSimplClient;
import com.aruba.simpl.client.okhttp.OkHttpSimplClient;
import com.aruba.simpl.common.interceptors.TierOneTokenPropagatorInterceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -25,17 +28,25 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@MockBean(
classes = {
TierOneTokenPropagatorInterceptor.class,
MtlsClientProperties.class,
EphemeralProofAdapter.class,
})
public class MtlsClientFactoryTest {
class MtlsClientFactoryTest {
@Autowired
MtlsClientFactory mtlsClientFactory;
@MockBean
@MockBean(answer = Answers.RETURNS_DEEP_STUBS)
private FeignSimplClient simplClient;
@MockBean(answer = Answers.RETURNS_DEEP_STUBS)
private OkHttpSimplClient okHttpSimplClient;
@MockBean
private ObjectMapper objectMapper;
@MockBean
private MtlsClientProperties mtlsClientProperties;
@Test
void buildAuthorityClient_success() throws Exception {
var url = "url";
......@@ -47,6 +58,7 @@ public class MtlsClientFactoryTest {
var simplClientBuilder = mock(Builder.class);
var feignBuilder = mock(feign.Feign.Builder.class);
given(mtlsClientProperties.type()).willReturn(MtlsClientProperties.Type.FEIGN);
given(keyStore.aliases()).willReturn(Collections.enumeration(List.of("keystore_alias")));
given(keyStore.getCertificateChain("keystore_alias")).willReturn(certs);
given(simplClient.builder(any())).willReturn(simplClientBuilder);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment