use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class UpdateCheckerTest method testPerformUpdateCheck_failSilently.
@Test
public void testPerformUpdateCheck_failSilently() throws InterruptedException, GeneralSecurityException, URISyntaxException, IOException {
String response = "HTTP/1.1 400 Bad Request\nContent-Length: 0\n\n";
try (TestWebServer badServer = new TestWebServer(false, Collections.singletonList(response), 1)) {
Optional<String> message = UpdateChecker.performUpdateCheck(configDir, "1.0.2", badServer.getEndpoint(), "tool-name", logEvent -> {
assertThat(logEvent.getLevel()).isEqualTo(LogEvent.Level.DEBUG);
assertThat(logEvent.getMessage()).contains("Update check failed; ");
});
assertThat(message).isEmpty();
}
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class UpdateCheckerTest method setUp.
@Before
public void setUp() throws InterruptedException, GeneralSecurityException, URISyntaxException, IOException {
String response = "HTTP/1.1 200 OK\nContent-Length:18\n\n{\"latest\":\"2.0.0\"}";
testWebServer = new TestWebServer(false, Collections.singletonList(response), 1);
configDir = temporaryFolder.getRoot().toPath();
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class RegistryClientTest method testAuthPullByWwwAuthenticate_basicAuthRequestedButNullCredential.
@Test
public void testAuthPullByWwwAuthenticate_basicAuthRequestedButNullCredential() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryException {
String blobResponse = "HTTP/1.1 200 OK\nContent-Length: 5678\n\n";
registry = new TestWebServer(false, Arrays.asList(blobResponse), 1);
RegistryClient registryClient = createRegistryClient(null);
registryClient.authPullByWwwAuthenticate("Basic foo");
Optional<BlobDescriptor> digestAndSize = registryClient.checkBlob(digest);
Assert.assertEquals(5678, digestAndSize.get().getSize());
MatcherAssert.assertThat(registry.getInputRead(), CoreMatchers.not(CoreMatchers.containsString("Authorization:")));
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class RegistryClientTest method testPullManifest_manifestList.
@Test
public void testPullManifest_manifestList() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryException {
String manifestResponse = "HTTP/1.1 200 OK\nContent-Length: 403\n\n{\n" + " \"schemaVersion\": 2,\n" + " \"mediaType\": \"application/vnd.docker.distribution.manifest.list.v2+json\",\n" + " \"manifests\": [\n" + " {\n" + " \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + " \"size\": 7143,\n" + " \"digest\": \"sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f\",\n" + " \"platform\": {\n" + " \"architecture\": \"amd64\",\n" + " \"os\": \"linux\"\n" + " }\n" + " }\n" + " ]\n" + "}";
registry = new TestWebServer(false, Arrays.asList(manifestResponse), 1);
RegistryClient registryClient = createRegistryClient(null);
ManifestAndDigest<?> manifestAndDigest = registryClient.pullManifest("image-tag");
Assert.assertEquals("sha256:a340fa38667f765f8cfd79d4bc684ec8a6f48cdd63abfe36e109f4125ee38488", manifestAndDigest.getDigest().toString());
Assert.assertTrue(manifestAndDigest.getManifest() instanceof V22ManifestListTemplate);
V22ManifestListTemplate manifestList = (V22ManifestListTemplate) manifestAndDigest.getManifest();
Assert.assertEquals(2, manifestList.getSchemaVersion());
Assert.assertEquals(Arrays.asList("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f"), manifestList.getDigestsForPlatform("amd64", "linux"));
MatcherAssert.assertThat(registry.getInputRead(), CoreMatchers.containsString("GET /v2/foo/bar/manifests/image-tag "));
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class RegistryClientTest method testDoBearerAuth_returnsFalseOnBasicAuth.
@Test
public void testDoBearerAuth_returnsFalseOnBasicAuth() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryException {
String basicAuth = "HTTP/1.1 401 Unauthorized\nContent-Length: 0\nWWW-Authenticate: Basic foo\n\n";
registry = new TestWebServer(false, Arrays.asList(basicAuth), 1);
RegistryClient registryClient = createRegistryClient(null);
Assert.assertFalse(registryClient.doPullBearerAuth());
Mockito.verify(eventHandlers).dispatch(logContains("attempting bearer auth"));
Mockito.verify(eventHandlers).dispatch(logContains("server requires basic auth"));
}
Aggregations