diff --git a/modules/gplazma2-ldap/pom.xml b/modules/gplazma2-ldap/pom.xml
index 56836095cf0..d9fc74901e0 100644
--- a/modules/gplazma2-ldap/pom.xml
+++ b/modules/gplazma2-ldap/pom.xml
@@ -34,23 +34,11 @@
${project.version}
- org.apache.directory.server
- apacheds-server-unit
- 1.5.5
- test
-
-
- org.apache.directory.server
- apacheds-server-integ
- 1.5.5
- test
-
-
- org.apache.directory.server
- apacheds-core
- 1.5.5
+ org.dcache
+ ldap4testing
test
+
diff --git a/modules/gplazma2-ldap/src/test/resources/org/dcache/gplazma/plugins/ldap/init.ldif b/modules/gplazma2-ldap/src/test/resources/org/dcache/gplazma/plugins/ldap/init.ldif
new file mode 100644
index 00000000000..d554224689f
--- /dev/null
+++ b/modules/gplazma2-ldap/src/test/resources/org/dcache/gplazma/plugins/ldap/init.ldif
@@ -0,0 +1,64 @@
+dn: o=dcache,c=org
+dc: o=dcache
+objectClass: top
+objectClass: domain
+
+dn: ou=people,o=dcache,c=org
+ou: people
+objectClass: top
+objectclass: organizationalunit
+
+dn: ou=group,o=dcache,c=org
+ou: group
+objectClass: top
+objectclass: organizationalunit
+
+dn: uid=kermit,ou=people,o=dcache,c=org
+objectClass: posixAccount
+objectClass: inetorgperson
+objectClass: organizationalperson
+objectClass: top
+uid: kermit
+description: This is the description for Kermit the Frog
+userPassword: kermitTheFrog
+employeeNumber: 1
+initials: kTf
+givenName: Kermit
+cn: Kermit The Frog
+sn: Frog
+mail: kermit.the.frog@dcache.org
+l: Hamburg
+st: DE
+gidNumber: 1000
+homeDirectory: /home/kermit
+uidNumber: 1000
+
+dn: uid=bernd,ou=people,o=dcache,c=org
+objectClass: posixAccount
+objectClass: inetorgperson
+objectClass: organizationalperson
+objectClass: top
+uid: bernd
+description: This is the description for Bernd das Brot
+userPassword: berndDasBrot
+employeeNumber: 2
+initials: BdB
+givenName: Bernd
+cn: Bernd das Brot
+sn: Brot
+mail: bernd.das.brot@dcache.org
+l: Hamburg
+st: DE
+gidNumber: 1000
+homeDirectory: /home/bernd
+uidNumber: 1001
+
+
+dn: cn=actor,ou=group,o=dcache,c=org
+objectClass: groupOfUniqueNames
+objectClass: posixGroup
+objectClass: top
+cn: actor
+uniqueMember: uid=bernd,ou=people,o=dcache,c=org
+uniqueMember: uid=kermit,ou=people,o=dcache,c=org
+gidNumber: 1001
diff --git a/modules/gplazma2-ldap/src/test/scala/org/dcache/gplazma/plugins/LdapPluginTest.scala b/modules/gplazma2-ldap/src/test/scala/org/dcache/gplazma/plugins/LdapPluginTest.scala
index ab4d94f6428..9d93f0df587 100644
--- a/modules/gplazma2-ldap/src/test/scala/org/dcache/gplazma/plugins/LdapPluginTest.scala
+++ b/modules/gplazma2-ldap/src/test/scala/org/dcache/gplazma/plugins/LdapPluginTest.scala
@@ -13,40 +13,59 @@ import scala.collection.convert.WrapAsJava.setAsJavaSet
import org.dcache.auth.{GroupNamePrincipal, GidPrincipal, UidPrincipal, UserNamePrincipal}
import org.dcache.gplazma.NoSuchPrincipalException
import org.dcache.auth.attributes.{HomeDirectory, RootDirectory}
-
-
+import org.dcache.ldap4testing.EmbeddedServer;
/**
* Tests for the gPlazma LDAP plugin.
*
* The tests are all ignored by default because they depend on DESY infrastructure.
*/
-@RunWith(classOf[JUnitRunner]) @Ignore
-class LdapPluginTest extends FlatSpec with Matchers {
-
- val pluginProperties = {
- val properties = new Properties
- properties.put(Ldap.LDAP_URL, "ldap://wof-dav.desy.de:389/")
- properties.put(Ldap.LDAP_ORG, "ou=NIS,o=DESY,c=DE")
- properties.put(Ldap.LDAP_USER_FILTER, "(uid=%s)")
- properties.put(Ldap.LDAP_PEOPLE_TREE, "People")
- properties.put(Ldap.LDAP_GROUP_TREE, "Groups")
- properties.put(Ldap.LDAP_USER_HOME, "/root")
- properties.put(Ldap.LDAP_USER_ROOT, "/root%homeDirectory%/home")
- properties.put(Ldap.LDAP_GROUP_MEMBER, "uniqueMember")
- properties
+@RunWith(classOf[JUnitRunner])
+class LdapPluginTest extends FlatSpec with Matchers with BeforeAndAfter{
+
+ var server : EmbeddedServer = _
+ var ldapPlugin : Ldap = _
+
+ before {
+ val initialLdif = ClassLoader.getSystemResourceAsStream("org/dcache/gplazma/plugins/ldap/init.ldif")
+ server = new EmbeddedServer(0, initialLdif)
+ server.start()
+
+ val pluginProperties = {
+ val properties = new Properties
+ properties.put(Ldap.LDAP_URL, "ldap://localhost:" + server.getSocketAddress().getPort())
+ properties.put(Ldap.LDAP_ORG, "o=dcache,c=org")
+ properties.put(Ldap.LDAP_USER_FILTER, "(uid=%s)")
+ properties.put(Ldap.LDAP_PEOPLE_TREE, "people")
+ properties.put(Ldap.LDAP_GROUP_TREE, "group")
+ properties.put(Ldap.LDAP_USER_HOME, "%homeDirectory%")
+ properties.put(Ldap.LDAP_USER_ROOT, "/")
+ properties.put(Ldap.LDAP_GROUP_MEMBER, "uniqueMember")
+
+ properties.put(Ldap.LDAP_AUTH, "simple")
+ properties.put(Ldap.LDAP_BINDDN, "uid=kermit,ou=people,o=dcache,c=org")
+ properties.put(Ldap.LDAP_BINDPW, "kermitTheFrog")
+
+ properties
+ }
+
+ ldapPlugin = new Ldap(pluginProperties)
+
}
- def ldapPlugin = new Ldap(pluginProperties)
+ after {
+ server.stop()
+ }
"map(Set[Principal])" should "return matching Uid and Gid Principals for an existent user name" in {
val principals = new util.HashSet[Principal]()
- principals add new UserNamePrincipal("testuser")
+ principals add new UserNamePrincipal("kermit")
ldapPlugin.map(principals)
- principals.size should be (3)
- principals should contain (new UserNamePrincipal("testuser"))
- principals should contain (new UidPrincipal("50999"))
- principals should contain (new GidPrincipal("3752", true))
+ principals.size should be (4)
+ principals should contain (new UserNamePrincipal("kermit"))
+ principals should contain (new UidPrincipal("1000"))
+ principals should contain (new GidPrincipal("1000", true))
+ principals should contain (new GidPrincipal("1001", false))
}
it should "leave the principals set unchanged for a non existent user name" in {
@@ -59,7 +78,7 @@ class LdapPluginTest extends FlatSpec with Matchers {
}
"map(UserNamePrincipal)" should "return a UidPrincipal for an existing user name" in {
- ldapPlugin.map(new UserNamePrincipal("testuser")) should be (new UidPrincipal("50999"))
+ ldapPlugin.map(new UserNamePrincipal("kermit")) should be (new UidPrincipal("1000"))
}
it should "throw a NoSuchPrincipalException if a user does not exist" in {
@@ -70,11 +89,11 @@ class LdapPluginTest extends FlatSpec with Matchers {
}
"reverseMap" should "return a Set containing a UserNamePrincipal for an existing Uid" in {
- ldapPlugin.reverseMap(new UidPrincipal("50999")) should contain (new UserNamePrincipal("testuser"))
+ ldapPlugin.reverseMap(new UidPrincipal("1000")) should contain (new UserNamePrincipal("kermit"))
}
it should "return a serializable Set" in {
- val set = ldapPlugin.reverseMap(new UidPrincipal("50999"))
+ val set = ldapPlugin.reverseMap(new UidPrincipal("1000"))
set.isInstanceOf[java.io.Serializable] should be (true)
}
@@ -86,23 +105,23 @@ class LdapPluginTest extends FlatSpec with Matchers {
}
it should "return a Set containing a GroupNamePrincipal for an existing Gid" in {
- ldapPlugin.reverseMap(new GidPrincipal("3752", true)) should contain (new GroupNamePrincipal("htw-berlin"))
+ ldapPlugin.reverseMap(new GidPrincipal("1001", true)) should contain (new GroupNamePrincipal("actor"))
}
it should "throw a NoSuchPrincipalException for a non existent Gid" in {
intercept[NoSuchPrincipalException] {
- ldapPlugin.reverseMap(new GidPrincipal("51000", true))
+ ldapPlugin.reverseMap(new GidPrincipal("1002", true))
}
}
"session" should "return the user's home and root directory, and the access rights" in {
val attr = new java.util.HashSet[AnyRef]()
- ldapPlugin.session(setAsJavaSet(Set[Principal](new UserNamePrincipal("testuser"))), attr)
+ ldapPlugin.session(setAsJavaSet(Set[Principal](new UserNamePrincipal("bernd"))), attr)
- attr should have size 3
- attr should contain (new HomeDirectory("/root"))
- attr should contain (new RootDirectory("/root/dcache-cloud/testuser/home"))
+ attr should have size 2
+ attr should contain (new HomeDirectory("/home/bernd"))
+ attr should contain (new RootDirectory("/"))
}
}
diff --git a/pom.xml b/pom.xml
index 2b1188153eb..5d7db29f783 100644
--- a/pom.xml
+++ b/pom.xml
@@ -827,6 +827,11 @@
rados4j
0.0.2
+
+ org.dcache
+ ldap4testing
+ 1.0
+