Skip to content

Commit cd428df

Browse files
test(did): assert @context shape before indexing
The dedicated ordering test indexed doc['@context'] and called .includes() without first checking the field exists, so a regression that dropped @context entirely would surface as a TypeError instead of the intended assertion message — defeating the reason the check is a separate test. Bind @context to a local, assert Array.isArray first, then check the ordering. Verified: with @context removed from the builder the test now fails with '@context must be present and an array' rather than a TypeError.
1 parent e371856 commit cd428df

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

test/well-known-did-nostr.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ describe('GET /.well-known/did/nostr/:pubkey (#407)', () => {
151151
const r = await fetch(`${baseUrl}/.well-known/did/nostr/${alicePk}.json`);
152152
assert.strictEqual(r.status, 200);
153153
const doc = await r.json();
154-
assert.strictEqual(doc['@context'][0], 'https://www.w3.org/ns/did/v1',
154+
// Assert the shape before indexing, so a dropped @context fails with
155+
// this message rather than a TypeError.
156+
const ctx = doc['@context'];
157+
assert.ok(Array.isArray(ctx), '@context must be present and an array');
158+
assert.strictEqual(ctx[0], 'https://www.w3.org/ns/did/v1',
155159
'@context must lead with the DID Core context');
156160
// The CID context must still be present — the document's Multikey
157161
// verification method is drawn from that vocabulary.
158-
assert.ok(doc['@context'].includes('https://www.w3.org/ns/cid/v1'),
162+
assert.ok(ctx.includes('https://www.w3.org/ns/cid/v1'),
159163
'@context must still include the CID v1 context');
160164
});
161165

0 commit comments

Comments
 (0)