Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/Package Updates #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: node_js
node_js:
- "12"
- "14"
- "15"
- '12'
- '14'
- '16'
- '18'
after_script:
- npm install -g codeclimate-test-reporter
- codeclimate-test-reporter < coverage/lcov.info
8 changes: 4 additions & 4 deletions __tests__/Embassy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ describe('Embassy', () => {
inst = new Embassy({ refreshScopes })
const token1 = inst.createToken()
await token1.grantScope('foo', 'bar')
expect(refreshScopes).toBeCalledTimes(1)
expect(refreshScopes).toHaveBeenCalledTimes(1)
const token2 = inst.createToken()
await token2.grantScope('foo', 'bar')
expect(refreshScopes).toBeCalledTimes(1)
expect(refreshScopes).toHaveBeenCalledTimes(1)
})
it('persists public keys to new Tokens', async () => {
const getPublicKey = jest.fn().mockResolvedValue(pub)
Expand All @@ -53,10 +53,10 @@ describe('Embassy', () => {
const token1 = inst.createToken({ sub: 'foo' })
const token1Str = await token1.sign('goodKey')
await token1.verify()
expect(getPublicKey).toBeCalledTimes(1)
expect(getPublicKey).toHaveBeenCalledTimes(1)
const token2 = inst.parseToken(token1Str)
await token2.verify()
expect(getPublicKey).toBeCalledTimes(1)
expect(getPublicKey).toHaveBeenCalledTimes(1)
})
})
describe('parseToken', () => {
Expand Down
25 changes: 14 additions & 11 deletions __tests__/Token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
TokenParseError
} from '../src'
import { pub, priv } from './fixtures/keys'
import delay from 'delay'

function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms))
}

const testTokenStr =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsImtpZCI6Imdvb2RLZXkifQ.eyJhdWQiOiJ0ZX' +
Expand Down Expand Up @@ -66,7 +69,7 @@ describe('Token', () => {
})
it('throws a TokenParseError if a bad token is passed in', () => {
const getInst = (opts: TokenOptions) => () => new Token(opts)
expect(getInst({ token: 'foo' })).toThrowError(TokenParseError)
expect(getInst({ token: 'foo' })).toThrow(TokenParseError)
})
})
describe('options', () => {
Expand Down Expand Up @@ -174,7 +177,7 @@ describe('Token', () => {
}
inst = new Token({ refreshScopes, refreshScopesAfterMs: 10 })
await inst.hasScope('foo', 'bar')
await delay(11)
await sleep(11)
await expect(inst.hasScope('bar', 'baz')).resolves.toBe(false)
})
it('grants, checks, and revokes scopes in combined format', async () => {
Expand Down Expand Up @@ -228,7 +231,7 @@ describe('Token', () => {
})
it('throws when there is no subject', async () => {
const throws = () => inst.sign('goodKey')
await expect(throws).rejects.toThrowError(/subject is required/)
await expect(throws).rejects.toThrow(/subject is required/)
})
it('throws when the key ID is not in the key map', async () => {
await expect(inst.sign('noKey', { subject: 'foo' })).rejects.toThrow(
Expand All @@ -248,7 +251,7 @@ describe('Token', () => {
it('rejects if the key is corrupt', async () => {
await expect(
inst.sign('corruptKey', { subject: 'foo' })
).rejects.toThrowError()
).rejects.toThrow()
})
it('calls getPrivateKey when the private key is not found', async () => {
inst = new Token({
Expand Down Expand Up @@ -288,9 +291,9 @@ describe('Token', () => {
})
inst = new Token({ getPrivateKey })
await inst.sign('privAlgo', { subject: 'foo' })
expect(getPrivateKey).toBeCalledTimes(1)
expect(getPrivateKey).toHaveBeenCalledTimes(1)
await inst.sign('privAlgo', { subject: 'foo' })
expect(getPrivateKey).toBeCalledTimes(1)
expect(getPrivateKey).toHaveBeenCalledTimes(1)
})
it('supports signing when an exp claim is already set', async () => {
const now = Math.floor(Date.now() / 1000)
Expand Down Expand Up @@ -360,16 +363,16 @@ describe('Token', () => {
const signed = await inst.sign('goodKey', { subject: 'foo' })
inst = new Token({ token: signed, getPublicKey })
await expect(inst.verify()).resolves.toBeTruthy()
expect(getPublicKey).toBeCalledTimes(1)
expect(getPublicKey).toBeCalledWith('goodKey')
expect(getPublicKey).toHaveBeenCalledTimes(1)
expect(getPublicKey).toHaveBeenCalledWith('goodKey')
})
it('calls function to get pub key synchronously', async () => {
const getPublicKey = jest.fn().mockReturnValue(pub)
const signed = await inst.sign('goodKey', { subject: 'foo' })
inst = new Token({ token: signed, getPublicKey })
await expect(inst.verify()).resolves.toBeTruthy()
expect(getPublicKey).toBeCalledTimes(1)
expect(getPublicKey).toBeCalledWith('goodKey')
expect(getPublicKey).toHaveBeenCalledTimes(1)
expect(getPublicKey).toHaveBeenCalledWith('goodKey')
})
it('gets public key when private key already exists', async () => {
const getPublicKey = jest.fn().mockResolvedValue(pub)
Expand Down
Loading