use of com.google.cloud.tools.jib.http.TestWebServer in project jib by google.
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 google.
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 google.
the class RegistryClientTest method setUpAuthServerAndRegistry.
/**
* Sets up an auth server and a registry. The auth server can return a bearer token up to {@code
* maxAuthTokens} times. The registry will initially return "401 Unauthorized" for {@code
* maxTokenResponses} times. (Therefore, a registry client has to get auth tokens from the auth
* server {@code maxAuthTokens} times. After that, the registry returns {@code finalResponse}.
*/
private void setUpAuthServerAndRegistry(int maxAuthTokens, @Nullable String finalResponse) throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException {
String tokenResponse = "HTTP/1.1 200 OK\nContent-Length: 26\n\n{\"token\":\"awesome-token!\"}";
authServer = new TestWebServer(false, Arrays.asList(tokenResponse), maxAuthTokens);
String bearerAuth = "HTTP/1.1 401 Unauthorized\nContent-Length: 0\nWWW-Authenticate: Bearer realm=\"" + authServer.getEndpoint() + "\"\n\n";
List<String> responses = new ArrayList<>(Collections.nCopies(maxAuthTokens, bearerAuth));
if (finalResponse != null) {
responses.add(finalResponse);
}
registry = new TestWebServer(false, responses, responses.size(), true);
}
use of com.google.cloud.tools.jib.http.TestWebServer in project jib by google.
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 google.
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