Search in sources :

Example 1 with CertificateAndPrivateKey

use of com.spotify.helios.client.tls.CertificateAndPrivateKey in project helios by spotify.

the class HttpsHandlersTest method testSshAgent.

@Test
public void testSshAgent() throws Exception {
    final byte[] random = new byte[255];
    new Random().nextBytes(random);
    final AgentProxy proxy = mock(AgentProxy.class);
    final Identity identity = mock(Identity.class);
    when(identity.getKeyBlob()).thenReturn(random);
    when(proxy.sign(any(Identity.class), any(byte[].class))).thenAnswer(new Answer<byte[]>() {

        @Override
        public byte[] answer(InvocationOnMock invocation) throws Throwable {
            final byte[] bytesToSign = (byte[]) invocation.getArguments()[1];
            return sha1digest(bytesToSign);
        }
    });
    final SshAgentHttpsHandler h = new SshAgentHttpsHandler("foo", true, proxy, identity);
    final CertificateAndPrivateKey pair = h.createCertificateAndPrivateKey();
    assertNotNull(pair);
    assertNotNull(pair.getCertificate());
    assertNotNull(pair.getPrivateKey());
}
Also used : SshAgentHttpsHandler(com.spotify.helios.client.HttpsHandlers.SshAgentHttpsHandler) Random(java.util.Random) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AgentProxy(com.spotify.sshagentproxy.AgentProxy) Identity(com.spotify.sshagentproxy.Identity) CertificateAndPrivateKey(com.spotify.helios.client.tls.CertificateAndPrivateKey) Test(org.junit.Test)

Example 2 with CertificateAndPrivateKey

use of com.spotify.helios.client.tls.CertificateAndPrivateKey in project helios by spotify.

the class HttpsHandlersTest method testCertificateFile.

@Test
public void testCertificateFile() throws Exception {
    final ClientCertificatePath clientCertificatePath = new ClientCertificatePath(Paths.get(getResource("UIDCACert.pem").getPath()), Paths.get(getResource("UIDCACert.key").getPath()));
    final HttpsHandlers.CertificateFileHttpsHandler h = new HttpsHandlers.CertificateFileHttpsHandler("foo", true, clientCertificatePath);
    final CertificateAndPrivateKey pair = h.createCertificateAndPrivateKey();
    assertNotNull(pair);
    assertNotNull(pair.getCertificate());
    assertNotNull(pair.getPrivateKey());
}
Also used : CertificateAndPrivateKey(com.spotify.helios.client.tls.CertificateAndPrivateKey) Test(org.junit.Test)

Aggregations

CertificateAndPrivateKey (com.spotify.helios.client.tls.CertificateAndPrivateKey)2 Test (org.junit.Test)2 SshAgentHttpsHandler (com.spotify.helios.client.HttpsHandlers.SshAgentHttpsHandler)1 AgentProxy (com.spotify.sshagentproxy.AgentProxy)1 Identity (com.spotify.sshagentproxy.Identity)1 Random (java.util.Random)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1