Skip to content
Browse files

* tests/add.ldif: Test LDIF

  • Loading branch information...
1 parent e1f0e91 commit 64f01097c7c362beeaad6757d2a85222691e259f @jeremycx committed Jan 3, 2013
Showing with 285 additions and 0 deletions.
  1. +31 −0 tests/add.ldif
  2. +7 −0 tests/add2.ldif
  3. +21 −0 tests/run_sync.sh
  4. +226 −0 tests/synctest.js
View
31 tests/add.ldif
@@ -0,0 +1,31 @@
+dn: cn=Edward,ou=Accounting,dc=sample,dc=com
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: Edward
+sn: Root
+userPassword:: e1NIQX01ZW42RzZNZXpScm9UM1hLcWtkUE9tWS9CZlE9
+
+dn: cn=Fred,ou=Accounting,dc=sample,dc=com
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: Fred
+sn: Root
+userPassword: ajsh
+
+dn: cn=Gary,ou=Accounting,dc=sample,dc=com
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: Gary
+sn: Root
+userPassword:: e1NIQX01ZW42RzZNZXpScm9UM1hLcWtkUE9tWS9CZlE9
+
+dn: cn=Hank,ou=Accounting,dc=sample,dc=com
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: Hank
+sn: Root
+userPassword:: e1NIQX01ZW42RzZNZXpScm9UM1hLcWtkUE9tWS9CZlE9
View
7 tests/add2.ldif
@@ -0,0 +1,7 @@
+dn: cn=Ian,ou=Accounting,dc=sample,dc=com
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: Ian
+sn: Root
+userPassword:: e1NIQX01ZW42RzZNZXpScm9UM1hLcWtkUE9tWS9CZlE9
View
21 tests/run_sync.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+SLAPD=/usr/local/libexec/slapd
+SLAPADD=/usr/local/sbin/slapadd
+MKDIR=/bin/mkdir
+RM=/bin/rm
+KILL=/bin/kill
+
+killall -9 slapd
+
+$RM -rf ./openldap-data
+$MKDIR openldap-data
+
+$SLAPADD -f slapd.conf < startup.ldif
+$SLAPADD -f slapd.conf < add.ldif
+# $SLAPD -d0 -f slapd.conf -hldap://localhost:1234 &
+
+node synctest.js
+
+# kill slapd
+# $KILL -15 `cat slapd.pid`
View
226 tests/synctest.js
@@ -0,0 +1,226 @@
+/*jshint globalstrict: true, node: true, trailing:true, unused:true, es5:true */
+
+"use strict";
+
+var LDAP = require('../LDAP');
+var ldap;
+var assert = require('assert');
+var schema;
+var spawn = require('child_process').spawn;
+var slapd;
+
+var tests = [
+ {
+ name: 'SEARCH AFTER RECONN2',
+ description: 'Searching after a reconnect',
+ fn: function() {
+ setTimeout(process.exit, 60000);
+ }
+ },
+ {
+ name: 'SEARCH AFTER RECONN',
+ description: 'Searching after a reconnect',
+ fn: function() {
+ ldap.search({
+ base: 'cn=Jason,ou=Accounting,dc=sample,dc=com',
+ attrs: 'cn sn',
+ scope: ldap.BASE
+ }, function(err, data) {
+ assert(!err, err);
+ assert(data && data[0] && data[0].cn && data[0].cn[0] == 'Jason', 'Search fail');
+ next();
+ });
+ }
+ },
+ {
+ name: 'SYNCREPL UPDATE',
+ description: 'Get update after server bounce',
+ fn: function() {
+ ldap.add('cn=Jason,ou=Accounting,dc=sample,dc=com',
+ [
+ { attr: 'objectClass', vals: [ 'organizationalPerson', 'person', 'top' ] },
+ { attr: 'sn', vals: [ 'Jones' ] },
+ { attr: 'cn', vals: [ 'Jason' ] },
+ { attr: 'userPassword', vals: [ 'foobarbaz' ] }
+ ], function(err) {
+ if (err) {
+ assert(!err, err.toString());
+ }
+ next();
+ });
+ }
+ },
+ {
+ name: 'SYNCREPL DISCONNECT',
+ description: 'Disconnect while syncrepl running',
+ fn: function() {
+ restartserver();
+ setTimeout(next, 5000); // lots of time to reconnect...
+ }
+ },
+ {
+ name: 'SYNCREPL',
+ description: 'Syncrepl',
+ fn: function() {
+ ldap.sync({
+ base: 'dc=sample,dc=com',
+ scope: ldap.SUBTREE,
+ filter: '(objectClass=*)',
+ attrs: '*',
+ rid: '767',
+ cookie: '',
+ syncentry: function(data) {
+ console.log('--------------------------');
+ console.log(data);
+ console.log('--------------------------');
+ if (data[0] && data[0].cn && data[0].cn[0] == 'Hank') {
+ console.log('Next for Hank');
+ next();
+ }
+ if (data[0] && data[0].cn && data[0].cn[0] == 'Ian') {
+ // this one will get SYNCREPL RESTART to continue.
+ console.log('Next for Ian');
+ next();
+ }
+ },
+ syncresult: function(data) {
+ console.log('Syncresult: ' + data);
+
+ },
+ syncintermediate: function(data) {
+ console.log('Intermediate: ' + data);
+ },
+ newcookie: function(cookie) {
+ console.log('--------------------------');
+ console.log('newcookie: ' + cookie);
+ console.log('--------------------------');
+ }
+ });
+ }
+ },
+ {
+ name: 'SYNCREPL BIND',
+ description: 'Bind in prep for ADD',
+ fn: function() {
+ ldap.simpleBind({
+ binddn: 'cn=Manager,dc=sample,dc=com',
+ password: 'secret'
+ }, function(err) {
+ assert(!err);
+ next();
+ });
+ }
+ },
+ {
+ name: 'SEARCH BEFORE RECONN',
+ description: 'Searching before a reconnect',
+ fn: function() {
+ ldap.search({
+ base: 'cn=Hank,ou=Accounting,dc=sample,dc=com',
+ attrs: 'cn sn',
+ scope: ldap.BASE
+ }, function(err, data) {
+ assert(!err, err);
+ assert(data && data[0] && data[0].cn && data[0].cn[0] == 'Hank', 'Search fail');
+ next();
+ });
+ }
+ },
+ {
+ name: 'OPEN',
+ fn: function() {
+ ldap.open(function(err) {
+ if (err) {
+ assert(!err, err.toString());
+ }
+ next();
+ });
+ ldap.on('disconnect', function() {
+ console.log('Got disconnect event');
+ })
+ .on('connect', function() {
+ console.log('Got connected event');
+ });
+
+ }
+ },
+ {
+ name: 'INST',
+ fn: function() {
+ try {
+ ldap = new LDAP({ uri: 'ldap://localhost:1234', version: 3 });
+ } catch (e) {
+ assert(false, 'Error in instantiation: ' + e.toString());
+ }
+ next();
+ }
+ },
+ {
+ name: 'INST - FAIL',
+ fn: function() {
+ try {
+ ldap = new LDAP();
+ } catch (e) {
+ next(); // should fail
+ return;
+ }
+ assert(false, 'Instantiate hould have failed');
+ }
+ },
+ {
+ name: 'KILL SERVER',
+ fn: function() {
+ try {
+ restartserver();
+ } catch (e) {
+ assert(false, 'Error in spawn of slapd');
+ }
+ setTimeout(next, 1000);
+ }
+ },
+ {
+ name: 'LAUNCH SERVER',
+ fn: function() {
+ try {
+ launchserver();
+ } catch (e) {
+ assert(false, 'Error in spawn of slapd');
+ }
+ setTimeout(next, 1000);
+ }
+ }
+];
+
+var currenttest = {
+ name: 'INIT',
+ fn: next
+}
+
+function launchserver() {
+ slapd = spawn('/usr/local/libexec/slapd', ['-d0', '-f', './slapd.conf', '-hldap://localhost:1234']);
+}
+
+function restartserver() {
+ var oldpid = slapd.pid;
+
+ slapd.kill('SIGKILL');
+ launchserver();
+ assert(oldpid !== slapd.pid, 'Server did not restart');
+}
+
+
+function next() {
+ console.log(currenttest.name +
+ " ".substr(0, 32 - currenttest.name.length) +
+ ' [OK]');
+
+ currenttest = tests.pop();
+ if (currenttest) {
+ process.nextTick(currenttest.fn);
+ } else {
+ ldap.close();
+ }
+}
+
+console.log('');
+next();

0 comments on commit 64f0109

Please sign in to comment.
Something went wrong with that request. Please try again.