### Question:
LdapModule extends AbstractQuercusModule { public static BooleanValue ldap_bind (LdapLinkResource linkIdentifier, @Optional String bindRdn, @Optional String bindPassword) { boolean success = linkIdentifier.simpleBind(bindRdn, bindPassword); return BooleanValue.create(success); }  static BooleanValue ldap_add(LdapLinkResource linkIdentifier, String dn, Map entry); static BooleanValue ldap_bind(LdapLinkResource linkIdentifier, @Optional String bindRdn,
                                          @Optional String bindPassword); @ReturnNullAsFalse static LdapLinkResource ldap_connect(String hostname, @Optional String port); @ReturnNullAsFalse static ArrayValue ldap_get_entries(LdapLinkResource linkIdentifier,
                                               LdapResultResource resultIdentifier); static BooleanValue ldap_modify(LdapLinkResource linkIdentifier, String dn,
                                            Map entry); @ReturnNullAsFalse static LdapResultResource ldap_read(LdapLinkResource linkIdentifier, String baseDN,
                                                String filter, @Optional List<String> attributes,
                                                @Optional("0") int attrsOnly,
                                                @Optional("0") long sizeLimit,
                                                @Optional("0") int timeLimit,
                                                @Optional("0") int deref); @ReturnNullAsFalse static LdapResultResource ldap_search(LdapLinkResource linkIdentifier, String baseDN,
                                                  String filter, @Optional List<String> attributes,
                                                  @Optional("0") int attrsOnly,
                                                  @Optional("0") long sizeLimit,
                                                  @Optional("0") int timeLimit,
                                                  @Optional("0") int deref); static BooleanValue ldap_set_option(LdapLinkResource linkIdentifier, String option,
                                                int newVal); static BooleanValue ldap_start_tls(LdapLinkResource linkIdentifier); static BooleanValue ldap_unbind(LdapLinkResource linkIdentifier); static int LDAP_OPT_REFERRALS; static int LDAP_OPT_PROTOCOL_VERSION; static final int LDAP_DEREF_NEVER; static final int LDAP_DEREF_SEARCHING; static final int LDAP_DEREF_FINDING; static final int LDAP_DEREF_ALWAYS; }### Answer:
@Test public void anonymousBind () { BooleanValue result = LdapModule.ldap_bind(_connection, "", ""); assertTrue("Trying anonymous bind", result.toBoolean()); }
@Test public void passwordlessBind () { BooleanValue result = LdapModule.ldap_bind(_connection, "cn=foo,dc=example,dc=com", ""); assertFalse("Binding with DN specified but empty password should fail", result.toBoolean()); }
@Test public void authenticatedBind () { BooleanValue result = LdapModule.ldap_bind(_connection, "cn=Manager,dc=example,dc=com", "secret"); assertTrue("Binding with manager DN and password", result.toBoolean()); }
@Test public void badPasswordBind () { BooleanValue result = LdapModule.ldap_bind(_connection, "cn=Manager,dc=example,dc=com", "s3kr1t"); assertFalse("Binding with manager DN and wrong password should fail", result.toBoolean()); }