This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
983b3a9
commit 0bd49c4
Showing
2 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
'use strict'; | ||
|
||
var request = require('supertest'), | ||
express = require('express'), | ||
fspath = require('path'), | ||
colors = require('colors'), | ||
assert = require('assert'); | ||
|
||
var lib = require(fspath.join(__dirname, '../lib/index')); | ||
|
||
function genericHandlers(router) { | ||
var handlers = require('./handlers2'); | ||
router.get('*', handlers.get); | ||
return router; | ||
} | ||
|
||
var acl = [{ | ||
'role': 'user', | ||
'paths': [ | ||
{ | ||
'path': '/', | ||
'verbs': ['GET'] | ||
}, | ||
{ | ||
'path': '/foo', | ||
'verbs': ['GET'] | ||
} | ||
] | ||
}]; | ||
|
||
describe('test-prefix.js - should let all through', function() { | ||
describe('strip prefix - true', function() { | ||
var app, router; | ||
app = express(); | ||
router = express.Router(); | ||
|
||
before(function() { | ||
router.all('*', function(req, res, next) { | ||
req.connection.pskRole = 'user'; | ||
next(); | ||
}); | ||
router.all( | ||
'*', | ||
lib('foobar', acl, function(){}, { | ||
prefix: '/fit' | ||
}) | ||
); | ||
app.use('/', genericHandlers(router)); | ||
}); | ||
it('/ should be 200', function(done) { | ||
request(app) | ||
.get('/') | ||
.expect(200, done); | ||
}); | ||
it('/fit/ should be 200', function(done) { | ||
request(app) | ||
.get('/fit/') | ||
.expect(200, done); | ||
}); | ||
it('/foo should be 200', function(done) { | ||
request(app) | ||
.get('/foo') | ||
.expect(200, done); | ||
}); | ||
it('/fit/foo should be 200', function(done) { | ||
request(app) | ||
.get('/fit/foo') | ||
.expect(200, done); | ||
}); | ||
}); | ||
describe('strip trailing slash - false', function() { | ||
var app, router; | ||
app = express(); | ||
router = express.Router(); | ||
|
||
before(function() { | ||
router.all('*', function(req, res, next) { | ||
req.connection.pskRole = 'user'; | ||
next(); | ||
}) | ||
router.all( | ||
'*', | ||
lib('foobar', acl, function(){}, { | ||
prefix: undefined | ||
}) | ||
); | ||
app.use('/', genericHandlers(router)); | ||
}); | ||
it('/ should be 200', function(done) { | ||
request(app) | ||
.get('/') | ||
.expect(200, done); | ||
}); | ||
it('/fit/ should be 401', function(done) { | ||
request(app) | ||
.get('/fit/') | ||
.expect(401, done); | ||
}); | ||
it('/foo should be 200', function(done) { | ||
request(app) | ||
.get('/foo') | ||
.expect(200, done); | ||
}); | ||
it('/fit/foo should be 401', function(done) { | ||
request(app) | ||
.get('/fit/foo') | ||
.expect(401, done); | ||
}); | ||
}); | ||
}); |