From 6add8b52e173a5e65beabfc394830c7202172167 Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Thu, 2 Jan 2014 13:56:47 -0800 Subject: [PATCH 1/6] version bump v0.11.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a935a73..cdfe5413 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harp", - "version": "0.11.0", + "version": "0.11.1", "description": "Static web server with built in preprocessing", "author": "Brock Whitten ", "contributors": [ From c14ba3c97705420138bf991dee78b0a0b6d8541f Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Thu, 2 Jan 2014 14:26:37 -0800 Subject: [PATCH 2/6] writes failing test for basic auth integration --- test/apps/auth/single/_harp.json | 3 +++ test/apps/auth/single/index.md | 3 +++ test/auth.js | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 test/apps/auth/single/_harp.json create mode 100644 test/apps/auth/single/index.md create mode 100644 test/auth.js diff --git a/test/apps/auth/single/_harp.json b/test/apps/auth/single/_harp.json new file mode 100644 index 00000000..680a72c8 --- /dev/null +++ b/test/apps/auth/single/_harp.json @@ -0,0 +1,3 @@ +{ + "basicAuth": "foo:bar" +} \ No newline at end of file diff --git a/test/apps/auth/single/index.md b/test/apps/auth/single/index.md new file mode 100644 index 00000000..067e436a --- /dev/null +++ b/test/apps/auth/single/index.md @@ -0,0 +1,3 @@ +# Hello World + +This is a protected page \ No newline at end of file diff --git a/test/auth.js b/test/auth.js new file mode 100644 index 00000000..54c06a5d --- /dev/null +++ b/test/auth.js @@ -0,0 +1,23 @@ +var should = require("should") +var request = require('request') +var path = require('path') +var harp = require("../") + +describe("basicAuth", function(){ + + describe("single", function(done){ + var projectPath = path.join(__dirname, "apps/auth/single") + + before(function(done){ + harp.server(projectPath, { port: 8310 }, done) + }) + + it("should be a protected page", function(done){ + request('http://localhost:8310/', function (e, r, b) { + r.statusCode.should.eql(401) + done() + }) + }) + }) + +}) \ No newline at end of file From ba25078a1b790d4594aa27144b3b39c1d302f141 Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Thu, 2 Jan 2014 16:25:01 -0800 Subject: [PATCH 3/6] implements basic auth --- lib/index.js | 4 +++- lib/middleware.js | 38 +++++++++++++++++++++++++++----- test/apps/auth/single/_harp.json | 2 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index eb97d585..5d6ee7a4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -24,6 +24,7 @@ exports.server = function(dirPath, options, callback){ connect.createServer( middleware.regProjectFinder(dirPath), middleware.setup, + middleware.basicAuth, middleware.underscore, middleware.mwl, middleware.static, @@ -47,6 +48,7 @@ exports.multihost = function(dirPath, options, callback){ middleware.index(dirPath), middleware.hostProjectFinder(dirPath), middleware.setup, + middleware.basicAuth, middleware.underscore, middleware.mwl, middleware.static, @@ -119,7 +121,7 @@ exports.pipeline = function(root){ poly.render(sourceFile, function(error, body){ if(error) return next(error) if(!body) return next() // 404 - + var outputType = polymer.helpers.outputType(sourceFile) var mimeType = helpers.mimeType(outputType) var charset = mime.charsets.lookup(mimeType) diff --git a/lib/middleware.js b/lib/middleware.js index 89875a53..870f875d 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -1,10 +1,11 @@ var path = require("path") var fs = require("fs") -var helpers = require("./helpers") -var mime = require("mime") -var polymer = require('terraform') -var pkg = require('../package.json') -var skin = require('./skin') +var helpers = require("./helpers") +var mime = require("mime") +var polymer = require('terraform') +var pkg = require('../package.json') +var skin = require('./skin') +var connect = require('connect') var send = require('../node_modules/connect/node_modules/send') , utils = require('../node_modules/connect/lib/utils') @@ -399,6 +400,33 @@ exports.setup = function(req, rsp, next){ next() } +/** + * Basic Auth + */ + +exports.basicAuth = function(req, rsp, next){ + + // default empty + var creds = [] + + // allow array + if(req.setup.config.hasOwnProperty("basicAuth") && req.setup.config["basicAuth"] instanceof Array) + creds = req.setup.config["basicAuth"] + + // allow string + if(req.setup.config.hasOwnProperty("basicAuth") && typeof req.setup.config["basicAuth"] === 'string') + creds = [req.setup.config["basicAuth"]] + + // move on if no creds + if(creds.length === 0) return next() + + // use connect auth lib iterate over all creds provided + connect.basicAuth(function(user, pass){ + return creds.some(function(cred){ + return cred === user + ":" + pass + }) + })(req, rsp, next) +} /** * Sets up the poly object diff --git a/test/apps/auth/single/_harp.json b/test/apps/auth/single/_harp.json index 680a72c8..aa2840d8 100644 --- a/test/apps/auth/single/_harp.json +++ b/test/apps/auth/single/_harp.json @@ -1,3 +1,3 @@ { - "basicAuth": "foo:bar" + "basicAuth": ["foo:baz", "foo:bar"] } \ No newline at end of file From 5291fc6db7487202a3cd19b09edde5c6c06013aa Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Mon, 6 Jan 2014 19:37:58 -0800 Subject: [PATCH 4/6] Replace `!!!` shorthand with `doctype` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even if we don’t update to Jade 1.0.0, it’s probably better to remove this sooner rather than later. --- lib/sample/_layout.jade | 2 +- test/apps/basic/public/404.jade | 2 +- test/apps/basic/public/_layout.jade | 2 +- test/apps/err-invalid-and-valid-stylsheets/public/_layout.jade | 2 +- test/apps/err-invalid-vars/public/index.jade | 2 +- test/apps/err-invalid-vars/public/style.jade | 2 +- test/apps/err-missing-404/public/_layout.jade | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/sample/_layout.jade b/lib/sample/_layout.jade index 040858b3..dd2d77b2 100644 --- a/lib/sample/_layout.jade +++ b/lib/sample/_layout.jade @@ -1,4 +1,4 @@ -!!! +doctype html head link(rel="stylesheet", href="/main.css") diff --git a/test/apps/basic/public/404.jade b/test/apps/basic/public/404.jade index de93d2ad..3020b903 100644 --- a/test/apps/basic/public/404.jade +++ b/test/apps/basic/public/404.jade @@ -1,4 +1,4 @@ -!!! +doctype html head style. diff --git a/test/apps/basic/public/_layout.jade b/test/apps/basic/public/_layout.jade index 4984b4f2..e7686925 100644 --- a/test/apps/basic/public/_layout.jade +++ b/test/apps/basic/public/_layout.jade @@ -1,4 +1,4 @@ -!!! +doctype html head link(rel="stylesheet", href="/css/main.css") diff --git a/test/apps/err-invalid-and-valid-stylsheets/public/_layout.jade b/test/apps/err-invalid-and-valid-stylsheets/public/_layout.jade index 0b20f53b..1e2c411f 100644 --- a/test/apps/err-invalid-and-valid-stylsheets/public/_layout.jade +++ b/test/apps/err-invalid-and-valid-stylsheets/public/_layout.jade @@ -1,4 +1,4 @@ -!!! +doctype html head link(rel="stylesheet", href="/css/main.css") diff --git a/test/apps/err-invalid-vars/public/index.jade b/test/apps/err-invalid-vars/public/index.jade index 58e3aa61..78668c92 100644 --- a/test/apps/err-invalid-vars/public/index.jade +++ b/test/apps/err-invalid-vars/public/index.jade @@ -1,4 +1,4 @@ -!!! +doctype html head link(rel="stylesheet", href="/main.css", type="text/css") diff --git a/test/apps/err-invalid-vars/public/style.jade b/test/apps/err-invalid-vars/public/style.jade index c94b77c2..5c758d05 100644 --- a/test/apps/err-invalid-vars/public/style.jade +++ b/test/apps/err-invalid-vars/public/style.jade @@ -1,4 +1,4 @@ -!!! +doctype html head link(rel="stylesheet", href="/bad.css", type="text/css") diff --git a/test/apps/err-missing-404/public/_layout.jade b/test/apps/err-missing-404/public/_layout.jade index 062079ba..4cc5ab3d 100644 --- a/test/apps/err-missing-404/public/_layout.jade +++ b/test/apps/err-missing-404/public/_layout.jade @@ -1,4 +1,4 @@ -!!! +doctype html head link(rel="stylesheet", href="/css/main.css") From af99a5a49f6e54317195a094417dc597a4c18579 Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Mon, 6 Jan 2014 19:46:43 -0800 Subject: [PATCH 5/6] =?UTF-8?q?Missed=20the=20most=20important=20one?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/templates/_layout.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/templates/_layout.jade b/lib/templates/_layout.jade index 2dc0b6bd..9620579d 100644 --- a/lib/templates/_layout.jade +++ b/lib/templates/_layout.jade @@ -1,4 +1,4 @@ -!!! +doctype html(lang="en") head meta(charset="utf-8") From 06fcc5171943303303fb69ea4e32ff8dde301a6a Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Wed, 8 Jan 2014 14:23:41 -0800 Subject: [PATCH 6/6] adds test for fetching via basic auth --- test/apps/auth/single/_harp.json | 2 +- test/auth.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/apps/auth/single/_harp.json b/test/apps/auth/single/_harp.json index aa2840d8..31b7d846 100644 --- a/test/apps/auth/single/_harp.json +++ b/test/apps/auth/single/_harp.json @@ -1,3 +1,3 @@ { - "basicAuth": ["foo:baz", "foo:bar"] + "basicAuth": ["foo:bar"] } \ No newline at end of file diff --git a/test/auth.js b/test/auth.js index 54c06a5d..4df2d218 100644 --- a/test/auth.js +++ b/test/auth.js @@ -18,6 +18,20 @@ describe("basicAuth", function(){ done() }) }) + + it("should fetch protected resource with correct creds", function(done){ + request({ + method: "GET", + url: 'http://localhost:8310/', + auth: { + 'user': 'foo', + 'pass': 'bar' + } + }, function (e, r, b) { + r.statusCode.should.eql(200) + done() + }) + }) }) }) \ No newline at end of file