From bdbea069adebe65b1bc7d0f1849bb1bcd0643b7a Mon Sep 17 00:00:00 2001 From: Mathew Woods Date: Thu, 20 Oct 2016 10:22:11 -0500 Subject: [PATCH] testing lines of code that are not documented...and documenting them - DK/MW --- README.md | 8 ++++++++ test/authorizer.test.js | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 368ae03..a86bd63 100644 --- a/README.md +++ b/README.md @@ -108,9 +108,17 @@ For more validation options see [auth0/jsonwebtoken](https://github.com/auth0/no Append the jwt token using query string: ```javascript +//// token part of query string //// var socket = io.connect('http://localhost:9000', { 'query': 'token=' + your_jwt }); + + +//// token coming in as Authorization Header //// +var socket = io.connect('http://localhost:9000', { + 'extraHeaders': { Authorization: `Bearer ${your_jwt}` } +}); + ``` Append the jwt token using 'Authorization Header' (Bearer Token): diff --git a/test/authorizer.test.js b/test/authorizer.test.js index 3e2efc3..654c0ae 100644 --- a/test/authorizer.test.js +++ b/test/authorizer.test.js @@ -27,7 +27,7 @@ describe('authorizer', function () { describe('when the user is logged in', function() { - beforeEach(function (done) { + before(function (done) { request.post({ url: 'http://localhost:9000/login', form: { username: 'jose', password: 'Pa123' }, @@ -38,6 +38,17 @@ describe('authorizer', function () { }.bind(this)); }); + it('auth headers are supported', function (done){ + var socket = io.connect('http://localhost:9000', { + 'forceNew':true, + 'extraHeaders': {'Authorization': `Bearer ${this.token}`} + }); + socket.on('connect', function(){ + socket.close(); + done(); + }).on('error', done); + }); + it('should do the handshake and connect', function (done){ var socket = io.connect('http://localhost:9000', { 'forceNew':true,