mirror of
https://github.com/hanzoai/node-jwks-rsa.git
synced 2026-09-24 17:00:54 +00:00
fixed typescript definitions and added tests
This commit is contained in:
@@ -35,6 +35,7 @@ node_modules
|
||||
# Build output
|
||||
lib
|
||||
!src/lib
|
||||
ts-output
|
||||
|
||||
# IDE files
|
||||
.idea/
|
||||
|
||||
Generated
+315
-338
File diff suppressed because it is too large
Load Diff
+10
-2
@@ -14,7 +14,10 @@
|
||||
"request": "^2.88.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.1.7",
|
||||
"@types/express-jwt": "0.0.42",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/nock": "^10.0.3",
|
||||
"babel-cli": "^6.9.0",
|
||||
"babel-core": "^6.9.0",
|
||||
"babel-eslint": "^6.0.4",
|
||||
@@ -32,13 +35,18 @@
|
||||
"passport": "^0.4.0",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"rimraf": "^2.6.3",
|
||||
"supertest": "^3.4.2"
|
||||
"supertest": "^3.4.2",
|
||||
"ts-node": "^8.2.0",
|
||||
"typescript": "^3.5.1"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf lib/",
|
||||
"clean:ts": "rimraf ts-output/",
|
||||
"compile": "babel -d lib/ src/",
|
||||
"prepublish": "npm run clean && npm run compile",
|
||||
"test": "NODE_ENV=test mocha --require babel-core/register --exit --timeout 5000 $(find ./tests -name *.tests.js)",
|
||||
"test:ts": "npm run clean:ts && tsc && NODE_ENV=test mocha --require babel-core/register --exit --timeout 5000 $(find ./ts-output -name *.tests.js)",
|
||||
"test:js": "NODE_ENV=test mocha --require babel-core/register --exit --timeout 5000 $(find ./tests -name *.tests.js)",
|
||||
"test": "npm run test:js && npm run test:ts",
|
||||
"test-watch": "NODE_ENV=test mocha --require babel-core/register --exit --timeout 5000 $(find ./tests -name *.tests.js) --watch",
|
||||
"release": "git tag $npm_package_version && git push && git push --tags && npm publish"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import nock from 'nock';
|
||||
import * as jwksRsaType from 'jwks-rsa';
|
||||
import {expect} from 'chai';
|
||||
const jwksRsa: typeof jwksRsaType = require('../src');
|
||||
|
||||
describe('typescript definition', () => {
|
||||
const jwksHost = 'http://my-authz-server';
|
||||
|
||||
const givenPublicCertOnAuthzServer = (kid: string, cert: string) => {
|
||||
nock(jwksHost)
|
||||
.get('/.well-known/jwks.json')
|
||||
.reply(200, {
|
||||
keys: [
|
||||
{
|
||||
alg: 'RS256',
|
||||
kty: 'RSA',
|
||||
use: 'sig',
|
||||
x5c: [cert],
|
||||
kid
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
describe('hapiJwt2KeyAsync', () => {
|
||||
it('should return a secret provider function', async () => {
|
||||
givenPublicCertOnAuthzServer('someKeyId', 'pk1');
|
||||
|
||||
const secretProvider = jwksRsa.hapiJwt2KeyAsync({
|
||||
jwksUri: `${jwksHost}/.well-known/jwks.json`
|
||||
});
|
||||
const { key } = await secretProvider({
|
||||
header: {
|
||||
'typ': 'JWT',
|
||||
'alg': 'RS256',
|
||||
'kid': 'someKeyId'
|
||||
}
|
||||
});
|
||||
|
||||
expect(key).to.contain('pk1');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"baseUrl": ".",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"noEmit": false,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"strictNullChecks": true,
|
||||
"esModuleInterop": true,
|
||||
"target": "es5",
|
||||
"outDir": "ts-output"
|
||||
},
|
||||
"include": [
|
||||
"index.d.ts",
|
||||
"tests/**/*.tests.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user