-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ApiResource configuration serialization bug fixed * Tests added
- Loading branch information
Showing
11 changed files
with
137 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
OIDC_TOKEN_URL=http://localhost:8080/connect/token | ||
OIDC_AUTHORIZE_URL=http://localhost:8080/connect/authorize | ||
OIDC_INTROSPECTION_URL=http://localhost:8080/connect/introspect |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[ | ||
{ | ||
"Name": "some-app", | ||
"Scopes": ["some-app-scope-1", "some-app-scope-2"] | ||
"Scopes": ["some-app-scope-1", "some-app-scope-2"], | ||
"ApiSecrets": ["some-app-secret-1"] | ||
} | ||
] | ||
] |
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
17 changes: 17 additions & 0 deletions
17
e2e/tests/__snapshots__/introspection-endpoint.spec.ts.snap
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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Introspection Endpoint Unknown token 1`] = ` | ||
Object { | ||
"active": false, | ||
} | ||
`; | ||
|
||
exports[`Introspection Endpoint Valid token 1`] = ` | ||
{ | ||
"iss": "http://localhost:8080", | ||
"aud": "some-app", | ||
"client_id": "introspect-client-id", | ||
"active": true, | ||
"scope": "some-app-scope-1" | ||
} | ||
`; |
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,81 @@ | ||
import * as querystring from 'querystring'; | ||
import * as dotenv from 'dotenv'; | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
|
||
import { sign } from 'jws'; | ||
import apiResources from '../config/api-resources.json'; | ||
import clients from '../config/clients-configuration.json'; | ||
import type { ApiResource, Client } from '../types'; | ||
|
||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); | ||
|
||
describe('Introspection Endpoint', () => { | ||
let apiResource: ApiResource; | ||
let requestConfig: AxiosRequestConfig; | ||
|
||
beforeAll(() => { | ||
dotenv.config(); | ||
apiResource = apiResources.find(aR => aR.Name === 'some-app'); | ||
expect(apiResource).toBeDefined(); | ||
const auth = btoa(`${apiResource.Name}:${apiResource.ApiSecrets?.[0]}`); | ||
requestConfig = { | ||
headers: { | ||
Authorization: `Basic ${auth}`, | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
}; | ||
}); | ||
|
||
test('Valid token', async () => { | ||
const client: Client = clients.find(c => c.ClientId === 'introspect-client-id'); | ||
expect(client).toBeDefined(); | ||
|
||
const parameters = { | ||
client_id: client.ClientId, | ||
client_secret: client.ClientSecrets?.[0], | ||
grant_type: 'client_credentials', | ||
scope: client.AllowedScopes[0], | ||
}; | ||
|
||
const tokenResponse = await axios.post(process.env.OIDC_TOKEN_URL, querystring.stringify(parameters)); | ||
|
||
expect(tokenResponse).toBeDefined(); | ||
const token = tokenResponse.data.access_token; | ||
expect(token).toBeDefined(); | ||
const requestBody = querystring.stringify({ | ||
token, | ||
}); | ||
|
||
const response = await axios.post(process.env.OIDC_INTROSPECTION_URL, requestBody, requestConfig); | ||
|
||
expect(response).toBeDefined(); | ||
expect(response.data).toMatchSnapshot(); | ||
}); | ||
|
||
test('Unknown token', async () => { | ||
const requestBody = querystring.stringify({ | ||
token: sign({ | ||
header: { | ||
alg: 'HS256', | ||
typ: 'JWT', | ||
}, | ||
payload: { | ||
nbf: 1597042883, | ||
exp: 1597042884, | ||
iss: 'http://localhost:8080', | ||
aud: 'some-app', | ||
client_id: 'introspect-client-id', | ||
jti: '96E474ECF2D289741861976143C2BF54', | ||
iat: 1597042883, | ||
scope: ['some-app-scope-1'], | ||
}, | ||
secret: 'very-strong-secret', | ||
}), | ||
}); | ||
|
||
const response = await axios.post(process.env.OIDC_INTROSPECTION_URL, requestBody, requestConfig); | ||
|
||
expect(response).toBeDefined(); | ||
expect(response.data).toMatchSnapshot(); | ||
}); | ||
}); |
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,5 @@ | ||
export default interface ApiResource { | ||
Name: string; | ||
Scopes?: string[]; | ||
ApiSecrets?: string[]; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import Claim from './claim'; | ||
import ApiResource from './api-resource'; | ||
import Client from './client'; | ||
import User from './user'; | ||
|
||
export { Claim, Client, User }; | ||
export { ApiResource, Claim, Client, User }; |
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,9 @@ | ||
module.exports = { | ||
test(arg) { | ||
return arg.iat && arg.exp && arg.nbf; | ||
}, | ||
print(val) { | ||
const { exp, iat, jti, nbf, auth_time, sid, at_hash, ...payload } = val; | ||
return JSON.stringify(payload, undefined, 2); | ||
}, | ||
}; |
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 was deleted.
Oops, something went wrong.