summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2006-08-14 23:41:10 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:15:36 -0500
commit1ace9b6ec0949aea9ca5897724b1acca8eee57d9 (patch)
tree03faa96563d37f85335d256019ccaa6dc37a1bc9
parentc846d461fa1edb97219be87c4ba37e97e85dd488 (diff)
downloadsamba-1ace9b6ec0949aea9ca5897724b1acca8eee57d9.tar.gz
samba-1ace9b6ec0949aea9ca5897724b1acca8eee57d9.tar.bz2
samba-1ace9b6ec0949aea9ca5897724b1acca8eee57d9.zip
r17543: Patch from Martin Kühl <martin.kuehl@gmail.com> to extend the
samba3sam test cases for ldb_map, and to include this into our default 'make test'. (This used to be commit f69a842314b3d5c57c3fa1f5b1bae3ee6d42da2b)
-rwxr-xr-xsource4/script/tests/test_ejs.sh3
-rwxr-xr-xtestprogs/ejs/samba3sam27
-rw-r--r--testprogs/ejs/samba3sam.js259
3 files changed, 281 insertions, 8 deletions
diff --git a/source4/script/tests/test_ejs.sh b/source4/script/tests/test_ejs.sh
index b4370b0384..aabefcf233 100755
--- a/source4/script/tests/test_ejs.sh
+++ b/source4/script/tests/test_ejs.sh
@@ -16,6 +16,7 @@ incdir=`dirname $0`
. $incdir/test_functions.sh
SCRIPTDIR=../testprogs/ejs
+DATADIR=../testdata
PATH=bin:$PATH
export PATH
@@ -28,6 +29,8 @@ testit "ejsnet.js" $SCRIPTDIR/ejsnet.js $CONFIGURATION -U$USERNAME%$PASSWORD $DO
testit "ldb.js" $SCRIPTDIR/ldb.js `pwd` $CONFIGURATION || failed=`expr $failed + 1`
+testit "samba3sam.js" $SCRIPTDIR/samba3sam.js `pwd` $DATADIR/samba3/ || failed=`expr $failed + 1`
+
testit "winreg" scripting/bin/winreg $CONFIGURATION ncalrpc: 'HKLM' -U$USERNAME%$PASSWORD || failed=`expr $failed + 1`
testok $0 $failed
diff --git a/testprogs/ejs/samba3sam b/testprogs/ejs/samba3sam
index 0f6d1a82ab..5d9fd6f514 100755
--- a/testprogs/ejs/samba3sam
+++ b/testprogs/ejs/samba3sam
@@ -48,14 +48,7 @@ ok = s4.connect("tdb://samba4.ldb");
assert(ok);
println("Initial samba4 LDIF...");
-var path = "../../source/setup/provision_init.ldif";
-var ldif = sys.file_load(mypath + path);
-ldif = substitute_var(ldif, local);
-assert(ldif != undefined);
-ok = s4.add(ldif);
-assert(ok);
-
-var path = "../../source/setup/provision_templates.ldif";
+var path = "../../testdata/samba3/provision_samba3sam.ldif"
var ldif = sys.file_load(mypath + path);
ldif = substitute_var(ldif, local);
assert(ldif != undefined);
@@ -112,6 +105,24 @@ for (var i in oc) {
assert(oc[i] == "posixGroup" || oc[i] == "group");
}
+println("Looking up by objectClass");
+msg = s4.search("(|(objectClass=user)(cn=Administrator))");
+assert(msg != undefined);
+assert(msg.length == 2);
+for (var i = 0; i < msg.length; i++) {
+ assert((msg[i].dn == "unixName=Administrator,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl") ||
+ (msg[i].dn == "unixName=nobody,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl"));
+}
+
+println("Looking up by objectClass");
+msg = s4.search("(|(objectClass=user)(cn=Administrator))");
+assert(msg != undefined);
+assert(msg.length == 2);
+for (var i = 0; i < msg.length; i++) {
+ assert((msg[i].dn == "unixName=Administrator,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl") ||
+ (msg[i].dn == "unixName=nobody,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl"));
+}
+
println("Adding a record that will be fallbacked");
ok = s4.add("
dn: cn=Foo,dc=idealx,dc=org
diff --git a/testprogs/ejs/samba3sam.js b/testprogs/ejs/samba3sam.js
new file mode 100644
index 0000000000..15bcd42632
--- /dev/null
+++ b/testprogs/ejs/samba3sam.js
@@ -0,0 +1,259 @@
+#!/usr/bin/env smbscript
+/*
+ (C) Jelmer Vernooij <jelmer@samba.org> 2005
+ (C) Martin Kuehl <mkhl@samba.org> 2006
+ Published under the GNU GPL
+ Sponsored by Google Summer of Code
+ */
+
+var sys;
+var ldb = ldb_init();
+var smb3 = ldb_init();
+var smb4 = ldb_init();
+var options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA");
+if (options == undefined) {
+ println("Failed to parse options");
+ return -1;
+}
+
+libinclude("base.js");
+
+if (options.ARGV.length != 2) {
+ println("Usage: samba3sam.js <TESTDIR> <DATADIR>");
+ return -1;
+}
+
+prefix = options.ARGV[0];
+datadir = options.ARGV[1];
+
+function setup_modules(sys, ldb, from, to) {
+ var ldif = sys.file_load(datadir + "provision_samba3sam.ldif");
+ ldif = substitute_var(ldif, from);
+ assert(ldif != undefined);
+ var ok = ldb.add(ldif);
+ assert(ok);
+
+ var ok = ldb.add("
+dn: @MAP=samba3sam
+@FROM: " + from.BASEDN + "
+@TO: " + to.BASEDN + "
+
+dn: @MODULES
+@LIST: rootdse,paged_results,server_sort,extended_dn,asq,samldb,objectclass,password_hash,operational,objectguid,rdn_name,samba3sam,partition
+
+dn: @PARTITION
+partition: " + from.BASEDN + ":" + from.URL + "
+partition: " + to.BASEDN + ":" + to.URL + "
+replicateEntries: @SUBCLASSES
+replicateEntries: @ATTRIBUTES
+replicateEntries: @INDEXLIST
+");
+ assert(ok);
+}
+
+function setup_data(sys, ldb, remote) {
+ var ldif = sys.file_load(datadir + "samba3.ldif");
+ ldif = substitute_var(ldif, remote);
+ assert(ldif != undefined);
+ var ok = ldb.add(ldif);
+ assert(ok);
+}
+
+function search_tests(ldb) {
+ println("Looking up by non-mapped attribute");
+ var msg = ldb.search("(cn=Administrator)");
+ assert(msg.length == 1);
+ assert(msg[0].cn == "Administrator");
+
+ println("Looking up by mapped attribute");
+ var msg = ldb.search("(name=Backup Operators)");
+ assert(msg.length == 1);
+ assert(msg[0].name == "Backup Operators");
+
+ println("Looking up by old name of renamed attribute");
+ var msg = ldb.search("(displayName=Backup Operators)");
+ assert(msg.length == 0);
+
+ println("Looking up mapped entry containing SID");
+ var msg = ldb.search("(cn=Replicator)");
+ assert(msg.length == 1);
+ println(msg[0].dn);
+ assert(msg[0].dn == "cn=Replicator,ou=Groups,sambaDomainName=TESTS,dc=vernstok,dc=nl");
+ assert(msg[0].objectSid == "S-1-5-21-4231626423-2410014848-2360679739-552");
+
+ println("Checking mapping of objectClass");
+ var oc = msg[0].objectClass;
+ assert(oc != undefined);
+ for (var i in oc) {
+ assert(oc[i] == "posixGroup" || oc[i] == "group");
+ }
+
+ println("Looking up by objectClass");
+ var msg = ldb.search("(|(objectClass=user)(cn=Administrator))");
+ assert(msg != undefined);
+ assert(msg.length == 2);
+ for (var i = 0; i < msg.length; i++) {
+ assert((msg[i].dn == "unixName=Administrator,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl") ||
+ (msg[i].dn == "unixName=nobody,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl"));
+ }
+}
+
+function modify_tests(ldb, remote) {
+ println("Adding a record that will be fallbacked");
+ ok = ldb.add("
+dn: cn=Foo,dc=idealx,dc=org
+foo: bar
+blah: Blie
+cn: Foo
+showInAdvancedViewOnly: TRUE
+");
+ assert(ok);
+
+ println("Checking for existence of record (local)");
+ /* TODO: This record must be searched in the local database, which is currently only supported for base searches
+ * msg = ldb.search("(cn=Foo)", new Array('foo','blah','cn','showInAdvancedViewOnly'));
+ * TODO: Actually, this version should work as well but doesn't...
+ * msg = ldb.search("(cn=Foo)", "dc=idealx,dc=org", ldb.LDB_SCOPE_SUBTREE new Array('foo','blah','cn','showInAdvancedViewOnly'));
+ */
+ msg = ldb.search("", "cn=Foo,dc=idealx,dc=org", ldb.LDB_SCOPE_BASE new Array('foo','blah','cn','showInAdvancedViewOnly'));
+ assert(msg.length == 1);
+ assert(msg[0].showInAdvancedViewOnly == "TRUE");
+ assert(msg[0].foo == "bar");
+ assert(msg[0].blah == "Blie");
+
+ println("Adding record that will be mapped");
+ ok = ldb.add("
+dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
+objectClass: user
+unixName: bin
+unicodePwd: geheim
+cn: Niemand
+");
+ assert(ok);
+
+ println("Checking for existence of record (remote)");
+ msg = ldb.search("(unixName=bin)", new Array('unixName','cn','dn', 'unicodePwd'));
+ assert(msg.length == 1);
+ assert(msg[0].cn == "Niemand");
+ assert(msg[0].unicodePwd == "geheim");
+
+ println("Checking for existence of record (local && remote)");
+ msg = ldb.search("(&(unixName=bin)(unicodePwd=geheim))", new Array('unixName','cn','dn', 'unicodePwd'));
+ assert(msg.length == 1); // TODO: should check with more records
+ assert(msg[0].cn == "Niemand");
+ assert(msg[0].unixName == "bin");
+ assert(msg[0].unicodePwd == "geheim");
+
+ println("Checking for existence of record (local || remote)");
+ msg = ldb.search("(|(unixName=bin)(unicodePwd=geheim))", new Array('unixName','cn','dn', 'unicodePwd'));
+ assert(msg.length == 1); // TODO: should check with more records
+ assert(msg[0].cn == "Niemand");
+ assert(msg[0].unixName == "bin" || msg[0].unicodePwd == "geheim");
+
+ println("Checking for data in destination database");
+ msg = remote.search("(cn=Niemand)");
+ assert(msg.length >= 1);
+ assert(msg[0].sambaSID == "S-1-5-21-4231626423-2410014848-2360679739-2001");
+ assert(msg[0].displayName == "Niemand");
+
+ println("Adding attribute...");
+ ok = ldb.modify("
+dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
+changetype: modify
+add: description
+description: Blah
+");
+ assert(ok);
+
+ println("Checking whether changes are still there...");
+ msg = ldb.search("(cn=Niemand)");
+ assert(msg.length >= 1);
+ assert(msg[0].cn == "Niemand");
+ assert(msg[0].description == "Blah");
+
+ println("Modifying attribute...");
+ ok = ldb.modify("
+dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
+changetype: modify
+replace: description
+description: Blie
+");
+ assert(ok);
+
+ println("Checking whether changes are still there...");
+ msg = ldb.search("(cn=Niemand)");
+ assert(msg.length >= 1);
+ assert(msg[0].description == "Blie");
+
+ println("Deleting attribute...");
+ ok = ldb.modify("
+dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
+changetype: modify
+delete: description
+");
+ assert(ok);
+
+ println("Checking whether changes are no longer there...");
+ msg = ldb.search("(cn=Niemand)");
+ assert(msg.length >= 1);
+ assert(msg[0].description == undefined);
+
+ println("Renaming record...");
+ ok = ldb.rename("cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl", "cn=Niemand,dc=vernstok,dc=nl");
+
+ println("Checking whether DN has changed...");
+ msg = ldb.search("(cn=Niemand)");
+ assert(msg.length == 1);
+ assert(msg[0].dn == "cn=Niemand,dc=vernstok,dc=nl");
+
+ println("Deleting record...");
+ ok = ldb.del("cn=Niemand,dc=vernstok,dc=nl");
+ assert(ok);
+
+ println("Checking whether record is gone...");
+ msg = ldb.search("(cn=Niemand)");
+ assert(msg.length == 0);
+}
+
+sys = sys_init();
+var ldbfile = prefix + "test.ldb";
+var ldburl = "tdb://" + ldbfile;
+
+var samba4 = new Object("samba4 partition info");
+var samba4.FILE = prefix + "samba4.ldb";
+var samba4.URL = "tdb://" + samba4.FILE;
+var samba4.BASEDN = "dc=vernstok,dc=nl";
+
+var samba3 = new Object("samba3 partition info");
+var samba3.FILE = prefix + "samba3.ldb";
+var samba3.URL = "tdb://" + samba3.FILE;
+var samba3.BASEDN = "cn=Samba3Sam," + samba4.BASEDN;
+
+sys.unlink(ldbfile);
+sys.unlink(samba3.FILE);
+sys.unlink(samba4.FILE);
+
+var ok = ldb.connect(ldburl);
+assert(ok);
+var ok = smb3.connect(samba3.URL);
+assert(ok);
+var ok = smb4.connect(samba4.URL);
+assert(ok);
+
+setup_data(sys, smb3, samba3);
+
+setup_modules(sys, ldb, samba4, samba3);
+
+ldb = ldb_init();
+var ok = ldb.connect(ldburl);
+assert(ok);
+
+search_tests(ldb, smb3);
+
+modify_tests(ldb, smb3);
+
+sys.unlink(ldbfile);
+sys.unlink(samba3.FILE);
+sys.unlink(samba4.FILE);
+
+return 0;