Skip to content

Instantly share code, notes, and snippets.

@molekilla
Created August 21, 2014 14:07
Show Gist options
  • Save molekilla/126c85344be1177e10b8 to your computer and use it in GitHub Desktop.
Save molekilla/126c85344be1177e10b8 to your computer and use it in GitHub Desktop.
hapi-bearer-token
/*globals expect:true*/
var Hapi = require('hapi');
var server = require('./../../../lib/hapi');
describe("Users controller", function() {
it("should return HTTP 401 when no bearer header auth is found", function(done) {
server.inject({ method: 'POST', url: '/api/v1/users' }, function (res) {
expect(res.statusCode).toBe(401);
done();
});
});
it("should return HTTP 500 when bearer code is a mismatch", function(done) {
server.inject({ method: 'POST', url: '/api/v1/users', headers: { authorization: "Bearer abc" } }, function (res) {
expect(res.statusCode).toBe(500);
done();
});
});
it("should return HTTP 200 for /api/v1/users", function(done) {
server.inject({ method: 'POST', url: '/api/v1/users', headers: { authorization: "Bearer a1b2c3" } }, function (res) {
expect(res.statusCode).toBe(201);
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment