Skip to content

Commit

Permalink
chore: rename variables that were breaking tests for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Aug 23, 2022
1 parent f46a859 commit a4fa4cd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 64 deletions.
24 changes: 10 additions & 14 deletions packages/auth/src/accessToken/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import { AccessToken } from './model'
import { Access } from '../access/model'
import { AccessTokenRoutes } from './routes'
import { createContext } from '../tests/context'
import {
TEST_KID_PATH,
KEY_REGISTRY_ORIGIN,
TEST_CLIENT_KEY
} from '../grant/routes.test'
import { KID_PATH, KID_ORIGIN, TEST_CLIENT_KEY } from '../grant/routes.test'

describe('Access Token Routes', (): void => {
let deps: IocContract<AppServices>
Expand Down Expand Up @@ -55,7 +51,7 @@ describe('Access Token Routes', (): void => {
finishMethod: FinishMethod.Redirect,
finishUri: 'https://example.com/finish',
clientNonce: crypto.randomBytes(8).toString('hex').toUpperCase(),
clientKeyId: KEY_REGISTRY_ORIGIN + TEST_KID_PATH,
clientKeyId: KID_ORIGIN + KID_PATH,
interactId: v4(),
interactRef: crypto.randomBytes(8).toString('hex').toUpperCase(),
interactNonce: crypto.randomBytes(8).toString('hex').toUpperCase()
Expand Down Expand Up @@ -125,8 +121,8 @@ describe('Access Token Routes', (): void => {
})

test('Successfully introspects valid token', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
.get(TEST_KID_PATH)
const scope = nock(KID_ORIGIN)
.get(KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk]
})
Expand Down Expand Up @@ -176,8 +172,8 @@ describe('Access Token Routes', (): void => {
})

test('Successfully introspects expired token', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
.get(TEST_KID_PATH)
const scope = nock(KID_ORIGIN)
.get(KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk]
})
Expand Down Expand Up @@ -252,8 +248,8 @@ describe('Access Token Routes', (): void => {
})

test('Returns status 204 if token has not expired', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
.get(TEST_KID_PATH)
const scope = nock(KID_ORIGIN)
.get(KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk]
})
Expand Down Expand Up @@ -281,8 +277,8 @@ describe('Access Token Routes', (): void => {
})

test('Returns status 204 if token has expired', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
.get(TEST_KID_PATH)
const scope = nock(KID_ORIGIN)
.get(KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk]
})
Expand Down
41 changes: 20 additions & 21 deletions packages/auth/src/client/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ import { Grant, GrantState, StartMethod, FinishMethod } from '../grant/model'
import { Access } from '../access/model'
import { AccessToken } from '../accessToken/model'
import { AccessType, Action } from '../access/types'
import { TEST_CLIENT_KEY } from '../grant/routes.test'
import { KID_ORIGIN, TEST_CLIENT_KEY } from '../grant/routes.test'

const KEY_REGISTRY_ORIGIN = 'https://openpayments.network'
const TEST_CLIENT_DISPLAY = {
name: 'Test Client',
url: 'https://example.com'
}

const TEST_KID_PATH = '/keys/test-key'
const TEST_PUBLIC_KEY = {
kid: KEY_REGISTRY_ORIGIN + TEST_KID_PATH,
kid: KID_ORIGIN + TEST_KID_PATH,
x: 'hin88zzQxp79OOqIFNCME26wMiz0yqjzgkcBe0MW8pE',
kty: 'OKP',
alg: 'EdDSA',
Expand Down Expand Up @@ -153,7 +152,7 @@ describe('Client Service', (): void => {
finishMethod: FinishMethod.Redirect,
finishUri: 'https://example.com/finish',
clientNonce: crypto.randomBytes(8).toString('hex').toUpperCase(),
clientKeyId: KEY_REGISTRY_ORIGIN + TEST_KID_PATH,
clientKeyId: KID_ORIGIN + TEST_KID_PATH,
interactId: v4(),
interactRef: crypto.randomBytes(8).toString('hex').toUpperCase(),
interactNonce: crypto.randomBytes(8).toString('hex').toUpperCase()
Expand Down Expand Up @@ -209,7 +208,7 @@ describe('Client Service', (): void => {
})

test('Validate POST / request with middleware', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get(TEST_KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk],
Expand Down Expand Up @@ -242,7 +241,7 @@ describe('Client Service', (): void => {
})

test('Validate /introspect request with middleware', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get(TEST_KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk]
Expand Down Expand Up @@ -273,7 +272,7 @@ describe('Client Service', (): void => {
})

test('Validate DEL /token request with middleware', async () => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get(TEST_KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk]
Expand Down Expand Up @@ -347,7 +346,7 @@ describe('Client Service', (): void => {
})

test('httpsig middleware fails if headers are invalid', async () => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get(TEST_KID_PATH)
.reply(200, {
keys: [TEST_CLIENT_KEY.jwk]
Expand Down Expand Up @@ -387,14 +386,14 @@ describe('Client Service', (): void => {
nbfDate.setTime(nbfDate.getTime() - 1000 * 60 * 60)
describe('Client Properties', (): void => {
test('Can validate client properties with registry', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get('/keys/correct')
.reply(200, {
...TEST_CLIENT_DISPLAY,
keys: [
{
...TEST_PUBLIC_KEY,
kid: KEY_REGISTRY_ORIGIN + '/keys/correct',
kid: KID_ORIGIN + '/keys/correct',
exp: Math.round(expDate.getTime() / 1000),
nbf: Math.round(nbfDate.getTime() / 1000),
revoked: false
Expand All @@ -408,7 +407,7 @@ describe('Client Service', (): void => {
proof: 'httpsig',
jwk: {
...TEST_PUBLIC_KEY,
kid: KEY_REGISTRY_ORIGIN + '/keys/correct'
kid: KID_ORIGIN + '/keys/correct'
}
}
})
Expand All @@ -418,7 +417,7 @@ describe('Client Service', (): void => {
})

test('Cannot validate client with incorrect display name', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get(TEST_KID_PATH)
.reply(200, {
display: {
Expand Down Expand Up @@ -448,7 +447,7 @@ describe('Client Service', (): void => {
})

test('Cannot validate client with incorrect uri', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get(TEST_KID_PATH)
.reply(200, {
...TEST_PUBLIC_KEY,
Expand Down Expand Up @@ -477,7 +476,7 @@ describe('Client Service', (): void => {
})

test('Cannot validate client with kid that doesnt resolve', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN).get('/wrong').reply(200)
const scope = nock(KID_ORIGIN).get('/wrong').reply(200)

const validClientKid = await clientService.validateClientWithRegistry({
display: TEST_CLIENT_DISPLAY,
Expand All @@ -495,7 +494,7 @@ describe('Client Service', (): void => {
})

test('Cannot validate client with jwk that doesnt have a public key', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get(TEST_KID_PATH)
.reply(200, {
...TEST_CLIENT_DISPLAY,
Expand Down Expand Up @@ -585,7 +584,7 @@ describe('Client Service', (): void => {
test('Cannot validate client with key that is not ready', async (): Promise<void> => {
const futureDate = new Date()
futureDate.setTime(futureDate.getTime() + 1000 * 60 * 60)
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get('/keys/notready')
.reply(200, {
...TEST_CLIENT_DISPLAY,
Expand All @@ -605,7 +604,7 @@ describe('Client Service', (): void => {
proof: 'httpsig',
jwk: {
...TEST_PUBLIC_KEY,
kid: KEY_REGISTRY_ORIGIN + '/keys/notready'
kid: KID_ORIGIN + '/keys/notready'
}
}
})
Expand All @@ -615,7 +614,7 @@ describe('Client Service', (): void => {
})

test('Cannot validate client with expired key', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get('/keys/invalidclient')
.reply(200, {
...TEST_CLIENT_DISPLAY,
Expand All @@ -635,7 +634,7 @@ describe('Client Service', (): void => {
proof: 'httpsig',
jwk: {
...TEST_PUBLIC_KEY,
kid: KEY_REGISTRY_ORIGIN + '/keys/invalidclient'
kid: KID_ORIGIN + '/keys/invalidclient'
}
}
})
Expand All @@ -645,7 +644,7 @@ describe('Client Service', (): void => {
})

test('Cannot validate client with revoked key', async (): Promise<void> => {
const scope = nock(KEY_REGISTRY_ORIGIN)
const scope = nock(KID_ORIGIN)
.get('/keys/revoked')
.reply(200, {
...TEST_CLIENT_DISPLAY,
Expand All @@ -665,7 +664,7 @@ describe('Client Service', (): void => {
proof: 'httpsig',
jwk: {
...TEST_PUBLIC_KEY,
kid: KEY_REGISTRY_ORIGIN + '/keys/revoked'
kid: KID_ORIGIN + '/keys/revoked'
}
}
})
Expand Down

0 comments on commit a4fa4cd

Please sign in to comment.