[nodejs-basic-auth-connect] Initial import
Jamie Nguyen
jamielinux at fedoraproject.org
Thu Mar 13 18:02:40 UTC 2014
commit 628d776a86fd8d55efcef9cff833bae703c34e93
Author: Jamie Nguyen <j at jamielinux.com>
Date: Thu Mar 13 18:02:26 2014 +0000
Initial import
.gitignore | 1 +
nodejs-basic-auth-connect.spec | 67 +++++++++++++++++++++++
sources | 1 +
test.js | 117 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 186 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e69de29..232eadf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/basic-auth-connect-1.0.0.tgz
diff --git a/nodejs-basic-auth-connect.spec b/nodejs-basic-auth-connect.spec
new file mode 100644
index 0000000..b20c7ba
--- /dev/null
+++ b/nodejs-basic-auth-connect.spec
@@ -0,0 +1,67 @@
+%{?nodejs_find_provides_and_requires}
+
+%global enable_tests 0
+
+Name: nodejs-basic-auth-connect
+Version: 1.0.0
+Release: 1%{?dist}
+Summary: Basic authentication middleware for Node.js and Connect
+License: MIT
+Group: System Environment/Libraries
+URL: https://github.com/expressjs/basic-auth-connect
+Source0: http://registry.npmjs.org/basic-auth-connect/-/basic-auth-connect-%{version}.tgz
+# This test file is not included in the NPM tarball.
+Source1: https://raw.github.com/expressjs/basic-auth-connect/7a0b814741446933cf78a303fd269b4f54d74f12/test.js
+
+BuildArch: noarch
+%if 0%{?fedora} >= 19
+ExclusiveArch: %{nodejs_arches} noarch
+%else
+ExclusiveArch: %{ix86} x86_64 %{arm} noarch
+%endif
+
+BuildRequires: nodejs-packaging
+
+%if 0%{?enable_tests}
+BuildRequires: mocha
+BuildRequires: npm(connect)
+BuildRequires: npm(should)
+BuildRequires: npm(supertest)
+%endif
+
+%description
+%{summary}.
+
+
+%prep
+%setup -q -n package
+cp -p %{SOURCE1} .
+
+
+%build
+#nothing to do
+
+
+%install
+mkdir -p %{buildroot}%{nodejs_sitelib}/basic-auth-connect
+cp -pr package.json index.js \
+ %{buildroot}%{nodejs_sitelib}/basic-auth-connect
+
+%nodejs_symlink_deps
+
+
+%if 0%{?enable_tests}
+%check
+%nodejs_symlink_deps --check
+NODE_ENV=test /usr/bin/mocha --require should --reporter spec
+%endif
+
+
+%files
+%doc README.md
+%{nodejs_sitelib}/basic-auth-connect
+
+
+%changelog
+* Sat Mar 08 2014 Jamie Nguyen <jamielinux at fedoraproject.org> - 1.0.0-1
+- initial package
diff --git a/sources b/sources
index e69de29..e715285 100644
--- a/sources
+++ b/sources
@@ -0,0 +1 @@
+cf1d903c052d9d704acde0cba82da8f2 basic-auth-connect-1.0.0.tgz
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..a3ed9d5
--- /dev/null
+++ b/test.js
@@ -0,0 +1,117 @@
+
+var request = require('supertest');
+var connect = require('connect');
+var basicAuth = require('./');
+
+function test(app, signature) {
+ describe(signature, function(){
+ describe('when missing Authorization', function(){
+ it('should respond with 401 and WWW-Authenticate', function(done){
+ request(app)
+ .get('/')
+ .end(function(err, res){
+ res.statusCode.should.equal(401);
+ res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
+ done();
+ });
+ })
+ })
+
+ describe('when valid', function(){
+ it('should next()', function(done){
+ request(app)
+ .get('/')
+ .set('Authorization', 'Basic dGo6dG9iaTpsZWFybmJvb3N0')
+ .end(function(err, res){
+ res.statusCode.should.equal(200);
+ res.text.should.equal('secret!');
+ done();
+ });
+ })
+ })
+
+ describe('when invalid credentials', function(){
+ it('should respond with 401', function(done){
+ request(app)
+ .get('/')
+ .set('Authorization', 'Basic dGo69iaQ==')
+ .end(function(err, res){
+ res.statusCode.should.equal(401);
+ res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
+ res.text.should.equal('Unauthorized');
+ done();
+ });
+ })
+ })
+
+ describe('when authorization header is not Basic', function(){
+ it('should respond with 400', function(done){
+ request(app)
+ .get('/')
+ .set('Authorization', 'Digest dGo69iaQ==')
+ .end(function(err, res){
+ res.statusCode.should.equal(400);
+ res.text.should.match(/Bad Request/);
+ done();
+ });
+ })
+ })
+
+ describe('when authorization header is malformed - contains only one part', function(){
+ it('should respond with 400', function(done){
+ request(app)
+ .get('/')
+ .set('Authorization', 'invalid')
+ .end(function(err, res){
+ res.statusCode.should.equal(400);
+ res.text.should.match(/Bad Request/);
+ done();
+ });
+ })
+ })
+ })
+}
+
+var app = connect();
+
+app.use(basicAuth('tj', 'tobi:learnboost'));
+
+app.use(function(req, res, next){
+ req.user.should.equal('tj');
+ res.end('secret!');
+});
+
+test(app, 'basicAuth(user, pass)');
+
+
+
+var app = connect();
+
+app.use(basicAuth(function(user, pass){
+ return 'tj' == user && 'tobi:learnboost' == pass;
+}));
+
+app.use(function(req, res, next){
+ req.user.should.equal('tj');
+ res.end('secret!');
+});
+
+test(app, 'basicAuth(callback)');
+
+
+
+var app = connect();
+
+app.use(basicAuth(function(user, pass, fn){
+ var ok = 'tj' == user && 'tobi:learnboost' == pass;
+ fn(null, ok
+ ? { name: 'tj' }
+ : null);
+}));
+
+app.use(function(req, res, next){
+ req.user.name.should.equal('tj');
+ res.end('secret!');
+});
+
+test(app, 'basicAuth(callback) async');
More information about the scm-commits
mailing list