/**
* Tests that authenticating a known user with a valid certificate chain will not yield null.
*/
@Test(groups = { UNIT })
public void testAuthenticateKnownUserWithValidCertificateChainYieldsValidResult() throws ConfigurationException {
ClientCertAuthenticationProcessor processor = createAuthorizationProcessor();
final String lookupKey = "anyKey";
final String matchPolicy = "dn";
Properties props = new Properties();
props.put(PROPERTY_USERNAME_LOOKUPKEY, lookupKey);
props.put(PROPERTY_USERNAME_MATCH_POLICY, matchPolicy);
props.put(PROPERTY_VERIFY_CERT_VALIDITY, "true");
processor.updated(props);
X509Certificate[] certChain = createValidCertificateChainWithDN("cn=Alice,dc=acme,dc=corp", "cn=Fido,ou=dev,dc=acme,dc=corp", "cn=Bob,ou=dev,dc=acme,dc=corp");
when(m_servletRequest.getAttribute(ATTRIBUTE_X509_CERTIFICATE)).thenReturn(certChain);
User user = mock(User.class);
when(user.getName()).thenReturn("bob");
when(m_userAdmin.getUser(eq(lookupKey), eq("CN=Bob,OU=dev,DC=acme,DC=corp"))).thenReturn(user);
User result = processor.authenticate(m_userAdmin, m_servletRequest);
assert result != null : "Expected a valid user to be returned!";
assert "bob".equals(user.getName()) : "Expected bob to be returned as user!";
}