Search in sources :

Example 6 with Identity

use of com.spotify.sshagentproxy.Identity in project helios by spotify.

the class AuthenticatingHttpConnectorTest method testOneIdentity_ResponseIsOk.

@Test
public void testOneIdentity_ResponseIsOk() throws Exception {
    final AgentProxy proxy = mock(AgentProxy.class);
    final Identity identity = mockIdentity();
    final AuthenticatingHttpConnector authConnector = createAuthenticatingConnector(Optional.of(proxy), ImmutableList.of(identity));
    final String path = "/another/one";
    final HttpsURLConnection connection = mock(HttpsURLConnection.class);
    when(connector.connect(argThat(matchesAnyEndpoint(path)), eq(method), eq(entity), eq(headers))).thenReturn(connection);
    when(connection.getResponseCode()).thenReturn(200);
    final URI uri = new URI("https://helios" + path);
    authConnector.connect(uri, method, entity, headers);
    verify(connector).setExtraHttpsHandler(sshAgentHttpsHandlerWithArgs(USER, proxy, identity));
}
Also used : AgentProxy(com.spotify.sshagentproxy.AgentProxy) Identity(com.spotify.sshagentproxy.Identity) URI(java.net.URI) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Test(org.junit.Test)

Example 7 with Identity

use of com.spotify.sshagentproxy.Identity in project helios by spotify.

the class AuthenticatingHttpConnectorTest method testOneIdentity_ServerReturns502BadGateway.

@Test
public void testOneIdentity_ServerReturns502BadGateway() throws Exception {
    final AgentProxy proxy = mock(AgentProxy.class);
    final Identity identity = mockIdentity();
    final AuthenticatingHttpConnector authConnector = createAuthenticatingConnector(Optional.of(proxy), ImmutableList.of(identity));
    final String path = "/foobar";
    final HttpsURLConnection connection = mock(HttpsURLConnection.class);
    when(connector.connect(argThat(matchesAnyEndpoint(path)), eq(method), eq(entity), eq(headers))).thenReturn(connection);
    when(connection.getResponseCode()).thenReturn(502);
    final URI uri = new URI("https://helios" + path);
    final HttpURLConnection returnedConnection = authConnector.connect(uri, method, entity, headers);
    assertSame("If there is only one identity do not expect any additional endpoints to " + "be called after the first returns Unauthorized", returnedConnection, connection);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) AgentProxy(com.spotify.sshagentproxy.AgentProxy) Identity(com.spotify.sshagentproxy.Identity) URI(java.net.URI) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Test(org.junit.Test)

Aggregations

Identity (com.spotify.sshagentproxy.Identity)7 AgentProxy (com.spotify.sshagentproxy.AgentProxy)5 Test (org.junit.Test)5 HttpURLConnection (java.net.HttpURLConnection)4 URI (java.net.URI)4 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)4 SshAgentHttpsHandler (com.spotify.helios.client.HttpsHandlers.SshAgentHttpsHandler)2 CertificateAndPrivateKey (com.spotify.helios.client.tls.CertificateAndPrivateKey)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1