aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml10
-rw-r--r--package.json4
-rw-r--r--parseLDIF.js17
-rwxr-xr-xtest/testAll.js22
4 files changed, 39 insertions, 14 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..638a933
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+language: node_js
+node_js:
+ - "0.11"
+ - "0.10"
+ - "0.8"
+ - "0.6"
+install: npm install tosource
+before_script:
+ - cd test
+script: node testAll.js
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..788bb42
--- /dev/null
+++ b/package.json
@@ -0,0 +1,4 @@
+{
+ "name" : "parseLDIF",
+ "main" : "./parseLDIF.js"
+}
diff --git a/parseLDIF.js b/parseLDIF.js
index e060f54..a79cb11 100644
--- a/parseLDIF.js
+++ b/parseLDIF.js
@@ -163,17 +163,24 @@ var Base64 = {
}
+// RFC 2849 uses givenname, RFC 4519 uses givenName, we rather support
+// both
const usefulFields = ["birthyear", "c", "cn", "description",
"facsimiletelephonenumber", "givenName", "homePhone", "l", "mail",
"mobile", "mozillaHomeCountryName", "mozillaHomeLocalityName",
"mozillaHomePostalCode", "mozillaHomeState", "mozillaHomeStreet",
"mozillaHomeUrl", "mozillaNickname", "o", "sn", "st", "street",
- "telephoneNumber", "title", "objectclass"
+ "telephoneNumber", "title", "objectclass", "givenname"
];
function debug(str) {
if (debugState) {
- print(str);
+ if (console) {
+ console.log(str);
+ }
+ else {
+ print(str);
+ }
}
}
@@ -188,7 +195,6 @@ function debug(str) {
* - doesn’t even consider change requests, only complete values
* - doesn’t include version: field (seems to be ignored by
* Thunderbird as well).
- * - ignores multi-value attributes completely
* - ignores < links
*/
function parseLDIF(inStr) {
@@ -289,7 +295,6 @@ function parseLDIF(inStr) {
return out_records;
}
-if (arguments && arguments.length == 1) {
- var lines = readFile(arguments[0]).replace(/\r\n/g,"\n");
- print(parseLDIF(lines.split("\n")).toSource());
+if (exports) {
+ exports.parseLDIF = parseLDIF;
}
diff --git a/test/testAll.js b/test/testAll.js
index 9aabd43..232baa4 100755
--- a/test/testAll.js
+++ b/test/testAll.js
@@ -1,6 +1,8 @@
-#!/usr/bin/rhino
+#!/usr/bin/node
-load("../parseLDIF.js");
+var parse = require("../parseLDIF.js");
+var fs = require("fs");
+var toSource = require('tosource');
Object.prototype.equals = function(x) {
var p;
@@ -88,19 +90,23 @@ var expResults = {
};
var resultsCount = Object.keys(expResults).length;
+var success = 0;
for (var key in expResults) {
if (expResults.hasOwnProperty(key)) {
- var lines = readFile("example0" + key + ".ldif").replace(/\r\n/g,"\n");
- observed = parseLDIF(lines.split("\n"));
+ var lines = fs.readFileSync("example0" + key + ".ldif", "utf-8").
+ replace(/\r\n/g,"\n");
+ observed = parse.parseLDIF(lines.split("\n"));
if (observed.equals(expResults[key])) {
- print(key + "/" + resultsCount + " ... OK");
+ console.log(key + "/" + resultsCount + " ... OK");
}
else {
- print("Test " + key + " fails! Expected:\n" +
- expResults[key].toSource() +
- "\n----\nObserved:\n" + observed.toSource());
+ console.log("Test " + key + " fails! Expected:\n" +
+ toSource(expResults[key]) +
+ "\n----\nObserved:\n" + toSource(observed));
+ success = 1;
}
}
}
+process.exit(success);