Skip to content

Commit

Permalink
fix ome#2025 - Fixing ldap tests post-refactoring (see ome#1382)
Browse files Browse the repository at this point in the history
With this commit, the basic reconfiguration of LDAP is finished.
Usability and performance improvements should be added to ome#1382

git-svn-id: file:///home/svn/omero/trunk@6550 05709c45-44f0-0310-885b-81a1db45b4a6
  • Loading branch information
joshmoore committed Apr 8, 2010
1 parent 0ce0dfe commit 88abf72
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 75 deletions.
26 changes: 4 additions & 22 deletions components/server/test/ome/server/itests/sec/LdapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void testSearchByAttribute() throws Exception {
@Test
public void testSearchByAttributes() throws Exception {
if (iLdap.getSetting()) {
String[] attrs = iLdap.getReqAttributes();
String[] vals = iLdap.getReqValues();
String[] attrs = new String[0];
String[] vals = new String[0];

List<Experimenter> exps = iLdap.searchByAttributes("", attrs, vals);

Expand Down Expand Up @@ -120,30 +120,15 @@ public void testFindExp() throws Exception {
}
}

@Test
public void testSearchAttributes() throws Exception {
if (iLdap.getSetting()) {
iLdap.getReqAttributes();
}

}

@Test
public void testValidatePassword() throws Exception {
if (iLdap.getSetting()) {
System.err.println(iLdap.validatePassword(
"cn=jsmith, ou=people, ou=example, o=com", "passwd"));
}
}

@Test
public void testCreateUserFromLdap() throws Exception {
if(iLdap.getSetting()) {
Experimenter exp = null;
try {
exp = iAdmin.lookupExperimenter("jmoore");
} catch (ApiUsageException e) {
iLdap.createUserFromLdap("jmoore", "XXX");
// iLdap.createUserFromLdap("jmoore", "XXX");
fail();
}

if(exp!=null)
Expand All @@ -156,9 +141,6 @@ public void testCreateUserFromLdap() throws Exception {
public void testGetReq() throws Exception {
if(iLdap.getSetting()) {
iLdap.getSetting();
iLdap.getReqAttributes();
iLdap.getReqGroups();
iLdap.getReqValues();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.List;

import ome.security.PasswordUtil;
import ome.security.auth.PasswordUtil;
import ome.security.basic.BasicMethodSecurity;
import ome.server.itests.AbstractManagedContextTest;
import ome.services.sessions.SessionManager;
Expand All @@ -33,7 +33,7 @@ public void testUserRoles() throws Exception {

msec = new BasicMethodSecurity();
msec.setSessionManager(mgr);
List<String> roles = PasswordUtil.userGroups(jdbc, "root");
List<String> roles = new PasswordUtil(jdbc).userGroups("root");
assertTrue(roles.size() >= 2);
boolean found = false;
for (int i = 0; i < roles.size(); i++) {
Expand Down
37 changes: 7 additions & 30 deletions components/server/test/ome/server/itests/sec/MockedLdapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import java.util.List;

import ome.api.local.LocalLdap;
import ome.api.ILdap;
import ome.logic.LdapImpl;
import ome.model.meta.Experimenter;
import ome.server.itests.AbstractManagedContextTest;
import ome.system.Roles;

import org.jmock.Mock;
import org.springframework.ldap.core.LdapOperations;
Expand All @@ -26,7 +27,7 @@
public class MockedLdapTest extends AbstractManagedContextTest {

// Using local versions since we need to mock them.
LocalLdap ldap;
ILdap ldap;
Mock mock;
LdapOperations ops;

Expand All @@ -35,8 +36,8 @@ public void setup() {
mock = new Mock(LdapOperations.class);
ops = (LdapOperations) mock.proxy();

LdapImpl limpl = new LdapImpl(null, ops, jdbcTemplate, "default",
"groups", "attributes", "values", true);
LdapImpl limpl = new LdapImpl(null, null, new Roles(),
null, null, null);
ldap = limpl;

}
Expand All @@ -62,8 +63,8 @@ public void testSearchByAttribute() throws Exception {

@Test
public void testSearchByAttributes() throws Exception {
String[] attrs = ldap.getReqAttributes();
String[] vals = ldap.getReqValues();
String[] attrs = new String[0];
String[] vals = new String[0];

List<Experimenter> exps = ldap.searchByAttributes("", attrs, vals);

Expand Down Expand Up @@ -104,28 +105,4 @@ public void testFindExp() throws Exception {
}
}

@Test
public void testSearchAttributes() throws Exception {
ldap.getReqAttributes();
}

@Test
public void testValidatePassword() throws Exception {
ldap.validatePassword("cn=jsmith, ou=people, ou=example, o=com",
"passwd");
}

@Test
public void testCreateUserFromLdap() throws Exception {
ldap.createUserFromLdap("jmoore", "XXX");
}

@Test
public void testGetReq() throws Exception {
ldap.getSetting();
ldap.getReqAttributes();
ldap.getReqGroups();
ldap.getReqValues();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void testCheckMethodThrowsException() throws Exception {
mockMgr.expects(once()).method("getUserRoles").will(returnValue(roles));

try {
msec.checkMethod(new AdminImpl(null, null, null, null, null, null, null),
msec.checkMethod(new AdminImpl(null, null, null, null, null, null, null, null, null),
sync, p);
} finally {
check();
Expand All @@ -94,7 +94,7 @@ public void testCheckMethodAllowsExecution() throws Exception {
mockMgr.expects(once()).method("getUserRoles").will(returnValue(roles));

try {
msec.checkMethod(new AdminImpl(null, null, null, null,null, null, null),
msec.checkMethod(new AdminImpl(null, null, null, null,null, null, null, null, null),
ec, p);
} finally {
check();
Expand All @@ -113,7 +113,7 @@ public void testCheckMethodAllowsExecutionEvenOnProxy() throws Exception {

ProxyFactory factory = new ProxyFactory();
factory.setInterfaces(new Class[] { IAdmin.class });
factory.setTarget(new AdminImpl(null, null, null, null, null, null, null));
factory.setTarget(new AdminImpl(null, null, null, null, null, null, null, null, null));
factory.addAdvice(new JamonPerformanceMonitorInterceptor());
IAdmin proxy = (IAdmin) factory.getProxy();
try {
Expand Down
39 changes: 21 additions & 18 deletions components/server/test/ome/server/utests/sec/PasswordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

import ome.api.ILdap;
import ome.conditions.ApiUsageException;
import ome.logic.LdapImpl;
import ome.security.auth.ConfigurablePasswordProvider;
import ome.security.auth.FilePasswordProvider;
import ome.security.auth.JdbcPasswordProvider;
import ome.security.auth.LdapPasswordProvider;
import ome.security.auth.PasswordChangeException;
import ome.security.auth.PasswordProvider;
import ome.security.auth.PasswordProviders;
import ome.security.auth.PasswordUtil;
import ome.security.auth.PasswordUtility;

import org.jmock.Mock;
Expand Down Expand Up @@ -54,7 +56,7 @@ static class PP extends ConfigurablePasswordProvider {

SimpleJdbcOperations jdbc;

ILdap ldap;
LdapImpl ldap;

protected void initJdbc() {
mockJdbc = mock(SimpleJdbcOperations.class);
Expand All @@ -64,7 +66,8 @@ protected void initJdbc() {
protected void initLdap(boolean setting) {
initJdbc();
mockLdap = mock(ILdap.class);
ldap = (ILdap) mockLdap.proxy();
// ldap = (ILdap) mockLdap.proxy();
ldap = null; // FIXME
mockLdap.expects(atLeastOnce()).method("getSetting").will(
returnValue(setting));
}
Expand Down Expand Up @@ -93,29 +96,29 @@ public void testConfigurableDefaultsThrows() throws Exception {
// FILE

public void testFileDefaults() throws Exception {
provider = new FilePasswordProvider(file);
provider = new FilePasswordProvider(null, file);
assertTrue(provider.hasPassword("test"));
assertTrue(provider.checkPassword("test", "test"));
assertFalse(provider.checkPassword("unknown", "anything"));
}

public void testFilesDontIgnoreUnknownReturnsNull() throws Exception {
provider = new FilePasswordProvider(file, true);
provider = new FilePasswordProvider(null, file, true);
assertFalse(provider.hasPassword("unknown"));
assertNull(provider.checkPassword("unknown", "anything"));
}

@Test(expectedExceptions = PasswordChangeException.class)
public void testFilesThrowsOnChange() throws Exception {
provider = new FilePasswordProvider(file, true);
provider = new FilePasswordProvider(null, file, true);
provider.changePassword("test", "something new");
}

// JDBC

public void tesJdbcDefaults() throws Exception {
initJdbc();
provider = new JdbcPasswordProvider(jdbc);
provider = new JdbcPasswordProvider(new PasswordUtil(jdbc));

userIdReturns1();
provider.hasPassword("test");
Expand All @@ -136,38 +139,38 @@ public void tesJdbcDefaults() throws Exception {
public void tesJdbcIgnoreUnknownReturnsFalse() throws Exception {
initJdbc();
userIdReturnsNull();
provider = new JdbcPasswordProvider(jdbc);
provider = new JdbcPasswordProvider(new PasswordUtil(jdbc));
assertFalse(provider.checkPassword("unknown", "anything"));
}

public void tesJdbcDontIgnoreUnknownReturnsNull() throws Exception {
initJdbc();
userIdReturnsNull();
provider = new JdbcPasswordProvider(jdbc, true);
provider = new JdbcPasswordProvider(new PasswordUtil(jdbc), true);
assertNull(provider.checkPassword("unknown", "anything"));
}

public void testJdbcChangesPassword() throws Exception {
initJdbc();
userIdReturns1();
mockJdbc.expects(once()).method("update").will(returnValue(1));
provider = new JdbcPasswordProvider(jdbc);
provider = new JdbcPasswordProvider(new PasswordUtil(jdbc));
provider.changePassword("a", "b");
}

@Test(expectedExceptions = PasswordChangeException.class)
public void testJdbcThrowsOnBadUsername() throws Exception {
initJdbc();
userIdReturnsNull();
provider = new JdbcPasswordProvider(jdbc);
provider = new JdbcPasswordProvider(new PasswordUtil(jdbc));
provider.changePassword("a", "b");
}

// LDAP

public void tesLdapDefaults() throws Exception {
initLdap(true);
provider = new LdapPasswordProvider(ldap, jdbc);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap);

String encoded = ((PasswordUtility) provider).encodePassword("test");
queryForObjectReturns(encoded);
Expand Down Expand Up @@ -196,7 +199,7 @@ public void tesLdapIgnoreUnknownCreatesFailsReturnsFalse() throws Exception {
initLdap(true);
userIdReturnsNull();
ldapCreatesUser(false);
provider = new LdapPasswordProvider(ldap, jdbc, true);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap, true);
assertNull(provider.checkPassword("unknown", "anything"));
}

Expand All @@ -205,15 +208,15 @@ public void tesLdapIgnoreUnknownCreatesSucceedsReturnsTrue()
initLdap(true);
userIdReturnsNull();
ldapCreatesUser(true);
provider = new LdapPasswordProvider(ldap, jdbc, true);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap, true);
assertTrue(provider.checkPassword("unknown", "anything"));
}

public void tesLdapIgnoreUnknownCreatesThrows() throws Exception {
initLdap(true);
userIdReturnsNull();
ldapCreatesUserAndThrows();
provider = new LdapPasswordProvider(ldap, jdbc, true);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap, true);
assertNull(provider.checkPassword("unknown", "anything"));
}

Expand All @@ -222,7 +225,7 @@ public void tesLdapDontIgnoreUnknownCreatesFailsReturnsFalse()
initLdap(true);
userIdReturnsNull();
ldapCreatesUser(false);
provider = new LdapPasswordProvider(ldap, jdbc, false);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap, false);
assertFalse(provider.checkPassword("unknown", "anything"));
}

Expand All @@ -231,22 +234,22 @@ public void tesLdapDontIgnoreUnknownCreatesSucceedsReturnsTrue()
initLdap(true);
userIdReturnsNull();
ldapCreatesUser(true);
provider = new LdapPasswordProvider(ldap, jdbc, false);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap, false);
assertTrue(provider.checkPassword("unknown", "anything"));
}

public void tesLdapDontIgnoreUnknownCreatesThrows() throws Exception {
initLdap(true);
userIdReturnsNull();
ldapCreatesUserAndThrows();
provider = new LdapPasswordProvider(ldap, jdbc, false);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap, false);
assertFalse(provider.checkPassword("unknown", "anything"));
}

@Test(expectedExceptions = PasswordChangeException.class)
public void testLdapChangesPasswordThrows() throws Exception {
initLdap(true);
provider = new LdapPasswordProvider(ldap, jdbc);
provider = new LdapPasswordProvider(new PasswordUtil(jdbc), ldap);
provider.changePassword("a", "b");
}

Expand Down

0 comments on commit 88abf72

Please sign in to comment.