@bsv/create-dpp-app 0.1.0-beta.1 → 0.1.0-beta.2
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/NOTICE +2 -0
- package/PATENTS +12 -0
- package/README.md +26 -6
- package/dist/index.js +36 -8
- package/package.json +9 -5
- package/template/Dockerfile +4 -2
- package/template/README.md +297 -42
- package/template/_env.example +82 -13
- package/template/_github/workflows/ci.yml +3 -3
- package/template/apps/api/API.md +86 -16
- package/template/apps/api/package.json +9 -4
- package/template/apps/api/src/bound-profiles.ts +590 -0
- package/template/apps/api/src/claims.ts +175 -56
- package/template/apps/api/src/cli.ts +64 -7
- package/template/apps/api/src/config.ts +124 -10
- package/template/apps/api/src/custody.ts +241 -69
- package/template/apps/api/src/dev-index.ts +58 -9
- package/template/apps/api/src/env-file.ts +55 -0
- package/template/apps/api/src/epcis/exchange.ts +434 -0
- package/template/apps/api/src/epcis/mongo-storage.ts +381 -0
- package/template/apps/api/src/epcis/routes.ts +364 -0
- package/template/apps/api/src/epcis/sources.ts +142 -0
- package/template/apps/api/src/go-live.ts +226 -0
- package/template/apps/api/src/http-error.ts +15 -0
- package/template/apps/api/src/identifiers.ts +1 -1
- package/template/apps/api/src/index-client.ts +131 -6
- package/template/apps/api/src/index-projects.ts +53 -0
- package/template/apps/api/src/lifecycle-authority.ts +49 -0
- package/template/apps/api/src/lifecycle.ts +485 -0
- package/template/apps/api/src/main.ts +10 -2
- package/template/apps/api/src/parties.ts +2 -2
- package/template/apps/api/src/platform.ts +72 -17
- package/template/apps/api/src/portability/commands.ts +224 -0
- package/template/apps/api/src/portability/export.ts +708 -0
- package/template/apps/api/src/portability/package.ts +270 -0
- package/template/apps/api/src/portability/restore.ts +863 -0
- package/template/apps/api/src/profiles.ts +38 -13
- package/template/apps/api/src/reader.ts +172 -3
- package/template/apps/api/src/resolver.ts +159 -0
- package/template/apps/api/src/sector-examples.ts +390 -0
- package/template/apps/api/src/server.ts +253 -60
- package/template/apps/api/src/store.ts +198 -21
- package/template/apps/api/src/validation-engine.ts +172 -0
- package/template/apps/api/src/wallet.ts +30 -17
- package/template/apps/api/src/worker.ts +20 -13
- package/template/apps/api/src/writer.ts +383 -131
- package/template/apps/api/test/bound-http.test.ts +496 -0
- package/template/apps/api/test/bound-profiles.test.ts +547 -0
- package/template/apps/api/test/config.test.ts +148 -3
- package/template/apps/api/test/custody-journal.test.ts +415 -0
- package/template/apps/api/test/custody-recovery-profile.test.ts +224 -0
- package/template/apps/api/test/custom-profile.test.ts +167 -0
- package/template/apps/api/test/env-file.test.ts +53 -0
- package/template/apps/api/test/epcis-fixtures.ts +270 -0
- package/template/apps/api/test/epcis-http.test.ts +1179 -0
- package/template/apps/api/test/epcis-mongo-storage.test.ts +313 -0
- package/template/apps/api/test/epcis-separation.test.ts +253 -0
- package/template/apps/api/test/epcis-web.test.ts +230 -0
- package/template/apps/api/test/exit-exercise.test.ts +1038 -0
- package/template/apps/api/test/external-index.test.ts +3 -2
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/context.jsonld +36 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/product.schema.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/shapes.ttl +112 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-gtin.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-serial.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/granularity-mismatch.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item-gtin-13.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item.json +42 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/missing-required-property.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/model-as-subject.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/no-passport-identifier.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/other-product.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/part-not-dishwasher-safe.json +45 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-artefact.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-second-registration.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/untrusted-binding.json +13 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/unlisted-context.json +47 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/wrong-binding-digest.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/binding.json +88 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/product.schema.json +25 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/item.json +26 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/missing-required-property.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/no-passport-identifier.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json +28 -0
- package/template/apps/api/test/go-live.test.ts +179 -0
- package/template/apps/api/test/gs1-global-setup.ts +33 -0
- package/template/apps/api/test/gs1-test-env.ts +5 -0
- package/template/apps/api/test/identifier-host.test.ts +256 -0
- package/template/apps/api/test/index-projects.test.ts +81 -0
- package/template/apps/api/test/lifecycle-claims.test.ts +546 -0
- package/template/apps/api/test/lifecycle-fixtures.ts +167 -0
- package/template/apps/api/test/lifecycle.test.ts +17 -6
- package/template/apps/api/test/manifest-notice.test.ts +36 -0
- package/template/apps/api/test/network-guard.ts +113 -0
- package/template/apps/api/test/portability.test.ts +655 -0
- package/template/apps/api/test/profile-bundle-resolver.test.ts +198 -0
- package/template/apps/api/test/retired-profiles.test.ts +216 -0
- package/template/apps/api/test/sector-cutover.test.ts +95 -0
- package/template/apps/api/test/sector-forms.test.ts +420 -0
- package/template/apps/api/test/unjoined-index.test.ts +62 -0
- package/template/apps/api/test/validation-engine.test.ts +328 -0
- package/template/apps/api/test/wallet-monitor.test.ts +38 -0
- package/template/apps/api/test/writer-journal.test.ts +327 -0
- package/template/apps/api/vitest.config.ts +3 -0
- package/template/apps/web/src/app.tsx +8 -4
- package/template/apps/web/src/components/bound/bound-passport-form.tsx +368 -0
- package/template/apps/web/src/components/bound/field-view.tsx +237 -0
- package/template/apps/web/src/components/bound/pieces.tsx +169 -0
- package/template/apps/web/src/components/bound/readings.tsx +152 -0
- package/template/apps/web/src/components/bound/structured-value.tsx +114 -0
- package/template/apps/web/src/components/claim-dialog.tsx +344 -0
- package/template/apps/web/src/components/epcis-events.tsx +119 -0
- package/template/apps/web/src/components/layout.tsx +17 -0
- package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
- package/template/apps/web/src/components/passport-form.tsx +2 -2
- package/template/apps/web/src/components/read-passport.tsx +4 -3
- package/template/apps/web/src/components/reading.tsx +32 -39
- package/template/apps/web/src/lib/api.ts +136 -26
- package/template/apps/web/src/lib/bound/battery-form.ts +269 -0
- package/template/apps/web/src/lib/bound/display.ts +122 -0
- package/template/apps/web/src/lib/bound/fields.ts +128 -0
- package/template/apps/web/src/lib/bound/form-model.ts +521 -0
- package/template/apps/web/src/lib/bound/forms.ts +15 -0
- package/template/apps/web/src/lib/bound/identity.ts +48 -0
- package/template/apps/web/src/lib/bound/textile-form.ts +236 -0
- package/template/apps/web/src/lib/bound/units.ts +37 -0
- package/template/apps/web/src/lib/epcis.ts +345 -0
- package/template/apps/web/src/lib/format.ts +27 -4
- package/template/apps/web/src/lib/lifecycle.ts +350 -0
- package/template/apps/web/src/pages/accept.tsx +8 -3
- package/template/apps/web/src/pages/events.tsx +388 -0
- package/template/apps/web/src/pages/new-passport.tsx +25 -2
- package/template/apps/web/src/pages/operations.tsx +22 -3
- package/template/apps/web/src/pages/passport.tsx +226 -162
- package/template/apps/web/src/pages/public-passport.tsx +50 -10
- package/template/apps/web/src/pages/wallet.tsx +1 -1
- package/template/apps/web/vite.config.ts +12 -4
- package/template/deploy/compose.yml +14 -2
- package/template/package.json +9 -3
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
// The HTTP surface for profiles held by a binding, and the one promise it
|
|
2
|
+
// has to keep above all: a restricted value of a product document reaches
|
|
3
|
+
// the holder who may open it and nobody else. One test issues passports
|
|
4
|
+
// carrying a value that appears nowhere else, then searches everything this
|
|
5
|
+
// application prints, lists, indexes and exports for it, the EPCIS exchange
|
|
6
|
+
// included. The last does the same for the credential of an EPCIS source.
|
|
7
|
+
import { once } from 'node:events'
|
|
8
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
9
|
+
import { tmpdir } from 'node:os'
|
|
10
|
+
import { join } from 'node:path'
|
|
11
|
+
import type { AddressInfo } from 'node:net'
|
|
12
|
+
import type { Server } from 'node:http'
|
|
13
|
+
import { format } from 'node:util'
|
|
14
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
15
|
+
import type { ViewCheck } from '../src/bound-profiles.js'
|
|
16
|
+
import { EPCIS_RECORD_KINDS } from '@bsv/dpp-credentials/epcis-exchange'
|
|
17
|
+
import { loadConfig } from '../src/config.js'
|
|
18
|
+
import { mintPassportId } from '../src/identifiers.js'
|
|
19
|
+
import { managedParties } from '../src/parties.js'
|
|
20
|
+
import { startEpcisExchange, type EpcisExchange } from '../src/epcis/exchange.js'
|
|
21
|
+
import { openPlatform, type Platform } from '../src/platform.js'
|
|
22
|
+
import type { AuthorisedReading, PassportReading } from '../src/reader.js'
|
|
23
|
+
import { createServer } from '../src/server.js'
|
|
24
|
+
import { epcisDocument, gs1Dir, item, objectEvent, startEpcisSource, type FixtureSource } from './epcis-fixtures.js'
|
|
25
|
+
|
|
26
|
+
type Json = Record<string, unknown>
|
|
27
|
+
|
|
28
|
+
/** The credential of the EPCIS source below. It is in no fixture and no key: wherever it turns up, it was copied there. */
|
|
29
|
+
const credential = 'EPCIS-CREDENTIAL-CANARY-4D1E88F0'
|
|
30
|
+
|
|
31
|
+
const grantsDir = mkdtempSync(join(tmpdir(), 'dpp-disclosure-grants-'))
|
|
32
|
+
const grantsFile = join(grantsDir, 'grants.json')
|
|
33
|
+
const config = loadConfig({ LIFECYCLE_AUTHORITY_GRANTS_FILE: grantsFile, NETWORK: 'main', PASSPORT_HOST: 'passports.example.com', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false' })
|
|
34
|
+
const brandId = 'dev-brand'
|
|
35
|
+
const printed: string[] = []
|
|
36
|
+
let platform: Platform
|
|
37
|
+
let exchange: EpcisExchange
|
|
38
|
+
let epcisSource: FixtureSource
|
|
39
|
+
let echoingSource: FixtureSource
|
|
40
|
+
let server: Server
|
|
41
|
+
let base: string
|
|
42
|
+
const spies: Array<{ mockRestore: () => void }> = []
|
|
43
|
+
|
|
44
|
+
beforeAll(async () => {
|
|
45
|
+
// Everything the process prints is kept: the platform's own log, the console and the two streams under it.
|
|
46
|
+
for (const method of ['log', 'info', 'warn', 'error', 'debug'] as const) spies.push(vi.spyOn(console, method).mockImplementation((...args: unknown[]) => void printed.push(format(...args))))
|
|
47
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
48
|
+
const write = stream.write.bind(stream)
|
|
49
|
+
spies.push(
|
|
50
|
+
vi.spyOn(stream, 'write').mockImplementation(((chunk: unknown, ...rest: unknown[]) => {
|
|
51
|
+
printed.push(typeof chunk === 'string' ? chunk : Buffer.from(chunk as Uint8Array).toString('utf8'))
|
|
52
|
+
return (write as (...args: unknown[]) => boolean)(chunk, ...rest)
|
|
53
|
+
}) as typeof stream.write)
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
const member = managedParties(config).member('developer')
|
|
57
|
+
const grants = [['100200300', 'LEAK-BAT-0001'], ['100200400', 'LEAK-TEX-0001']].map(([itemReference, serial]) => ({
|
|
58
|
+
issuer: member.did, issuerKey: member.identityKey,
|
|
59
|
+
passportId: mintPassportId({ host: config.passportHost, prefix: config.gs1Prefix }, itemReference, serial),
|
|
60
|
+
role: 'observer', purpose: 'claim', validFrom: '2026-11-04T07:00:00Z', validUntil: '2026-11-04T08:00:00Z',
|
|
61
|
+
}))
|
|
62
|
+
writeFileSync(grantsFile, JSON.stringify({ grants }))
|
|
63
|
+
platform = await openPlatform({ config, mode: 'test', log: (line) => printed.push(line) })
|
|
64
|
+
const party = platform.parties.brand(brandId)
|
|
65
|
+
await platform.store.saveBrand({ id: brandId, name: 'Development brand', identityKey: party.identityKey, did: party.did, createdAt: new Date().toISOString() })
|
|
66
|
+
// Two EPCIS sources on this machine. One wants the credential. The other answers with whatever credential it was sent, as a careless source might.
|
|
67
|
+
epcisSource = await startEpcisSource(Array.from({ length: 5 }, (_, index) => objectEvent(index + 1, [item(`LEAK-${index + 1}`)])), { requireAuthorization: `Bearer ${credential}` })
|
|
68
|
+
echoingSource = await startEpcisSource([], { answer: { status: 200, mediaType: 'application/ld+json', body: JSON.stringify({ type: 'EPCISQueryDocument', note: `you sent ${credential}` }) } })
|
|
69
|
+
const sources = loadConfig({
|
|
70
|
+
DPP_GS1_ARTEFACTS_DIR: gs1Dir(),
|
|
71
|
+
DPP_GS1_ARTEFACTS_OFFLINE: 'true',
|
|
72
|
+
EPCIS_SOURCES: 'supplier-a,echo,stranger',
|
|
73
|
+
EPCIS_SOURCE_SUPPLIER_A_URL: epcisSource.baseUrl,
|
|
74
|
+
EPCIS_SOURCE_SUPPLIER_A_LOCAL_TEST: 'true',
|
|
75
|
+
EPCIS_SOURCE_SUPPLIER_A_BEARER_TOKEN: credential,
|
|
76
|
+
EPCIS_SOURCE_ECHO_URL: echoingSource.baseUrl,
|
|
77
|
+
EPCIS_SOURCE_ECHO_LOCAL_TEST: 'true',
|
|
78
|
+
EPCIS_SOURCE_ECHO_HEADER_NAME: 'X-Api-Key',
|
|
79
|
+
EPCIS_SOURCE_ECHO_HEADER_VALUE: credential,
|
|
80
|
+
// The same source again, under a credential it does not accept.
|
|
81
|
+
EPCIS_SOURCE_STRANGER_URL: epcisSource.baseUrl,
|
|
82
|
+
EPCIS_SOURCE_STRANGER_LOCAL_TEST: 'true',
|
|
83
|
+
EPCIS_SOURCE_STRANGER_BASIC_USER: 'operator',
|
|
84
|
+
EPCIS_SOURCE_STRANGER_BASIC_PASSWORD: credential,
|
|
85
|
+
}).epcis
|
|
86
|
+
exchange = await startEpcisExchange({ config: sources, log: (line) => printed.push(line) })
|
|
87
|
+
const app = createServer({ platform, exchange, devSession: { userId: 'developer', email: 'developer@localhost', name: 'Developer', brandIds: [brandId] } })
|
|
88
|
+
server = app.listen(0, '127.0.0.1')
|
|
89
|
+
await once(server, 'listening')
|
|
90
|
+
base = `http://127.0.0.1:${(server.address() as AddressInfo).port}`
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
afterAll(async () => {
|
|
94
|
+
server.closeAllConnections()
|
|
95
|
+
server.close()
|
|
96
|
+
await exchange.close()
|
|
97
|
+
await epcisSource.close()
|
|
98
|
+
await echoingSource.close()
|
|
99
|
+
await platform.close()
|
|
100
|
+
for (const spy of spies) spy.mockRestore()
|
|
101
|
+
rmSync(grantsDir, { recursive: true, force: true })
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const get = async (path: string): Promise<{ status: number; text: string; body: any }> => {
|
|
105
|
+
const response = await fetch(`${base}${path}`)
|
|
106
|
+
const text = await response.text()
|
|
107
|
+
return { status: response.status, text, body: text === '' ? undefined : JSON.parse(text) }
|
|
108
|
+
}
|
|
109
|
+
const post = async (path: string, body: unknown, raw?: string): Promise<{ status: number; text: string; body: any }> => {
|
|
110
|
+
const response = await fetch(`${base}${path}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: raw ?? JSON.stringify(body) })
|
|
111
|
+
const text = await response.text()
|
|
112
|
+
return { status: response.status, text, body: text === '' ? undefined : JSON.parse(text) }
|
|
113
|
+
}
|
|
114
|
+
const ref = (passportId: string): string => encodeURIComponent(passportId)
|
|
115
|
+
/** A body sent as the bytes given, which is how an EPCIS document is uploaded. */
|
|
116
|
+
const upload = async (path: string, text: string, mediaType = 'application/ld+json'): Promise<{ status: number; text: string; body: any }> => {
|
|
117
|
+
const response = await fetch(`${base}${path}`, { method: 'POST', headers: { 'content-type': mediaType }, body: text })
|
|
118
|
+
const answer = await response.text()
|
|
119
|
+
let body: unknown
|
|
120
|
+
try {
|
|
121
|
+
body = answer === '' ? undefined : JSON.parse(answer)
|
|
122
|
+
} catch {
|
|
123
|
+
body = undefined
|
|
124
|
+
}
|
|
125
|
+
return { status: response.status, text: answer, body }
|
|
126
|
+
}
|
|
127
|
+
/** Everything the EPCIS store holds, as text: every record of every kind, and the retained bytes of every import. */
|
|
128
|
+
async function epcisStore(): Promise<string> {
|
|
129
|
+
const out: string[] = []
|
|
130
|
+
for (const kind of Object.values(EPCIS_RECORD_KINDS)) for (const held of await exchange.storage.list(kind, { limit: 100_000 })) out.push(JSON.stringify(held))
|
|
131
|
+
for (const record of await exchange.listImports({ limit: 200 })) out.push(Buffer.from((await exchange.storage.getBytes(record.sha256))!).toString('latin1'))
|
|
132
|
+
return out.join('\n')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The profile's example as the API serves it, under a serial of the test's own. */
|
|
136
|
+
async function exampleFor(profile: string, serial: string): Promise<{ itemReference: string; serial: string; passportId: string; product: Json }> {
|
|
137
|
+
const { body } = await get(`/api/profiles/${encodeURIComponent(profile)}`)
|
|
138
|
+
const example = body.examples[0] as { itemReference: string; serial: string; passportId: string; product: Json }
|
|
139
|
+
const swap = (value: string): string => value.replaceAll(example.serial, serial)
|
|
140
|
+
return { itemReference: example.itemReference, serial, passportId: swap(example.passportId), product: JSON.parse(swap(JSON.stringify(example.product))) as Json }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
describe('profiles over HTTP', () => {
|
|
144
|
+
it('lists the manifest profiles and the bound profiles, each with its format', async () => {
|
|
145
|
+
const { body } = await get('/api/profiles')
|
|
146
|
+
const formats = Object.fromEntries((body as Array<{ id: string; format: string }>).map((p) => [p.id, p.format]))
|
|
147
|
+
// The retired sector profiles are not among them: the bound profiles replace them.
|
|
148
|
+
expect(formats).toEqual({ 'general@2': 'manifest', 'eu-battery@1': 'binding', 'eu-textile@1': 'binding', 'eu-battery@2': 'binding', 'eu-textile@2': 'binding' })
|
|
149
|
+
expect((await get('/api/health')).body.validationEngine).toBe(true)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('describes a bound profile: its split, its contexts and an example for this deployment', async () => {
|
|
153
|
+
const { body } = await get('/api/profiles/eu-battery%402')
|
|
154
|
+
expect(body).toMatchObject({ id: 'eu-battery@2', format: 'binding', engine: { available: true }, demonstration: true })
|
|
155
|
+
expect(body.access.public).toContain('gs1:gtin')
|
|
156
|
+
expect(body.access.public).not.toContain('eubat:hasBatteryState')
|
|
157
|
+
expect(body.contexts.map((c: { path: string }) => c.path)).toContain('battery-context.jsonld')
|
|
158
|
+
expect(body.prefixes.gs1).toBe('https://ref.gs1.org/voc/')
|
|
159
|
+
const example = body.examples[0]
|
|
160
|
+
expect(example.passportId).toMatch(/^https:\/\/passports\.example\.com\/01\/0952\d{10}\/21\//)
|
|
161
|
+
expect(example.product.id).toBe(example.passportId)
|
|
162
|
+
expect(example.product['@context']).toEqual(body.contexts.filter((c: { path: string }) => ['dpp-core-context.jsonld', 'battery-context.jsonld'].includes(c.path)).map((c: { uri: string }) => c.uri))
|
|
163
|
+
// A manifest profile is described as before.
|
|
164
|
+
const general = (await get('/api/profiles/general%402')).body
|
|
165
|
+
expect(general.format).toBe('manifest')
|
|
166
|
+
expect(general.fields.length).toBeGreaterThan(0)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('serves the code lists the profile\'s own vocabulary defines', async () => {
|
|
170
|
+
const { body } = await get('/api/profiles/eu-textile%402/codes?class=eutex:CareSymbolCode&class=eutex:FabricType&class=nothing:Here')
|
|
171
|
+
expect(body['eutex:CareSymbolCode'].map((c: { value: string }) => c.value)).toContain('eutex:Wash30')
|
|
172
|
+
expect(body['eutex:CareSymbolCode'].find((c: { value: string }) => c.value === 'eutex:Wash30').label).not.toBe('')
|
|
173
|
+
expect(body['eutex:FabricType'].map((c: { value: string }) => c.value).sort()).toEqual(['eutex:Denim', 'eutex:Knitted', 'eutex:WovenNonDenim'])
|
|
174
|
+
expect(body['nothing:Here']).toEqual([])
|
|
175
|
+
const battery = (await get('/api/profiles/eu-battery%402/codes?class=oec:OperatorRole&class=eubat:BatteryCategory')).body
|
|
176
|
+
expect(battery['oec:OperatorRole']).toHaveLength(11)
|
|
177
|
+
expect(battery['eubat:BatteryCategory'].map((c: { value: string }) => c.value)).toContain('eubat:IndustrialBattery')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('issues from a product document, and refuses one whose serial is not the passport\'s', async () => {
|
|
181
|
+
const example = await exampleFor('eu-battery@2', 'HTTP-BAT-0001')
|
|
182
|
+
const wrong = await post(`/api/brands/${brandId}/passports`, { profile: 'eu-battery@2', itemReference: example.itemReference, serial: 'HTTP-BAT-0002', product: example.product })
|
|
183
|
+
expect(wrong.status).toBe(409)
|
|
184
|
+
expect(wrong.body).toMatchObject({ error: 'product-invalid', cause: 'product-identity-mismatch' })
|
|
185
|
+
expect((wrong.body.validation as ViewCheck).steps.at(-1)).toMatchObject({ step: 'passport-identity', status: 'fail' })
|
|
186
|
+
expect((await get(`/api/passports/${ref(example.passportId.replace('0001', '0002'))}`)).status).toBe(404)
|
|
187
|
+
|
|
188
|
+
const issued = await post(`/api/brands/${brandId}/passports`, { profile: 'eu-battery@2', itemReference: example.itemReference, serial: example.serial, product: example.product })
|
|
189
|
+
expect(issued.status).toBe(200)
|
|
190
|
+
expect(issued.body).toMatchObject({ passportId: example.passportId, profile: 'eu-battery@2' })
|
|
191
|
+
expect(issued.body.payload.product['eubat:batteryModelIdentifier']).toBe('HC-LFP-48-100')
|
|
192
|
+
expect(issued.body.payload.product['eubat:hasBatteryState']).toBeUndefined()
|
|
193
|
+
|
|
194
|
+
const missing = await post(`/api/brands/${brandId}/passports`, { profile: 'eu-battery@2', itemReference: example.itemReference, serial: 'HTTP-BAT-0003', payload: {} })
|
|
195
|
+
expect(missing.body.error).toBe('product-required')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it.each(['eu-battery@2', 'eu-textile@2'] as const)('refuses a contradictory expanded GTIN before issuing under %s', async (profile) => {
|
|
199
|
+
const example = await exampleFor(profile, 'HTTP-IDENTITY-001')
|
|
200
|
+
const { 'gs1:gtin': gtin, ...product } = example.product
|
|
201
|
+
expect(gtin).not.toBe('09521000001428')
|
|
202
|
+
const refused = await post(`/api/brands/${brandId}/passports`, {
|
|
203
|
+
profile, itemReference: example.itemReference, serial: example.serial,
|
|
204
|
+
product: { ...product, 'https://ref.gs1.org/voc/gtin': '09521000001428' },
|
|
205
|
+
})
|
|
206
|
+
expect(refused.status).toBe(409)
|
|
207
|
+
expect(refused.body).toMatchObject({ error: 'product-invalid', cause: 'product-identity-mismatch' })
|
|
208
|
+
expect((await get(`/api/passports/${ref(example.passportId)}`)).status).toBe(404)
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it('reports the two views apart: the public one to anyone, the authorised one to the holder', async () => {
|
|
212
|
+
const example = await exampleFor('eu-battery@2', 'HTTP-BAT-0001')
|
|
213
|
+
const reading = (await get(`/api/verify?passportId=${ref(example.passportId)}`)).body as PassportReading
|
|
214
|
+
expect(reading.payloadChecks[0].publicView).toMatchObject({ view: 'public', status: 'pass' })
|
|
215
|
+
expect(reading.product?.publicProduct['eubat:hasBatteryState']).toBeUndefined()
|
|
216
|
+
// A public reading carries no authorised view and no restricted part at all.
|
|
217
|
+
expect(reading).not.toHaveProperty('authorisedView')
|
|
218
|
+
expect(reading).not.toHaveProperty('restrictedProduct')
|
|
219
|
+
|
|
220
|
+
const authorised = (await post(`/api/passports/${ref(example.passportId)}/authorised-view`, {})).body as AuthorisedReading
|
|
221
|
+
expect(authorised.ownerTier.status).toBe('pass')
|
|
222
|
+
expect(authorised.authorisedView).toMatchObject({ view: 'authorised', status: 'pass' })
|
|
223
|
+
expect(authorised.product).toEqual(example.product)
|
|
224
|
+
|
|
225
|
+
// A passport under a manifest profile has no such view, and a passport of another brand is not this session's to open.
|
|
226
|
+
const general = (await get('/api/profiles/general%402')).body.sample as Json
|
|
227
|
+
const other = await post(`/api/brands/${brandId}/passports`, { profile: 'general@2', itemReference: '100000055', serial: 'HTTP-GEN-0001', payload: general, ownerFields: {} })
|
|
228
|
+
expect(other.status).toBe(200)
|
|
229
|
+
expect((await post(`/api/passports/${ref(other.body.passportId)}/authorised-view`, {})).body.error).toBe('profile-not-bound')
|
|
230
|
+
const foreign = await exampleFor('eu-battery@2', 'HTTP-BAT-0009')
|
|
231
|
+
await platform.writer.issue({ brandId: 'someone-else', brand: platform.parties.brand('someone-else'), passportId: foreign.passportId, profile: 'eu-battery@2', product: foreign.product })
|
|
232
|
+
expect((await post(`/api/passports/${ref(foreign.passportId)}/authorised-view`, {})).status).toBe(403)
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
describe('the authorised view, asked by someone it does not belong to', () => {
|
|
237
|
+
let anonymous: Server
|
|
238
|
+
let open: string
|
|
239
|
+
|
|
240
|
+
beforeAll(async () => {
|
|
241
|
+
// The same platform behind a server that knows no session: what a request from someone who has not signed in meets.
|
|
242
|
+
anonymous = createServer({ platform }).listen(0, '127.0.0.1')
|
|
243
|
+
await once(anonymous, 'listening')
|
|
244
|
+
open = `http://127.0.0.1:${(anonymous.address() as AddressInfo).port}`
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
afterAll(() => {
|
|
248
|
+
anonymous.closeAllConnections()
|
|
249
|
+
anonymous.close()
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
const ask = async (passportId: string, body: unknown): Promise<{ status: number; text: string; body: any }> => {
|
|
253
|
+
const response = await fetch(`${open}/api/passports/${ref(passportId)}/authorised-view`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
|
|
254
|
+
const text = await response.text()
|
|
255
|
+
return { status: response.status, text, body: JSON.parse(text) }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
it('answers 401 to a request with no session while the brand holds the passport, and opens nothing', async () => {
|
|
259
|
+
const example = await exampleFor('eu-battery@2', 'HTTP-ANON-0001')
|
|
260
|
+
expect((await post(`/api/brands/${brandId}/passports`, { profile: 'eu-battery@2', itemReference: example.itemReference, serial: example.serial, product: example.product })).status).toBe(200)
|
|
261
|
+
for (const body of [{}, { claimCode: 'anything' }]) {
|
|
262
|
+
const answer = await ask(example.passportId, body)
|
|
263
|
+
expect(answer.status).toBe(401)
|
|
264
|
+
expect(answer.body).toEqual({ error: 'sign-in-required', description: 'sign in first' })
|
|
265
|
+
expect(answer.text).not.toContain('eubat:hasBatteryState')
|
|
266
|
+
}
|
|
267
|
+
// The control: the same request with the brand's session opens it.
|
|
268
|
+
const member = await post(`/api/passports/${ref(example.passportId)}/authorised-view`, {})
|
|
269
|
+
expect(member.status).toBe(200)
|
|
270
|
+
expect((member.body as AuthorisedReading).authorisedView.status).toBe('pass')
|
|
271
|
+
expect(member.text).toContain('eubat:hasBatteryState')
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('answers 403 to a request for a handed-on passport without the claim code it was accepted with, or with another one', async () => {
|
|
275
|
+
const example = await exampleFor('eu-textile@2', 'HTTP-RECIPIENT-0001')
|
|
276
|
+
expect((await post(`/api/brands/${brandId}/passports`, { profile: 'eu-textile@2', itemReference: example.itemReference, serial: example.serial, product: example.product })).status).toBe(200)
|
|
277
|
+
const offered = await post(`/api/passports/${ref(example.passportId)}/offer`, { terms: { word: 'Sold' } })
|
|
278
|
+
expect(offered.status).toBe(200)
|
|
279
|
+
const { offer, claimCode } = offered.body as { offer: { requestId: string }; claimCode: string }
|
|
280
|
+
expect((await post(`/api/offers/${encodeURIComponent(offer.requestId)}/accept`, { claimCode })).status).toBe(200)
|
|
281
|
+
|
|
282
|
+
for (const body of [{}, { claimCode: 'not-the-claim-code' }, { claimCode: `${claimCode}0` }]) {
|
|
283
|
+
const answer = await ask(example.passportId, body)
|
|
284
|
+
expect(answer.status).toBe(403)
|
|
285
|
+
expect(answer.body).toMatchObject({ error: 'claim-code-required' })
|
|
286
|
+
expect(answer.text).not.toContain('eutex:hasWaterUsage')
|
|
287
|
+
}
|
|
288
|
+
// The brand's session is no longer a way in either: the passport is the recipient's.
|
|
289
|
+
expect((await post(`/api/passports/${ref(example.passportId)}/authorised-view`, {})).status).toBe(403)
|
|
290
|
+
|
|
291
|
+
// The recipient opens the restricted part sealed during the transfer using the accepted claim code.
|
|
292
|
+
const holder = await ask(example.passportId, { claimCode })
|
|
293
|
+
expect(holder.status).toBe(200)
|
|
294
|
+
expect((holder.body as AuthorisedReading).ownerTier.status).toBe('pass')
|
|
295
|
+
expect((holder.body as AuthorisedReading).authorisedView.status).toBe('pass')
|
|
296
|
+
expect((holder.body as AuthorisedReading).restrictedProduct).toHaveProperty('eutex:hasWaterUsage', example.product['eutex:hasWaterUsage'])
|
|
297
|
+
})
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
describe('a restricted value', () => {
|
|
301
|
+
// A value that is in no fixture, no log line and no key: wherever it turns up, it was copied there.
|
|
302
|
+
const canary = 'RESTRICTED-CANARY-7F3A91C2'
|
|
303
|
+
|
|
304
|
+
const withCanary = (profile: string, product: Json): Json => {
|
|
305
|
+
const copy = structuredClone(product)
|
|
306
|
+
if (profile === 'eu-battery@2') {
|
|
307
|
+
copy['eubat:manufacturerIdentifier'] = canary
|
|
308
|
+
;(copy['eubat:hasSupplyChainDueDiligence'] as Json)['eubat:auditBody'] = `${canary} audit body`
|
|
309
|
+
;((copy['eubat:hasMaterialComposition'] as Json[])[0]['schema:name'] as Json)['@value'] = `${canary} material`
|
|
310
|
+
} else {
|
|
311
|
+
;(copy['eutex:hasSubstancesOfConcern'] as Json[])[0]['oec:substanceLocation'] = `${canary} location`
|
|
312
|
+
;(copy['oec:hasOperatorInformation'] as Json)['gs1:organizationName'] = `${canary} operator`
|
|
313
|
+
copy['eutex:hasCutAndSewFacility'] = { ...(copy['eutex:hasCutAndSewFacility'] as Json), 'schema:name': `${canary} facility` }
|
|
314
|
+
}
|
|
315
|
+
return copy
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
it('reaches the holder who opens it, and nothing this application prints, lists, indexes or exports', async () => {
|
|
319
|
+
const seen: Array<[string, string]> = []
|
|
320
|
+
const keep = (where: string, text: string): string => {
|
|
321
|
+
seen.push([where, text])
|
|
322
|
+
return text
|
|
323
|
+
}
|
|
324
|
+
const passports: string[] = []
|
|
325
|
+
|
|
326
|
+
for (const [profile, serial] of [
|
|
327
|
+
['eu-battery@2', 'LEAK-BAT-0001'],
|
|
328
|
+
['eu-textile@2', 'LEAK-TEX-0001'],
|
|
329
|
+
] as const) {
|
|
330
|
+
const example = await exampleFor(profile, serial)
|
|
331
|
+
const product = withCanary(profile, example.product)
|
|
332
|
+
passports.push(example.passportId)
|
|
333
|
+
|
|
334
|
+
// Issued, then updated, so the value passes through both write paths.
|
|
335
|
+
const issued = await post(`/api/brands/${brandId}/passports`, { profile, itemReference: example.itemReference, serial, product })
|
|
336
|
+
expect(issued.status).toBe(200)
|
|
337
|
+
keep(`issue response, ${profile}`, issued.text)
|
|
338
|
+
const updated = await post(`/api/passports/${ref(example.passportId)}/update`, { product: { ...product, 'oec:lastUpdated': '2026-11-04T08:00:00Z' } })
|
|
339
|
+
expect(updated.status).toBe(200)
|
|
340
|
+
keep(`update response, ${profile}`, updated.text)
|
|
341
|
+
|
|
342
|
+
// A write that is refused, with the value inside the document: the refusal is answered and not printed.
|
|
343
|
+
const refused = await post(`/api/brands/${brandId}/passports`, { profile, itemReference: example.itemReference, serial: `${serial}-X`, product })
|
|
344
|
+
expect(refused.status).toBe(409)
|
|
345
|
+
// A body that is not JSON, with the value in it: the parser's own error quotes the body.
|
|
346
|
+
const garbled = await post(`/api/brands/${brandId}/passports`, undefined, `{"profile":"${profile}","product":{"x":"${canary}"`)
|
|
347
|
+
expect(garbled.status).toBe(400)
|
|
348
|
+
expect(garbled.body.error).toBe('body-not-json')
|
|
349
|
+
keep(`garbled body response, ${profile}`, garbled.text)
|
|
350
|
+
|
|
351
|
+
// The control: the holder's view does carry the value, so this search can find it where it is.
|
|
352
|
+
const authorised = await post(`/api/passports/${ref(example.passportId)}/authorised-view`, {})
|
|
353
|
+
expect(authorised.text).toContain(canary)
|
|
354
|
+
expect((authorised.body as AuthorisedReading).authorisedView.status).toBe('pass')
|
|
355
|
+
|
|
356
|
+
// Everything another reader can ask for.
|
|
357
|
+
keep(`journal view, ${profile}`, (await get(`/api/passports/${ref(example.passportId)}`)).text)
|
|
358
|
+
keep(`verify, ${profile}`, (await get(`/api/verify?passportId=${ref(example.passportId)}`)).text)
|
|
359
|
+
const claim = await post(`/api/passports/${ref(example.passportId)}/claims`, { assertedRole: 'observer', event: { type: 'ObjectEvent', eventID: `urn:uuid:6c000000-0000-4000-8000-${profile === 'eu-battery@2' ? '0000000000b1' : '0000000000b2'}`, eventTime: '2026-11-04T07:00:00.000Z', eventTimeZoneOffset: '+00:00', epcList: [example.passportId], action: 'OBSERVE', bizStep: 'inspecting', disposition: 'conformant' } })
|
|
360
|
+
expect(claim.status, claim.text).toBe(200)
|
|
361
|
+
keep(`claim, ${profile}`, claim.text)
|
|
362
|
+
keep(`claim bytes, ${profile}`, (await get(`/api/lifecycle-claims/${ref(claim.body.attestationId)}`)).text)
|
|
363
|
+
keep(`claims, ${profile}`, (await get(`/api/passports/${ref(example.passportId)}/claims`)).text)
|
|
364
|
+
const offer = await post(`/api/passports/${ref(example.passportId)}/offer`, { terms: { word: 'Sold' } })
|
|
365
|
+
keep(`offer, ${profile}`, offer.text)
|
|
366
|
+
keep(`offers, ${profile}`, (await get(`/api/passports/${ref(example.passportId)}/offers`)).text)
|
|
367
|
+
keep(`offer preview, ${profile}`, (await get(`/api/offers/${encodeURIComponent(offer.body.offer.requestId)}`)).text)
|
|
368
|
+
|
|
369
|
+
// The index this process runs: its lookup, and its public history and evidence exports.
|
|
370
|
+
const lookup = await fetch(`${platform.index.url}/lookup`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ service: 'ls_dpp', query: { passportId: example.passportId } }) })
|
|
371
|
+
const answer = (await lookup.json()) as { outputs: Array<{ beef: number[] }> }
|
|
372
|
+
expect(answer.outputs.length).toBeGreaterThan(0)
|
|
373
|
+
for (const output of answer.outputs) keep(`index lookup bytes, ${profile}`, Buffer.from(output.beef).toString('latin1'))
|
|
374
|
+
for (const path of ['/history', '/evidence-package', '/evidence-export']) {
|
|
375
|
+
keep(`index ${path}, ${profile}`, await (await fetch(`${platform.index.url}${path}?passportId=${ref(example.passportId)}`)).text())
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// The EPCIS exchange: events that name both passports are imported, and everything it lists and exports is searched too.
|
|
380
|
+
const events = epcisDocument(passports.map((passportId, index) => objectEvent(index + 1, [passportId], { bizStep: 'shipping', disposition: 'in_transit' })))
|
|
381
|
+
const imported = await upload('/api/epcis/imports?requestId=leak-events', JSON.stringify(events))
|
|
382
|
+
expect(imported.status).toBe(201)
|
|
383
|
+
keep('epcis import response', imported.text)
|
|
384
|
+
keep('epcis imports', (await get('/api/epcis/imports')).text)
|
|
385
|
+
keep('epcis import record', (await get(`/api/epcis/imports/${ref(imported.body.record.importId)}`)).text)
|
|
386
|
+
keep('epcis original', (await get(`/api/epcis/imports/${ref(imported.body.record.importId)}/original`)).text)
|
|
387
|
+
for (const passportId of passports) {
|
|
388
|
+
const named = await get(`/api/epcis/events?identifier=${ref(passportId)}`)
|
|
389
|
+
expect(named.body.events).toHaveLength(1)
|
|
390
|
+
keep(`epcis events, ${passportId}`, named.text)
|
|
391
|
+
}
|
|
392
|
+
keep('epcis status', (await get('/api/epcis/status')).text)
|
|
393
|
+
keep('epcis conflicts', (await get('/api/epcis/conflicts')).text)
|
|
394
|
+
keep('epcis store', await epcisStore())
|
|
395
|
+
|
|
396
|
+
keep('passport list', (await get(`/api/brands/${brandId}/passports`)).text)
|
|
397
|
+
keep('operations', (await get('/api/operations')).text)
|
|
398
|
+
keep('operations run', (await post('/api/operations/run', {})).text)
|
|
399
|
+
keep('health', (await get('/api/health')).text)
|
|
400
|
+
keep('profiles', (await get('/api/profiles')).text)
|
|
401
|
+
// The journal as the store holds it, which is what a database dump would show.
|
|
402
|
+
keep('journal', JSON.stringify(await platform.store.listPassports()))
|
|
403
|
+
keep('everything printed', printed.join('\n'))
|
|
404
|
+
|
|
405
|
+
// The listings did return the passports, so an empty answer is not what kept the value out.
|
|
406
|
+
for (const passportId of passports) expect(seen.find(([where]) => where === 'passport list')![1]).toContain(passportId)
|
|
407
|
+
expect(seen.find(([where]) => where === 'journal')![1]).toContain('ciphertext')
|
|
408
|
+
expect(printed.length).toBeGreaterThan(0)
|
|
409
|
+
|
|
410
|
+
const leaks = seen.filter(([, text]) => text.includes(canary)).map(([where]) => where)
|
|
411
|
+
expect(leaks).toEqual([])
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
it('is not echoed in an error the API did not expect', async () => {
|
|
415
|
+
// An error object can carry the request among its properties; only its name and stack are printed.
|
|
416
|
+
const error = Object.assign(new Error('unexpected'), { body: `{"secret":"${canary}"}` })
|
|
417
|
+
const spy = vi.spyOn(platform.store, 'getBrand').mockRejectedValueOnce(error)
|
|
418
|
+
const before = printed.length
|
|
419
|
+
const answer = await post(`/api/brands/${brandId}/passports`, { profile: 'eu-battery@2', itemReference: '100200300', serial: 'LEAK-ERR-0001', product: {} })
|
|
420
|
+
spy.mockRestore()
|
|
421
|
+
expect(answer.status).toBe(500)
|
|
422
|
+
const lines = printed.slice(before).join('\n')
|
|
423
|
+
expect(lines).toMatch(/request failed: Error: unexpected/)
|
|
424
|
+
expect(lines).not.toContain(canary)
|
|
425
|
+
})
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
describe('the credential of an EPCIS source', () => {
|
|
429
|
+
// Every form the credential travels in: as it is, as an address would spell it, and as a basic authorisation carries it.
|
|
430
|
+
const forms = [credential, encodeURIComponent(credential), Buffer.from(`operator:${credential}`).toString('base64')]
|
|
431
|
+
|
|
432
|
+
it('reaches the source it was configured for, and nothing this application answers, lists, stores, exports or prints', async () => {
|
|
433
|
+
const seen: Array<[string, string]> = []
|
|
434
|
+
const keep = (where: string, text: string): string => {
|
|
435
|
+
seen.push([where, text])
|
|
436
|
+
return text
|
|
437
|
+
}
|
|
438
|
+
const before = printed.length
|
|
439
|
+
|
|
440
|
+
// The source is described: that a credential is set, and which kind.
|
|
441
|
+
const described = await get('/api/epcis/sources')
|
|
442
|
+
expect(described.body.map((source: Json) => [source.sourceId, source.credentialConfigured, source.credentialScheme])).toEqual([['supplier-a', true, 'bearer'], ['echo', true, 'header'], ['stranger', true, 'basic']])
|
|
443
|
+
keep('sources', described.text)
|
|
444
|
+
keep('status', (await get('/api/epcis/status')).text)
|
|
445
|
+
|
|
446
|
+
// A pull that works, over several pages. The control: the source did receive the credential, so this search can find it where it is.
|
|
447
|
+
const pulled = await post('/api/epcis/sources/supplier-a/pulls', { queryId: 'leak', query: { perPage: 2 } })
|
|
448
|
+
expect(pulled.body).toMatchObject({ outcome: 'ok', events: { total: 5 }, pull: { source: { credentialsConfigured: true } } })
|
|
449
|
+
expect(epcisSource.requests.filter((request) => request.headers.authorization === `Bearer ${credential}`)).toHaveLength(3)
|
|
450
|
+
keep('pull result', pulled.text)
|
|
451
|
+
keep('pull state', (await get('/api/epcis/sources/supplier-a/pulls/leak')).text)
|
|
452
|
+
for (const page of pulled.body.pages as Json[]) {
|
|
453
|
+
keep(`page import ${String(page.page)}`, (await get(`/api/epcis/imports/${ref(String(page.importId))}`)).text)
|
|
454
|
+
keep(`page original ${String(page.page)}`, (await get(`/api/epcis/imports/${ref(String(page.importId))}/original`)).text)
|
|
455
|
+
}
|
|
456
|
+
keep('events of a pulled item', (await get(`/api/epcis/events?identifier=${ref(item('LEAK-3'))}`)).text)
|
|
457
|
+
|
|
458
|
+
// A source that refuses the credential it is sent, and one that sends it back in its answer. Neither answer is kept, and neither refusal quotes it.
|
|
459
|
+
const refused = await post('/api/epcis/sources/stranger/pulls', { queryId: 'leak', query: {} })
|
|
460
|
+
expect(refused.body).toMatchObject({ outcome: 'source-authentication-required', pages: [] })
|
|
461
|
+
expect(epcisSource.requests.at(-1)!.headers.authorization).toBe(`Basic ${Buffer.from(`operator:${credential}`).toString('base64')}`)
|
|
462
|
+
keep('refused pull', refused.text)
|
|
463
|
+
const echoed = await post('/api/epcis/sources/echo/pulls', { queryId: 'leak', query: {} })
|
|
464
|
+
expect(echoed.body).toMatchObject({ outcome: 'invalid-source', reason: 'credential-echoed', pages: [] })
|
|
465
|
+
expect(echoingSource.requests.at(-1)!.headers['x-api-key']).toBe(credential)
|
|
466
|
+
keep('echoed pull', echoed.text)
|
|
467
|
+
keep('echoed pull state', (await get('/api/epcis/sources/echo/pulls/leak')).text)
|
|
468
|
+
|
|
469
|
+
// A request that carries the credential itself: as a query value, which the pull refuses, and in a body that is not JSON.
|
|
470
|
+
const carried = await post('/api/epcis/sources/supplier-a/pulls', { queryId: 'carried', query: { eventIds: [`urn:example:${credential}`] } })
|
|
471
|
+
expect(carried.status).toBe(400)
|
|
472
|
+
keep('pull with the credential as a query value', carried.text)
|
|
473
|
+
const garbled = await post('/api/epcis/sources/supplier-a/pulls', undefined, `{"queryId":"${credential}`)
|
|
474
|
+
expect(garbled.status).toBe(400)
|
|
475
|
+
expect(garbled.body.error).toBe('body-not-json')
|
|
476
|
+
keep('garbled pull request', garbled.text)
|
|
477
|
+
|
|
478
|
+
keep('imports', (await get('/api/epcis/imports?limit=200')).text)
|
|
479
|
+
keep('conflicts', (await get('/api/epcis/conflicts')).text)
|
|
480
|
+
keep('health', (await get('/api/health')).text)
|
|
481
|
+
keep('operations', (await get('/api/operations')).text)
|
|
482
|
+
// The store, which is what a database dump would show, and every line printed since this test began.
|
|
483
|
+
keep('epcis store', await epcisStore())
|
|
484
|
+
keep('everything printed', printed.slice(before).join('\n'))
|
|
485
|
+
|
|
486
|
+
// The listings did hold the pulled pages and the log did follow the pulls, so an empty answer is not what kept the credential out.
|
|
487
|
+
expect((await get('/api/epcis/imports?limit=200')).body.imports.filter((entry: Json) => (entry.provenance as Json).kind === 'query')).toHaveLength(3)
|
|
488
|
+
expect(seen.find(([where]) => where === 'epcis store')![1]).toContain('"credentialsConfigured":true')
|
|
489
|
+
expect(printed.slice(before).some((line) => line.startsWith('EPCIS pull supplier-a/leak:') && line.includes('"credentialSent":true'))).toBe(true)
|
|
490
|
+
|
|
491
|
+
const leaks = seen.filter(([, text]) => forms.some((form) => text.includes(form))).map(([where]) => where)
|
|
492
|
+
expect(leaks).toEqual([])
|
|
493
|
+
// Nor is it anywhere this file's earlier tests printed.
|
|
494
|
+
expect(forms.some((form) => printed.join('\n').includes(form))).toBe(false)
|
|
495
|
+
})
|
|
496
|
+
})
|