From c61c7167ee7a7f8e5524936c4c8668396b1f0024 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Fri, 18 Oct 2024 14:40:34 +0200 Subject: [PATCH] feat(mockwebserver): io.fabric8:mockwebserver is based on Vert.x Web Signed-off-by: Marc Nuri --- junit/mockwebserver/pom.xml | 5 - .../mockwebserver/DefaultMockServer.java | 49 +++--- .../io/fabric8/mockwebserver/MockServer.java | 20 ++- .../fabric8/mockwebserver/ServerResponse.java | 4 +- .../mockwebserver/crud/CrudDispatcher.java | 14 +- .../mockwebserver/http/MockResponse.java | 4 - .../internal/ChunkedResponse.java | 5 +- .../internal/MockDispatcher.java | 20 +-- .../internal/MockSSLContextFactory.java | 39 ----- .../internal/MockServerExpectationImpl.java | 4 +- .../internal/SimpleResponse.java | 5 +- .../internal/WebSocketSession.java | 25 ++-- .../mockwebserver/utils/BodyProvider.java | 2 +- .../mockwebserver/utils/CertUtils.java | 113 -------------- .../mockwebserver/utils/PKCS1Util.java | 141 ------------------ .../mockwebserver/utils/ResponseProvider.java | 4 +- .../utils/ResponseProviders.java | 4 +- .../fabric8/mockwebserver/utils/SSLUtils.java | 72 --------- .../resources/ssl/fabric8-private-key.pem | 50 ------- .../src/main/resources/ssl/fabric8.crt | 31 ---- .../src/main/resources/ssl/fabric8.csr | 27 ---- .../src/main/resources/ssl/fabric8.pub | 1 - .../DefaultMockServerCrudTest.groovy | 1 - .../DefaultMockServerHttpsTest.groovy | 37 ++++- .../DefaultMockServerTest.groovy | 5 +- .../MockWebServerHttpsTest.groovy | 7 +- .../crud/CrudDispatcherTest.groovy | 2 +- 27 files changed, 116 insertions(+), 575 deletions(-) delete mode 100644 junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockSSLContextFactory.java delete mode 100644 junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/CertUtils.java delete mode 100644 junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/PKCS1Util.java delete mode 100644 junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/SSLUtils.java delete mode 100644 junit/mockwebserver/src/main/resources/ssl/fabric8-private-key.pem delete mode 100644 junit/mockwebserver/src/main/resources/ssl/fabric8.crt delete mode 100644 junit/mockwebserver/src/main/resources/ssl/fabric8.csr delete mode 100644 junit/mockwebserver/src/main/resources/ssl/fabric8.pub diff --git a/junit/mockwebserver/pom.xml b/junit/mockwebserver/pom.xml index 85c2136b4e5..1c2ea32f0fb 100644 --- a/junit/mockwebserver/pom.xml +++ b/junit/mockwebserver/pom.xml @@ -35,10 +35,6 @@ io.vertx vertx-web - - com.squareup.okhttp3 - mockwebserver - com.fasterxml.jackson.core jackson-databind @@ -87,7 +83,6 @@ - diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/DefaultMockServer.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/DefaultMockServer.java index cee4d8f0679..9d39b7c94ba 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/DefaultMockServer.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/DefaultMockServer.java @@ -16,14 +16,12 @@ package io.fabric8.mockwebserver; import io.fabric8.mockwebserver.dsl.MockServerExpectation; +import io.fabric8.mockwebserver.http.Dispatcher; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.internal.MockDispatcher; -import io.fabric8.mockwebserver.internal.MockSSLContextFactory; import io.fabric8.mockwebserver.internal.MockServerExpectationImpl; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.vertx.core.net.SelfSignedCertificate; -import java.io.IOException; import java.net.InetAddress; import java.net.Proxy; import java.util.HashMap; @@ -63,8 +61,9 @@ public DefaultMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { + public DefaultMockServer( + Context context, MockWebServer server, Map> responses, Dispatcher dispatcher, + boolean useHttps) { this.context = context; this.useHttps = useHttps; this.server = server; @@ -77,7 +76,7 @@ public DefaultMockServer(Context context, MockWebServer server, Map map = Collections.synchronizedMap(new LinkedHashMap<>()); protected final Context context; @@ -53,7 +47,7 @@ public CrudDispatcher(Context context, AttributeExtractor attributeExtractor, Re @Override public MockResponse dispatch(RecordedRequest request) { String path = request.getPath(); - switch (request.getMethod().toUpperCase()) { + switch (request.method()) { case POST: return handleCreate(request); case PUT: diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MockResponse.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MockResponse.java index 16e67f04f36..d695d05435c 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MockResponse.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MockResponse.java @@ -179,10 +179,6 @@ public MockResponse removeHeader(String name) { } public MockResponse withWebSocketUpgrade(WebSocketListener listener) { - // TODO: Check if this is necessary with Vert.x - // setStatus("HTTP/1.1 101 Switching Protocols"); - // setHeader("Connection", "Upgrade"); - // setHeader("Upgrade", "websocket"); body = null; webSocketListener = listener; return this; diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/ChunkedResponse.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/ChunkedResponse.java index 13b4c7be93e..67e8db2a509 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/ChunkedResponse.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/ChunkedResponse.java @@ -16,10 +16,10 @@ package io.fabric8.mockwebserver.internal; import io.fabric8.mockwebserver.ServerResponse; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.utils.ResponseProvider; import io.fabric8.mockwebserver.utils.ResponseProviders; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.RecordedRequest; import java.util.List; import java.util.concurrent.TimeUnit; @@ -59,6 +59,7 @@ public ResponseProvider> getBodyProvider() { @Override public MockResponse toMockResponse(RecordedRequest request) { MockResponse mockResponse = new MockResponse(); + mockResponse.setHttpVersion(request.getHttpVersion()); mockResponse.setHeaders(bodyProvider.getHeaders()); mockResponse.setChunkedBody(concatBody(request), DEFAULT_MAX_CHUNK_SIZE); mockResponse.setResponseCode(bodyProvider.getStatusCode(request)); diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockDispatcher.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockDispatcher.java index 32b818dd14c..5a3291e5eaa 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockDispatcher.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockDispatcher.java @@ -17,11 +17,9 @@ import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.HttpMethod; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.RecordedRequest; -import okhttp3.mockwebserver.SocketPolicy; +import io.fabric8.mockwebserver.http.Dispatcher; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import java.util.Collection; import java.util.Map; @@ -37,20 +35,14 @@ public MockDispatcher(Map> responses) { this.responses = responses; } - @Override - public MockResponse peek() { - return new MockResponse().setSocketPolicy(SocketPolicy.EXPECT_CONTINUE); - } - @Override public MockResponse dispatch(RecordedRequest request) { for (WebSocketSession webSocketSession : webSocketSessions) { webSocketSession.dispatch(request); } - HttpMethod method = HttpMethod.valueOf(request.getMethod()); String path = request.getPath(); - SimpleRequest key = new SimpleRequest(method, path); + SimpleRequest key = new SimpleRequest(request.method(), path); SimpleRequest keyForAnyMethod = new SimpleRequest(path); if (responses.containsKey(key)) { Queue queue = responses.get(key); @@ -59,12 +51,12 @@ public MockResponse dispatch(RecordedRequest request) { Queue queue = responses.get(keyForAnyMethod); return handleResponse(queue.peek(), queue, request); } - return new MockResponse().setResponseCode(404); + return new MockResponse().setHttpVersion(request.getHttpVersion()).setResponseCode(404); } private MockResponse handleResponse(ServerResponse response, Queue queue, RecordedRequest request) { if (response == null) { - return new MockResponse().setResponseCode(404); + return new MockResponse().setHttpVersion(request.getHttpVersion()).setResponseCode(404); } else if (!response.isRepeatable()) { queue.remove(); } diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockSSLContextFactory.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockSSLContextFactory.java deleted file mode 100644 index eb8d90340af..00000000000 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockSSLContextFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.mockwebserver.internal; - -import io.fabric8.mockwebserver.MockServerException; -import io.fabric8.mockwebserver.utils.SSLUtils; - -import javax.net.ssl.KeyManager; -import javax.net.ssl.SSLContext; - -public class MockSSLContextFactory { - - private MockSSLContextFactory() { - } - - public static SSLContext create() { - try { - KeyManager[] keyManagers = SSLUtils.keyManagers(MockSSLContextFactory.class.getResourceAsStream("/ssl/fabric8.crt"), - MockSSLContextFactory.class.getResourceAsStream("/ssl/fabric8-private-key.pem"), - "RSA", ""); - return SSLUtils.sslContext(keyManagers, null, true); - } catch (Exception e) { - throw new MockServerException("Exception creating SSLContext", e); - } - } -} diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java index ec01cebe62e..83ad81b1148 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java @@ -27,11 +27,11 @@ import io.fabric8.mockwebserver.dsl.ReturnOrWebsocketable; import io.fabric8.mockwebserver.dsl.TimesOnceableOrHttpHeaderable; import io.fabric8.mockwebserver.dsl.WebSocketSessionBuilder; +import io.fabric8.mockwebserver.http.Headers; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.utils.BodyProvider; import io.fabric8.mockwebserver.utils.ResponseProvider; import io.fabric8.mockwebserver.utils.ResponseProviders; -import okhttp3.Headers; -import okhttp3.mockwebserver.RecordedRequest; import java.util.ArrayDeque; import java.util.ArrayList; diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/SimpleResponse.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/SimpleResponse.java index 637f179c892..f0456062350 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/SimpleResponse.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/SimpleResponse.java @@ -16,10 +16,10 @@ package io.fabric8.mockwebserver.internal; import io.fabric8.mockwebserver.ServerResponse; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.utils.ResponseProvider; import io.fabric8.mockwebserver.utils.ResponseProviders; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.RecordedRequest; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -64,6 +64,7 @@ public ResponseProvider getBodyProvider() { @Override public MockResponse toMockResponse(RecordedRequest request) { MockResponse mockResponse = new MockResponse(); + mockResponse.setHttpVersion(request.getHttpVersion()); mockResponse.setHeaders(bodyProvider.getHeaders()); mockResponse.setResponseCode(bodyProvider.getStatusCode(request)); diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/WebSocketSession.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/WebSocketSession.java index cf35c8e4814..c13384a909e 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/WebSocketSession.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/WebSocketSession.java @@ -16,12 +16,11 @@ package io.fabric8.mockwebserver.internal; import io.fabric8.mockwebserver.MockServerException; -import io.fabric8.mockwebserver.dsl.HttpMethod; -import okhttp3.Response; -import okhttp3.WebSocket; -import okhttp3.WebSocketListener; -import okhttp3.mockwebserver.RecordedRequest; -import okio.ByteString; +import io.fabric8.mockwebserver.http.ByteString; +import io.fabric8.mockwebserver.http.RecordedRequest; +import io.fabric8.mockwebserver.http.Response; +import io.fabric8.mockwebserver.http.WebSocket; +import io.fabric8.mockwebserver.http.WebSocketListener; import java.util.ArrayList; import java.util.Collection; @@ -63,8 +62,12 @@ public void onClosing(WebSocket webSocket, int code, String reason) { } @Override - public void onOpen(WebSocket webSocket, Response response) { + public void onBeforeAccept(WebSocket webSocket, Response response) { activeSockets.add(webSocket); + } + + @Override + public void onOpen(WebSocket webSocket, Response response) { //Schedule all timed events for (WebSocketMessage msg : open) { send(webSocket, msg); @@ -114,10 +117,9 @@ private void checkIfShouldSendAgain(WebSocket ws, WebSocketMessage msg) { } public void dispatch(RecordedRequest request) { - HttpMethod method = HttpMethod.valueOf(request.getMethod()); - String path = request.getPath(); - SimpleRequest key = new SimpleRequest(method, path); - SimpleRequest keyForAnyMethod = new SimpleRequest(path); + final String path = request.getPath(); + final SimpleRequest key = new SimpleRequest(request.method(), path); + final SimpleRequest keyForAnyMethod = new SimpleRequest(path); if (httpRequestEvents.containsKey(key)) { Queue queue = httpRequestEvents.get(key); activeSockets.forEach(ws -> send(ws, queue, "from http " + path)); @@ -185,6 +187,7 @@ public void shutdown() { executor.shutdownNow(); } } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw MockServerException.launderThrowable(e); } } diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/BodyProvider.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/BodyProvider.java index a138ef6f18c..f4d7803f47e 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/BodyProvider.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/BodyProvider.java @@ -15,7 +15,7 @@ */ package io.fabric8.mockwebserver.utils; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; /** * A class that allows returning the body of a response given a certain request. diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/CertUtils.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/CertUtils.java deleted file mode 100644 index 0226d25d0bb..00000000000 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/CertUtils.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.mockwebserver.utils; - -import okio.ByteString; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.security.KeyFactory; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.RSAPrivateCrtKeySpec; -import java.util.Base64; - -public class CertUtils { - - private CertUtils() { - } - - public static InputStream getInputStreamFromDataOrFile(String data, String file) throws FileNotFoundException { - if (data != null) { - final byte[] bytes; - ByteString decoded = ByteString.decodeBase64(data); - if (decoded != null) { - bytes = decoded.toByteArray(); - } else { - bytes = data.getBytes(); - } - - return new ByteArrayInputStream(bytes); - } - if (file != null) { - return new FileInputStream(file); - } - return null; - } - - public static KeyStore createKeyStore(InputStream certInputStream, InputStream keyInputStream, String clientKeyAlgo, - char[] clientKeyPassphrase) - throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException { - CertificateFactory certFactory = CertificateFactory.getInstance("X509"); - X509Certificate cert = (X509Certificate) certFactory.generateCertificate(certInputStream); - - byte[] keyBytes = decodeKey(keyInputStream); - - PrivateKey privateKey; - - KeyFactory keyFactory = KeyFactory.getInstance(clientKeyAlgo); - try { - // First let's try PKCS8 - privateKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(keyBytes)); - } catch (InvalidKeySpecException e) { - // Otherwise try PKCS8 - RSAPrivateCrtKeySpec keySpec = PKCS1Util.decodePKCS1(keyBytes); - privateKey = keyFactory.generatePrivate(keySpec); - } - - KeyStore keyStore = KeyStore.getInstance("JKS"); - keyStore.load(null, clientKeyPassphrase); - - String alias = cert.getSubjectX500Principal().getName(); - keyStore.setKeyEntry(alias, privateKey, clientKeyPassphrase, new Certificate[] { cert }); - - return keyStore; - } - - public static KeyStore createKeyStore(String clientCertData, String clientCertFile, String clientKeyData, - String clientKeyFile, String clientKeyAlgo, char[] clientKeyPassphrase) - throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException { - try (InputStream certInputStream = getInputStreamFromDataOrFile(clientCertData, clientCertFile); - InputStream keyInputStream = getInputStreamFromDataOrFile(clientKeyData, clientKeyFile)) { - return createKeyStore(certInputStream, keyInputStream, clientKeyAlgo, clientKeyPassphrase); - } - } - - private static byte[] decodeKey(InputStream keyInputStream) throws IOException { - try (BufferedReader keyReader = new BufferedReader(new InputStreamReader(keyInputStream)); - ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - String line; - while ((line = keyReader.readLine()) != null) { - baos.write(line.trim().getBytes()); - } - return Base64.getDecoder().decode(baos.toByteArray()); - } - } -} diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/PKCS1Util.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/PKCS1Util.java deleted file mode 100644 index f2865515abd..00000000000 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/PKCS1Util.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.mockwebserver.utils; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.security.spec.RSAPrivateCrtKeySpec; - -/** - * This code is inspired and taken over from net.auth.core:oauth - * (albeit in a highly stripped variation): - *

- * Source is from http://oauth.googlecode.com/svn/code/java/ which is licensed - * under the APL (http://oauth.googlecode.com/svn/code/java/LICENSE.txt) - *

- * All credits go to the original author (zhang) - * - * @author roland - * @since 30/09/15 - */ -class PKCS1Util { - - private PKCS1Util() { - } - - public static RSAPrivateCrtKeySpec decodePKCS1(byte[] keyBytes) throws IOException { - DerParser parser = new DerParser(keyBytes); - Asn1Object sequence = parser.read(); - sequence.validateSequence(); - parser = new DerParser(sequence.getValue()); - parser.read(); - - return new RSAPrivateCrtKeySpec(next(parser), next(parser), - next(parser), next(parser), - next(parser), next(parser), - next(parser), next(parser)); - } - - // ========================================================================================== - - private static BigInteger next(DerParser parser) throws IOException { - return parser.read().getInteger(); - } - - static class DerParser { - - private final InputStream in; - - DerParser(byte[] bytes) { - this.in = new ByteArrayInputStream(bytes); - } - - Asn1Object read() throws IOException { - int tag = in.read(); - - if (tag == -1) { - throw new IOException("Invalid DER: stream too short, missing tag"); - } - - int length = getLength(); - byte[] value = new byte[length]; - if (in.read(value) < length) { - throw new IOException("Invalid DER: stream too short, missing value"); - } - - return new Asn1Object(tag, value); - } - - private int getLength() throws IOException { - int i = in.read(); - if (i == -1) { - throw new IOException("Invalid DER: length missing"); - } - - if ((i & ~0x7F) == 0) { - return i; - } - - int num = i & 0x7F; - if (i >= 0xFF || num > 4) { - throw new IOException("Invalid DER: length field too big (" - + i + ")"); - } - - byte[] bytes = new byte[num]; - if (in.read(bytes) < num) { - throw new IOException("Invalid DER: length too short"); - } - - return new BigInteger(1, bytes).intValue(); - } - } - - static class Asn1Object { - - private final int type; - private final byte[] value; - private final int tag; - - public Asn1Object(int tag, byte[] value) { - this.tag = tag; - this.type = tag & 0x1F; - this.value = value; - } - - public byte[] getValue() { - return value; - } - - BigInteger getInteger() throws IOException { - if (type != 0x02) { - throw new IOException("Invalid DER: object is not integer"); //$NON-NLS-1$ - } - return new BigInteger(value); - } - - void validateSequence() throws IOException { - if (type != 0x10) { - throw new IOException("Invalid DER: not a sequence"); - } - if ((tag & 0x20) != 0x20) { - throw new IOException("Invalid DER: can't parse primitive entity"); - } - } - } -} diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProvider.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProvider.java index 53d591c44f0..7ebb324d1b9 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProvider.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProvider.java @@ -15,8 +15,8 @@ */ package io.fabric8.mockwebserver.utils; -import okhttp3.Headers; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.Headers; +import io.fabric8.mockwebserver.http.RecordedRequest; /** * A class that allows returning a response given a certain request. diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProviders.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProviders.java index cf297aafffc..fe9dba39862 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProviders.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/ResponseProviders.java @@ -15,8 +15,8 @@ */ package io.fabric8.mockwebserver.utils; -import okhttp3.Headers; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.Headers; +import io.fabric8.mockwebserver.http.RecordedRequest; import java.util.Arrays; import java.util.Collections; diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/SSLUtils.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/SSLUtils.java deleted file mode 100644 index 53c6635b830..00000000000 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/SSLUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.mockwebserver.utils; - -import java.io.IOException; -import java.io.InputStream; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.security.spec.InvalidKeySpecException; - -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -import static io.fabric8.mockwebserver.utils.CertUtils.createKeyStore; - -public final class SSLUtils { - - private SSLUtils() { - //Utility - } - - public static SSLContext sslContext(KeyManager[] keyManagers, TrustManager[] trustManagers, boolean trustCerts) - throws KeyManagementException, NoSuchAlgorithmException { - if (trustManagers == null && trustCerts) { - trustManagers = new TrustManager[] { new X509TrustManager() { - public void checkClientTrusted(X509Certificate[] chain, String s) { - } - - public void checkServerTrusted(X509Certificate[] chain, String s) { - } - - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - } }; - } - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(keyManagers, trustManagers, new SecureRandom()); - return sslContext; - } - - public static KeyManager[] keyManagers(InputStream certInputStream, InputStream keyInputStream, String algo, - String passphrase) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, - InvalidKeySpecException, IOException { - KeyStore keyStore = createKeyStore(certInputStream, keyInputStream, algo, passphrase.toCharArray()); - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); - kmf.init(keyStore, passphrase.toCharArray()); - return kmf.getKeyManagers(); - } -} diff --git a/junit/mockwebserver/src/main/resources/ssl/fabric8-private-key.pem b/junit/mockwebserver/src/main/resources/ssl/fabric8-private-key.pem deleted file mode 100644 index b6bb69d0c55..00000000000 --- a/junit/mockwebserver/src/main/resources/ssl/fabric8-private-key.pem +++ /dev/null @@ -1,50 +0,0 @@ -MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDeWNPC4SJE8DKX -GU5JISsrY1nnI249vmO6x+pEflcGBqaReQehRUNeMFGje92jZk+0xh8NbNFf4Ofs -wJ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0afNQAhZzcOHMihoBJtrIVmr6C8sjmW9gMO+ -oDeVVXBBlH67xhwikMsiXw3qZ6nmkDAL/Hh+Hq2pOpwr2FPompNFGYc/w6LvMp75 -YUbgytay3y3KPc/gyzHgeiK/XbuvUtenVkDFCmzLa9aqpbt1VVbwW1bG39jKFL9t -W6PF+EI2nNZzfnIvQvsFIgNdHIztjOT9NEpOIUPJAoIBAHEOnd9aooCPIj3lzvoD -Vqe5mzW3qmXgwCZ2jIULcjVkf9TahiLYz18LAk62hWpOYepB4eNBJNE0BDHHDYlb -6xb1LGaxs1KMwcM5QLufis6Gq/7FNXuFXvyCB60fDLb2DeD/TYWn/B609ttsQvNF -OQv7LIQI8ZxKV0JHWhL2R4ivhIG9/i1lwxDWOdUYYb9U0NwuVKc/173Zza8eCZ3O -niBebcAg/iMtLAHO2nIPs8gojXDgl+YHtdUuyQmogH7CEl6KFK41IvQJGjldLWn7 -tjeXcvrkMndC9LUAG5UuZDmTWMVeLrXZyNX8v3+Iggs8yJX7luAX5ZcIAflQryeQ -TAECggEAIMqnk2FFxbbCR034TARA/n9XPY5XYufTpq9WtIaRuMvA3I5/oLKg65B9 -5XDCzwr0RiJR8pzlJ6Pmtm01rzNpNvzVOwIe3QS8F10nVLsrhDXB9bq55UtAUYZX -pNCO4qLC004YemEHKKp4NrRXquGcPvzJ67Ezl4f/E9rMvTdUjzhhZ80m+80adP4o -8MXBA/5BYBKLZRkEtyin3etVAvJM6/oUv4zREbod/sWyhFq3O2ka3rFhV0ymDEr6 -dphptKrzseopjAVi05DFIR7k1D3YN4NB7nt4N8JC5ucCYhCFq6juBO6bGHFGZ3t9 -Sqju3/8JhKlPzgcIeEtTEncKaJh9UA== diff --git a/junit/mockwebserver/src/main/resources/ssl/fabric8.crt b/junit/mockwebserver/src/main/resources/ssl/fabric8.crt deleted file mode 100644 index 5b01aa30127..00000000000 --- a/junit/mockwebserver/src/main/resources/ssl/fabric8.crt +++ /dev/null @@ -1,31 +0,0 @@ ------BEGIN C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/l6hxnpFbLxKGgvZ+6mnaNgJGi1rzyZAgMBAAEw -DQYJKoZIhvcNAQELBQADggIBAJ1tNTAnPgAbfhXVxtVnnNPFGsrmUgtBj0f8NsY3 -F0ODX50TIjbVLYp7j3u+dgZu9/ruTOHcGLywNi5mJWB+s27KJJn3nBFPmd9d/QIV -zmjn5IVvikXezEjECQOscwDhwpSbzHqLoieDTJntVUyaNctAZM1YOxVKO97pCDdw -tV74xDzdnI/4JQFQPfshD699r3dtU5ax/jiVCvqM5hTAJ2M/UVyQtxm3lKzMYLNu -77chlVf8/hTop9B6Q4tD6Ajj2KPxaHB7y+5lhci5Rvb2YLVDs0HLq8UJmoJW3FLw -slrjs0NerSWoz5JfhmOQ0N9E3NBdV/kGr27WUeSlNOYh5bqneDCX+hPrO/4NtvpG -WnnJX9W6S6e5GBFsNwQIB9SQCjj9zKWqgszS937HRd9gLmnOCPm7jbCO5uOjDo5q -0t+E20r9xv+4il1QV7tkGg13texGDR43aGzsSNQ66PXOwzeeCPkFzrSu1QFBh7LL -69VMJIbgm3ywYJjO0vIi0mW+kAiqcniIxbDTcCuEI0yuVLyRNaAe6kWWLMVaJLUw -V4TNAOT7x8ZYGQGjhz2DAImvXMwZTK2wRwyv8S11G+ebIIUb4EXGbMksjU6tTquq -ViHO3TGAKPTHIjCYdNT/ZGYQ/PHXLmaDGSOcoW8FPT9ROPxXRSNicNfzLJk/o4Im -AZC5 ------END CERTIFICATE----- diff --git a/junit/mockwebserver/src/main/resources/ssl/fabric8.csr b/junit/mockwebserver/src/main/resources/ssl/fabric8.csr deleted file mode 100644 index ef0eea5121d..00000000000 --- a/junit/mockwebserver/src/main/resources/ssl/fabric8.csr +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIIEoTCCAokCAQAwXDELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx -FTATBgNVBAcMDERlZmF1bHQgQ2l0eTEhMB8GA1UECgwYSW50ZXJuZXQ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DYm48idGUDEa1QNqqC7Wt0qDM8iZtYaHoc9D -wOSD4KGOUOvzooqKmRzHRRRXfL/K3xzFOFAbxJf5YbVHmRGHEWbEXwnjhz1PHgmS -sXNtmVSt7/ycGKRUHyK4s2xIol45EaD7B+80st0fj0n5WGnpX0Wx/XxIepoD7/dG -H3HNjJD9UyGW3l2q6TojQrYLdTo+k9/CS6yMbbI++QyPlv/cnI1JpS/9+wvF8RrX -1AfWplKt+T8gOs64Ns7triUGD96IAqZfj46olQBN90BwCZ1BasneZyDYhClRCrfN -0znZT0cwgCs0q+UU+WmMcfBWO7ctKj3cz3+SmX+R16nTFi5Uuj3J9ED0V1o687jZ -YgtA3vz5F9lf9DaKJ/23GuA2X7HYWCUDiLtB2junYNJ0toJNJw== ------END CERTIFICATE REQUEST----- diff --git a/junit/mockwebserver/src/main/resources/ssl/fabric8.pub b/junit/mockwebserver/src/main/resources/ssl/fabric8.pub deleted file mode 100644 index ba5c2260a5e..00000000000 --- a/junit/mockwebserver/src/main/resources/ssl/fabric8.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDeWNPC4SJE8DKXGU5JISsrY1nnI249vmO6x+pEflcGBqaReQehRUNeMFGje92jZk+0xh8NbNFf4OfswJnSXHAupOI6CFERS2aym4IuGX24c7WvoMeH0I8/w8TJTEKNmWCcduaZx5z041gdkQHQKetYJkzVhh5p2tbIsYlBLe/XGH3IzAVbeFd6GUDK32EyFNrSSOtMEOwbejmH2wJysLFxGsJFySbnvyEdjDvTdGpNdqPRCU93K/BfRo1ycqSZiSObAh605Ddo3DMQlE0rk0im4BQXxwvaVuhbzszR8XIln8/QT5HysiDY5R2hgQq1yJtXtbL7yFGQSeNe1CG9Gb1JNnHCdAkf+n9RFVoisjsn8MGcSCxpTs0G16Oia41nQaKLByqh4++aithhUcd96ujYnIceljMycpkL0VMXzZ7xwHHU+aHPRkRQsDzbf0x0b7MwQD5XkE1rYPzw/TwJ6qhpPoxzlQ/H5hqEl9zdPpZyQLcfr5YluaRDSTAaR1QruqlWM2Zzy5iBthvx7hrYNQ/Re5pbp+b4M7h1I6zvohrMiCbtvMQrWYZWGtOHPsW+tUXTQyb2vIYIGIZMsLZzOijXn78/0IA07xuivqlQ/jmC6jNZAZCC5PRss9KQLWJWu9V3jEcK5dCstJv5eocZ6RWy8ShoL2fupp2jYCRota88mQ== diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerCrudTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerCrudTest.groovy index c089cf90801..842deb932aa 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerCrudTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerCrudTest.groovy @@ -21,7 +21,6 @@ import io.vertx.core.Vertx import io.vertx.core.buffer.Buffer import io.vertx.ext.web.client.HttpResponse import io.vertx.ext.web.client.WebClient -import okhttp3.mockwebserver.MockWebServer import spock.lang.Shared import spock.lang.Specification import spock.util.concurrent.PollingConditions diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerHttpsTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerHttpsTest.groovy index e441c8a4d52..297bd2925df 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerHttpsTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerHttpsTest.groovy @@ -15,24 +15,36 @@ */ package io.fabric8.mockwebserver -import okhttp3.OkHttpClient +import io.vertx.core.Vertx +import io.vertx.ext.web.client.WebClient +import io.vertx.ext.web.client.WebClientOptions import spock.lang.Shared import spock.lang.Specification +import spock.util.concurrent.PollingConditions class DefaultMockServerHttpsTest extends Specification { - DefaultMockServer server - @Shared - OkHttpClient client = new OkHttpClient() + static def vertx = Vertx.vertx() + DefaultMockServer server + WebClient client def setup() { server = new DefaultMockServer(true) server.start() + client = WebClient.create(vertx, new WebClientOptions() + .setSsl(true) + .setTrustOptions(server.getSelfSignedCertificate().trustOptions()) + .setKeyCertOptions(server.getSelfSignedCertificate().keyCertOptions())) } def cleanup() { server.shutdown() + client.close() + } + + def cleanupSpec() { + vertx.close() } def "url, with path, returns URL with HTTPS protocol"() { @@ -42,4 +54,21 @@ class DefaultMockServerHttpsTest extends Specification { then: assert result.startsWith("https://") } + + + def "GET /, with empty store, should return 404"() { + given: "An HTTP request to /" + def request = client.get(server.port, server.getHostName(), "/").ssl(true).send() + and: "An instance of PollingConditions" + def conditions = new PollingConditions(timeout: 10) + + when: "The request is completed" + conditions.eventually { + assert request.isComplete() + } + + then: "The response has status code 404" + request.result().statusCode() == 404 + request.result().body() == null + } } diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy index 4454a9b3913..9dc85c6ca9c 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy @@ -15,6 +15,8 @@ */ package io.fabric8.mockwebserver +import io.fabric8.mockwebserver.http.Headers +import io.fabric8.mockwebserver.http.RecordedRequest import io.fabric8.mockwebserver.internal.WebSocketMessage import io.fabric8.mockwebserver.utils.ResponseProvider import io.vertx.core.Future @@ -26,8 +28,6 @@ import io.vertx.ext.web.client.WebClient import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicInteger -import okhttp3.Headers -import okhttp3.mockwebserver.RecordedRequest import spock.lang.Shared import spock.lang.Specification import spock.util.concurrent.PollingConditions @@ -441,6 +441,7 @@ class DefaultMockServerTest extends Specification { conditions.eventually { assert wsReq.isComplete() assert wsReq.result() != null + assert wsReq.result().closeStatusCode() != null } then: "Expect the close code to be 1002" diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerHttpsTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerHttpsTest.groovy index 2ba771c5e05..19212720984 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerHttpsTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerHttpsTest.groovy @@ -31,14 +31,17 @@ class MockWebServerHttpsTest extends Specification { @Shared static def vertx = Vertx.vertx() - WebClient client MockWebServer server + WebClient client def setup() { - client = WebClient.create(vertx, new WebClientOptions().setSsl(true).setTrustAll(true)) server = new MockWebServer() server.useHttps() server.start() + client = WebClient.create(vertx, new WebClientOptions() + .setSsl(true) + .setTrustOptions(server.getSelfSignedCertificate().trustOptions()) + .setKeyCertOptions(server.getSelfSignedCertificate().keyCertOptions())) } def cleanup() { diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/crud/CrudDispatcherTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/crud/CrudDispatcherTest.groovy index 4e15b93042c..c1a81f69028 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/crud/CrudDispatcherTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/crud/CrudDispatcherTest.groovy @@ -17,12 +17,12 @@ package io.fabric8.mockwebserver.crud import io.fabric8.mockwebserver.Context import io.fabric8.mockwebserver.DefaultMockServer +import io.fabric8.mockwebserver.MockWebServer import io.fabric8.mockwebserver.ServerRequest import io.fabric8.mockwebserver.ServerResponse import io.vertx.core.Vertx import io.vertx.core.buffer.Buffer import io.vertx.ext.web.client.WebClient -import okhttp3.mockwebserver.MockWebServer import spock.lang.Shared import spock.lang.Specification import spock.util.concurrent.AsyncConditions