fixed typescript definitions and added tests

This commit is contained in:
Igor Sechyn
2019-06-04 09:26:29 +08:00
parent 0be96628e2
commit 60f5c0aeb6
5 changed files with 393 additions and 340 deletions
+1
View File
@@ -35,6 +35,7 @@ node_modules
# Build output # Build output
lib lib
!src/lib !src/lib
ts-output
# IDE files # IDE files
.idea/ .idea/
+315 -338
View File
File diff suppressed because it is too large Load Diff
+10 -2
View File
@@ -14,7 +14,10 @@
"request": "^2.88.0" "request": "^2.88.0"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.1.7",
"@types/express-jwt": "0.0.42", "@types/express-jwt": "0.0.42",
"@types/mocha": "^5.2.7",
"@types/nock": "^10.0.3",
"babel-cli": "^6.9.0", "babel-cli": "^6.9.0",
"babel-core": "^6.9.0", "babel-core": "^6.9.0",
"babel-eslint": "^6.0.4", "babel-eslint": "^6.0.4",
@@ -32,13 +35,18 @@
"passport": "^0.4.0", "passport": "^0.4.0",
"passport-jwt": "^4.0.0", "passport-jwt": "^4.0.0",
"rimraf": "^2.6.3", "rimraf": "^2.6.3",
"supertest": "^3.4.2" "supertest": "^3.4.2",
"ts-node": "^8.2.0",
"typescript": "^3.5.1"
}, },
"scripts": { "scripts": {
"clean": "rimraf lib/", "clean": "rimraf lib/",
"clean:ts": "rimraf ts-output/",
"compile": "babel -d lib/ src/", "compile": "babel -d lib/ src/",
"prepublish": "npm run clean && npm run compile", "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", "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" "release": "git tag $npm_package_version && git push && git push --tags && npm publish"
}, },
+43
View File
@@ -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');
});
});
});
+24
View File
@@ -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"
]
}