Skip to content
Snippets Groups Projects
Commit 0c9ed63f authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-5412 Avoid mocking with https (okhttp-tls)

parent 9aab3232
No related branches found
No related tags found
No related merge requests found
...@@ -94,12 +94,6 @@ ...@@ -94,12 +94,6 @@
<version>${okio.version}</version> <version>${okio.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<version>${okio.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -13,7 +13,6 @@ import org.junit.jupiter.api.DisplayName; ...@@ -13,7 +13,6 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
...@@ -21,8 +20,7 @@ import de.ozgcloud.eingang.Application; ...@@ -21,8 +20,7 @@ import de.ozgcloud.eingang.Application;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.MockWebServer;
import okhttp3.tls.HandshakeCertificates; import okhttp3.mockwebserver.internal.duplex.DuplexResponseBody;
import okhttp3.tls.HeldCertificate;
@ActiveProfiles({ "itcase", "local" }) @ActiveProfiles({ "itcase", "local" })
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = Application.class)
...@@ -36,34 +34,16 @@ class XtaServiceITCase { ...@@ -36,34 +34,16 @@ class XtaServiceITCase {
@Autowired @Autowired
private XtaProperties properties; private XtaProperties properties;
@Autowired
@Qualifier("xtaKeyStore")
KeyStore xtaKeyStore;
@BeforeEach @BeforeEach
@SneakyThrows @SneakyThrows
public void createServer() { public void createServer() {
nachrichtenBrokerMock = new MockWebServer(); nachrichtenBrokerMock = new MockWebServer();
nachrichtenBrokerMock.requireClientAuth();
{
// Setup trust between client and the NachrichtenbrokerMock for HTTPS
// (See https://github.com/square/okhttp/blob/master/okhttp-tls/README.md)
HeldCertificate localhostCertificate = new HeldCertificate.Builder()
.addSubjectAlternativeName("localhost")
.build();
HandshakeCertificates serverCertificates = new HandshakeCertificates.Builder()
.heldCertificate(localhostCertificate)
.addTrustedCertificate((X509Certificate) xtaKeyStore.getCertificate("xtatestkey"))
.build();
xtaKeyStore.setCertificateEntry("nachrichtenbroker", localhostCertificate.certificate());
nachrichtenBrokerMock.useHttps(serverCertificates.sslSocketFactory(), false);
}
nachrichtenBrokerMock.start(InetAddress.getByName("127.0.0.1"), 0); nachrichtenBrokerMock.start(InetAddress.getByName("127.0.0.1"), 0);
properties.getServer().setAddress(nachrichtenBrokerMock.getHostName() + ":" + nachrichtenBrokerMock.getPort()); var serverProperties = properties.getServer();
serverProperties.setAddress(nachrichtenBrokerMock.getHostName() + ":" + nachrichtenBrokerMock.getPort());
serverProperties.setProtocol("http");
} }
@AfterEach @AfterEach
...@@ -78,7 +58,8 @@ class XtaServiceITCase { ...@@ -78,7 +58,8 @@ class XtaServiceITCase {
@BeforeEach @BeforeEach
void enqueueResponse() { void enqueueResponse() {
nachrichtenBrokerMock.enqueue(new MockResponse().setBody("<some/>")); var response = new MockResponse().setBody("<some/>");
nachrichtenBrokerMock.enqueue(response);
} }
@AfterEach @AfterEach
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment