@crombolo/remote-conformance 0.43.1 → 0.44.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +46 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/remote-conformance",
3
- "version": "0.43.1",
3
+ "version": "0.44.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
@@ -137,12 +137,58 @@ export async function runConformance(options: ConformanceOptions): Promise<Confo
137
137
  assert(typeof body[field] === 'number', `${field} is missing`)
138
138
  })
139
139
 
140
+ // Optional: signing in from CI (story 160). A remote that offers it says how, and
141
+ // refuses a token it cannot verify with the same answer whatever was wrong.
142
+ const ci = (state.discovery?.auth as Json | undefined)?.ci as Json | undefined
143
+ const capabilities = (state.discovery?.capabilities as unknown[] | undefined) ?? []
144
+ if (capabilities.includes('ci-sign-in')) {
145
+ await check('ci-sign-in: discovery names the exchange, its audience and issuers', async () => {
146
+ for (const field of ['tokenExchange', 'grantType', 'subjectTokenType', 'audience'])
147
+ assert(typeof ci?.[field] === 'string', `auth.ci.${field} is missing`)
148
+ assert(Array.isArray(ci?.issuers), 'auth.ci.issuers is missing')
149
+ assert(
150
+ ci?.grantType === 'urn:ietf:params:oauth:grant-type:token-exchange',
151
+ 'auth.ci.grantType is not token exchange',
152
+ )
153
+ })
154
+ await check('ci-sign-in: a token it cannot verify is refused, and not echoed', async () => {
155
+ const forged = 'eyJhbGciOiJub25lIn0.eyJpc3MiOiJodHRwczovL2V4YW1wbGUuaW52YWxpZCJ9.'
156
+ const response = await http(String(ci?.tokenExchange), {
157
+ method: 'POST',
158
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
159
+ body: new URLSearchParams({
160
+ grant_type: String(ci?.grantType),
161
+ subject_token: forged,
162
+ subject_token_type: String(ci?.subjectTokenType),
163
+ }).toString(),
164
+ })
165
+ assert(response.status === 400, `answered ${response.status}`)
166
+ const text = await response.text()
167
+ assert(text.includes('invalid_grant'), 'the refusal is not invalid_grant')
168
+ assert(!text.includes(forged), 'the refusal repeats the token')
169
+ })
170
+ }
171
+
140
172
  await check('the API refuses a request without a token, as a problem', async () => {
141
173
  const response = await http(`${state.api}/environments`)
142
174
  assert(response.status === 401, `answered ${response.status}`)
143
175
  assert(isProblem(response), 'not application/problem+json')
144
176
  })
145
177
 
178
+ // Optional: applying a bundle (story 167). A remote that takes bundles checks
179
+ // what it is sent before anything else, and says so as a problem.
180
+ if (capabilities.includes('bundle-apply')) {
181
+ await check('bundle-apply: a bundle that is not the one described is refused', async () => {
182
+ const response = await api(`environments/${state.environment}/bundles`, {
183
+ method: 'PUT',
184
+ headers: { 'crombolo-sha256': '0'.repeat(64), 'content-type': 'application/gzip' },
185
+ body: new Uint8Array([31, 139, 8, 0]),
186
+ })
187
+ assert(response.status === 400 || response.status === 403, `answered ${response.status}`)
188
+ assert(isProblem(response), 'not application/problem+json')
189
+ })
190
+ }
191
+
146
192
  await check('environments lists what the token may do', async () => {
147
193
  const response = await api('environments')
148
194
  assert(response.status === 200, `answered ${response.status}`)