[Pkg-javascript-commits] [node-keygrip] 52/68: refactor tests to use mocha

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Fri Jun 27 22:13:28 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to branch master
in repository node-keygrip.

commit cafbfef4a24d7c7e89a93eee31b8f508609990aa
Author: Jonathan Ong <jonathanrichardong at gmail.com>
Date:   Sat May 17 15:18:54 2014 -0700

    refactor tests to use mocha
---
 .gitignore   |  2 ++
 package.json |  7 ++++--
 test.js      | 70 ++++++++++++++++++++++++++++++++++--------------------------
 3 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/.gitignore b/.gitignore
index 92dfc88..4662435 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 lib/defaultKeys.js
 defaultKeys.js
+node_modules
+.DS_Store*
diff --git a/package.json b/package.json
index 35740da..e45908c 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,10 @@
   "version": "1.0.0",
   "description": "Key signing and verification for rotated credentials",
   "scripts": {
-    "test": "node test.js"
+    "test": "mocha --reporter spec"
   },
-  "repository": "expressjs/keygrip"
+  "repository": "expressjs/keygrip",
+  "devDependencies": {
+    "mocha": "1"
+  }
 }
diff --git a/test.js b/test.js
index 7fe7352..c660ce5 100644
--- a/test.js
+++ b/test.js
@@ -5,54 +5,64 @@ var assert = require("assert")
   , Keygrip = require("./")
   , keylist, keys, hash, index
 
-// keygrip takes an array of keys. If missing or empty, it will throw.
-assert.throws(function() {
-	keys = new Keygrip(/* empty list */);
-}, /must be provided/);
+describe('keygrip(keys)', function () {
+  it('should throw if keys are missing or empty', function () {
+    // keygrip takes an array of keys. If missing or empty, it will throw.
+    assert.throws(function() {
+      keys = new Keygrip(/* empty list */);
+    }, /must be provided/);
+  })
+})
 
-// Randomly generated key - don't use this for something real. Don't be that person.
-keys = new Keygrip(['06ae66fdc6c2faf5a401b70e0bf885cb']);  
+describe('keygrip([key])', function () {
+  it('should sign a string', function () {
+    // Randomly generated key - don't use this for something real. Don't be that person.
+    keys = new Keygrip(['06ae66fdc6c2faf5a401b70e0bf885cb']);
 
-// .sign returns the hash for the first key
-// all hashes are SHA1 HMACs in url-safe base64
-hash = keys.sign("bieberschnitzel")
-assert.ok(/^[\w\-]{27}$/.test(hash))
-
-
-// but we're going to use our list.
-// (note that the 'new' operator is optional)
-keylist = ["SEKRIT3", "SEKRIT2", "SEKRIT1"] // keylist will be modified in place, so don't reuse
-keys = Keygrip(keylist)
-testKeygripInstance(keys);
-
-
-// now pass in a different hmac algorithm and encoding
-keylist = ["Newest", "AnotherKey", "Oldest"]
-keys = Keygrip(keylist, "sha256", "hex")
-testKeygripInstance(keys);
+    // .sign returns the hash for the first key
+    // all hashes are SHA1 HMACs in url-safe base64
+    hash = keys.sign("bieberschnitzel")
+    assert.ok(/^[\w\-]{27}$/.test(hash))
+  })
+})
 
+describe('keygrip([keys...])', function () {
+  it('should sign a string', function () {
+    // but we're going to use our list.
+    // (note that the 'new' operator is optional)
+    keylist = ["SEKRIT3", "SEKRIT2", "SEKRIT1"] // keylist will be modified in place, so don't reuse
+    keys = Keygrip(keylist)
+    testKeygripInstance(keys);
+  })
 
+  it('should sign a string with a different algorithm and encoding', function () {
+    // now pass in a different hmac algorithm and encoding
+    keylist = ["Newest", "AnotherKey", "Oldest"]
+    keys = Keygrip(keylist, "sha256", "hex")
+    testKeygripInstance(keys);
+  })
+})
 
 function testKeygripInstance(keys) {
 	hash = keys.sign("bieberschnitzel")
-	
+
 	// .index returns the index of the first matching key
 	index = keys.index("bieberschnitzel", hash)
 	assert.equal(index, 0)
-	
+
 	// .verify returns the a boolean indicating a matched key
 	var matched = keys.verify("bieberschnitzel", hash)
 	assert.ok(matched)
-	
+
 	index = keys.index("bieberschnitzel", "o_O")
 	assert.equal(index, -1)
-	
+
 	// rotate a new key in, and an old key out
 	keylist.unshift("SEKRIT4")
 	keylist.pop()
-	
+
 	// if index > 0, it's time to re-sign
 	index = keys.index("bieberschnitzel", hash)
 	assert.equal(index, 1)
-	hash = keys.sign("bieberschnitzel")	
-}
\ No newline at end of file
+	hash = keys.sign("bieberschnitzel")
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-keygrip.git



More information about the Pkg-javascript-commits mailing list