Skip to content

Commit

Permalink
Merge branch 'master' into disable-unwanted-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
theninj4 committed May 16, 2016
2 parents 9d76c47 + 67a311c commit 21dc309
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var bodyParser = require("body-parser");
var cookieParser = require("cookie-parser");
var jsonApi = require("./jsonApi.js");
var debug = require("./debugging.js");
var responseHelper = require("./responseHelper.js");
var url = require("url");

app.use(function(req, res, next) {
Expand Down Expand Up @@ -113,7 +114,14 @@ router.authenticate = function(request, res, callback) {
router._authFunction(request, function(err) {
if (!err) return callback();

res.status(401).end();
var errorWrapper = {
status: "401",
code: "UNAUTHORIZED",
title: "Authentication Failed",
detail: err || "You are not authorised to access this resource."
};
var payload = responseHelper.generateError(request, errorWrapper);
res.status(401).json(payload);
});
};

Expand Down
10 changes: 5 additions & 5 deletions test/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var request = require("request");
var assert = require("assert");
var jsonApiTestServer = require("../example/server.js");

var helpers = require("./helpers.js");

describe("Testing jsonapi-server", function() {
describe("authentication", function() {
Expand All @@ -14,10 +14,10 @@ describe("Testing jsonapi-server", function() {
"blockMe": "please"
}
};
request(data, function(err, res) {
request(data, function(err, res, json) {
assert.equal(err, null);
assert.equal(res.statusCode, "401", "Expecting 401");

helpers.validateError(json);
done();
});
});
Expand All @@ -30,10 +30,10 @@ describe("Testing jsonapi-server", function() {
"cookie": "blockMe=please"
}
};
request(data, function(err, res) {
request(data, function(err, res, json) {
assert.equal(err, null);
assert.equal(res.statusCode, "401", "Expecting 401");

helpers.validateError(json);
done();
});
});
Expand Down

0 comments on commit 21dc309

Please sign in to comment.