@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,224 @@
|
|
|
1
|
+
import { createMemoryEpcisStorage } from '@bsv/dpp-credentials/epcis-exchange'
|
|
2
|
+
import { acceptanceCommitment, evidencePackageSigner, EVIDENCE_PACKAGE_PROTOCOL, signEvidenceManifest, type EvidencePackageManifest, type InventoryEntry, type ManagedAcceptanceRecord } from '@bsv/dpp-protocol'
|
|
3
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { loadConfig } from '../src/config.js'
|
|
5
|
+
import { mintPassportId } from '../src/identifiers.js'
|
|
6
|
+
import { openPlatform, type Platform } from '../src/platform.js'
|
|
7
|
+
import { exportApplication, type ExportedApplication } from '../src/portability/export.js'
|
|
8
|
+
import { APPLICATION_EXPORT_DESCRIPTOR, passportFolder, recordBytes, sha256Hex } from '../src/portability/package.js'
|
|
9
|
+
import { restoreApplication, verifyApplicationPackage } from '../src/portability/restore.js'
|
|
10
|
+
import { samplePayload } from '../src/profiles.js'
|
|
11
|
+
|
|
12
|
+
const profile = 'managed-custody@3' as const
|
|
13
|
+
const config = loadConfig({ NETWORK: 'main', PASSPORT_HOST: 'passports.example.com', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false' })
|
|
14
|
+
const id = mintPassportId({ host: config.passportHost, prefix: config.gs1Prefix }, '100000206', 'RECOVERY')
|
|
15
|
+
const folder = passportFolder(id)
|
|
16
|
+
let platform: Platform
|
|
17
|
+
let base: ExportedApplication
|
|
18
|
+
let completed: ManagedAcceptanceRecord
|
|
19
|
+
let pending: ManagedAcceptanceRecord
|
|
20
|
+
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
platform = await openPlatform({ config, mode: 'test', log: () => {} })
|
|
23
|
+
const brandId = 'recovery-brand'
|
|
24
|
+
const brand = platform.parties.brand(brandId)
|
|
25
|
+
await platform.writer.issue({ brandId, brand, passportId: id, profile: 'general@2', payload: samplePayload('general@2', true) })
|
|
26
|
+
async function offer() {
|
|
27
|
+
const record = (await platform.store.getPassport(id))!
|
|
28
|
+
const created = await platform.custody.offer({ record, holder: platform.custody.holderOf(record), terms: { word: 'Handed on' } })
|
|
29
|
+
return { requestId: created.offer.requestId, claimCode: created.claimCode! }
|
|
30
|
+
}
|
|
31
|
+
completed = (await platform.custody.accept(await offer())).record
|
|
32
|
+
const awaiting = await offer()
|
|
33
|
+
vi.spyOn(platform.writer, 'transfer').mockRejectedValueOnce(new Error('wallet offline'))
|
|
34
|
+
await expect(platform.custody.accept(awaiting)).rejects.toThrow('wallet offline')
|
|
35
|
+
pending = (await platform.store.getOffer(awaiting.requestId))!.record!
|
|
36
|
+
base = await exportApplication({ platform, epcis: { storage: createMemoryEpcisStorage(), sources: [] }, access: 'authorised-recovery' })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
afterAll(async () => { await platform?.close() })
|
|
40
|
+
|
|
41
|
+
type PackageCopy = { manifest: EvidencePackageManifest; files: Map<string, Uint8Array> }
|
|
42
|
+
const authorityPath = (record: ManagedAcceptanceRecord) => `${folder}/authority/${acceptanceCommitment(record)}.json`
|
|
43
|
+
const reference = (record: ManagedAcceptanceRecord) => `acceptance:sha256:${acceptanceCommitment(record)}`
|
|
44
|
+
|
|
45
|
+
/** Build a valid exporter signature over each altered set of recovery records. */
|
|
46
|
+
async function signedCopy(change: (copy: PackageCopy) => void | Promise<void>) {
|
|
47
|
+
const manifest = structuredClone(base.manifest)
|
|
48
|
+
manifest.profiles = [...new Set([...(manifest.profiles ?? []), profile])]
|
|
49
|
+
const files = new Map(base.files)
|
|
50
|
+
await change({ manifest, files })
|
|
51
|
+
manifest.inventory = manifest.inventory.filter(entry => files.has(entry.path)).map(entry => {
|
|
52
|
+
const bytes = files.get(entry.path)!
|
|
53
|
+
return { ...entry, sha256: sha256Hex(bytes), byteLength: bytes.length }
|
|
54
|
+
})
|
|
55
|
+
const signed = await signEvidenceManifest(manifest, { sign: async data => (await platform.wallet.custodian.createSignature({
|
|
56
|
+
data, protocolID: EVIDENCE_PACKAGE_PROTOCOL, keyID: manifest.passportId, counterparty: 'anyone',
|
|
57
|
+
})).signature })
|
|
58
|
+
return { manifestText: JSON.stringify(signed), files }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const trust = () => ({ exporterKey: platform.wallet.identityKey, trustedBindingDigests: [] })
|
|
62
|
+
|
|
63
|
+
function removeAuthority(copy: PackageCopy) {
|
|
64
|
+
copy.files.delete(authorityPath(completed))
|
|
65
|
+
const descriptor = structuredClone(base.descriptor)
|
|
66
|
+
descriptor.passports[0]!.acceptanceRecords = 0
|
|
67
|
+
copy.files.set(APPLICATION_EXPORT_DESCRIPTOR, recordBytes(descriptor))
|
|
68
|
+
const path = `${folder}/journal.json`
|
|
69
|
+
const record = JSON.parse(new TextDecoder().decode(copy.files.get(path)!))
|
|
70
|
+
copy.files.set(path, recordBytes({ ...record, acceptanceRecords: [] }))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe('managed custody recovery profile selection and carriage', () => {
|
|
74
|
+
it('reads an earlier signed package and refuses an operation requiring its successor', async () => {
|
|
75
|
+
const historical = await signedCopy(({ manifest }) => { manifest.profiles = manifest.profiles!.filter(value => value !== profile) })
|
|
76
|
+
expect((await verifyApplicationPackage(historical, trust())).journals).toHaveLength(1)
|
|
77
|
+
await expect(verifyApplicationPackage(historical, { ...trust(), requiredCustodyProfile: profile })).rejects.toMatchObject({ code: 'not-selected' })
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('refuses a signed profile list that is a string or has a non-string member', async () => {
|
|
81
|
+
for (const malformed of [`earlier-${profile}`, [profile, 3]]) {
|
|
82
|
+
const pkg = await signedCopy(({ manifest }) => { Object.assign(manifest, { profiles: malformed }) })
|
|
83
|
+
await expect(verifyApplicationPackage(pkg, { ...trust(), requiredCustodyProfile: profile })).rejects.toMatchObject({ code: 'manifest-invalid' })
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('checks a nested authority entry against the signed index inventory and the completed transfer', async () => {
|
|
88
|
+
const nestedRoot = `${folder}/index/`
|
|
89
|
+
const path = 'authority/acceptance.json'
|
|
90
|
+
const indexManifest = `${nestedRoot}manifest.json`
|
|
91
|
+
async function addNested(copy: PackageCopy, record: ManagedAcceptanceRecord, outer: Partial<InventoryEntry> = {}) {
|
|
92
|
+
const nested = JSON.parse(new TextDecoder().decode(copy.files.get(indexManifest)!)) as EvidencePackageManifest
|
|
93
|
+
const bytes = recordBytes(record)
|
|
94
|
+
const entry: InventoryEntry = { path, category: 'authority', mediaType: 'application/json', representation: record.acceptanceFormat, sha256: sha256Hex(bytes), byteLength: bytes.length }
|
|
95
|
+
const key = platform.wallet.identityKey
|
|
96
|
+
const signed = await signEvidenceManifest({
|
|
97
|
+
...nested, exporter: { ...nested.exporter, id: key }, profiles: [], inventory: [...nested.inventory, entry],
|
|
98
|
+
signature: { suite: 'bsv-ecdsa-der', signer: evidencePackageSigner(key, id) },
|
|
99
|
+
}, { sign: async data => (await platform.wallet.custodian.createSignature({ data, protocolID: EVIDENCE_PACKAGE_PROTOCOL, keyID: id, counterparty: 'anyone' })).signature })
|
|
100
|
+
copy.files.set(indexManifest, recordBytes(signed))
|
|
101
|
+
copy.files.set(nestedRoot + path, bytes)
|
|
102
|
+
copy.manifest.inventory.push({ ...entry, path: nestedRoot + path, representation: 'dpp-nested-authority@1', ...outer })
|
|
103
|
+
}
|
|
104
|
+
const valid = await signedCopy(pkg => addNested(pkg, completed))
|
|
105
|
+
expect((await verifyApplicationPackage(valid, trust())).journals[0]!.acceptanceRecords).toEqual([completed])
|
|
106
|
+
for (const outer of [{ representation: completed.acceptanceFormat }, { represents: 'sha256:' + '00'.repeat(32) }, { category: 'reports' as const }]) {
|
|
107
|
+
const changed = await signedCopy(pkg => addNested(pkg, completed, outer))
|
|
108
|
+
await expect(verifyApplicationPackage(changed, trust())).rejects.toMatchObject({ code: 'index-evidence-refused' })
|
|
109
|
+
}
|
|
110
|
+
const unmatched = await signedCopy(pkg => addNested(pkg, pending))
|
|
111
|
+
await expect(verifyApplicationPackage(unmatched, trust())).rejects.toMatchObject({ code: 'index-evidence-refused' })
|
|
112
|
+
const hidden = await signedCopy(async pkg => {
|
|
113
|
+
await addNested(pkg, completed)
|
|
114
|
+
removeAuthority(pkg)
|
|
115
|
+
const offerPath = `application/offers/${sha256Hex(completed.requestId)}.json`
|
|
116
|
+
const offer = JSON.parse(new TextDecoder().decode(pkg.files.get(offerPath)!))
|
|
117
|
+
delete offer.record
|
|
118
|
+
pkg.files.set(offerPath, recordBytes(offer))
|
|
119
|
+
pkg.manifest.completeness.absent.push(reference(completed))
|
|
120
|
+
})
|
|
121
|
+
await expect(verifyApplicationPackage(hidden, trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('refuses a missing authority copy even if the exporter declared an acceptance it still carries in the offer absent', async () => {
|
|
125
|
+
const copy = await signedCopy(pkg => { removeAuthority(pkg); pkg.manifest.completeness.absent.push(reference(completed)) })
|
|
126
|
+
await expect(verifyApplicationPackage(copy, trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('requires one absent declaration for a lost completed record and accepts its retained transfer', async () => {
|
|
130
|
+
const lost = (pkg: PackageCopy) => {
|
|
131
|
+
removeAuthority(pkg)
|
|
132
|
+
const path = `application/offers/${sha256Hex(completed.requestId)}.json`
|
|
133
|
+
const offer = JSON.parse(new TextDecoder().decode(pkg.files.get(path)!))
|
|
134
|
+
delete offer.record
|
|
135
|
+
pkg.files.set(path, recordBytes(offer))
|
|
136
|
+
}
|
|
137
|
+
const declared = await signedCopy(pkg => { lost(pkg); pkg.manifest.completeness.absent.push(reference(completed)) })
|
|
138
|
+
const verified = await verifyApplicationPackage(declared, trust())
|
|
139
|
+
expect(verified.journals[0]!.acceptanceRecords).toEqual([])
|
|
140
|
+
expect(verified.offers.find(offer => offer.requestId === completed.requestId)).toMatchObject({ status: 'transferred' })
|
|
141
|
+
const destination = await openPlatform({ config, mode: 'test', log: () => {} })
|
|
142
|
+
try {
|
|
143
|
+
const report = await restoreApplication({ verified, platform: destination, epcis: { storage: createMemoryEpcisStorage(), sources: [] }, rebuildIndex: true })
|
|
144
|
+
expect(report.attention).toContainEqual(expect.stringContaining(reference(completed)))
|
|
145
|
+
} finally {
|
|
146
|
+
await destination.close()
|
|
147
|
+
}
|
|
148
|
+
await expect(verifyApplicationPackage(await signedCopy(lost), trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('uses the recorded send outcome when an index already holds an interrupted transfer', async () => {
|
|
152
|
+
function interrupt(pkg: PackageCopy) {
|
|
153
|
+
removeAuthority(pkg)
|
|
154
|
+
const path = `${folder}/journal.json`
|
|
155
|
+
const journal = JSON.parse(new TextDecoder().decode(pkg.files.get(path)!))
|
|
156
|
+
const draft = journal.states.at(-1)
|
|
157
|
+
Object.assign(draft, { network: 'unanswered', acceptance: completed })
|
|
158
|
+
pkg.files.set(path, recordBytes(journal))
|
|
159
|
+
const offerPath = `application/offers/${sha256Hex(completed.requestId)}.json`
|
|
160
|
+
const offer = JSON.parse(new TextDecoder().decode(pkg.files.get(offerPath)!))
|
|
161
|
+
delete offer.transferTxid
|
|
162
|
+
pkg.files.set(offerPath, recordBytes({ ...offer, status: 'accepted' }))
|
|
163
|
+
}
|
|
164
|
+
const verified = await verifyApplicationPackage(await signedCopy(interrupt), trust())
|
|
165
|
+
expect(verified.journals[0]!.acceptanceRecords).toEqual([])
|
|
166
|
+
expect(verified.offers.find(offer => offer.requestId === completed.requestId)?.record).toEqual(completed)
|
|
167
|
+
const missingOffer = await signedCopy(pkg => {
|
|
168
|
+
interrupt(pkg)
|
|
169
|
+
const path = `${folder}/journal.json`
|
|
170
|
+
const journal = JSON.parse(new TextDecoder().decode(pkg.files.get(path)!))
|
|
171
|
+
delete journal.states.at(-1).acceptance
|
|
172
|
+
pkg.files.set(path, recordBytes(journal))
|
|
173
|
+
pkg.files.delete(`application/offers/${sha256Hex(completed.requestId)}.json`)
|
|
174
|
+
const descriptor = JSON.parse(new TextDecoder().decode(pkg.files.get(APPLICATION_EXPORT_DESCRIPTOR)!))
|
|
175
|
+
descriptor.records.offers -= 1
|
|
176
|
+
pkg.files.set(APPLICATION_EXPORT_DESCRIPTOR, recordBytes(descriptor))
|
|
177
|
+
})
|
|
178
|
+
await expect(verifyApplicationPackage(missingOffer, trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
179
|
+
const falseLoss = await signedCopy(pkg => {
|
|
180
|
+
interrupt(pkg)
|
|
181
|
+
pkg.manifest.completeness.absent.push(reference(completed))
|
|
182
|
+
})
|
|
183
|
+
await expect(verifyApplicationPackage(falseLoss, trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('refuses a declaration of loss when a completed journal state still carries its signed acceptance', async () => {
|
|
187
|
+
const copy = await signedCopy(pkg => {
|
|
188
|
+
removeAuthority(pkg)
|
|
189
|
+
const path = `${folder}/journal.json`
|
|
190
|
+
const journal = JSON.parse(new TextDecoder().decode(pkg.files.get(path)!))
|
|
191
|
+
journal.states.at(-1).acceptance = completed
|
|
192
|
+
pkg.files.set(path, recordBytes(journal))
|
|
193
|
+
const offerPath = `application/offers/${sha256Hex(completed.requestId)}.json`
|
|
194
|
+
const offer = JSON.parse(new TextDecoder().decode(pkg.files.get(offerPath)!))
|
|
195
|
+
delete offer.record
|
|
196
|
+
pkg.files.set(offerPath, recordBytes(offer))
|
|
197
|
+
pkg.manifest.completeness.absent.push(reference(completed))
|
|
198
|
+
})
|
|
199
|
+
await expect(verifyApplicationPackage(copy, trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it('refuses a retained authority entry that names a pending acceptance and has no completed transfer', async () => {
|
|
203
|
+
const copy = await signedCopy(({ manifest, files }) => {
|
|
204
|
+
const path = authorityPath(pending)
|
|
205
|
+
const source = manifest.inventory.find(entry => entry.path === authorityPath(completed))!
|
|
206
|
+
manifest.inventory.push({ ...source, path, represents: `sha256:${acceptanceCommitment(pending)}` })
|
|
207
|
+
files.set(path, recordBytes(pending))
|
|
208
|
+
const journalPath = `${folder}/journal.json`
|
|
209
|
+
const record = JSON.parse(new TextDecoder().decode(files.get(journalPath)!))
|
|
210
|
+
files.set(journalPath, recordBytes({ ...record, acceptanceRecords: [completed, pending] }))
|
|
211
|
+
const descriptor = structuredClone(base.descriptor)
|
|
212
|
+
descriptor.passports[0]!.acceptanceRecords = 2
|
|
213
|
+
files.set(APPLICATION_EXPORT_DESCRIPTOR, recordBytes(descriptor))
|
|
214
|
+
})
|
|
215
|
+
await expect(verifyApplicationPackage(copy, trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('refuses an acceptance declared absent alongside its authority copy or withheld from recovery', async () => {
|
|
219
|
+
for (const category of ['absent', 'withheld'] as const) {
|
|
220
|
+
const copy = await signedCopy(({ manifest }) => manifest.completeness[category].push(reference(completed) + (category === 'withheld' ? ' not-public' : '')))
|
|
221
|
+
await expect(verifyApplicationPackage(copy, trust())).rejects.toMatchObject({ code: 'records-inconsistent' })
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
})
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// A profile of your own, held by a binding in a folder: the configuration
|
|
2
|
+
// names the folder and the digest of the binding this deployment reviewed,
|
|
3
|
+
// and the profile is registered at start-up without a line of source
|
|
4
|
+
// changing. The folders under test/fixtures/custom-profile are the two
|
|
5
|
+
// example profiles of the DPP repository, example-bottle@1 and
|
|
6
|
+
// example-notebook@1, with the vectors that say what each accepts.
|
|
7
|
+
import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync, appendFileSync } from 'node:fs'
|
|
8
|
+
import { tmpdir } from 'node:os'
|
|
9
|
+
import { CURRENT_SECTOR_BINDINGS } from '@bsv/dpp-profiles'
|
|
10
|
+
import { dirname, join } from 'node:path'
|
|
11
|
+
import { fileURLToPath } from 'node:url'
|
|
12
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
13
|
+
import { profileBindingDigest } from '@bsv/dpp-profiles'
|
|
14
|
+
import { loadConfig } from '../src/config.js'
|
|
15
|
+
import { mintPassportId } from '../src/identifiers.js'
|
|
16
|
+
import { openPlatform, type Platform } from '../src/platform.js'
|
|
17
|
+
import { samplePayload } from '../src/profiles.js'
|
|
18
|
+
|
|
19
|
+
type Json = Record<string, unknown>
|
|
20
|
+
|
|
21
|
+
const fixtures = join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'custom-profile')
|
|
22
|
+
const bottle = join(fixtures, 'example-bottle@1')
|
|
23
|
+
const notebook = join(fixtures, 'example-notebook@1')
|
|
24
|
+
const digestOf = (folder: string): string => profileBindingDigest(new Uint8Array(readFileSync(join(folder, 'binding.json'))))
|
|
25
|
+
const vector = (folder: string, name: string): { passportId: string; payload: { product: Json } } => JSON.parse(readFileSync(join(folder, 'vectors', name), 'utf8'))
|
|
26
|
+
|
|
27
|
+
const scratch = mkdtempSync(join(tmpdir(), 'dpp-custom-profile-'))
|
|
28
|
+
const opened: Platform[] = []
|
|
29
|
+
const brandId = 'brand-custom-1'
|
|
30
|
+
|
|
31
|
+
/** A platform with these settings, and every line it logged while starting. */
|
|
32
|
+
async function start(settings: Record<string, string>): Promise<{ platform: Platform; lines: string[] }> {
|
|
33
|
+
const lines: string[] = []
|
|
34
|
+
const config = loadConfig({ NETWORK: 'main', PASSPORT_HOST: 'passports.example', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false', ...settings })
|
|
35
|
+
const platform = await openPlatform({ config, mode: 'test', log: (line) => lines.push(line) })
|
|
36
|
+
opened.push(platform)
|
|
37
|
+
return { platform, lines }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
afterAll(async () => {
|
|
41
|
+
for (const platform of opened) await platform.close()
|
|
42
|
+
rmSync(scratch, { recursive: true, force: true })
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('a custom profile from a folder', () => {
|
|
46
|
+
it('refuses other trusted custom bytes under a packaged successor name', async () => {
|
|
47
|
+
const folder = mkdtempSync(join(tmpdir(), 'dpp-reserved-sector-'))
|
|
48
|
+
try {
|
|
49
|
+
cpSync(bottle, folder, { recursive: true })
|
|
50
|
+
const file = join(folder, 'binding.json')
|
|
51
|
+
const definition = JSON.parse(readFileSync(file, 'utf8'))
|
|
52
|
+
Object.assign(definition, { id: 'eu-battery', version: 2, profile: 'eu-battery@2' })
|
|
53
|
+
writeFileSync(file, JSON.stringify(definition))
|
|
54
|
+
const { platform } = await start({ CUSTOM_PROFILE_DIRS: folder, TRUSTED_BINDING_DIGESTS: digestOf(folder) })
|
|
55
|
+
expect(platform.profiles.get('eu-battery@2')?.bindingDigest).toBe(CURRENT_SECTOR_BINDINGS.find(entry => entry.profile === 'eu-battery@2')!.bindingDigest)
|
|
56
|
+
expect(platform.profiles.refusals).toEqual([expect.objectContaining({ code: 'binding-conflict' })])
|
|
57
|
+
} finally {
|
|
58
|
+
rmSync(folder, { recursive: true, force: true })
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('is registered when its digest is trusted, and writes and reads end to end', async () => {
|
|
63
|
+
const { platform, lines } = await start({ CUSTOM_PROFILE_DIRS: `${bottle}, ${notebook}`, TRUSTED_BINDING_DIGESTS: `${digestOf(bottle)},${digestOf(notebook)}` })
|
|
64
|
+
expect(platform.profiles.refusals).toEqual([])
|
|
65
|
+
expect(platform.profiles.list().map((p) => p.profile)).toEqual(['eu-battery@1', 'eu-textile@1', 'eu-battery@2', 'eu-textile@2', 'example-bottle@1', 'example-notebook@1'])
|
|
66
|
+
expect(lines.some((line) => line.includes('example-bottle@1 registered from') && line.includes(digestOf(bottle)))).toBe(true)
|
|
67
|
+
|
|
68
|
+
const policy = { host: platform.config.passportHost, prefix: platform.config.gs1Prefix }
|
|
69
|
+
const brand = platform.parties.brand(brandId)
|
|
70
|
+
// example-bottle@1 runs every step: a schema, a context of its own, shapes with a SPARQL constraint, and the identity rules.
|
|
71
|
+
const item = vector(bottle, 'item.json')
|
|
72
|
+
const passportId = mintPassportId(policy, '123454321', 'BTL-0001')
|
|
73
|
+
expect(passportId).toBe(item.passportId)
|
|
74
|
+
const outcome = await platform.writer.issue({ brandId, brand, passportId, profile: 'example-bottle@1', product: item.payload.product })
|
|
75
|
+
expect(outcome.entry.index).toBe('admitted')
|
|
76
|
+
const reading = await platform.read(passportId)
|
|
77
|
+
expect(reading.checks.find((c) => c.name === 'schema')?.status).toBe('pass')
|
|
78
|
+
expect(reading.payloadChecks[0].publicView.steps.map((s) => [s.step, s.status])).toEqual([
|
|
79
|
+
['envelope', 'pass'],
|
|
80
|
+
['binding', 'pass'],
|
|
81
|
+
['json-schema', 'pass'],
|
|
82
|
+
['json-ld-expand', 'pass'],
|
|
83
|
+
['shacl', 'pass'],
|
|
84
|
+
['passport-identity', 'pass'],
|
|
85
|
+
])
|
|
86
|
+
// The shapes recommend a care note; the warning is reported and does not block.
|
|
87
|
+
expect(reading.payloadChecks[0].publicView.findings.map((f) => f.severity)).toEqual(['Warning'])
|
|
88
|
+
// The binding makes no split, so the whole document is public and the holder's view is the same document.
|
|
89
|
+
expect(reading.product?.publicProduct).toEqual(item.payload.product)
|
|
90
|
+
expect(reading.product?.access).toBeUndefined()
|
|
91
|
+
const authorised = await platform.readAuthorised((await platform.store.getPassport(passportId))!, brand)
|
|
92
|
+
expect(authorised.authorisedView.status).toBe('pass')
|
|
93
|
+
expect(authorised.restrictedProduct).toBeUndefined()
|
|
94
|
+
expect(authorised.product).toEqual(item.payload.product)
|
|
95
|
+
|
|
96
|
+
// The profile's own negative vectors are refused by the writer.
|
|
97
|
+
const part = vector(bottle, 'part-not-dishwasher-safe.json')
|
|
98
|
+
await expect(platform.writer.issue({ brandId, brand, passportId: mintPassportId(policy, '123454321', 'BTL-0002'), profile: 'example-bottle@1', product: { ...part.payload.product, id: 'https://id.example/01/09521234543213/21/BTL-0002', serialNumber: 'BTL-0002' } })).rejects.toMatchObject({ code: 'product-invalid' })
|
|
99
|
+
const other = vector(bottle, 'other-product.json')
|
|
100
|
+
await expect(platform.writer.issue({ brandId, brand, passportId: mintPassportId(policy, '123454321', 'BTL-0003'), profile: 'example-bottle@1', product: other.payload.product })).rejects.toMatchObject({ code: 'product-invalid', data: { cause: 'product-identity-mismatch' } })
|
|
101
|
+
|
|
102
|
+
// example-notebook@1 is plain JSON under a schema.
|
|
103
|
+
const page = vector(notebook, 'item.json')
|
|
104
|
+
const notebookId = mintPassportId(policy, '987600010', 'NB-0001')
|
|
105
|
+
expect(notebookId).toBe(page.passportId)
|
|
106
|
+
await platform.writer.issue({ brandId, brand, passportId: notebookId, profile: 'example-notebook@1', product: page.payload.product })
|
|
107
|
+
expect((await platform.read(notebookId)).payloadChecks[0].publicView.status).toBe('pass')
|
|
108
|
+
await expect(platform.writer.issue({ brandId, brand, passportId: mintPassportId(policy, '987600010', 'NB-0002'), profile: 'example-notebook@1', product: { ...page.payload.product, id: 'https://id.example/01/09529876000101/21/NB-0002', serialNumber: 'NB-0002', pages: 'many' } })).rejects.toMatchObject({ code: 'product-invalid', data: { cause: 'schema-invalid' } })
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('is refused at start-up when its digest is not trusted, naming the digest to review, and the API carries on without it', async () => {
|
|
112
|
+
const { platform, lines } = await start({ CUSTOM_PROFILE_DIRS: bottle, TRUSTED_BINDING_DIGESTS: digestOf(notebook) })
|
|
113
|
+
expect(platform.profiles.refusals).toHaveLength(1)
|
|
114
|
+
expect(platform.profiles.refusals[0]).toMatchObject({ source: bottle, code: 'binding-untrusted' })
|
|
115
|
+
expect(platform.profiles.refusals[0].detail).toContain(digestOf(bottle))
|
|
116
|
+
expect(platform.profiles.refusals[0].detail).toContain('TRUSTED_BINDING_DIGESTS')
|
|
117
|
+
expect(lines.some((line) => line.includes('binding-untrusted') && line.includes('The API continues without it.'))).toBe(true)
|
|
118
|
+
expect(platform.profiles.list().map((p) => p.profile)).toEqual(['eu-battery@1', 'eu-textile@1', 'eu-battery@2', 'eu-textile@2'])
|
|
119
|
+
|
|
120
|
+
// Nothing is written under the refused profile, a reading of one says not checked, and every other profile works.
|
|
121
|
+
const policy = { host: platform.config.passportHost, prefix: platform.config.gs1Prefix }
|
|
122
|
+
const brand = platform.parties.brand(brandId)
|
|
123
|
+
const item = vector(bottle, 'item.json')
|
|
124
|
+
await expect(platform.writer.issue({ brandId, brand, passportId: item.passportId, profile: 'example-bottle@1', product: item.payload.product })).rejects.toMatchObject({ code: 'profile-unknown' })
|
|
125
|
+
const validation = await platform.profiles.validatePublic({ profile: 'example-bottle', profileVersion: 1, payloadPublic: JSON.stringify(item.payload), passportId: item.passportId })
|
|
126
|
+
expect(await platform.profiles.viewCheck('public', validation)).toMatchObject({ status: 'not-checked', cause: 'profile-unknown' })
|
|
127
|
+
const general = await platform.writer.issue({ brandId, brand, passportId: mintPassportId(policy, '100000088', 'GEN-0001'), profile: 'general@2', payload: samplePayload('general@2', true), ownerFields: {} })
|
|
128
|
+
expect(general.entry.index).toBe('admitted')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('is refused when a file changed after its binding was trusted', async () => {
|
|
132
|
+
// An artefact changed: the binding still has the trusted digest, and records the file it expected.
|
|
133
|
+
const longer = join(scratch, 'longer')
|
|
134
|
+
cpSync(bottle, longer, { recursive: true })
|
|
135
|
+
appendFileSync(join(longer, 'shapes.ttl'), '\n# a rule added later\n')
|
|
136
|
+
// The repository's own altered file: one fact changed and the length kept.
|
|
137
|
+
const sameLength = join(scratch, 'same-length')
|
|
138
|
+
cpSync(bottle, sameLength, { recursive: true })
|
|
139
|
+
writeFileSync(join(sameLength, 'background.ttl'), readFileSync(join(bottle, 'vectors', 'registration', 'altered-background.ttl')))
|
|
140
|
+
// The binding itself changed: it has another digest, which nobody trusted.
|
|
141
|
+
const rebound = join(scratch, 'rebound')
|
|
142
|
+
cpSync(bottle, rebound, { recursive: true })
|
|
143
|
+
writeFileSync(join(rebound, 'binding.json'), readFileSync(join(bottle, 'binding.json'), 'utf8').replace('Example refillable bottle', 'Example refillable flask'))
|
|
144
|
+
const missing = join(scratch, 'missing')
|
|
145
|
+
|
|
146
|
+
const { platform, lines } = await start({ CUSTOM_PROFILE_DIRS: [longer, sameLength, rebound, missing].join(','), TRUSTED_BINDING_DIGESTS: digestOf(bottle) })
|
|
147
|
+
expect(platform.profiles.refusals.map((r) => [r.source, r.code])).toEqual([
|
|
148
|
+
[longer, 'artefact-length-mismatch'],
|
|
149
|
+
[sameLength, 'artefact-digest-mismatch'],
|
|
150
|
+
[rebound, 'binding-untrusted'],
|
|
151
|
+
[missing, 'binding-unavailable'],
|
|
152
|
+
])
|
|
153
|
+
expect(platform.profiles.refusals[0].detail).toContain('shapes.ttl')
|
|
154
|
+
expect(platform.profiles.refusals[1].detail).toContain('background.ttl')
|
|
155
|
+
expect(platform.profiles.refusals[2].detail).toContain(digestOf(rebound))
|
|
156
|
+
expect(lines.filter((line) => line.includes('The API continues without it.'))).toHaveLength(4)
|
|
157
|
+
expect(platform.profiles.get('example-bottle@1')).toBeUndefined()
|
|
158
|
+
expect(platform.profiles.list().map((p) => p.profile)).toEqual(['eu-battery@1', 'eu-textile@1', 'eu-battery@2', 'eu-textile@2'])
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('stops the start for a trusted digest that is not a digest, naming the setting', () => {
|
|
162
|
+
expect(() => loadConfig({ TRUSTED_BINDING_DIGESTS: 'example-bottle@1' })).toThrow(/TRUSTED_BINDING_DIGESTS/)
|
|
163
|
+
expect(() => loadConfig({ TRUSTED_BINDING_DIGESTS: digestOf(bottle).toUpperCase() })).toThrow(/lower-case/)
|
|
164
|
+
expect(loadConfig({ CUSTOM_PROFILE_DIRS: ' a , ,b ', TRUSTED_BINDING_DIGESTS: '' }).customProfiles).toEqual({ dirs: ['a', 'b'], trustedBindingDigests: [] })
|
|
165
|
+
expect(loadConfig({}).customProfiles).toEqual({ dirs: [], trustedBindingDigests: [] })
|
|
166
|
+
})
|
|
167
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
5
|
+
import { generateRootKey, readEnvFile, updateEnvFile } from '../src/env-file.js'
|
|
6
|
+
|
|
7
|
+
const temps: string[] = []
|
|
8
|
+
afterAll(() => {
|
|
9
|
+
for (const dir of temps) rmSync(dir, { recursive: true, force: true })
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
function envFile(content: string): string {
|
|
13
|
+
const dir = mkdtempSync(join(tmpdir(), 'dpp-env-'))
|
|
14
|
+
temps.push(dir)
|
|
15
|
+
const path = join(dir, '.env')
|
|
16
|
+
writeFileSync(path, content)
|
|
17
|
+
return path
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('the .env file', () => {
|
|
21
|
+
it('generates a wallet root key into a file that has none, and keeps one already there', async () => {
|
|
22
|
+
const path = envFile('NETWORK=test\nWALLET_ROOT_KEY=\n')
|
|
23
|
+
const env: NodeJS.ProcessEnv = {}
|
|
24
|
+
expect(await generateRootKey(path, env)).toBe(true)
|
|
25
|
+
expect(env.WALLET_ROOT_KEY).toMatch(/^[0-9a-f]{64}$/)
|
|
26
|
+
expect(readEnvFile(path)).toEqual({ NETWORK: 'test', WALLET_ROOT_KEY: env.WALLET_ROOT_KEY })
|
|
27
|
+
const kept = env.WALLET_ROOT_KEY
|
|
28
|
+
expect(await generateRootKey(path, env)).toBe(false)
|
|
29
|
+
expect(readEnvFile(path).WALLET_ROOT_KEY).toBe(kept)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('rewrites the named keys in place, keeps every other line and comment, and appends a key the file lacks', async () => {
|
|
33
|
+
const path = envFile('# The chain\nNETWORK=main\n\n# Index\nINDEX_URL=\nINDEX_SUBMIT_TOKEN=\nLIVE_PUBLISHING=false\n')
|
|
34
|
+
await updateEnvFile(path, { INDEX_URL: 'https://index.example', INDEX_SUBMIT_TOKEN: 'a'.repeat(64), WALLET_ROOT_KEY: 'b'.repeat(64) })
|
|
35
|
+
expect(readFileSync(path, 'utf8')).toBe('# The chain\nNETWORK=main\n\n# Index\nINDEX_URL=https://index.example\nINDEX_SUBMIT_TOKEN=' + 'a'.repeat(64) + '\nLIVE_PUBLISHING=false\nWALLET_ROOT_KEY=' + 'b'.repeat(64) + '\n')
|
|
36
|
+
expect(statSync(path).mode & 0o777).toBe(0o600)
|
|
37
|
+
expect(readEnvFile(path)).toMatchObject({ NETWORK: 'main', INDEX_URL: 'https://index.example', WALLET_ROOT_KEY: 'b'.repeat(64) })
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('rewrites every occurrence of a duplicated key, so what the API reads is what was written', async () => {
|
|
41
|
+
const path = envFile('INDEX_SUBMIT_TOKEN=\n# pasted from a provider\nINDEX_SUBMIT_TOKEN=old\nLIVE_PUBLISHING=false\n')
|
|
42
|
+
await updateEnvFile(path, { INDEX_SUBMIT_TOKEN: 'new' })
|
|
43
|
+
expect(readFileSync(path, 'utf8')).toBe('INDEX_SUBMIT_TOKEN=new\n# pasted from a provider\nINDEX_SUBMIT_TOKEN=new\nLIVE_PUBLISHING=false\n')
|
|
44
|
+
expect(readEnvFile(path).INDEX_SUBMIT_TOKEN).toBe('new')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('creates the file when it does not exist and reads nothing from a missing one', async () => {
|
|
48
|
+
const path = join(dirname(envFile('')), 'missing.env')
|
|
49
|
+
expect(readEnvFile(path)).toEqual({})
|
|
50
|
+
await updateEnvFile(path, { LIVE_PUBLISHING: 'true' })
|
|
51
|
+
expect(readFileSync(path, 'utf8')).toBe('LIVE_PUBLISHING=true\n')
|
|
52
|
+
})
|
|
53
|
+
})
|