From c61c7167ee7a7f8e5524936c4c8668396b1f0024 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Fri, 18 Oct 2024 14:40:34 +0200 Subject: [PATCH 1/2] 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 -wJnSXHAupOI6CFERS2aym4IuGX24c7WvoMeH0I8/w8TJTEKNmWCcduaZx5z041gd -kQHQKetYJkzVhh5p2tbIsYlBLe/XGH3IzAVbeFd6GUDK32EyFNrSSOtMEOwbejmH -2wJysLFxGsJFySbnvyEdjDvTdGpNdqPRCU93K/BfRo1ycqSZiSObAh605Ddo3DMQ -lE0rk0im4BQXxwvaVuhbzszR8XIln8/QT5HysiDY5R2hgQq1yJtXtbL7yFGQSeNe -1CG9Gb1JNnHCdAkf+n9RFVoisjsn8MGcSCxpTs0G16Oia41nQaKLByqh4++aithh -Ucd96ujYnIceljMycpkL0VMXzZ7xwHHU+aHPRkRQsDzbf0x0b7MwQD5XkE1rYPzw -/TwJ6qhpPoxzlQ/H5hqEl9zdPpZyQLcfr5YluaRDSTAaR1QruqlWM2Zzy5iBthvx -7hrYNQ/Re5pbp+b4M7h1I6zvohrMiCbtvMQrWYZWGtOHPsW+tUXTQyb2vIYIGIZM -sLZzOijXn78/0IA07xuivqlQ/jmC6jNZAZCC5PRss9KQLWJWu9V3jEcK5dCstJv5 -eocZ6RWy8ShoL2fupp2jYCRota88mQIDAQABAoICAGCtnuYNnij7iAPLLQ7/LRYg -jObDsRuHvTVp16MQjCZCngqC5Z5pz3EU8Wp0YVq7Ec04mCfuONvHnxCCbl/Zca3W -Y8d39kfe0Ti4BVKmItQg+87xydB0DtVa+iXM0uNe3XMq//m9obGZaKbydiddEsex -X5c4SeEdFmcNSvDcWHzeWVMF4w5ytRaSBGox1sE/8CWfLzBT61XHP1yjDd1wlrbn -O7G8VP5PTMbcQucep1onS/OIaNUYddv3gWlSD9/ykVjFAzUERlOB63I6CZP45o4o -wJPWKIE3aLECqmxe35Mcee/JqVwtt7qXZNrkkROZtnHcv4ZbA5wJhKOm+USP/I0Z -K3iHDTOE++LTWNUIOaUXjiowJ6V4rXf8x3hftLz95RnN1rZWXV7T+OCCW+VduGaC -139UM9mEJn0W5DAmFCjpPHLHqfNupbnoi+nuTIuu9+0aqtMchbTSFmnIiEJOeyJ/ -JvONLhB39XT08QkAf7IKFiqLeWIy6E9IR4TdOO3KBMbjtJTaMkj6q8C8C4evFF04 -tuPPgT6UAA5TxihBAipHd1mIs/yTTGSZMMPb4vLFlw8cEJllC0qIbJpVc45YauDI -kXnhoXcrjEdTy/aMiXlnxAu/l/PkHVcuOCP5kCGIyHX0g/Ig3y8nseVgRZc8i9Kf -vKH8tOFfaUPq0s6WffABAoIBAQD7fDX+RsU7Mi9iFXqPSbbuCRz8yBG54DJDh3Vt -+Y4BzGqboUDxCvpTbpw7vy4R67upFZ0G6p3PLTEimOfSFp7/KH0Gije3b7yexRwM -GVxf+d+Im1cgPhzfqAF92CIjIWGUXGqOvVX7hMBkhDdqgsaINB2jpzJTv47HgXfp -7Lf3op94thJP+tbMDvRuM+a1l5VJgrytVIdUBI0FaPWULdm5z2Sndua65oUBsVP5 -eMRQqIT+9qwMAkONoxCjADyD/yAdA55e2lAH8DM3FDhXpf048XLun5c49PppvcbW -3vpm262oiBXdxuCadsAb2RZogvJ30fKOqZnt4yrt8PR0+HP5AoIBAQDiVrOI0ziE -hGazvQkB5Rqcx7fMmOZ0s3jsqJAbNrwwuZjY6vC2659XiqVcyNp4RanbvofsQSBs -zN4DF0Rx72S+8ELIbk+cZ0Jwkix03cRNNkKbiUrUKr+zrvQbVEi+NRbz11Leoqw4 -cEcykuF3bjQvdE4R72ckQPdXEv1z/bRrCNyZq2qxdD38scHHFjM8PC9t2dghMUpN -9pS3BTLEYZBCCZ6kxq4z45dDxqosX2OImtHnVecHAPf3xy48cjDau9E1hkgClEdk -MSjPIpYz3zg0qH9Ef3qVkDv+6VuBdE/j6B65HC8z3fTcwluPc+AfhYkHykxKcCdn -tR9Kd+7sOfWhAoIBAQCaQXNA+BnsmHjV+gTGNVn+ohpktzegQvOx1jnibit70O4n -bf7Om4Q2fudYAol4tpbSPQ6nemu386lq5k1z4So/qo8d3tQUMXaKEK+GgFvYBwXk -3hvQDClbysq3bUZrNAONpC48Rcii0afNQAhZzcOHMihoBJtrIVmr6C8sjmW9gMO+ -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 CERTIFICATE----- -MIIFPzCCAycCFFa1f+dP0SR0nMoPfO+MrMRNfjHaMA0GCSqGSIb3DQEBCwUAMFwx -CzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMRUwEwYDVQQHDAxEZWZh -dWx0IENpdHkxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0y -MTExMDMwODU0NTRaFw0zMTExMDEwODU0NTRaMFwxCzAJBgNVBAYTAkFVMRMwEQYD -VQQIDApTb21lLVN0YXRlMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxITAfBgNVBAoM -GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCAiIwDQYJKoZIhvcNAQEBBQADggIP -ADCCAgoCggIBAN5Y08LhIkTwMpcZTkkhKytjWecjbj2+Y7rH6kR+VwYGppF5B6FF -Q14wUaN73aNmT7TGHw1s0V/g5+zAmdJccC6k4joIURFLZrKbgi4Zfbhzta+gx4fQ -jz/DxMlMQo2ZYJx25pnHnPTjWB2RAdAp61gmTNWGHmna1sixiUEt79cYfcjMBVt4 -V3oZQMrfYTIU2tJI60wQ7Bt6OYfbAnKwsXEawkXJJue/IR2MO9N0ak12o9EJT3cr -8F9GjXJypJmJI5sCHrTkN2jcMxCUTSuTSKbgFBfHC9pW6FvOzNHxciWfz9BPkfKy -INjlHaGBCrXIm1e1svvIUZBJ417UIb0ZvUk2ccJ0CR/6f1EVWiKyOyfwwZxILGlO -zQbXo6JrjWdBoosHKqHj75qK2GFRx33q6Nichx6WMzJymQvRUxfNnvHAcdT5oc9G -RFCwPNt/THRvszBAPleQTWtg/PD9PAnqqGk+jHOVD8fmGoSX3N0+lnJAtx+vliW5 -pENJMBpHVCu6qVYzZnPLmIG2G/HuGtg1D9F7mlun5vgzuHUjrO+iGsyIJu28xCtZ -hlYa04c+xb61RdNDJva8hggYhkywtnM6KNefvz/QgDTvG6K+qVD+OYLqM1kBkILk -9Gyz0pAtYla71XeMRwrl0Ky0m/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 -FTATBgNVBAcMDERlZmF1bHQgQ2l0eTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0 -cyBQdHkgTHRkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA3ljTwuEi -RPAylxlOSSErK2NZ5yNuPb5jusfqRH5XBgamkXkHoUVDXjBRo3vdo2ZPtMYfDWzR -X+Dn7MCZ0lxwLqTiOghREUtmspuCLhl9uHO1r6DHh9CPP8PEyUxCjZlgnHbmmcec -9ONYHZEB0CnrWCZM1YYeadrWyLGJQS3v1xh9yMwFW3hXehlAyt9hMhTa0kjrTBDs -G3o5h9sCcrCxcRrCRckm578hHYw703RqTXaj0QlPdyvwX0aNcnKkmYkjmwIetOQ3 -aNwzEJRNK5NIpuAUF8cL2lboW87M0fFyJZ/P0E+R8rIg2OUdoYEKtcibV7Wy+8hR -kEnjXtQhvRm9STZxwnQJH/p/URVaIrI7J/DBnEgsaU7NBtejomuNZ0GiiwcqoePv -morYYVHHfero2JyHHpYzMnKZC9FTF82e8cBx1Pmhz0ZEULA8239MdG+zMEA+V5BN -a2D88P08CeqoaT6Mc5UPx+YahJfc3T6WckC3H6+WJbmkQ0kwGkdUK7qpVjNmc8uY -gbYb8e4a2DUP0XuaW6fm+DO4dSOs76IazIgm7bzEK1mGVhrThz7FvrVF00Mm9ryG -CBiGTLC2czoo15+/P9CANO8bor6pUP45guozWQGQguT0bLPSkC1iVrvVd4xHCuXQ -rLSb+XqHGekVsvEoaC9n7qado2AkaLWvPJkCAwEAAaAAMA0GCSqGSIb3DQEBCwUA -A4ICAQCExP0WiJbGkhbpIRVN30seLat5upU3WauQy4fGeDKZAq37LguhzeHkWXtu -Rifb5fz8e7PTOz1fwjHJ8pBQsy5mRoMDXYdtyn6S6A2xGTPUYT82mN6BSJbwJDQm -Y4l4Lhg+7cEvqls+Mx9Dq0eSlM7hH7ezOl5c25U+lG74dHLT2gq5ornjdBk2JKnx -2c95646UomKJKVZtzfPLFRJhmVOr2ndkzooF1GlWXZsU57hflH0Y6argAqC+Y/Hu -AFqsm48Uwixex1FfX53aEFnZG1vkDYm48idGUDEa1QNqqC7Wt0qDM8iZtYaHoc9D -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 From 7c99ca37339259a7036742fc7dd512cf8e567a13 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Fri, 18 Oct 2024 14:52:22 +0200 Subject: [PATCH 2/2] refactor(mockwebserver): Kubernetes Client is compatible with Vert.x-based mockwebserver Signed-off-by: Marc Nuri --- .../test/v1beta1/AuthorizationPolicyTest.java | 2 +- .../test/v1beta1/DestinationRuleTest.java | 2 +- .../istio/test/v1beta1/GatewayTest.java | 2 +- .../test/v1beta1/PeerAuthenticationTest.java | 2 +- .../istio/test/v1beta1/ServiceEntryTest.java | 2 +- .../istio/test/v1beta1/SidecarTest.java | 2 +- .../test/v1beta1/VirtualServiceTest.java | 2 +- .../istio/test/v1beta1/WorkloadEntryTest.java | 2 +- .../io/fabric8/knative/test/ServiceTest.java | 2 +- .../fabric8/tekton/v1beta1/PipelineTest.java | 2 +- .../okhttp/ConnectionPoolLeakageTest.java | 8 +- .../client/okhttp/OkHttpClientProxyTest.java | 5 -- junit/kubernetes-server-mock/pom.xml | 16 ++-- .../mock/KubernetesAttributesExtractor.java | 2 +- .../server/mock/KubernetesCrudDispatcher.java | 6 +- .../mock/KubernetesMixedDispatcher.java | 8 +- .../server/mock/KubernetesMockServer.java | 4 +- .../mock/KubernetesMockServerExtension.java | 13 +-- .../client/server/mock/KubernetesServer.java | 24 +---- .../server/mock/WatchEventsListener.java | 6 +- .../crud/KubernetesCrudDispatcherHandler.java | 4 +- .../client/server/mock/crud/PatchHandler.java | 4 +- .../client/server/mock/crud/PostHandler.java | 2 +- .../client/server/mock/crud/PutHandler.java | 2 +- .../mock/KubernetesMixedDispatcherTest.java | 33 +++---- .../KubernetesCrudDispatcherTestBase.java | 2 +- .../fabric8/mockwebserver/http/MediaType.java | 6 +- .../mockwebserver/http/WebSocketListener.java | 5 +- .../internal/MockServerExpectationImpl.java | 4 +- .../internal/WebSocketSession.java | 11 +-- .../utils/ResponseProviders.java | 2 +- .../vertx/HttpServerRequestHandler.java | 7 +- .../DefaultMockServerTest.groovy | 23 ++++- .../DefaultMockServerWebSocketTest.groovy | 85 ++++++++++++++---- .../mockwebserver/MockWebServerTest.groovy | 1 - .../http/WebSocketListenerTest.groovy | 22 ++++- junit/openshift-server-mock/pom.xml | 7 ++ .../server/mock/OpenShiftMockServer.java | 4 +- .../mock/OpenShiftMockServerExtension.java | 9 +- .../client/server/mock/OpenShiftServer.java | 4 +- .../AbstractHttpClientProxyHttpsTest.java | 47 ++++------ .../http/AbstractHttpClientProxyTest.java | 33 ++++--- .../AbstractHttpLoggingInterceptorTest.java | 8 +- .../client/http/AbstractHttpPostTest.java | 2 +- .../client/http/AbstractHttpPutTest.java | 2 +- .../AbstractSimultaneousConnectionsTest.java | 88 ++++++------------- .../client/internal/CertUtilsTest.java | 2 +- .../mock/CreateOrReplaceResourceTest.java | 2 +- .../client/mock/CustomResourceTest.java | 11 ++- .../client/mock/DeploymentTest.java | 2 +- .../kubernetes/client/mock/MixedCrudTest.java | 7 +- .../kubernetes/client/mock/PodCrudTest.java | 4 +- .../client/mock/PropagationPolicyTest.java | 2 +- .../client/mock/RequestConfigTest.java | 2 +- .../client/mock/ResourceListTest.java | 2 +- .../kubernetes/client/mock/ResourceTest.java | 6 +- .../kubernetes/client/mock/ServiceTest.java | 6 +- .../client/mock/StatefulSetTest.java | 2 +- ...ypedClusterScopeCustomResourceApiTest.java | 2 +- .../mock/TypedCustomResourceApiTest.java | 2 +- .../client/server/mock/AdaptTest.java | 7 +- .../log4j/lookup/KubernetesLookupTest.java | 1 + pom.xml | 12 +-- 63 files changed, 302 insertions(+), 299 deletions(-) diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/AuthorizationPolicyTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/AuthorizationPolicyTest.java index f0d1ba1478e..d0a86707426 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/AuthorizationPolicyTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/AuthorizationPolicyTest.java @@ -29,7 +29,7 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/DestinationRuleTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/DestinationRuleTest.java index 44a4091b093..88735f032c1 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/DestinationRuleTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/DestinationRuleTest.java @@ -27,7 +27,7 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java index 67df8eadd96..7d607c7c4d5 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java @@ -25,7 +25,7 @@ import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.snakeyaml.engine.v2.api.Load; diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/PeerAuthenticationTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/PeerAuthenticationTest.java index 0eb665a497b..660b302d526 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/PeerAuthenticationTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/PeerAuthenticationTest.java @@ -24,7 +24,7 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/ServiceEntryTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/ServiceEntryTest.java index 49ff961e39e..c1c282f4a7a 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/ServiceEntryTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/ServiceEntryTest.java @@ -23,7 +23,7 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/SidecarTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/SidecarTest.java index c48e6d9ddf1..b121fc4ad08 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/SidecarTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/SidecarTest.java @@ -22,7 +22,7 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java index b121b5940c6..c24d1f99ee2 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java @@ -35,7 +35,7 @@ import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.snakeyaml.engine.v2.api.Load; diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/WorkloadEntryTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/WorkloadEntryTest.java index 576e153ea39..6a33cf52dd0 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/WorkloadEntryTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/WorkloadEntryTest.java @@ -21,7 +21,7 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/extensions/knative/tests/src/test/java/io/fabric8/knative/test/ServiceTest.java b/extensions/knative/tests/src/test/java/io/fabric8/knative/test/ServiceTest.java index be21b7233db..a3ae73214a4 100644 --- a/extensions/knative/tests/src/test/java/io/fabric8/knative/test/ServiceTest.java +++ b/extensions/knative/tests/src/test/java/io/fabric8/knative/test/ServiceTest.java @@ -21,7 +21,7 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/extensions/tekton/tests/src/test/java/io/fabric8/tekton/v1beta1/PipelineTest.java b/extensions/tekton/tests/src/test/java/io/fabric8/tekton/v1beta1/PipelineTest.java index d73c004d561..38f4e5369d3 100644 --- a/extensions/tekton/tests/src/test/java/io/fabric8/tekton/v1beta1/PipelineTest.java +++ b/extensions/tekton/tests/src/test/java/io/fabric8/tekton/v1beta1/PipelineTest.java @@ -18,8 +18,8 @@ import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.tekton.client.TektonClient; -import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/ConnectionPoolLeakageTest.java b/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/ConnectionPoolLeakageTest.java index 906ed1981ba..38e7d61c8c9 100644 --- a/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/ConnectionPoolLeakageTest.java +++ b/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/ConnectionPoolLeakageTest.java @@ -18,10 +18,10 @@ import io.fabric8.kubernetes.client.http.AsyncBody; import io.fabric8.kubernetes.client.http.HttpClient; import io.fabric8.kubernetes.client.http.HttpResponse; +import io.fabric8.mockwebserver.MockWebServer; +import io.fabric8.mockwebserver.http.MockResponse; import okhttp3.ConnectionPool; import okhttp3.Protocol; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -53,7 +53,7 @@ void setUp() { } @AfterEach - void tearDown() throws Exception { + void tearDown() { server.shutdown(); connectionPool.evictAll(); } @@ -63,7 +63,7 @@ void tearDown() throws Exception { @ValueSource(strings = { "h2_prior_knowledge", "http/1.1" }) void consumeBytes(String protocol) throws Exception { final Protocol p = Protocol.get(protocol); - server.setProtocols(Collections.singletonList(p)); + server.setProtocols(Collections.singletonList(io.fabric8.mockwebserver.vertx.Protocol.get(p.toString()))); server.start(); clientBuilder.getBuilder().protocols(Collections.singletonList(p)); try (HttpClient httpClient = clientBuilder.build()) { diff --git a/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientProxyTest.java b/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientProxyTest.java index 9972a2db619..aa1dadc8cb7 100644 --- a/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientProxyTest.java +++ b/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientProxyTest.java @@ -24,9 +24,4 @@ public class OkHttpClientProxyTest extends AbstractHttpClientProxyTest { protected HttpClient.Factory getHttpClientFactory() { return new OkHttpClientFactory(); } - - @Override - protected void proxyConfigurationOtherAuthAddsRequiredHeaders() throws Exception { - // OkHttp uses a response intercept to add the auth proxy headers in case the original response failed - } } diff --git a/junit/kubernetes-server-mock/pom.xml b/junit/kubernetes-server-mock/pom.xml index bb1d4de8e08..14a9853abe1 100644 --- a/junit/kubernetes-server-mock/pom.xml +++ b/junit/kubernetes-server-mock/pom.xml @@ -41,12 +41,21 @@ io.fabric8 mockwebserver - + + org.junit.jupiter + junit-jupiter-api + provided + org.junit.jupiter junit-jupiter-engine test + + junit + junit + provided + org.slf4j @@ -54,11 +63,6 @@ ${slf4j.version} test - - org.junit.jupiter - junit-jupiter-api - provided - org.junit.jupiter junit-jupiter-params diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index d35ad46e60e..5d1ff1e4309 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -24,7 +24,7 @@ import io.fabric8.mockwebserver.crud.Attribute; import io.fabric8.mockwebserver.crud.AttributeExtractor; import io.fabric8.mockwebserver.crud.AttributeSet; -import okhttp3.HttpUrl; +import io.fabric8.mockwebserver.http.HttpUrl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesCrudDispatcher.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesCrudDispatcher.java index b916969e7e9..5af8e8e4940 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesCrudDispatcher.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesCrudDispatcher.java @@ -30,9 +30,8 @@ import io.fabric8.mockwebserver.crud.Attribute; import io.fabric8.mockwebserver.crud.AttributeSet; import io.fabric8.mockwebserver.crud.CrudDispatcher; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.RecordedRequest; -import okhttp3.mockwebserver.SocketPolicy; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -292,7 +291,6 @@ public MockResponse handleWatch(String path) { .filter(entry -> watch.attributeMatches(entry.getKey())) .forEach(entry -> watch.sendWebSocketResponse(entry.getValue(), Action.ADDED)))); watchEventListeners.add(watchEventListener); - mockResponse.setSocketPolicy(SocketPolicy.KEEP_OPEN); return mockResponse.withWebSocketUpgrade(watchEventListener); } diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcher.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcher.java index 7daa72e0105..29f891ae13d 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcher.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcher.java @@ -19,11 +19,11 @@ import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; import io.fabric8.mockwebserver.dsl.HttpMethod; +import io.fabric8.mockwebserver.http.Dispatcher; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.internal.MockDispatcher; import io.fabric8.mockwebserver.internal.SimpleRequest; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.RecordedRequest; import java.util.Collections; import java.util.List; @@ -58,7 +58,7 @@ public KubernetesMixedDispatcher( } @Override - public MockResponse dispatch(RecordedRequest request) throws InterruptedException { + public MockResponse dispatch(RecordedRequest request) { final Queue responseQueue = responses.get( new SimpleRequest(HttpMethod.valueOf(request.getMethod()), request.getPath())); if (responseQueue != null && !responseQueue.isEmpty()) { diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java index db94c7113d0..2297f9de441 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java @@ -37,11 +37,11 @@ import io.fabric8.kubernetes.client.utils.Serialization; 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.fabric8.mockwebserver.http.Dispatcher; import io.fabric8.mockwebserver.internal.MockDispatcher; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; import java.net.HttpURLConnection; import java.net.InetAddress; diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServerExtension.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServerExtension.java index 7ad84905817..c8c82359082 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServerExtension.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServerExtension.java @@ -16,15 +16,14 @@ package io.fabric8.kubernetes.client.server.mock; import io.fabric8.kubernetes.client.Client; -import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.NamespacedKubernetesClient; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.mockwebserver.Context; +import io.fabric8.mockwebserver.MockWebServer; import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; +import io.fabric8.mockwebserver.http.Dispatcher; import io.fabric8.mockwebserver.internal.MockDispatcher; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; @@ -148,14 +147,6 @@ protected void destroyStatic() { staticClient.close(); } - /** - * @deprecated no longer used - */ - @Deprecated - protected Class getClientType() { - return KubernetesClient.class; - } - protected Class getKubernetesMockServerType() { return KubernetesMockServer.class; } diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java index ea3b39a14d7..5a0de1a2f7e 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java @@ -18,11 +18,11 @@ import io.fabric8.kubernetes.client.NamespacedKubernetesClient; import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext; import io.fabric8.mockwebserver.Context; +import io.fabric8.mockwebserver.MockWebServer; import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.rules.ExternalResource; import java.net.InetAddress; @@ -95,26 +95,6 @@ public MockServerExpectation expect() { return mock.expect(); } - @Deprecated - public void expectAndReturnAsJson(String path, int code, T body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsString(String path, int code, String body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsJson(String method, String path, int code, T body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsString(String method, String path, int code, String body) { - expect().withPath(path).andReturn(code, body).always(); - } - public KubernetesMockServer getKubernetesMockServer() { return mock; } diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/WatchEventsListener.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/WatchEventsListener.java index ab11a0f61f3..ba81bbd4dff 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/WatchEventsListener.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/WatchEventsListener.java @@ -22,10 +22,10 @@ import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.mockwebserver.Context; import io.fabric8.mockwebserver.crud.AttributeSet; +import io.fabric8.mockwebserver.http.Response; +import io.fabric8.mockwebserver.http.WebSocket; +import io.fabric8.mockwebserver.http.WebSocketListener; import io.fabric8.mockwebserver.internal.WebSocketMessage; -import okhttp3.Response; -import okhttp3.WebSocket; -import okhttp3.WebSocketListener; import org.slf4j.Logger; import java.util.Set; diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherHandler.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherHandler.java index a82e349ec0a..459014f5ff5 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherHandler.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherHandler.java @@ -21,8 +21,8 @@ import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.Utils; import io.fabric8.mockwebserver.crud.AttributeSet; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import java.net.HttpURLConnection; diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java index d6518043375..cc1cfc94594 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java @@ -22,9 +22,9 @@ import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.Utils; import io.fabric8.mockwebserver.crud.AttributeSet; +import io.fabric8.mockwebserver.http.MediaType; +import io.fabric8.mockwebserver.http.MockResponse; import io.fabric8.zjsonpatch.JsonPatch; -import okhttp3.MediaType; -import okhttp3.mockwebserver.MockResponse; import java.net.HttpURLConnection; import java.util.Iterator; diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PostHandler.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PostHandler.java index 9980caaa97b..a3c016a263d 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PostHandler.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PostHandler.java @@ -23,7 +23,7 @@ import io.fabric8.kubernetes.client.utils.Utils; import io.fabric8.mockwebserver.crud.Attribute; import io.fabric8.mockwebserver.crud.AttributeSet; -import okhttp3.mockwebserver.MockResponse; +import io.fabric8.mockwebserver.http.MockResponse; import java.net.HttpURLConnection; import java.time.ZoneOffset; diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java index 81ebd0f02e8..75ebd3d255b 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java @@ -19,7 +19,7 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.mockwebserver.crud.AttributeSet; -import okhttp3.mockwebserver.MockResponse; +import io.fabric8.mockwebserver.http.MockResponse; import java.net.HttpURLConnection; import java.util.Map; diff --git a/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcherTest.java b/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcherTest.java index 1c78461ad62..e13c86c53cd 100644 --- a/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcherTest.java +++ b/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesMixedDispatcherTest.java @@ -20,21 +20,18 @@ import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; import io.fabric8.mockwebserver.dsl.HttpMethod; +import io.fabric8.mockwebserver.http.Buffer; +import io.fabric8.mockwebserver.http.Headers; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.internal.SimpleRequest; import io.fabric8.mockwebserver.internal.SimpleResponse; -import okhttp3.Headers; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.RecordedRequest; -import okio.Buffer; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import java.net.Socket; import java.nio.charset.StandardCharsets; import java.util.ArrayDeque; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Queue; @@ -48,25 +45,21 @@ class KubernetesMixedDispatcherTest { private Map> responses; private KubernetesMixedDispatcher dispatcher; - private Socket socket; - @BeforeEach void setUp() { responses = new HashMap<>(); dispatcher = new KubernetesMixedDispatcher(responses); - socket = Mockito.mock(Socket.class, Mockito.RETURNS_DEEP_STUBS); } @Test @DisplayName("dispatch, with matching expectation, returns expectation") - void dispatchWithMatchingExpectation() throws Exception { + void dispatchWithMatchingExpectation() { // Given responses.compute(new SimpleRequest(HttpMethod.GET, "/api/v1/resources/my-resource"), (k, v) -> new ArrayDeque<>()) .add(new SimpleResponse(true, 200, "resourceBody", null)); // When - final MockResponse result = dispatcher.dispatch(new RecordedRequest( - "GET /api/v1/resources/my-resource HTTP/1.1", EMPTY_HEADERS, Collections.emptyList(), - 0, new Buffer(), 0, socket)); + final MockResponse result = dispatcher.dispatch(new RecordedRequest("HTTP/1.1", HttpMethod.GET, + "/api/v1/resources/my-resource", EMPTY_HEADERS, null)); // Then assertThat(result) .hasFieldOrPropertyWithValue("status", "HTTP/1.1 200 OK") @@ -76,19 +69,17 @@ void dispatchWithMatchingExpectation() throws Exception { @Test @DisplayName("dispatch, with existing CRUD resource, returns CRUD resource") - void dispatchWithCrudExistentResource() throws Exception { + void dispatchWithCrudExistentResource() { // Given final Buffer requestBody = new Buffer(); requestBody.writeString("{\"kind\": \"Resource\", \"apiVersion\": \"v1\",\"metadata\": {\"name\": \"my-resource\"}}", StandardCharsets.UTF_8); requestBody.flush(); - dispatcher.dispatch(new RecordedRequest( - "POST /api/v1/resources HTTP/1.1", EMPTY_HEADERS, Collections.emptyList(), - requestBody.size(), requestBody, 0, socket)); + dispatcher.dispatch(new RecordedRequest("HTTP/1.1", HttpMethod.POST, + "/api/v1/resources", EMPTY_HEADERS, requestBody)); // When - final MockResponse result = dispatcher.dispatch(new RecordedRequest( - "GET /api/v1/resources/my-resource HTTP/1.1", EMPTY_HEADERS, Collections.emptyList(), - 0, new Buffer(), 0, socket)); + final MockResponse result = dispatcher.dispatch(new RecordedRequest("HTTP/1.1", HttpMethod.GET, + "/api/v1/resources/my-resource", EMPTY_HEADERS, null)); // Then assertThat(result) .hasFieldOrPropertyWithValue("status", "HTTP/1.1 200 OK") diff --git a/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherTestBase.java b/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherTestBase.java index feaa3aec369..60c23af07d8 100644 --- a/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherTestBase.java +++ b/junit/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherTestBase.java @@ -19,7 +19,7 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesCrudDispatcher; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.mockwebserver.Context; -import okhttp3.mockwebserver.MockWebServer; +import io.fabric8.mockwebserver.MockWebServer; import org.assertj.core.api.Condition; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MediaType.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MediaType.java index 05a49ce013a..bc292fc0726 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MediaType.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/MediaType.java @@ -20,11 +20,11 @@ import java.util.regex.Pattern; /** - * Compatibility layer for OkHttp. + * Provides tooling to parse and manipulate media types. * - * @deprecated should not be needed anymore + *

+ * Compatibility layer for OkHttp. */ -@Deprecated public class MediaType { private static final String TOKEN = "([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)"; private static final String QUOTED = "\"([^\"]*)\""; diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/WebSocketListener.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/WebSocketListener.java index d652c015485..7d9a3700077 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/WebSocketListener.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/http/WebSocketListener.java @@ -15,6 +15,8 @@ */ package io.fabric8.mockwebserver.http; +import java.nio.charset.StandardCharsets; + public abstract class WebSocketListener { /** @@ -40,10 +42,11 @@ public void onMessage(WebSocket webSocket, String text) { */ @Deprecated public void onMessage(WebSocket webSocket, ByteString bytes) { + onMessage(webSocket, bytes.utf8()); } public void onMessage(WebSocket webSocket, byte[] bytes) { - onMessage(webSocket, ByteString.of(bytes)); + onMessage(webSocket, new String(bytes, StandardCharsets.UTF_8)); } /** 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 83ad81b1148..c9ee9cd0309 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 @@ -230,7 +230,7 @@ private ServerResponse createResponse(boolean repeatable, long delay, TimeUnit d } private ResponseProvider toString(final ResponseProvider provider) { - return new ResponseProvider() { + return new ResponseProvider<>() { @Override public String getBody(RecordedRequest request) { Object object = provider.getBody(request); @@ -255,7 +255,7 @@ public void setHeaders(Headers headers) { } private ResponseProvider> listToString(final ResponseProvider> provider) { - return new ResponseProvider>() { + return new ResponseProvider<>() { @Override public List getBody(RecordedRequest request) { List objects = provider.getBody(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 c13384a909e..67f5349b023 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,12 @@ package io.fabric8.mockwebserver.internal; import io.fabric8.mockwebserver.MockServerException; -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.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -79,11 +79,6 @@ public void onOpen(WebSocket webSocket, Response response) { closeActiveSocketsIfApplicable(); } - @Override - public void onMessage(WebSocket webSocket, ByteString bytes) { - onMessage(webSocket, bytes.utf8()); - } - @Override public void onMessage(WebSocket webSocket, String in) { Queue queue = requestEvents.get(in); @@ -109,7 +104,7 @@ private void send(WebSocket ws, Queue queue, String in) { } private void checkIfShouldSendAgain(WebSocket ws, WebSocketMessage msg) { - String text = msg.isBinary() ? ByteString.of(msg.getBytes()).utf8() : msg.getBody(); + String text = msg.isBinary() ? new String(msg.getBytes(), StandardCharsets.UTF_8) : msg.getBody(); if (sentWebSocketMessagesRequestEvents.containsKey(text)) { Queue queue = sentWebSocketMessagesRequestEvents.get(text); send(ws, queue, text); @@ -163,7 +158,7 @@ private void send(final WebSocket ws, final WebSocketMessage message) { executor.schedule(() -> { if (ws != null) { if (message.isBinary()) { - ws.send(ByteString.of(message.getBytes())); + ws.send(message.getBytes()); } else { ws.send(message.getBody()); } 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 fe9dba39862..c838e494a59 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 @@ -54,7 +54,7 @@ public static ResponseProvider> ofAll(int statusCode, R... elements) public static ResponseProvider of(final int statusCode, final BodyProvider bodyProvider) { if (bodyProvider != null) { - return new ResponseProvider() { + return new ResponseProvider<>() { private Headers headers = new Headers.Builder().build(); @Override diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/vertx/HttpServerRequestHandler.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/vertx/HttpServerRequestHandler.java index 75cfdd1f48f..53c760ac1d3 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/vertx/HttpServerRequestHandler.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/vertx/HttpServerRequestHandler.java @@ -42,8 +42,11 @@ protected HttpServerRequestHandler(Vertx vertx) { @Override public final void handle(HttpServerRequest event) { - final Handler exceptionHandler = err -> event.response().setStatusCode(500).setStatusMessage(err.getMessage()) - .send(); + final Handler exceptionHandler = err -> { + if (!event.response().headWritten()) { + event.response().setStatusCode(500).setStatusMessage(err.getMessage()).send(); + } + }; event.resume(); final Future body; if (hasBody(event)) { 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 9dc85c6ca9c..1f0ad639356 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy @@ -194,7 +194,7 @@ class DefaultMockServerTest extends Specification { } } - def "takeRequest, with timeout and no requests, should return null and don't block (after timeout)"() { + def "takeRequest, with timeout and no requests, should return null and don't block after timeout"() { when: def result = server.takeRequest(1, TimeUnit.MICROSECONDS) @@ -651,4 +651,25 @@ class DefaultMockServerTest extends Specification { receivedMessages.poll() == "CREATED" receivedMessages.poll() == "WS-CREATED" } + + def "when setting a chunked response it should be sent in chunks"() { + given: "An expectation with chunked response" + server.expect().get().withPath("/api/v1/chunked-response") + .andReturnChunked(200, "A response that should be sent in chunks") + .always() + and: "A request" + def request = client.get(server.port, server.getHostName(), "/api/v1/chunked-response").send() + and: "An instance of PollingConditions" + def conditions = new PollingConditions(timeout: 10) + + when: "The request is completed" + conditions.eventually { + assert request.isComplete() + } + + then: "Expect the response to match the expectation" + request.result().statusCode() == 200 + request.result().body().toString() == "28\r\nA response that should be sent in chunks\r\n0\r\n" + request.result().headers().get("Transfer-Encoding") == "chunked" + } } diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerWebSocketTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerWebSocketTest.groovy index a0a31958e42..63257f329ea 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerWebSocketTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerWebSocketTest.groovy @@ -18,9 +18,12 @@ package io.fabric8.mockwebserver import io.vertx.core.AsyncResult import io.vertx.core.Handler import io.vertx.core.Vertx +import io.vertx.core.http.HttpClientOptions +import io.vertx.core.http.HttpMethod +import io.vertx.core.http.HttpVersion +import io.vertx.core.http.RequestOptions import io.vertx.core.http.WebSocket import io.vertx.core.http.WebSocketClient -import io.vertx.core.http.WebSocketConnectOptions import java.util.concurrent.ConcurrentLinkedQueue import java.util.stream.IntStream import spock.lang.Shared @@ -171,37 +174,81 @@ class DefaultMockServerWebSocketTest extends Specification { } // https://github.com/fabric8io/mockwebserver/issues/77 + // n.b. Uses an HTTP client in its simplest form (emulating a WebSocket protocol negotiation) + // since it's the only reliable way to get the protocol negotiation headers (in this case 'sec-websocket-protocol') def "andUpgradeToWebSocket, with request header 'sec-websocket-protocol', should create response with matching header"() { given: "A WebSocket expectation" server.expect() .withPath("/websocket") .andUpgradeToWebSocket().open().waitFor(10L).andEmit("done").done().always() - and: "A WebSocket request" - def wsReq = wsClient.webSocket().connect(new WebSocketConnectOptions() - .setPort(server.port) + and: "An HTTP client" + def httpClient = vertx.createHttpClient(new HttpClientOptions() + .setProtocolVersion(HttpVersion.HTTP_1_1)) + and: "A simple HTTP request to retrieve the headers and status" + // Emulates an HTTP Request as a WebSocket client would perform it + // This is mimicking what jdk.internal.net.http.websocket.OpeningHandshake does + def request = httpClient.request(new RequestOptions() + .setPort(server.getPort()) .setHost(server.getHostName()) .setURI("/websocket") - .addSubProtocol("v4.channel.k8s.io")) - and: "A WebSocket listener" - String secWebSocketProtocol - wsReq.onComplete { ws -> - if (ws.result() != null && ws.result().headers() != null) { - secWebSocketProtocol = ws.result().headers().get("sec-websocket-protocol") - } - } - def currentResult = wsReq.result() - if (currentResult != null && currentResult.headers() != null) { - secWebSocketProtocol = currentResult.headers().get("sec-websocket-protocol") - } + .setMethod(HttpMethod.GET) + .putHeader("sec-websocket-protocol", "v4.channel.k8s.io") + .putHeader("sec-websocket-version", "13") + .putHeader("sec-websocket-key", Base64.getEncoder().encodeToString(new byte[16])) + .putHeader("connection", "upgrade") + .putHeader("upgrade", "websocket") + .putHeader("origin", "http://localhost")) + .compose { req -> + req.send() + } and: "An instance of PollingConditions" def conditions = new PollingConditions(timeout: 10) - when: "The request is sent and completed" + when: "The request is completed" conditions.eventually { - assert secWebSocketProtocol != null + assert request.isComplete() } then: "Expect the response to contain a matching header" - secWebSocketProtocol == "v4.channel.k8s.io" + request.result().statusCode() == 101 + request.result().headers().get("sec-websocket-protocol") == "v4.channel.k8s.io" + + cleanup: + httpClient.close() + } + + def "andUpgradeToWebSocket, with invalid request should respond with 400 status message"() { + given: "A WebSocket expectation" + server.expect() + .withPath("/websocket") + .andUpgradeToWebSocket().open().waitFor(10L).andEmit("done").done().always() + and: "An HTTP client" + def httpClient = vertx.createHttpClient(new HttpClientOptions() + .setProtocolVersion(HttpVersion.HTTP_1_1)) + and: "A simple HTTP request to retrieve the headers and status" + // Emulates an HTTP Request as a WebSocket client would perform it + // This is mimicking what jdk.internal.net.http.websocket.OpeningHandshake does + def request = httpClient.request(new RequestOptions() + .setPort(server.getPort()) + .setHost(server.getHostName()) + .setURI("/websocket") + .setMethod(HttpMethod.GET) + .putHeader("connection", "upgrade")) + .compose { req -> + req.send() + } + and: "An instance of PollingConditions" + def conditions = new PollingConditions(timeout: 10) + + when: "The request is completed" + conditions.eventually { + assert request.isComplete() + } + + then: "Expect the response to have a client error status code" + request.result().statusCode() == 400 + + cleanup: + httpClient.close() } } diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerTest.groovy index 40d6a5237ee..beb9182edb0 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/MockWebServerTest.groovy @@ -20,7 +20,6 @@ import io.fabric8.mockwebserver.http.RecordedRequest import io.vertx.core.Future import io.vertx.core.Vertx import io.vertx.ext.web.client.WebClient -import io.vertx.ext.web.client.WebClientOptions import java.util.concurrent.TimeUnit import spock.lang.Shared import spock.lang.Specification diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/http/WebSocketListenerTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/http/WebSocketListenerTest.groovy index 9b877a10e92..b1df8bc3a4c 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/http/WebSocketListenerTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/http/WebSocketListenerTest.groovy @@ -20,13 +20,13 @@ import spock.lang.Specification class WebSocketListenerTest extends Specification { - def "onMessage(WebSocket,byte[]) calls deprecated onMessage(WebSocket,ByteString) method"() { + def "onMessage(WebSocket,byte[]) calls onMessage(WebSocket,String) method by default"() { given: String message def listener = new WebSocketListener(){ @Override - void onMessage(WebSocket webSocket, ByteString bytes) { - message = bytes.utf8() + void onMessage(WebSocket webSocket, String msg) { + message = msg } } when: @@ -34,4 +34,20 @@ class WebSocketListenerTest extends Specification { then: message == "Hello, world!" } + + @SuppressWarnings('GrDeprecatedAPIUsage') + def "onMessage(WebSocket,ByteString) calls onMessage(WebSocket,String) method by default"() { + given: + String message + def listener = new WebSocketListener(){ + @Override + void onMessage(WebSocket webSocket, String msg) { + message = msg + } + } + when: + listener.onMessage(null, ByteString.of("Hello, world!".getBytes(StandardCharsets.UTF_8))) + then: + message == "Hello, world!" + } } diff --git a/junit/openshift-server-mock/pom.xml b/junit/openshift-server-mock/pom.xml index 44f93f1b38a..4f98748e8ba 100644 --- a/junit/openshift-server-mock/pom.xml +++ b/junit/openshift-server-mock/pom.xml @@ -44,6 +44,13 @@ assertj-core test + + + junit + junit + provided + + org.junit.jupiter junit-jupiter-api diff --git a/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServer.java b/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServer.java index 454137c78f2..3f31342618a 100644 --- a/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServer.java +++ b/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServer.java @@ -17,12 +17,12 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.mockwebserver.Context; +import io.fabric8.mockwebserver.MockWebServer; import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; +import io.fabric8.mockwebserver.http.Dispatcher; import io.fabric8.openshift.client.NamespacedOpenShiftClient; import io.fabric8.openshift.client.OpenShiftConfig; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; import java.util.Map; import java.util.Queue; diff --git a/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServerExtension.java b/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServerExtension.java index 7cb0a6eba84..dd775f655a6 100644 --- a/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServerExtension.java +++ b/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftMockServerExtension.java @@ -18,11 +18,11 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; import io.fabric8.mockwebserver.Context; +import io.fabric8.mockwebserver.MockWebServer; import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; import io.fabric8.openshift.client.NamespacedOpenShiftClient; import io.fabric8.openshift.client.OpenShiftClient; -import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.extension.ExtensionContext; import java.lang.reflect.Field; @@ -58,11 +58,6 @@ protected void destroy() { } } - @Override - protected Class getClientType() { - return OpenShiftClient.class; - } - @Override protected Class getKubernetesMockServerType() { return OpenShiftMockServer.class; @@ -100,7 +95,7 @@ protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, openShiftClient = instantOpenShiftClient; openShiftMockServer = instantOpenShiftMockServer; } - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, openShiftClient)); + setFieldIfEqualsToProvidedType(context, isStatic, field, OpenShiftClient.class, (i, f) -> f.set(i, openShiftClient)); setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, openShiftMockServer)); } diff --git a/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java b/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java index b670b7c51c9..c2a1bdd1d35 100644 --- a/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java +++ b/junit/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java @@ -18,12 +18,12 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; import io.fabric8.mockwebserver.Context; +import io.fabric8.mockwebserver.MockWebServer; import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; import io.fabric8.mockwebserver.dsl.MockServerExpectation; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.openshift.client.NamespacedOpenShiftClient; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; import org.junit.rules.ExternalResource; import java.util.HashMap; diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyHttpsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyHttpsTest.java index fe7b8c059f7..2c21a9ff2a1 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyHttpsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyHttpsTest.java @@ -15,22 +15,20 @@ */ package io.fabric8.kubernetes.client.http; +import io.fabric8.kubernetes.client.RequestConfigBuilder; import io.fabric8.kubernetes.client.internal.SSLUtils; 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.fabric8.mockwebserver.dsl.HttpMethod; +import io.fabric8.mockwebserver.http.Headers; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.internal.MockDispatcher; -import io.fabric8.mockwebserver.internal.MockSSLContextFactory; import io.fabric8.mockwebserver.internal.SimpleRequest; import io.fabric8.mockwebserver.internal.SimpleResponse; import io.fabric8.mockwebserver.utils.ResponseProvider; -import okhttp3.Headers; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import okhttp3.mockwebserver.SocketPolicy; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -49,42 +47,32 @@ public abstract class AbstractHttpClientProxyHttpsTest { - private static SocketPolicy defaultResponseSocketPolicy; private static Map> responses; - private static DefaultMockServer server; + private static DefaultMockServer proxyServer; @BeforeAll static void beforeAll() { - defaultResponseSocketPolicy = SocketPolicy.KEEP_OPEN; responses = new HashMap<>(); - final MockWebServer okHttpMockWebServer = new MockWebServer(); - final MockDispatcher dispatcher = new MockDispatcher(responses) { - @Override - public MockResponse peek() { - return new MockResponse().setSocketPolicy(defaultResponseSocketPolicy); - } - }; - server = new DefaultMockServer(new Context(), okHttpMockWebServer, responses, dispatcher, true); - server.start(); - okHttpMockWebServer.useHttps(MockSSLContextFactory.create().getSocketFactory(), true); + proxyServer = new DefaultMockServer(new Context(), new MockWebServer(), responses, new MockDispatcher(responses), false); + proxyServer.start(); } @AfterAll static void afterAll() { - server.shutdown(); + proxyServer.shutdown(); } protected abstract HttpClient.Factory getHttpClientFactory(); @Test - @DisplayName("Proxied HttpClient adds required headers to the request") + @DisplayName("Proxied HttpClient with basic authorization adds required headers to the request") protected void proxyConfigurationAddsRequiredHeadersForHttps() throws Exception { final AtomicReference initialConnectRequest = new AtomicReference<>(); final ResponseProvider bodyProvider = new ResponseProvider() { @Override public String getBody(RecordedRequest request) { - return ""; + return "\n"; } @Override @@ -93,7 +81,6 @@ public void setHeaders(Headers headers) { @Override public int getStatusCode(RecordedRequest request) { - defaultResponseSocketPolicy = SocketPolicy.UPGRADE_TO_SSL_AT_END; // for jetty to upgrade after the challenge if (request.getHeader(StandardHttpHeaders.PROXY_AUTHORIZATION) != null) { initialConnectRequest.compareAndSet(null, request); return 200; @@ -107,20 +94,20 @@ public Headers getHeaders() { } }; - responses.computeIfAbsent(new SimpleRequest(HttpMethod.CONNECT, "/"), k -> new ArrayDeque<>()) + responses.computeIfAbsent(new SimpleRequest(HttpMethod.CONNECT, "example.com:443"), k -> new ArrayDeque<>()) .add(new SimpleResponse(true, bodyProvider, null, 0, TimeUnit.SECONDS)); // Given final HttpClient.Builder builder = getHttpClientFactory().newBuilder() .sslContext(null, SSLUtils.trustManagers(null, null, true, null, null)) - .proxyAddress(new InetSocketAddress("localhost", server.getPort())) + .proxyAddress(new InetSocketAddress("localhost", proxyServer.getPort())) .proxyAuthorization(basicCredentials("auth", "cred")); + builder.tag(new RequestConfigBuilder().withRequestRetryBackoffInterval(1).build()); try (HttpClient client = builder.build()) { - // When - client.sendAsync(client.newHttpRequestBuilder() - .uri(String.format("https://0.0.0.0:%s/not-found", server.getPort() + 1)).build(), String.class) + // When (just send and ignore response, we only care about the CONNECT request headers) + client.sendAsync(client.newHttpRequestBuilder().uri("https://example.com/proxied").build(), String.class) + .exceptionally(t -> null) .get(30, TimeUnit.SECONDS); - - // if it fails, then authorization was not set + // Then assertThat(initialConnectRequest) .doesNotHaveNullValue() .hasValueMatching(r -> r.getHeader("Proxy-Authorization").equals("Basic YXV0aDpjcmVk")); diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyTest.java index c04397ad8aa..92e6878c95b 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpClientProxyTest.java @@ -16,9 +16,9 @@ package io.fabric8.kubernetes.client.http; import io.fabric8.mockwebserver.DefaultMockServer; +import io.fabric8.mockwebserver.http.Headers; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.utils.ResponseProvider; -import okhttp3.Headers; -import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -30,19 +30,20 @@ import static io.fabric8.kubernetes.client.utils.HttpClientUtils.basicCredentials; import static org.assertj.core.api.Assertions.assertThat; +@SuppressWarnings("HttpUrlsUsage") public abstract class AbstractHttpClientProxyTest { - private static DefaultMockServer server; + private static DefaultMockServer proxyServer; @BeforeAll static void beforeAll() { - server = new DefaultMockServer(false); - server.start(); + proxyServer = new DefaultMockServer(false); + proxyServer.start(); } @AfterAll static void afterAll() { - server.shutdown(); + proxyServer.shutdown(); } protected abstract HttpClient.Factory getHttpClientFactory(); @@ -50,7 +51,7 @@ static void afterAll() { @Test @DisplayName("Proxied HttpClient with basic authorization adds required headers to the request") protected void proxyConfigurationBasicAuthAddsRequiredHeaders() throws Exception { - server.expect().get().withPath("/").andReply(new ResponseProvider() { + proxyServer.expect().get().withPath("http://example.com/proxied").andReply(new ResponseProvider() { @Override public String getBody(RecordedRequest request) { @@ -74,17 +75,16 @@ public Headers getHeaders() { }).always(); // Given final HttpClient.Builder builder = getHttpClientFactory().newBuilder() - .proxyAddress(new InetSocketAddress("localhost", server.getPort())) + .proxyAddress(new InetSocketAddress("localhost", proxyServer.getPort())) .proxyAuthorization(basicCredentials("auth", "cred")); try (HttpClient client = builder.build()) { // When - client.sendAsync(client.newHttpRequestBuilder() - .uri(String.format("http://0.0.0.0:%s/not-found", server.getPort())).build(), String.class) + client.sendAsync(client.newHttpRequestBuilder().uri("http://example.com/proxied").build(), String.class) .get(10L, TimeUnit.SECONDS); // Then - assertThat(server.getLastRequest()) + assertThat(proxyServer.getLastRequest()) .extracting(RecordedRequest::getHeaders) - .returns("0.0.0.0:" + server.getPort(), h -> h.get("Host")) + .returns("example.com", h -> h.get("Host")) .returns("Basic YXV0aDpjcmVk", h -> h.get("Proxy-Authorization")); } } @@ -94,17 +94,16 @@ public Headers getHeaders() { protected void proxyConfigurationOtherAuthAddsRequiredHeaders() throws Exception { // Given final HttpClient.Builder builder = getHttpClientFactory().newBuilder() - .proxyAddress(new InetSocketAddress("localhost", server.getPort())) + .proxyAddress(new InetSocketAddress("localhost", proxyServer.getPort())) .proxyAuthorization("Other kind of auth"); try (HttpClient client = builder.build()) { // When - client.sendAsync(client.newHttpRequestBuilder() - .uri(String.format("http://0.0.0.0:%s/not-found", server.getPort())).build(), String.class) + client.sendAsync(client.newHttpRequestBuilder().uri("http://example.com/proxied").build(), String.class) .get(10L, TimeUnit.SECONDS); // Then - assertThat(server.getLastRequest()) + assertThat(proxyServer.getLastRequest()) .extracting(RecordedRequest::getHeaders) - .returns("0.0.0.0:" + server.getPort(), h -> h.get("Host")) + .returns("example.com", h -> h.get("Host")) .returns("Other kind of auth", h -> h.get("Proxy-Authorization")); } } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java index e95d3004e1f..6cdd5b33604 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java @@ -17,14 +17,14 @@ 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.fabric8.mockwebserver.http.Buffer; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.internal.SimpleRequest; import io.fabric8.mockwebserver.utils.ResponseProviders; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import okio.Buffer; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPostTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPostTest.java index 47a406f0314..50866bc85ce 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPostTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPostTest.java @@ -16,7 +16,7 @@ package io.fabric8.kubernetes.client.http; import io.fabric8.mockwebserver.DefaultMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java index e24dc11a4ca..9bcbae71877 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java @@ -16,7 +16,7 @@ package io.fabric8.kubernetes.client.http; import io.fabric8.mockwebserver.DefaultMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractSimultaneousConnectionsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractSimultaneousConnectionsTest.java index 6b940fa4a63..06d3cb71854 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractSimultaneousConnectionsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractSimultaneousConnectionsTest.java @@ -18,11 +18,13 @@ import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; -import okhttp3.Protocol; -import okhttp3.Response; -import okhttp3.WebSocketListener; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; +import io.fabric8.mockwebserver.MockWebServer; +import io.fabric8.mockwebserver.MockWebServerListener; +import io.fabric8.mockwebserver.http.MockResponse; +import io.fabric8.mockwebserver.http.RecordedHttpConnection; +import io.fabric8.mockwebserver.http.Response; +import io.fabric8.mockwebserver.http.WebSocketListener; +import io.fabric8.mockwebserver.vertx.Protocol; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -30,17 +32,11 @@ import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; -import java.io.Closeable; import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; import java.net.URI; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -51,8 +47,6 @@ import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; -import javax.net.ServerSocketFactory; - import static org.assertj.core.api.Assertions.assertThat; public abstract class AbstractSimultaneousConnectionsTest { @@ -63,7 +57,7 @@ public abstract class AbstractSimultaneousConnectionsTest { private static final int MAX_HTTP_1_CONNECTIONS = 2048; // Should be able to at least make 2048 private static final int MAX_HTTP_1_WS_CONNECTIONS = 1024; // Should be able to at least make 1024 - private RegisteredServerSocketFactory serverSocketFactory; + private RegisteredConnections registeredConnections; private MockWebServer mockWebServer; private ExecutorService httpExecutor; private HttpServer httpServer; @@ -72,9 +66,9 @@ public abstract class AbstractSimultaneousConnectionsTest { @BeforeEach void prepareServerAndBuilder() throws IOException { - serverSocketFactory = new RegisteredServerSocketFactory(); + registeredConnections = new RegisteredConnections(); mockWebServer = new MockWebServer(); - mockWebServer.setServerSocketFactory(serverSocketFactory); + mockWebServer.addListener(registeredConnections); httpExecutor = Executors.newCachedThreadPool(); httpServer = HttpServer.create(new InetSocketAddress(0), 0); httpServer.setExecutor(httpExecutor); @@ -84,8 +78,7 @@ void prepareServerAndBuilder() throws IOException { } @AfterEach - void stopServer() throws IOException { - serverSocketFactory.close(); + void stopServer() { mockWebServer.shutdown(); httpServer.stop(0); httpExecutor.shutdownNow(); @@ -93,7 +86,7 @@ void stopServer() throws IOException { protected abstract HttpClient.Factory getHttpClientFactory(); - private void withHttp1() throws IOException { + private void withHttp1() { mockWebServer.setProtocols(Collections.singletonList(Protocol.HTTP_1_1)); mockWebServer.start(); } @@ -150,17 +143,18 @@ public void http1WebSocketConnectionsBeforeUpgrade() throws Exception { @DisabledOnOs(OS.WINDOWS) public void http1WebSocketConnections() throws Exception { withHttp1(); - final Collection serverSockets = ConcurrentHashMap.newKeySet(); + final Collection serverSockets = ConcurrentHashMap.newKeySet(); final Collection clientSockets = ConcurrentHashMap.newKeySet(); final CyclicBarrier cyclicBarrier = new CyclicBarrier(2); final CountDownLatch latch = new CountDownLatch(MAX_HTTP_1_WS_CONNECTIONS); final MockResponse response = new MockResponse() .withWebSocketUpgrade(new WebSocketListener() { @Override - public void onOpen(okhttp3.WebSocket webSocket, Response response) { + public void onOpen(io.fabric8.mockwebserver.http.WebSocket webSocket, Response response) { try { cyclicBarrier.await(1, TimeUnit.SECONDS); } catch (Exception ignore) { + // Ignored } serverSockets.add(webSocket); webSocket.send("go on"); @@ -185,11 +179,11 @@ public void onMessage(WebSocket webSocket, String text) { assertThat(latch.await(60L, TimeUnit.SECONDS)).isTrue(); assertThat(serverSockets.size()) .isEqualTo(MAX_HTTP_1_WS_CONNECTIONS) - .isLessThanOrEqualTo((int) serverSocketFactory.activeConnections()); + .isLessThanOrEqualTo(registeredConnections.activeConnections()); // assertThat(clientSockets) // .hasSize(MAX_HTTP_1_WS_CONNECTIONS); } finally { - for (okhttp3.WebSocket socket : serverSockets) { + for (io.fabric8.mockwebserver.http.WebSocket socket : serverSockets) { socket.close(1000, "done"); } } @@ -222,7 +216,7 @@ private DelayedResponseHandler(int requestCount, HttpHandler handler) { } @Override - public void handle(HttpExchange exchange) throws IOException { + public void handle(HttpExchange exchange) { exchanges.add(exchange); await(); if (exchanges.size() == requestCount) { @@ -237,54 +231,26 @@ public final void await() { } catch (Exception ex) { throw new RuntimeException("Failed to await the barrier"); } - ; } } - private static class RegisteredServerSocketFactory extends ServerSocketFactory implements Closeable { - - private final Set connections = new HashSet<>(); + private static class RegisteredConnections implements MockWebServerListener { - final long activeConnections() { - return connections.stream().filter(Socket::isConnected).filter(s -> !s.isClosed()).count(); - } + private final Set connections = ConcurrentHashMap.newKeySet(); - @Override - public final void close() { - for (Socket socket : connections) { - try { - socket.close(); - } catch (IOException ignored) { - // ignored - } - } - } - - @Override - public ServerSocket createServerSocket() throws IOException { - return new ServerSocket() { - @Override - public Socket accept() throws IOException { - final Socket socket = super.accept(); - connections.add(socket); - return socket; - } - }; - } - - @Override - public ServerSocket createServerSocket(int port) throws IOException { - throw new SocketException("not implemented"); + final int activeConnections() { + return connections.size(); } @Override - public ServerSocket createServerSocket(int port, int backlog) throws IOException { - throw new SocketException("not implemented"); + public void onConnection(RecordedHttpConnection connection) { + connections.add(connection); + MockWebServerListener.super.onConnection(connection); } @Override - public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException { - throw new SocketException("not implemented"); + public void onConnectionClosed(RecordedHttpConnection connection) { + connections.remove(connection); } } } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java index e296f287ead..06e00cda1ef 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java @@ -40,9 +40,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; class CertUtilsTest { diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java index 6e6b4b69964..6d2aad04ac4 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java @@ -32,7 +32,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceTest.java index 4bb7cdd7e30..5e914c7ba8f 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceTest.java @@ -37,7 +37,7 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.Utils; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -385,6 +385,7 @@ public void eventReceived(Action action, GenericKubernetesResource resource) { @Override public void onClose(WatcherException cause) { + // NO OP } }); @@ -416,6 +417,7 @@ public void eventReceived(Action action, GenericKubernetesResource resource) { @Override public void onClose(WatcherException cause) { + // NO OP } }); @@ -450,6 +452,7 @@ public void eventReceived(Action action, GenericKubernetesResource resource) { @Override public void onClose(WatcherException cause) { + // NO OP } }); @@ -483,6 +486,7 @@ public void eventReceived(Action action, GenericKubernetesResource resource) { @Override public void onClose(WatcherException cause) { + // NO OP } }); @@ -520,6 +524,7 @@ public void eventReceived(Action action, GenericKubernetesResource resource) { @Override public void onClose(WatcherException cause) { + // NO OP } }); @@ -557,6 +562,7 @@ public void eventReceived(Action action, GenericKubernetesResource resource) { @Override public void onClose(WatcherException cause) { + // NO OP } }); @@ -567,7 +573,7 @@ public void onClose(WatcherException cause) { @Test @DisplayName("Should be able to test watch with Namespace and ListOptions provided") - void testWatchWithNamespaceAndListOptions() throws IOException, InterruptedException { + void testWatchWithNamespaceAndListOptions() throws InterruptedException { // Given server.expect().withPath( "/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos?allowWatchBookmarks=true&resourceVersion=1003&timeoutSeconds=30&watch=true") @@ -594,6 +600,7 @@ public void eventReceived(Action action, GenericKubernetesResource resource) { @Override public void onClose(WatcherException cause) { + // NO OP } }); diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java index c5bc30acc07..c2fc47e1fd5 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java @@ -38,7 +38,7 @@ import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Utils; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/MixedCrudTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/MixedCrudTest.java index dedec302736..815c569f90b 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/MixedCrudTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/MixedCrudTest.java @@ -24,11 +24,10 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.mockwebserver.Context; +import io.fabric8.mockwebserver.MockWebServer; import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -45,10 +44,6 @@ class MixedCrudTest { private KubernetesMockServer server; private KubernetesClient client; - @BeforeAll - static void beforeAll() { - } - @BeforeEach void setUp() { final Map> responses = new HashMap<>(); diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodCrudTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodCrudTest.java index d8e03086a59..a4451109dfa 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodCrudTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodCrudTest.java @@ -26,7 +26,6 @@ import io.fabric8.kubernetes.client.WatcherException; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import junit.framework.AssertionFailedError; import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; @@ -34,6 +33,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -289,7 +289,7 @@ public void eventReceived(Action action, Pod resource) { addLatch.countDown(); break; default: - throw new AssertionFailedError(action.toString().concat(" isn't recognised.")); + throw assertionFailure().message(action.toString().concat(" isn't recognised.")).build(); } } diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PropagationPolicyTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PropagationPolicyTest.java index 1e8ed43c7ce..5edd83db5db 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PropagationPolicyTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PropagationPolicyTest.java @@ -37,7 +37,7 @@ import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Utils; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/RequestConfigTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/RequestConfigTest.java index 5b762884808..563c5175e95 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/RequestConfigTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/RequestConfigTest.java @@ -21,7 +21,7 @@ import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceListTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceListTest.java index 3ef8f175765..68628f2ccce 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceListTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceListTest.java @@ -37,7 +37,7 @@ import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceTest.java index bbb3a7ef307..f069a1f8bbf 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ResourceTest.java @@ -39,7 +39,7 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.Utils; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -285,7 +285,7 @@ public void eventReceived(Action action, Pod resource) { @Override public void onClose(WatcherException cause) { - + // NO OP } }); assertTrue(latch.await(5000, MILLISECONDS)); @@ -293,7 +293,7 @@ public void onClose(WatcherException cause) { } @Test - void testWaitUntilReady() throws InterruptedException { + void testWaitUntilReady() { Pod pod1 = new PodBuilder().withNewMetadata() .withName("pod1") .withResourceVersion("1") diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ServiceTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ServiceTest.java index a96e14c7d9d..5fb64b931d4 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ServiceTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ServiceTest.java @@ -31,7 +31,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,9 +39,9 @@ import java.util.Collections; import java.util.concurrent.TimeUnit; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @EnableKubernetesMockClient class ServiceTest { diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java index 65704494d86..7f5b0c4d4fa 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java @@ -34,7 +34,7 @@ import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Utils; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedClusterScopeCustomResourceApiTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedClusterScopeCustomResourceApiTest.java index 6a26d24ae8f..b1f1cdf9363 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedClusterScopeCustomResourceApiTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedClusterScopeCustomResourceApiTest.java @@ -27,7 +27,7 @@ import io.fabric8.kubernetes.client.mock.crd.StarStatus; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.Test; import java.net.HttpURLConnection; diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedCustomResourceApiTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedCustomResourceApiTest.java index addfaeb4b5d..cb2717f5c47 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedCustomResourceApiTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/TypedCustomResourceApiTest.java @@ -27,7 +27,7 @@ import io.fabric8.kubernetes.client.mock.crd.PodSetStatus; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import okhttp3.mockwebserver.RecordedRequest; +import io.fabric8.mockwebserver.http.RecordedRequest; import org.junit.jupiter.api.Test; import java.net.HttpURLConnection; diff --git a/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/AdaptTest.java b/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/AdaptTest.java index d89746c7137..77de954ba0f 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/AdaptTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/AdaptTest.java @@ -20,10 +20,10 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; +import io.fabric8.mockwebserver.http.Headers; +import io.fabric8.mockwebserver.http.RecordedRequest; import io.fabric8.mockwebserver.utils.ResponseProvider; import io.fabric8.openshift.client.OpenShiftClient; -import okhttp3.Headers; -import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.Test; import java.net.HttpURLConnection; @@ -64,7 +64,7 @@ void testCheckIfAvailableAPIGroupsContainOpenShiftOpenShift4() { .andReturn(HttpURLConnection.HTTP_OK, "{\"authorization_endpoint\":\"" + authorizationEndpoint + "\"}") .once(); server.expect().get().withPath("/oauth/authorize?response_type=token&client_id=openshift-challenging-client") - .andReply(new ResponseProvider() { + .andReply(new ResponseProvider<>() { @Override public Object getBody(RecordedRequest recordedRequest) { return null; @@ -85,6 +85,7 @@ public Headers getHeaders() { @Override public void setHeaders(Headers headers) { + // NO OP } }).once(); server.expect().withPath("/apis").andReturn(HttpURLConnection.HTTP_OK, new APIGroupListBuilder() diff --git a/log4j/src/test/java/io/fabric8/kubernetes/log4j/lookup/KubernetesLookupTest.java b/log4j/src/test/java/io/fabric8/kubernetes/log4j/lookup/KubernetesLookupTest.java index 0e734fa4108..6b4a816ec98 100644 --- a/log4j/src/test/java/io/fabric8/kubernetes/log4j/lookup/KubernetesLookupTest.java +++ b/log4j/src/test/java/io/fabric8/kubernetes/log4j/lookup/KubernetesLookupTest.java @@ -173,6 +173,7 @@ void containers_smoke_test(String containerName) throws Exception { @Test void initialize_works_with_mock_client() { + KubernetesLookup.clear(); final Pod pod = mockClient.pods().resource(createPod()).create(); final Namespace namespace = mockClient.namespaces().resource(createNamespace()).create(); final StrLookup lookup = new KubernetesLookup() { diff --git a/pom.xml b/pom.xml index 91955815c11..6acea8a0eb4 100644 --- a/pom.xml +++ b/pom.xml @@ -108,6 +108,7 @@ 4.0.23 + 4.13.2 5.11.2 3.26.3 4.2.2 @@ -761,11 +762,6 @@ okhttp ${okhttp.version} - - com.squareup.okhttp3 - mockwebserver - ${okhttp.version} - org.apache.commons commons-compress @@ -909,6 +905,12 @@ test + + junit + junit + ${junit4.version} + test + org.junit.jupiter junit-jupiter-api