@crombolo/remote-conformance 0.66.0 → 0.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +67 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/remote-conformance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.0",
|
|
4
4
|
"description": "Checks a server against the Crombolo remote protocol: discovery, sign-in, environments, pulls, pushes and media by reference.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface ConformanceOptions {
|
|
|
22
22
|
push?: boolean
|
|
23
23
|
/** How long to wait for a job, in milliseconds. */
|
|
24
24
|
timeoutMs?: number
|
|
25
|
+
/**
|
|
26
|
+
* Mints a token one of the providers `auth.people` names issued for the
|
|
27
|
+
* remote, for a person signed in to it once (story 364): the exchange is
|
|
28
|
+
* then checked end to end. Without it, only its refusals are.
|
|
29
|
+
*/
|
|
30
|
+
personToken?: (provider: { id: string; issuer: string; audience: string }) => Promise<string>
|
|
25
31
|
fetch?: typeof fetch
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -169,6 +175,67 @@ export async function runConformance(options: ConformanceOptions): Promise<Confo
|
|
|
169
175
|
})
|
|
170
176
|
}
|
|
171
177
|
|
|
178
|
+
// Optional: a person signed in through a provider (story 364). Offered by
|
|
179
|
+
// discovery alone, with the same endpoint and grant as CI's.
|
|
180
|
+
const people = (state.discovery?.auth as Json | undefined)?.people as Json | undefined
|
|
181
|
+
if (people) {
|
|
182
|
+
const providers = (people.providers as Json[] | undefined) ?? []
|
|
183
|
+
const exchange = (token: string) =>
|
|
184
|
+
http(String(people.tokenExchange), {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
187
|
+
body: new URLSearchParams({
|
|
188
|
+
grant_type: String(people.grantType),
|
|
189
|
+
subject_token: token,
|
|
190
|
+
subject_token_type: String(people.subjectTokenType),
|
|
191
|
+
}).toString(),
|
|
192
|
+
})
|
|
193
|
+
const refusal = async (response: Response, token: string) => {
|
|
194
|
+
assert(response.status === 400, `answered ${response.status}`)
|
|
195
|
+
const text = await response.text()
|
|
196
|
+
assert(text.includes('invalid_grant'), 'the refusal is not invalid_grant')
|
|
197
|
+
assert(!text.includes(token), 'the refusal repeats the token')
|
|
198
|
+
}
|
|
199
|
+
await check(
|
|
200
|
+
'people: discovery names the exchange and each provider, issuer and audience',
|
|
201
|
+
async () => {
|
|
202
|
+
for (const field of ['tokenExchange', 'grantType', 'subjectTokenType', 'audience'])
|
|
203
|
+
assert(typeof people[field] === 'string', `auth.people.${field} is missing`)
|
|
204
|
+
assert(providers.length > 0, 'auth.people.providers is empty')
|
|
205
|
+
for (const provider of providers)
|
|
206
|
+
for (const field of ['id', 'issuer', 'audience'])
|
|
207
|
+
assert(typeof provider[field] === 'string', `a provider's ${field} is missing`)
|
|
208
|
+
},
|
|
209
|
+
)
|
|
210
|
+
await check("people: an unsigned token naming a provider's issuer is refused", async () => {
|
|
211
|
+
const claims = Buffer.from(JSON.stringify({ iss: providers[0]?.issuer })).toString(
|
|
212
|
+
'base64url',
|
|
213
|
+
)
|
|
214
|
+
const forged = `eyJhbGciOiJub25lIn0.${claims}.`
|
|
215
|
+
await refusal(await exchange(forged), forged)
|
|
216
|
+
})
|
|
217
|
+
await check('people: a minted token signs the person in, once', async () => {
|
|
218
|
+
const provider = providers[0]
|
|
219
|
+
if (!options.personToken || !provider) return 'skip'
|
|
220
|
+
const token = await options.personToken({
|
|
221
|
+
id: String(provider.id),
|
|
222
|
+
issuer: String(provider.issuer),
|
|
223
|
+
audience: String(provider.audience),
|
|
224
|
+
})
|
|
225
|
+
const answer = await exchange(token)
|
|
226
|
+
assert(answer.status === 200, `answered ${answer.status}`)
|
|
227
|
+
const body = (await answer.json()) as Json
|
|
228
|
+
assert(typeof body.access_token === 'string', 'no access_token')
|
|
229
|
+
assert(body.token_type === 'Bearer', 'token_type is not Bearer')
|
|
230
|
+
const me = await http(`${state.api}/me`, {
|
|
231
|
+
headers: { authorization: `Bearer ${String(body.access_token)}` },
|
|
232
|
+
})
|
|
233
|
+
assert(me.status === 200, `me answered ${me.status}`)
|
|
234
|
+
assert(((await me.json()) as Json).kind === 'person', 'me is not a person')
|
|
235
|
+
await refusal(await exchange(token), token)
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
|
|
172
239
|
await check('the API refuses a request without a token, as a problem', async () => {
|
|
173
240
|
const response = await http(`${state.api}/environments`)
|
|
174
241
|
assert(response.status === 401, `answered ${response.status}`)
|