use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class RegistryAuthenticatorTest method testUserAgent.
@Test
public void testUserAgent() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryCredentialsNotSentException {
try (TestWebServer server = new TestWebServer(false)) {
try {
RegistryAuthenticator authenticator = RegistryAuthenticator.fromAuthenticationMethod("Bearer realm=\"" + server.getEndpoint() + "\"", registryEndpointRequestProperties, "Competent-Agent", new FailoverHttpClient(true, false, ignored -> {
})).get();
authenticator.authenticatePush(null);
} catch (RegistryAuthenticationFailedException ex) {
// Doesn't matter if auth fails. We only examine what we sent.
}
MatcherAssert.assertThat(server.getInputRead(), CoreMatchers.containsString("User-Agent: Competent-Agent"));
}
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class RegistryClientTest method testAuthPullByWwwAuthenticate_bearerAuth.
@Test
public void testAuthPullByWwwAuthenticate_bearerAuth() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryException {
String tokenResponse = "HTTP/1.1 200 OK\nContent-Length: 26\n\n{\"token\":\"awesome-token!\"}";
authServer = new TestWebServer(false, Arrays.asList(tokenResponse), 1);
String blobResponse = "HTTP/1.1 200 OK\nContent-Length: 5678\n\n";
registry = new TestWebServer(false, Arrays.asList(blobResponse), 1);
RegistryClient registryClient = createRegistryClient(Credential.from("user", "pass"));
registryClient.authPullByWwwAuthenticate("Bearer realm=\"" + authServer.getEndpoint() + "\"");
Optional<BlobDescriptor> digestAndSize = registryClient.checkBlob(digest);
Assert.assertEquals(5678, digestAndSize.get().getSize());
Mockito.verify(eventHandlers).dispatch(logContains("bearer auth succeeded"));
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class RegistryClientTest method testConfigureBasicAuth.
@Test
public void testConfigureBasicAuth() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryException {
String basicAuth = "HTTP/1.1 200 OK\nContent-Length: 56789\n\n";
registry = new TestWebServer(false, Arrays.asList(basicAuth), 1);
RegistryClient registryClient = createRegistryClient(Credential.from("user", "pass"));
registryClient.configureBasicAuth();
Optional<BlobDescriptor> digestAndSize = registryClient.checkBlob(digest);
Assert.assertEquals(56789, digestAndSize.get().getSize());
MatcherAssert.assertThat(registry.getInputRead(), CoreMatchers.containsString("Authorization: Basic dXNlcjpwYXNz"));
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class RegistryClientTest method testAuthPullByWwwAuthenticate_basicAuth.
@Test
public void testAuthPullByWwwAuthenticate_basicAuth() 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(Credential.from("user", "pass"));
registryClient.authPullByWwwAuthenticate("Basic foo");
Optional<BlobDescriptor> digestAndSize = registryClient.checkBlob(digest);
Assert.assertEquals(5678, digestAndSize.get().getSize());
MatcherAssert.assertThat(registry.getInputRead(), CoreMatchers.containsString("Authorization: Basic dXNlcjpwYXNz"));
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by GoogleContainerTools.
the class UpdateCheckerTest method testPerformUpdateCheck_newJsonField.
@Test
public void testPerformUpdateCheck_newJsonField() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException {
String response = "HTTP/1.1 200 OK\nContent-Length:43\n\n{\"latest\":\"2.0.0\",\"unknownField\":\"unknown\"}";
try (TestWebServer server = new TestWebServer(false, Collections.singletonList(response), 1)) {
setupLastUpdateCheck();
Optional<String> message = UpdateChecker.performUpdateCheck(configDir, "1.0.2", server.getEndpoint(), "tool-name", ignored -> {
});
assertThat(message).hasValue("2.0.0");
}
}
Aggregations