-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add specCompliance option, option to set case insensitive for b…
…earerType (#172) * feat: add bearerTypeCaseSensitive option * feat: add bearerTypeCaseSensitive option * set correct specCompliance value in readme.md * Update Readme.md Co-authored-by: KaKa <[email protected]> Signed-off-by: Aras Abbasi <[email protected]> --------- Signed-off-by: Aras Abbasi <[email protected]> Co-authored-by: KaKa <[email protected]>
- Loading branch information
1 parent
c27b75a
commit bf525cb
Showing
9 changed files
with
235 additions
and
14 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
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
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,15 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const test = tap.test | ||
const Fastify = require('fastify') | ||
const plugin = require('../') | ||
const { FST_BEARER_AUTH_INVALID_SPEC } = require('../lib/errors') | ||
|
||
test('throws FST_BEARER_AUTH_INVALID_SPEC when invalid value for specCompliance was used', async (t) => { | ||
t.plan(1) | ||
|
||
const fastify = Fastify() | ||
|
||
t.rejects(() => fastify.register(plugin, { keys: new Set(['123456']), specCompliance: 'invalid' }), new FST_BEARER_AUTH_INVALID_SPEC()) | ||
}) |
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,85 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const test = tap.test | ||
const fastify = require('fastify')() | ||
const plugin = require('../') | ||
|
||
fastify.register(plugin, { keys: new Set(['123456']), specCompliance: 'rfc6749' }) | ||
|
||
fastify.get('/test', (req, res) => { | ||
res.send({ hello: 'world' }) | ||
}) | ||
|
||
test('bearerType starting with capital letter', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'Bearer 123456' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 200) | ||
t.same(JSON.parse(response.body), { hello: 'world' }) | ||
}) | ||
|
||
test('bearerType all lowercase', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'bearer 123456' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 200) | ||
t.same(JSON.parse(response.body), { hello: 'world' }) | ||
}) | ||
|
||
test('bearerType all uppercase', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'Bearer 123456' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 200) | ||
t.same(JSON.parse(response.body), { hello: 'world' }) | ||
}) | ||
|
||
test('invalid key route fails correctly', async (t) => { | ||
t.plan(2) | ||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'bearer 987654' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 401) | ||
t.match(JSON.parse(response.body).error, /invalid authorization header/) | ||
}) | ||
|
||
test('missing space between bearerType and key fails correctly', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'bearer123456' | ||
} | ||
}) | ||
t.equal(response.statusCode, 401) | ||
t.match(JSON.parse(response.body).error, /invalid authorization header/) | ||
}) |
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,85 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const test = tap.test | ||
const fastify = require('fastify')() | ||
const plugin = require('../') | ||
|
||
fastify.register(plugin, { keys: new Set(['123456']), specCompliance: 'rfc6750' }) | ||
|
||
fastify.get('/test', (req, res) => { | ||
res.send({ hello: 'world' }) | ||
}) | ||
|
||
test('bearerType starting with capital letter', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'Bearer 123456' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 200) | ||
t.same(JSON.parse(response.body), { hello: 'world' }) | ||
}) | ||
|
||
test('bearerType all lowercase', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'bearer 123456' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 401) | ||
t.match(JSON.parse(response.body).error, /invalid authorization header/) | ||
}) | ||
|
||
test('bearerType all uppercase', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'Bearer 123456' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 200) | ||
t.same(JSON.parse(response.body), { hello: 'world' }) | ||
}) | ||
|
||
test('invalid key route fails correctly', async (t) => { | ||
t.plan(2) | ||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'bearer 987654' | ||
} | ||
}) | ||
|
||
t.equal(response.statusCode, 401) | ||
t.match(JSON.parse(response.body).error, /invalid authorization header/) | ||
}) | ||
|
||
test('missing space between bearerType and key fails correctly', async (t) => { | ||
t.plan(2) | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
authorization: 'bearer123456' | ||
} | ||
}) | ||
t.equal(response.statusCode, 401) | ||
t.match(JSON.parse(response.body).error, /invalid authorization header/) | ||
}) |
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