Skip to content
Permalink
Browse files
JCLOUDS-1551: Update version of OkHttp 3.14.9
  • Loading branch information
korlov42 authored and gaul committed Feb 12, 2021
1 parent 56ad552 commit 44ff69d144ff4fa0fa980cfba0d2c14fd9175f85
Showing 130 changed files with 1,127 additions and 889 deletions.
@@ -104,7 +104,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>
@@ -115,6 +115,18 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<scope>test</scope>
<exclusions>
<!-- Already provided by jclouds-sshj -->
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-depchain</artifactId>
@@ -21,16 +21,18 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import okhttp3.TlsVersion;

import org.jclouds.docker.suppliers.DockerSSLContextSupplier;
import org.jclouds.domain.Credentials;
import org.jclouds.http.okhttp.OkHttpClientSupplier;
import org.jclouds.location.Provider;

import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.squareup.okhttp.ConnectionSpec;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.TlsVersion;


@Singleton
public class DockerOkHttpClientSupplier implements OkHttpClientSupplier {
@@ -46,18 +48,18 @@ public class DockerOkHttpClientSupplier implements OkHttpClientSupplier {

@Override
public OkHttpClient get() {
OkHttpClient client = new OkHttpClient();
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
ConnectionSpec tlsSpec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_0, TlsVersion.TLS_1_1, TlsVersion.TLS_1_2)
.build();
ConnectionSpec cleartextSpec = new ConnectionSpec.Builder(ConnectionSpec.CLEARTEXT)
.build();
client.setConnectionSpecs(ImmutableList.of(tlsSpec, cleartextSpec));
clientBuilder.connectionSpecs(ImmutableList.of(tlsSpec, cleartextSpec));
// check if identity and credential are files, to set up sslContext
if (new File(creds.get().identity).isFile() && new File(creds.get().credential).isFile()) {
client.setSslSocketFactory(dockerSSLContextSupplier.get().getSocketFactory());
clientBuilder.sslSocketFactory(dockerSSLContextSupplier.get().getSocketFactory());
}
return client;
return clientBuilder.build();
}

}
@@ -20,6 +20,9 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;

import org.jclouds.docker.DockerApi;
import org.jclouds.docker.config.DockerParserModule;
import org.jclouds.docker.domain.Config;
@@ -32,8 +35,7 @@
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableList;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;


/**
* Mock tests for the {@link org.jclouds.docker.features.ContainerApi} class.
@@ -43,7 +45,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest {

public void testListContainers() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/containers.json")));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
assertEquals(api.listContainers(), new ContainersParseTest().expected());
assertSent(server, "GET", "/containers/json");
@@ -54,7 +56,7 @@ public void testListContainers() throws Exception {

public void testListNonexistentContainers() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
assertEquals(api.listContainers(), ImmutableList.of());
assertSent(server, "GET", "/containers/json");
@@ -66,7 +68,7 @@ public void testListNonexistentContainers() throws Exception {
@Test(timeOut = 10000L)
public void testListAllContainers() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/containers.json")));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
assertEquals(api.listContainers(ListContainerOptions.Builder.all(true)), new ContainersParseTest().expected());
assertSent(server, "GET", "/containers/json?all=true");
@@ -77,7 +79,7 @@ public void testListAllContainers() throws Exception {

public void testGetContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container.json")));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getContainerApi();
String containerId = "e475abdf3e139a5e1e158b38b6cb290a1bec856d39d5a951f015dfb8fcba7331";
try {
assertEquals(api.inspectContainer(containerId), new ContainerParseTest().expected());
@@ -89,7 +91,7 @@ public void testGetContainer() throws Exception {

public void testCreateContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container-creation.json")));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
Config containerConfig = Config.builder()
.cmd(ImmutableList.of("date"))
.attachStdin(false)
@@ -110,7 +112,7 @@ public void testCreateContainer() throws Exception {

public void testRemoveContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
String containerId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9";

try {
@@ -124,7 +126,7 @@ public void testRemoveContainer() throws Exception {

public void testStartContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.startContainer("1");
assertSent(server, "POST", "/containers/1/start");
@@ -135,7 +137,7 @@ public void testStartContainer() throws Exception {

public void testStopContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.stopContainer("1");
assertSent(server, "POST", "/containers/1/stop");
@@ -147,7 +149,7 @@ public void testStopContainer() throws Exception {

public void testCommitContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(201));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.commit();
assertSent(server, "POST", "/commit");
@@ -158,7 +160,7 @@ public void testCommitContainer() throws Exception {

public void testPauseContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.pause("1");
assertSent(server, "POST", "/containers/1/pause");
@@ -169,7 +171,7 @@ public void testPauseContainer() throws Exception {

public void testUnpauseContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.unpause("1");
assertSent(server, "POST", "/containers/1/unpause");
@@ -180,7 +182,7 @@ public void testUnpauseContainer() throws Exception {

public void testAttachContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.attach("1");
assertSent(server, "POST", "/containers/1/attach");
@@ -191,7 +193,7 @@ public void testAttachContainer() throws Exception {

public void testWaitContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.wait("1");
assertSent(server, "POST", "/containers/1/wait");
@@ -202,7 +204,7 @@ public void testWaitContainer() throws Exception {

public void testRestartContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.restart("1");
assertSent(server, "POST", "/containers/1/restart");
@@ -213,7 +215,7 @@ public void testRestartContainer() throws Exception {

public void testKillContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.kill("1");
assertSent(server, "POST", "/containers/1/kill");
@@ -224,7 +226,7 @@ public void testKillContainer() throws Exception {

public void testCopyFileFromContainer() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi();
ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi();
try {
api.copy("1", Resource.create("test"));
assertSent(server, "POST", "/containers/1/copy");
@@ -22,6 +22,9 @@

import java.util.List;

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;

import org.jclouds.docker.DockerApi;
import org.jclouds.docker.config.DockerParserModule;
import org.jclouds.docker.domain.ImageHistory;
@@ -33,8 +36,7 @@
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableList;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;


/**
* Mock tests for the {@link org.jclouds.docker.features.ImageApi} class.
@@ -44,7 +46,7 @@ public class ImageApiMockTest extends BaseDockerMockTest {

public void testCreateImage() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200));
ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi();
ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi();
try {
api.createImage(CreateImageOptions.Builder.fromImage("base"));
assertSent(server, "POST", "/images/create?fromImage=base");
@@ -55,7 +57,7 @@ public void testCreateImage() throws Exception {

public void testGetImage() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/image.json")));
ImageApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getImageApi();
ImageApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getImageApi();
try {
String imageId = "cbba6639a342646deed70d7ea6162fa2a0acea9300f911f4e014555fe37d3456";
assertEquals(api.inspectImage(imageId), new ImageParseTest().expected());
@@ -67,7 +69,7 @@ public void testGetImage() throws Exception {

public void testListImages() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/images.json")));
ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi();
ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi();
try {
assertEquals(api.listImages(), new ImagesParseTest().expected());
assertSent(server, "GET", "/images/json");
@@ -78,7 +80,7 @@ public void testListImages() throws Exception {

public void testTagImage() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(201));
ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi();
ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi();
try {
api.tagImage("633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6", "jclouds", "testTag", true);
assertSent(server, "POST",
@@ -90,7 +92,7 @@ public void testTagImage() throws Exception {

public void testDeleteImage() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi();
ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi();
try {
api.deleteImage("1");
assertSent(server, "DELETE", "/images/1");
@@ -105,7 +107,7 @@ public void testGetHistory() throws Exception {
new MockResponse().setBody(payloadFromResource("/history.json")),
new MockResponse().setBody(payloadFromResource("/history-apiver22.json")),
new MockResponse().setResponseCode(404));
ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi();
ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi();
try {
assertEquals(api.getHistory("ubuntu"), new HistoryParseTest().expected());
assertSent(server, "GET", "/images/ubuntu/history");

0 comments on commit 44ff69d

Please sign in to comment.