Browse files

added Forbidden response error

  • Loading branch information...
1 parent 869d72f commit 148ce06ec090d32a0474ececfbea95207fbd5b1a @coen-hyde coen-hyde committed Mar 16, 2012
Showing with 25 additions and 0 deletions.
  1. +5 −0 lib/journey/errors.js
  2. +20 −0 test/journey-test.js
View
5 lib/journey/errors.js
@@ -34,3 +34,8 @@ this.NotAuthorized = function (msg) {
this.headers = {};
this.body = { error: msg || 'Not Authorized' };
};
+this.Forbidden = function (msg) {
+ this.status = 403;
+ this.headers = {};
+ this.body = { error: msg || 'Forbidden' };
+};
View
20 test/journey-test.js
@@ -104,6 +104,16 @@ router.map(function (map) {
bind(function (res) { res.send(200, {"Content-Type":"text/html"}, "OK"); });
});
});
+
+ map.path('/forbidden', function() {
+ forbidden_filter = function (request, body, cb) {
+ cb(new journey.Forbidden());
+ }
+
+ this.filter(forbidden_filter, function () {
+ this.get('/response').bind(function (res) { res.send(200, {"Content-Type":"text/html"}, "OK"); });
+ });
+ });
});
var mock = require('../lib/journey/mock-request').mock(router);
@@ -304,6 +314,16 @@ vows.describe('Journey').addBatch({
assert.equal(res.headers.allow, 'GET');
}
},
+ // This request is trying to access a non accessible location on the webserver, so Journey responds
+ // with a 403 'Forbidden'
+ "A request to a forbidden location": {
+ topic: function () {
+ return get('/forbidden/response');
+ },
+ "returns a 403": function (res) {
+ assert.equal(res.status, 403);
+ }
+ },
//
// SERVER ERRORS (5xx)

0 comments on commit 148ce06

Please sign in to comment.