From cc255998a1ad72324a3e21ed3c0ab97b6e4c72b7 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Mon, 7 Nov 2011 13:05:15 -0700
Subject: [PATCH] port to nodejs 0.6.0 without breaking support for 0.4.x. 
 closes #535

---
 bin/browserid                         | 29 ++++++++++++---------------
 bin/keysigner                         | 17 +++++++---------
 bin/verifier                          |  2 +-
 lib/browserid/ca.js                   |  8 ++++----
 lib/browserid/email.js                |  6 +++---
 lib/browserid/http_forward.js         |  2 +-
 lib/browserid/wsapi.js                | 12 +++++------
 lib/keysigner/ca.js                   | 10 ++++-----
 lib/validate.js                       |  2 +-
 package.json                          |  8 ++++----
 tests/ca-test.js                      |  4 ++--
 tests/cert-emails-test.js             |  4 ++--
 tests/cookie-session-security-test.js |  6 +++---
 tests/db-test.js                      |  4 ++--
 tests/forgotten-email-test.js         |  2 +-
 tests/lib/start-stop.js               |  4 ++--
 tests/lib/test_env.js                 |  1 -
 tests/lib/wsapi.js                    |  2 +-
 tests/password-bcrypt-update-test.js  |  4 ++--
 tests/password-length-test.js         |  2 +-
 20 files changed, 61 insertions(+), 68 deletions(-)

diff --git a/bin/browserid b/bin/browserid
index 75b8e889c..985da85a5 100755
--- a/bin/browserid
+++ b/bin/browserid
@@ -41,24 +41,21 @@ path = require('path'),
 url = require('url'),
 http = require('http');
 sessions = require('connect-cookie-session'),
-urlparse = require('urlparse');
-
-// add lib/ to the require path
-require.paths.unshift(path.join(__dirname, '..', 'lib'));
+urlparse = require('urlparse'),
+express = require('express');
 
 const
-wsapi = require('browserid/wsapi.js'),
-ca = require('browserid/ca.js'),
-httputils = require('httputils.js'),
-express = require('express'),
-secrets = require('secrets.js'),
-db = require('db.js'),
-config = require('configuration.js'),
-heartbeat = require('heartbeat.js'),
-metrics = require("metrics.js"),
-logger = require("logging.js").logger
-forward = require('browserid/http_forward'),
-shutdown = require('shutdown');
+wsapi = require('../lib/browserid/wsapi.js'),
+ca = require('../lib/browserid/ca.js'),
+httputils = require('../lib/httputils.js'),
+secrets = require('../lib/secrets.js'),
+db = require('../lib/db.js'),
+config = require('../lib/configuration.js'),
+heartbeat = require('../lib/heartbeat.js'),
+metrics = require('../lib/metrics.js'),
+logger = require('../lib/logging.js').logger
+forward = require('../lib/browserid/http_forward'),
+shutdown = require('../lib/shutdown');
 
 var app = undefined;
 
diff --git a/bin/keysigner b/bin/keysigner
index 90314d82a..c62d67b92 100755
--- a/bin/keysigner
+++ b/bin/keysigner
@@ -41,17 +41,14 @@ const
 path = require('path'),
 express = require('express');
 
-// add lib/ to the require path for our own libs
-require.paths.unshift(path.join(__dirname, '..', 'lib'));
-
 const
-config = require('configuration.js'),
-validate = require('validate.js'),
-metrics = require("metrics.js"),
-logger = require("logging.js").logger,
-ca = require('keysigner/ca.js'),
-heartbeat = require('heartbeat'),
-shutdown = require('shutdown');
+config = require('../lib/configuration.js'),
+validate = require('../lib/validate.js'),
+metrics = require('../lib/metrics.js'),
+logger = require('../lib/logging.js').logger,
+ca = require('../lib/keysigner/ca.js'),
+heartbeat = require('../lib/heartbeat'),
+shutdown = require('../lib/shutdown');
 
 // create an express server
 var app = express.createServer();
diff --git a/bin/verifier b/bin/verifier
index ee641c35c..ef7d65dc3 100755
--- a/bin/verifier
+++ b/bin/verifier
@@ -37,7 +37,7 @@
  * ***** END LICENSE BLOCK ***** */
 
 const
-sys = require("sys"),
+util = require("util"),
 path = require('path'),
 url = require('url'),
 fs = require('fs'),
diff --git a/lib/browserid/ca.js b/lib/browserid/ca.js
index ab07a592b..be126993d 100644
--- a/lib/browserid/ca.js
+++ b/lib/browserid/ca.js
@@ -39,11 +39,11 @@
 var jwcert = require('jwcrypto/jwcert'),
     jwk = require('jwcrypto/jwk'),
     jws = require('jwcrypto/jws'),
-    configuration = require('configuration'),
+    config = require('../configuration.js'),
     path = require("path"),
     fs = require("fs");
 
-var HOSTNAME = configuration.get('hostname');
+var HOSTNAME = config.get('hostname');
 
 function parsePublicKey(serializedPK) {
   return jwk.PublicKey.deserialize(serializedPK);
@@ -58,7 +58,7 @@ function parseCert(serializedCert) {
 function certify(email, publicKey, expiration) {
   if (expiration == null)
     throw "expiration cannot be null";
-  return new jwcert.JWCert(HOSTNAME, expiration, publicKey, {email: email}).sign(configuration.get('secret_key'));
+  return new jwcert.JWCert(HOSTNAME, expiration, publicKey, {email: email}).sign(config.get('secret_key'));
 }
 
 function verifyChain(certChain, cb) {
@@ -79,4 +79,4 @@ exports.certify = certify;
 exports.verifyChain = verifyChain;
 exports.parsePublicKey = parsePublicKey;
 exports.parseCert = parseCert;
-exports.PUBLIC_KEY = configuration.get('public_key');
+exports.PUBLIC_KEY = config.get('public_key');
diff --git a/lib/browserid/email.js b/lib/browserid/email.js
index b3b746018..b0b873d70 100644
--- a/lib/browserid/email.js
+++ b/lib/browserid/email.js
@@ -34,13 +34,13 @@
  * ***** END LICENSE BLOCK ***** */
 
 const
-db = require('db.js'),
+db = require('../db.js'),
 emailer = require('nodemailer'),
 fs = require('fs'),
 path = require('path'),
 mustache = require('mustache'),
-config = require('configuration.js'),
-logger = require('logging.js').logger;
+config = require('../configuration.js'),
+logger = require('../logging.js').logger;
 
 /* if smtp parameters are configured, use them */
 var smtp_params = config.get('smtp');
diff --git a/lib/browserid/http_forward.js b/lib/browserid/http_forward.js
index 5db137c2c..0a9468f79 100644
--- a/lib/browserid/http_forward.js
+++ b/lib/browserid/http_forward.js
@@ -2,7 +2,7 @@ const
 url = require('url'),
 http = require('http'),
 https = require('https'),
-logger = require('logging.js').logger,
+logger = require('../logging.js').logger,
 querystring = require('querystring');
 
 module.exports = function(dest, req, res, cb) {
diff --git a/lib/browserid/wsapi.js b/lib/browserid/wsapi.js
index 0e94ed046..5194a066a 100644
--- a/lib/browserid/wsapi.js
+++ b/lib/browserid/wsapi.js
@@ -39,17 +39,17 @@
 // with HTTP methods and the like, apply middleware, etc.
 
 const
-db = require('db.js'),
+db = require('../db.js'),
 url = require('url'),
-httputils = require('httputils.js'),
+httputils = require('../httputils.js'),
 email = require('./email.js'),
 bcrypt = require('bcrypt'),
 crypto = require('crypto'),
-logger = require('logging.js').logger,
+logger = require('../logging.js').logger,
 ca = require('./ca.js'),
-config = require('configuration.js'),
-validate = require('validate'),
-forward = require('browserid/http_forward');
+config = require('../configuration.js'),
+validate = require('../validate'),
+forward = require('./http_forward.js');
 
 // log a user out, clearing everything from their session except the csrf token
 function clearAuthenticatedUser(session) {
diff --git a/lib/keysigner/ca.js b/lib/keysigner/ca.js
index ab07a592b..e5fe4f884 100644
--- a/lib/keysigner/ca.js
+++ b/lib/keysigner/ca.js
@@ -39,11 +39,11 @@
 var jwcert = require('jwcrypto/jwcert'),
     jwk = require('jwcrypto/jwk'),
     jws = require('jwcrypto/jws'),
-    configuration = require('configuration'),
     path = require("path"),
-    fs = require("fs");
+    fs = require("fs"),
+    config = require('../configuration.js');
 
-var HOSTNAME = configuration.get('hostname');
+var HOSTNAME = config.get('hostname');
 
 function parsePublicKey(serializedPK) {
   return jwk.PublicKey.deserialize(serializedPK);
@@ -58,7 +58,7 @@ function parseCert(serializedCert) {
 function certify(email, publicKey, expiration) {
   if (expiration == null)
     throw "expiration cannot be null";
-  return new jwcert.JWCert(HOSTNAME, expiration, publicKey, {email: email}).sign(configuration.get('secret_key'));
+  return new jwcert.JWCert(HOSTNAME, expiration, publicKey, {email: email}).sign(config.get('secret_key'));
 }
 
 function verifyChain(certChain, cb) {
@@ -79,4 +79,4 @@ exports.certify = certify;
 exports.verifyChain = verifyChain;
 exports.parsePublicKey = parsePublicKey;
 exports.parseCert = parseCert;
-exports.PUBLIC_KEY = configuration.get('public_key');
+exports.PUBLIC_KEY = config.get('public_key');
diff --git a/lib/validate.js b/lib/validate.js
index 56161cea8..0dceafa66 100644
--- a/lib/validate.js
+++ b/lib/validate.js
@@ -46,7 +46,7 @@
 
 const
 logger = require('./logging.js').logger,
-httputils = require('httputils.js');
+httputils = require('./httputils.js');
 
 module.exports = function (params) {
   return function(req, resp, next) {
diff --git a/package.json b/package.json
index 8499c3c57..5f5c922c0 100644
--- a/package.json
+++ b/package.json
@@ -3,13 +3,13 @@
   , "version": "0.0.1"
   , "private": true
   , "dependencies": {
-      "connect": "1.6.2"
-    , "express": "2.4.3"
+      "connect": "1.7.2"
+    , "express": "2.5.0"
     , "xml2js": "0.1.5"
     , "nodemailer": "0.1.18"
     , "mustache": "0.3.1-dev"
-    , "vows": "0.5.8"
-    , "bcrypt": "0.4.0"
+    , "vows": "0.5.13"
+    , "bcrypt": "*"
     , "ejs": "0.4.3"
     , "temp": "0.2.0"
     , "express-csrf": "0.3.2"
diff --git a/tests/ca-test.js b/tests/ca-test.js
index c990798d0..959da6642 100755
--- a/tests/ca-test.js
+++ b/tests/ca-test.js
@@ -41,8 +41,8 @@ const assert = require('assert'),
 vows = require('vows'),
 start_stop = require('./lib/start-stop.js'),
 wsapi = require('./lib/wsapi.js'),
-email = require('browserid/email.js'),
-ca = require('browserid/ca.js'),
+email = require('../lib/browserid/email.js'),
+ca = require('../lib/browserid/ca.js'),
 jwcert = require('jwcrypto/jwcert'),
 jwk = require('jwcrypto/jwk'),
 jws = require('jwcrypto/jws');
diff --git a/tests/cert-emails-test.js b/tests/cert-emails-test.js
index 59d0521f1..3155c85bb 100755
--- a/tests/cert-emails-test.js
+++ b/tests/cert-emails-test.js
@@ -41,8 +41,8 @@ const assert = require('assert'),
 vows = require('vows'),
 start_stop = require('./lib/start-stop.js'),
 wsapi = require('./lib/wsapi.js'),
-email = require('browserid/email.js'),
-ca = require('browserid/ca.js'),
+email = require('../lib/browserid/email.js'),
+ca = require('../lib/browserid/ca.js'),
 jwcert = require('jwcrypto/jwcert'),
 jwk = require('jwcrypto/jwk'),
 jws = require('jwcrypto/jws'),
diff --git a/tests/cookie-session-security-test.js b/tests/cookie-session-security-test.js
index b6dce5906..9070a55cd 100755
--- a/tests/cookie-session-security-test.js
+++ b/tests/cookie-session-security-test.js
@@ -41,9 +41,9 @@ const assert = require('assert'),
 vows = require('vows'),
 start_stop = require('./lib/start-stop.js'),
 wsapi = require('./lib/wsapi.js'),
-wcli = require('wsapi_client');
-email = require('browserid/email.js'),
-ca = require('browserid/ca.js'),
+wcli = require('../lib/wsapi_client.js');
+email = require('../lib/browserid/email.js'),
+ca = require('../lib/browserid/ca.js'),
 jwcert = require('jwcrypto/jwcert'),
 jwk = require('jwcrypto/jwk'),
 jws = require('jwcrypto/jws');
diff --git a/tests/db-test.js b/tests/db-test.js
index 6f7d92c5e..c03b22197 100755
--- a/tests/db-test.js
+++ b/tests/db-test.js
@@ -44,8 +44,8 @@ assert = require('assert'),
 vows = require('vows'),
 fs = require('fs'),
 path = require('path'),
-db = require('db.js'),
-configuration = require('configuration.js');
+db = require('../lib/db.js'),
+configuration = require('../lib/configuration.js');
 
 var suite = vows.describe('db');
 // disable vows (often flakey?) async error behavior
diff --git a/tests/forgotten-email-test.js b/tests/forgotten-email-test.js
index 25ee67630..3f30279d7 100755
--- a/tests/forgotten-email-test.js
+++ b/tests/forgotten-email-test.js
@@ -41,7 +41,7 @@ const assert = require('assert'),
 vows = require('vows'),
 start_stop = require('./lib/start-stop.js'),
 wsapi = require('./lib/wsapi.js'),
-email = require('browserid/email.js');
+email = require('../lib/browserid/email.js');
 
 var suite = vows.describe('forgotten-email');
 
diff --git a/tests/lib/start-stop.js b/tests/lib/start-stop.js
index 1f2893910..6bb240e36 100644
--- a/tests/lib/start-stop.js
+++ b/tests/lib/start-stop.js
@@ -40,8 +40,8 @@ path = require('path'),
 wsapi = require('./wsapi.js'),
 spawn = require('child_process').spawn,
 events = require('events'),
-config = require('configuration'),
-db = require('db');
+config = require('../../lib/configuration.js'),
+db = require('../../lib/db.js');
 
 var proc = undefined;
 
diff --git a/tests/lib/test_env.js b/tests/lib/test_env.js
index 9017cebc5..40f12e4c8 100644
--- a/tests/lib/test_env.js
+++ b/tests/lib/test_env.js
@@ -46,4 +46,3 @@ if (undefined === process.env['NODE_ENV']) {
   console.log("(Woah.  Running tests without a test_ configuration.  Is this *really* what you want?)");
 }
 
-require.paths.unshift(require('path').join(__dirname, '..', '..', 'lib'));
diff --git a/tests/lib/wsapi.js b/tests/lib/wsapi.js
index d41d25314..91a0941c6 100644
--- a/tests/lib/wsapi.js
+++ b/tests/lib/wsapi.js
@@ -34,7 +34,7 @@
  * ***** END LICENSE BLOCK ***** */
 
 const
-wcli = require('wsapi_client');
+wcli = require('../../lib/wsapi_client');
 
 // the client "context"
 var context = {};
diff --git a/tests/password-bcrypt-update-test.js b/tests/password-bcrypt-update-test.js
index 15f684112..bb5470e47 100755
--- a/tests/password-bcrypt-update-test.js
+++ b/tests/password-bcrypt-update-test.js
@@ -42,8 +42,8 @@ require('assert'),
 vows = require('vows'),
 start_stop = require('./lib/start-stop.js'),
 wsapi = require('./lib/wsapi.js'),
-db = require('db.js'),
-config = require('configuration.js'),
+db = require('../lib/db.js'),
+config = require('../lib/configuration.js'),
 bcrypt = require('bcrypt');
 
 var suite = vows.describe('password-length');
diff --git a/tests/password-length-test.js b/tests/password-length-test.js
index 055afd202..0a4b7e2dc 100755
--- a/tests/password-length-test.js
+++ b/tests/password-length-test.js
@@ -42,7 +42,7 @@ require('assert'),
 vows = require('vows'),
 start_stop = require('./lib/start-stop.js'),
 wsapi = require('./lib/wsapi.js'),
-email = require('browserid/email.js');
+email = require('../lib/browserid/email.js');
 
 var suite = vows.describe('password-length');
 
-- 
GitLab