Search in sources :

Example 6 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.

the class RegistryEndpointCallerTest method mockResponseException.

private static ResponseException mockResponseException(int statusCode) {
    ResponseException mock = Mockito.mock(ResponseException.class);
    Mockito.when(mock.getStatusCode()).thenReturn(statusCode);
    return mock;
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) ResponseException(com.google.cloud.tools.jib.http.ResponseException)

Example 7 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.

the class RegistryEndpointCallerTest method testCall_credentialsForcedOverHttp.

@Test
public void testCall_credentialsForcedOverHttp() throws IOException, RegistryException {
    ResponseException unauthorizedException = mockResponseException(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
    setUpRegistryResponse(unauthorizedException);
    System.setProperty(JibSystemProperties.SEND_CREDENTIALS_OVER_HTTP, "true");
    try {
        endpointCaller.call();
        Assert.fail("Call should have failed");
    } catch (RegistryCredentialsNotSentException ex) {
        throw new AssertionError("should have sent credentials", ex);
    } catch (RegistryUnauthorizedException ex) {
        Assert.assertEquals("Unauthorized for serverUrl/imageName", ex.getMessage());
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) ResponseException(com.google.cloud.tools.jib.http.ResponseException) RegistryUnauthorizedException(com.google.cloud.tools.jib.api.RegistryUnauthorizedException) Test(org.junit.Test)

Example 8 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.

the class ManifestPusherTest method testHandleHttpResponseException_quayIo.

/**
 * Quay.io returns an undocumented 415 / MANIFEST_INVALID.
 */
@Test
public void testHandleHttpResponseException_quayIo() throws ResponseException {
    ResponseException exception = Mockito.mock(ResponseException.class);
    Mockito.when(exception.getStatusCode()).thenReturn(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
    Mockito.when(exception.getContent()).thenReturn("{\"errors\":[{\"code\":\"MANIFEST_INVALID\"," + "\"detail\":{\"message\":\"manifest schema version not supported\"}," + "\"message\":\"manifest invalid\"}]}");
    try {
        testManifestPusher.handleHttpResponseException(exception);
        Assert.fail();
    } catch (RegistryErrorException ex) {
        MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.containsString("Registry may not support pushing OCI Manifest or " + "Docker Image Manifest Version 2, Schema 2"));
    }
}
Also used : ResponseException(com.google.cloud.tools.jib.http.ResponseException) Test(org.junit.Test)

Example 9 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.

the class ManifestPusherTest method testHandleHttpResponseException_otherError.

@Test
public void testHandleHttpResponseException_otherError() throws RegistryErrorException {
    ResponseException exception = Mockito.mock(ResponseException.class);
    Mockito.when(exception.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED);
    try {
        testManifestPusher.handleHttpResponseException(exception);
        Assert.fail();
    } catch (ResponseException ex) {
        Assert.assertSame(exception, ex);
    }
}
Also used : ResponseException(com.google.cloud.tools.jib.http.ResponseException) Test(org.junit.Test)

Example 10 with ResponseException

use of com.google.cloud.tools.jib.http.ResponseException in project jib by GoogleContainerTools.

the class ManifestPusherTest method testHandleHttpResponseException_dockerRegistry_manifestInvalid.

/**
 * Docker Registry 2.2 returns a 400 / MANIFEST_INVALID.
 */
@Test
public void testHandleHttpResponseException_dockerRegistry_manifestInvalid() throws ResponseException {
    ResponseException exception = Mockito.mock(ResponseException.class);
    Mockito.when(exception.getStatusCode()).thenReturn(HttpStatus.SC_BAD_REQUEST);
    Mockito.when(exception.getContent()).thenReturn("{\"errors\":[{\"code\":\"MANIFEST_INVALID\"," + "\"message\":\"manifest invalid\",\"detail\":{}}]}");
    try {
        testManifestPusher.handleHttpResponseException(exception);
        Assert.fail();
    } catch (RegistryErrorException ex) {
        MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.containsString("Registry may not support pushing OCI Manifest or " + "Docker Image Manifest Version 2, Schema 2"));
    }
}
Also used : ResponseException(com.google.cloud.tools.jib.http.ResponseException) Test(org.junit.Test)

Aggregations

ResponseException (com.google.cloud.tools.jib.http.ResponseException)44 Test (org.junit.Test)32 NoHttpResponseException (org.apache.http.NoHttpResponseException)18 RegistryUnauthorizedException (com.google.cloud.tools.jib.api.RegistryUnauthorizedException)8 ErrorResponseTemplate (com.google.cloud.tools.jib.registry.json.ErrorResponseTemplate)6 InsecureRegistryException (com.google.cloud.tools.jib.api.InsecureRegistryException)4 RegistryAuthenticationFailedException (com.google.cloud.tools.jib.api.RegistryAuthenticationFailedException)4 Request (com.google.cloud.tools.jib.http.Request)4 Response (com.google.cloud.tools.jib.http.Response)4 ErrorEntryTemplate (com.google.cloud.tools.jib.registry.json.ErrorEntryTemplate)4 IOException (java.io.IOException)4 JibContainer (com.google.cloud.tools.jib.api.JibContainer)2 RegistryException (com.google.cloud.tools.jib.api.RegistryException)2 BlobHttpContent (com.google.cloud.tools.jib.http.BlobHttpContent)2 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)2 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)2 RegistryCredentialsNotSentException (com.google.cloud.tools.jib.registry.RegistryCredentialsNotSentException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 ExecutionException (java.util.concurrent.ExecutionException)2