use of keywhiz.auth.mutualssl.CertificatePrincipal in project keywhiz by square.
the class ClientAuthenticatorTest method ignoresMultipleSpiffeIds.
@Test
public void ignoresMultipleSpiffeIds() throws Exception {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate multipleSpiffeClientCert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(multipleSpiffePem.getBytes(UTF_8)));
Principal multipleSpiffePrincipal = new CertificatePrincipal(multipleSpiffeClientCert.getSubjectDN().toString(), new X509Certificate[] { multipleSpiffeClientCert });
// Use only the (malformatted) SPIFFE IDs to retrieve a client (which should fail)
when(clientAuthTypeConfig.useCommonName()).thenReturn(false);
when(clientAuthTypeConfig.useSpiffeId()).thenReturn(true);
assertThat(authenticator.authenticate(multipleSpiffePrincipal, false)).isEmpty();
verifyNoInteractions(clientDAO);
}
use of keywhiz.auth.mutualssl.CertificatePrincipal in project keywhiz by square.
the class ClientAuthenticatorTest method setUp.
@Before
public void setUp() throws Exception {
clientSpiffe = new URI(clientSpiffeStr);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate clientCert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(clientPem.getBytes(UTF_8)));
certPrincipal = new CertificatePrincipal(clientCert.getSubjectDN().toString(), new X509Certificate[] { clientCert });
spiffePrincipal = new SpiffePrincipal(new URI(clientSpiffeStr));
authenticator = new ClientAuthenticator(clientDAO, clientDAO, clientAuthConfig);
when(clientDAO.getClientByName(clientName)).thenReturn(Optional.of(client));
when(clientDAO.getClientBySpiffeId(clientSpiffe)).thenReturn(Optional.of(client));
when(clientAuthConfig.typeConfig()).thenReturn(clientAuthTypeConfig);
when(clientAuthTypeConfig.useCommonName()).thenReturn(true);
when(clientAuthTypeConfig.useSpiffeId()).thenReturn(true);
}
Aggregations