Search in sources :

Example 6 with LdapKeyManager

use of com.gitblit.transport.ssh.LdapKeyManager in project gitblit by gitblit.

the class LdapPublicKeyManagerTest method testGetKeys.

@Test
public void testGetKeys() throws LDAPException {
    String keyRsaOne = getRsaPubKey("UserOne@example.com");
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", keyRsaOne));
    String keyRsaTwo = getRsaPubKey("UserTwo@example.com");
    String keyDsaTwo = getDsaPubKey("UserTwo@example.com");
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "sshPublicKey", keyRsaTwo, keyDsaTwo));
    String keyRsaThree = getRsaPubKey("UserThree@example.com");
    String keyDsaThree = getDsaPubKey("UserThree@example.com");
    String keyEcThree = getEcPubKey("UserThree@example.com");
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", keyEcThree, keyRsaThree, keyDsaThree));
    LdapKeyManager kmgr = new LdapKeyManager(settings);
    List<SshKey> keys = kmgr.getKeys("UserOne");
    assertNotNull(keys);
    assertTrue(keys.size() == 1);
    assertEquals(keyRsaOne, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserTwo");
    assertNotNull(keys);
    assertTrue(keys.size() == 2);
    if (keyRsaTwo.equals(keys.get(0).getRawData())) {
        assertEquals(keyDsaTwo, keys.get(1).getRawData());
    } else if (keyDsaTwo.equals(keys.get(0).getRawData())) {
        assertEquals(keyRsaTwo, keys.get(1).getRawData());
    } else {
        fail("Mismatch in UserTwo keys.");
    }
    keys = kmgr.getKeys("UserThree");
    assertNotNull(keys);
    assertTrue(keys.size() == 3);
    assertEquals(keyEcThree, keys.get(0).getRawData());
    assertEquals(keyRsaThree, keys.get(1).getRawData());
    assertEquals(keyDsaThree, keys.get(2).getRawData());
    keys = kmgr.getKeys("UserFour");
    assertNotNull(keys);
    assertTrue(keys.size() == 0);
}
Also used : SshKey(com.gitblit.transport.ssh.SshKey) Modification(com.unboundid.ldap.sdk.Modification) LdapKeyManager(com.gitblit.transport.ssh.LdapKeyManager) Test(org.junit.Test)

Aggregations

LdapKeyManager (com.gitblit.transport.ssh.LdapKeyManager)6 SshKey (com.gitblit.transport.ssh.SshKey)6 Modification (com.unboundid.ldap.sdk.Modification)6 Test (org.junit.Test)6 Signature (java.security.Signature)1