Skip to content

Commit

Permalink
Fixing Local Auth guard & test
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Aug 27, 2014
1 parent 4b67d75 commit 46ca355
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
17 changes: 13 additions & 4 deletions lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var turtleio = require( "turtle.io" ),
REGEX_GETREWRITE = /HEAD|OPTIONS/i,
REGEX_BODY = /POST|PUT|PATCH/i,
REGEX_FORMENC = /application\/x-www-form-urlencoded/,
REGEX_BODY_SPLIT = /&|=/;
REGEX_BODY_SPLIT = /&|=/;

/**
* Tenso
Expand Down Expand Up @@ -186,7 +186,7 @@ function auth ( obj, config ) {
stateful = ( async || config.auth.local.enabled || config.security.csrf ),
authMap = {},
authUris = [],
sesh, fnCookie, fnSesh, luscaCsrf, luscaCsp, luscaXframe, luscaP3p, luscaHsts, luscaXssProtection, protection, passportAuth, passportInit, passportSession;
keys, sesh, fnCookie, fnSesh, luscaCsrf, luscaCsp, luscaXframe, luscaP3p, luscaHsts, luscaXssProtection, protection, passportAuth, passportInit, passportSession;

function asyncFlag () {
arguments[0].protectAsync = true;
Expand Down Expand Up @@ -254,6 +254,11 @@ function auth ( obj, config ) {
authUris = array.keys( authMap );
}

if ( config.auth.local.enabled ) {
authUris.push( "/" );
authUris.push( "/login" );
}

if ( stateful ) {
sesh = {
secret: config.session.secret || uuid(),
Expand Down Expand Up @@ -321,7 +326,11 @@ function auth ( obj, config ) {
} );

if ( authUris.length > 0 ) {
config.routes.get["/auth"] = authMap;
keys = array.keys( authMap ).length > 0;

if ( keys ) {
config.routes.get["/auth"] = authMap;
}

( function () {
var regex = "(?!/auth/(";
Expand All @@ -335,7 +344,7 @@ function auth ( obj, config ) {
obj.server.use( regex, guard ).blacklist( guard );
} )();

config.routes.get["/login"] = ( config.auth.local.enabled || config.auth.saml.enabled ) ? {login_uri: "/auth", instruction: "POST username/password to authenticate"} : {login_uri: "/auth"};
config.routes.get["/login"] = ( config.auth.local.enabled || config.auth.saml.enabled ) ? ( keys ? {login_uri: "/auth", instruction: "POST username/password to authenticate"} : {instruction: "POST username/password to authenticate"} ) : {login_uri: "/auth"};
}
else if ( config.auth.local.enabled || config.auth.saml.enabled ) {
config.routes.get["/login"] = {instruction: "POST username/password to authenticate"};
Expand Down
15 changes: 12 additions & 3 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function auth ( obj, config ) {
stateful = ( async || config.auth.local.enabled || config.security.csrf ),
authMap = {},
authUris = [],
sesh, fnCookie, fnSesh, luscaCsrf, luscaCsp, luscaXframe, luscaP3p, luscaHsts, luscaXssProtection, protection, passportAuth, passportInit, passportSession;
keys, sesh, fnCookie, fnSesh, luscaCsrf, luscaCsp, luscaXframe, luscaP3p, luscaHsts, luscaXssProtection, protection, passportAuth, passportInit, passportSession;

function asyncFlag () {
arguments[0].protectAsync = true;
Expand Down Expand Up @@ -83,6 +83,11 @@ function auth ( obj, config ) {
authUris = array.keys( authMap );
}

if ( config.auth.local.enabled ) {
authUris.push( "/" );
authUris.push( "/login" );
}

if ( stateful ) {
sesh = {
secret: config.session.secret || uuid(),
Expand Down Expand Up @@ -150,7 +155,11 @@ function auth ( obj, config ) {
} );

if ( authUris.length > 0 ) {
config.routes.get["/auth"] = authMap;
keys = array.keys( authMap ).length > 0;

if ( keys ) {
config.routes.get["/auth"] = authMap;
}

( function () {
var regex = "(?!/auth/(";
Expand All @@ -164,7 +173,7 @@ function auth ( obj, config ) {
obj.server.use( regex, guard ).blacklist( guard );
} )();

config.routes.get["/login"] = ( config.auth.local.enabled || config.auth.saml.enabled ) ? {login_uri: "/auth", instruction: "POST username/password to authenticate"} : {login_uri: "/auth"};
config.routes.get["/login"] = ( config.auth.local.enabled || config.auth.saml.enabled ) ? ( keys ? {login_uri: "/auth", instruction: "POST username/password to authenticate"} : {instruction: "POST username/password to authenticate"} ) : {login_uri: "/auth"};
}
else if ( config.auth.local.enabled || config.auth.saml.enabled ) {
config.routes.get["/login"] = {instruction: "POST username/password to authenticate"};
Expand Down
2 changes: 1 addition & 1 deletion src/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ var turtleio = require( "turtle.io" ),
REGEX_GETREWRITE = /HEAD|OPTIONS/i,
REGEX_BODY = /POST|PUT|PATCH/i,
REGEX_FORMENC = /application\/x-www-form-urlencoded/,
REGEX_BODY_SPLIT = /&|=/;
REGEX_BODY_SPLIT = /&|=/;
8 changes: 3 additions & 5 deletions test/tenso_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,10 @@ describe("Local", function () {

describe("GET /uuid (invalid)", function () {
it("returns an 'unauthorized' error", function (done) {
api( port )
api( port, true )
.get("/uuid")
.expectStatus(401)
.expectValue("data", null)
.expectValue("error", "Unauthorized")
.expectValue("status", 401)
.expectStatus(302)
.expectHeader("Location", "/login")
.end(function(err) {
if (err) throw err;
done();
Expand Down

0 comments on commit 46ca355

Please sign in to comment.