package net.hackergarten.ldapauth;

import java.util.Map;

import junit.framework.TestCase;

/**
 * Implement some basic test using the public ldap from forumsys.
 *
 * see http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
 */
public class LdapAuthenticatorTest extends TestCase {

    public void testGetUid() throws Exception {
        LdapAuthenticator ldapAuthenticator = new LdapAuthenticator("dc=example,dc=com", "ldap://ldap.forumsys.com:389/");
        ldapAuthenticator.setUidProperty("cn");
        String uid = ldapAuthenticator.getUid("read-only-admin");
        assertEquals("cn=read-only-admin,dc=example,dc=com",uid);
    }

    public void testBind() throws Exception {
        LdapAuthenticator ldapAuthenticator = new LdapAuthenticator("dc=example,dc=com", "ldap://ldap.forumsys.com:389/");
        boolean authenticated = ldapAuthenticator.testBind("cn=read-only-admin,dc=example,dc=com", "password");
        assertTrue(authenticated);
    }

    public void testSearch() throws Exception{
        LdapAuthenticator ldapAuthenticator = new LdapAuthenticator("dc=example,dc=com", "ldap://ldap.forumsys.com:389/");
        ldapAuthenticator.setUidProperty("uid");
        ldapAuthenticator.setSearchAttributes("uid");
        Map<String, String> result = ldapAuthenticator.search("riemann");
        assertNotNull(result);
        assertEquals(1,result.size());
        assertEquals("riemann", ((Map.Entry)result.entrySet().toArray()[0]).getValue());
    }
}

@@ -690,286 +690,981 @@
 test
-Bind() throws Exception %7B%0A        LdapAuthenticator ldapAuthenticator = new LdapAuthenticator(%22dc=example,dc=com%22, %22ldap://ldap.forumsys.com:389/%22);%0A        boolean authenticated = ldapAuthenticator.testBind(%22cn=read-only-admin,dc=example,dc=com%22, %22password%22);%0A        assertTru
+SearchForUnknownUserReturnsNull() throws Exception %7B%0A        LdapAuthenticator ldapAuthenticator = new LdapAuthenticator(%22dc=example,dc=com%22, %22ldap://ldap.forumsys.com:389/%22);%0A        ldapAuthenticator.setUidProperty(%22cn%22);%0A        String uid = ldapAuthenticator.getUid(%22non-existent-user%22);%0A        assertNull(uid);%0A    %7D%0A%0A    public void testBind() throws Exception %7B%0A        LdapAuthenticator ldapAuthenticator = new LdapAuthenticator(%22dc=example,dc=com%22, %22ldap://ldap.forumsys.com:389/%22);%0A        boolean authenticated = ldapAuthenticator.testBind(%22cn=read-only-admin,dc=example,dc=com%22, %22password%22);%0A        assertTrue(authenticated);%0A    %7D%0A%0A    public void testBindFailsOnInvalidPassword() throws Exception %7B%0A        LdapAuthenticator ldapAuthenticator = new LdapAuthenticator(%22dc=example,dc=com%22, %22ldap://ldap.forumsys.com:389/%22);%0A        boolean authenticated = ldapAuthenticator.testBind(%22cn=read-only-admin,dc=example,dc=com%22, %22wrongPassword%22);%0A        assertFals
 e(au

implement non-happy flow tests