javascript-solid-server 0.0.185 → 0.0.187
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/.claude/settings.local.json +5 -188
- package/.github/CODEOWNERS +27 -0
- package/CONTRIBUTING.md +98 -0
- package/LICENSING.md +30 -0
- package/README.md +2 -1
- package/package.json +1 -1
- package/src/handlers/container.js +24 -16
- package/src/server.js +87 -9
- package/src/ui/server-root.html +70 -0
- package/src/ui/server-root.js +173 -0
- package/src/wac/parser.js +50 -9
- package/test/error-handler.test.js +82 -0
- package/test/server-root.test.js +192 -0
- package/test/wac.test.js +234 -1
- package/.claude/scheduled_tasks.lock +0 -1
package/test/wac.test.js
CHANGED
|
@@ -13,7 +13,17 @@ import {
|
|
|
13
13
|
assertHeader,
|
|
14
14
|
getBaseUrl
|
|
15
15
|
} from './helpers.js';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
parseAcl,
|
|
18
|
+
AccessMode,
|
|
19
|
+
generateOwnerAcl,
|
|
20
|
+
generatePrivateAcl,
|
|
21
|
+
generateInboxAcl,
|
|
22
|
+
generatePublicFolderAcl,
|
|
23
|
+
generatePublicReadAcl,
|
|
24
|
+
serializeAcl,
|
|
25
|
+
relativizeOwnerWebId
|
|
26
|
+
} from '../src/wac/parser.js';
|
|
17
27
|
import { checkAccess, getRequiredMode } from '../src/wac/checker.js';
|
|
18
28
|
|
|
19
29
|
describe('WAC Parser', () => {
|
|
@@ -238,6 +248,208 @@ describe('WAC Parser', () => {
|
|
|
238
248
|
assert.ok(publicAuth);
|
|
239
249
|
});
|
|
240
250
|
});
|
|
251
|
+
|
|
252
|
+
// Phase 1 of #427 (#428): generators should preserve relative resourceUrls
|
|
253
|
+
// verbatim so callers can emit host-portable ACLs. The parser already
|
|
254
|
+
// resolves them at check time against the .acl's URL.
|
|
255
|
+
describe('relative resourceUrl portability (#428)', () => {
|
|
256
|
+
const webId = 'https://alice.example/profile/card.jsonld#me';
|
|
257
|
+
|
|
258
|
+
it('generateOwnerAcl preserves "./" in accessTo and default', () => {
|
|
259
|
+
const acl = generateOwnerAcl('./', webId, true);
|
|
260
|
+
const owner = acl['@graph'].find(a => a['@id'] === '#owner');
|
|
261
|
+
const pub = acl['@graph'].find(a => a['@id'] === '#public');
|
|
262
|
+
assert.strictEqual(owner['acl:accessTo']['@id'], './');
|
|
263
|
+
assert.strictEqual(owner['acl:default']['@id'], './');
|
|
264
|
+
assert.strictEqual(pub['acl:accessTo']['@id'], './');
|
|
265
|
+
// #public intentionally has no default — child resources require auth
|
|
266
|
+
assert.strictEqual(pub['acl:default'], undefined);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('generatePrivateAcl preserves "./"', () => {
|
|
270
|
+
const acl = generatePrivateAcl('./', webId);
|
|
271
|
+
const owner = acl['@graph'][0];
|
|
272
|
+
assert.strictEqual(owner['acl:accessTo']['@id'], './');
|
|
273
|
+
assert.strictEqual(owner['acl:default']['@id'], './');
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('generateInboxAcl preserves "./"', () => {
|
|
277
|
+
const acl = generateInboxAcl('./', webId);
|
|
278
|
+
for (const auth of acl['@graph']) {
|
|
279
|
+
assert.strictEqual(auth['acl:accessTo']['@id'], './');
|
|
280
|
+
assert.strictEqual(auth['acl:default']['@id'], './');
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('generatePublicFolderAcl preserves "./"', () => {
|
|
285
|
+
const acl = generatePublicFolderAcl('./', webId);
|
|
286
|
+
for (const auth of acl['@graph']) {
|
|
287
|
+
assert.strictEqual(auth['acl:accessTo']['@id'], './');
|
|
288
|
+
assert.strictEqual(auth['acl:default']['@id'], './');
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('generatePublicReadAcl preserves a relative resource basename', () => {
|
|
293
|
+
const acl = generatePublicReadAcl('./publicTypeIndex.jsonld');
|
|
294
|
+
assert.strictEqual(
|
|
295
|
+
acl['@graph'][0]['acl:accessTo']['@id'],
|
|
296
|
+
'./publicTypeIndex.jsonld'
|
|
297
|
+
);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Phase 2 of #427 (#430): generators should also preserve a relative
|
|
301
|
+
// ownerWebId verbatim, so the on-disk pod is host-portable for the
|
|
302
|
+
// owner half of the rule too. The parser already resolves relative
|
|
303
|
+
// agents (PR #65 / #64) — this just exercises the writer side.
|
|
304
|
+
it('generateOwnerAcl preserves a relative ownerWebId (#430)', () => {
|
|
305
|
+
const acl = generateOwnerAcl('./', './profile/card.jsonld#me', true);
|
|
306
|
+
const owner = acl['@graph'].find(a => a['@id'] === '#owner');
|
|
307
|
+
assert.strictEqual(owner['acl:agent']['@id'], './profile/card.jsonld#me');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('generatePrivateAcl preserves a relative ownerWebId (#430)', () => {
|
|
311
|
+
const acl = generatePrivateAcl('./', '../profile/card.jsonld#me');
|
|
312
|
+
assert.strictEqual(acl['@graph'][0]['acl:agent']['@id'], '../profile/card.jsonld#me');
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('generateInboxAcl preserves a relative ownerWebId (#430)', () => {
|
|
316
|
+
const acl = generateInboxAcl('./', '../profile/card.jsonld#me');
|
|
317
|
+
const owner = acl['@graph'].find(a => a['@id'] === '#owner');
|
|
318
|
+
assert.strictEqual(owner['acl:agent']['@id'], '../profile/card.jsonld#me');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('generatePublicFolderAcl preserves a relative ownerWebId (#430)', () => {
|
|
322
|
+
const acl = generatePublicFolderAcl('./', './card.jsonld#me');
|
|
323
|
+
const owner = acl['@graph'].find(a => a['@id'] === '#owner');
|
|
324
|
+
assert.strictEqual(owner['acl:agent']['@id'], './card.jsonld#me');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('round-trip: relative ownerWebId resolves to .acl base URL on parse (#430)', async () => {
|
|
328
|
+
// Same ACL document, two hosts — agent should resolve to whichever
|
|
329
|
+
// host asked, just like accessTo. This is what makes the on-disk
|
|
330
|
+
// pod portable for the owner half.
|
|
331
|
+
const generated = generateOwnerAcl('./', './profile/card.jsonld#me', true);
|
|
332
|
+
const wire = serializeAcl(generated);
|
|
333
|
+
const auths1 = await parseAcl(wire, 'http://localhost:4444/.acl');
|
|
334
|
+
const auths2 = await parseAcl(wire, 'http://0.0.0.0:4444/.acl');
|
|
335
|
+
const owner1 = auths1.find(a => a.id === '#owner');
|
|
336
|
+
const owner2 = auths2.find(a => a.id === '#owner');
|
|
337
|
+
assert.ok(owner1.agents.includes('http://localhost:4444/profile/card.jsonld#me'),
|
|
338
|
+
`Expected localhost agent, got: ${JSON.stringify(owner1.agents)}`);
|
|
339
|
+
assert.ok(owner2.agents.includes('http://0.0.0.0:4444/profile/card.jsonld#me'),
|
|
340
|
+
`Expected 0.0.0.0 agent, got: ${JSON.stringify(owner2.agents)}`);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// The relativizeOwnerWebId helper drives the Phase 2 callers. Cover
|
|
344
|
+
// the layouts Copilot asked about so callers don't need to hardcode.
|
|
345
|
+
describe('relativizeOwnerWebId helper', () => {
|
|
346
|
+
const podUri = 'http://h/alice/';
|
|
347
|
+
|
|
348
|
+
it('emits "./<tail>" from the pod root', () => {
|
|
349
|
+
assert.strictEqual(
|
|
350
|
+
relativizeOwnerWebId(`${podUri}profile/card.jsonld#me`, podUri, ''),
|
|
351
|
+
'./profile/card.jsonld#me'
|
|
352
|
+
);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('emits "../<tail>" from an immediate child folder', () => {
|
|
356
|
+
assert.strictEqual(
|
|
357
|
+
relativizeOwnerWebId(`${podUri}profile/card.jsonld#me`, podUri, 'private/'),
|
|
358
|
+
'../profile/card.jsonld#me'
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('handles legacy /profile/card#me layout', () => {
|
|
363
|
+
// Pre-#282 pods used extensionless `profile/card`. The helper just
|
|
364
|
+
// slices the tail, so any layout works.
|
|
365
|
+
assert.strictEqual(
|
|
366
|
+
relativizeOwnerWebId(`${podUri}profile/card#me`, podUri, ''),
|
|
367
|
+
'./profile/card#me'
|
|
368
|
+
);
|
|
369
|
+
assert.strictEqual(
|
|
370
|
+
relativizeOwnerWebId(`${podUri}profile/card#me`, podUri, 'private/'),
|
|
371
|
+
'../profile/card#me'
|
|
372
|
+
);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('handles a custom (non-profile/) WebID shape', () => {
|
|
376
|
+
assert.strictEqual(
|
|
377
|
+
relativizeOwnerWebId(`${podUri}me#me`, podUri, ''),
|
|
378
|
+
'./me#me'
|
|
379
|
+
);
|
|
380
|
+
assert.strictEqual(
|
|
381
|
+
relativizeOwnerWebId(`${podUri}me#me`, podUri, 'public/'),
|
|
382
|
+
'../me#me'
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it('returns the absolute WebID unchanged for foreign owners', () => {
|
|
387
|
+
const foreign = 'https://other.example/profile/card.jsonld#me';
|
|
388
|
+
assert.strictEqual(
|
|
389
|
+
relativizeOwnerWebId(foreign, podUri, ''),
|
|
390
|
+
foreign
|
|
391
|
+
);
|
|
392
|
+
assert.strictEqual(
|
|
393
|
+
relativizeOwnerWebId(foreign, podUri, 'private/'),
|
|
394
|
+
foreign
|
|
395
|
+
);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it('round-trips through the parser back to the absolute WebID', async () => {
|
|
399
|
+
// Helper output is correct iff parsing it under the same pod URI
|
|
400
|
+
// yields the original absolute WebID. Covers both modern and
|
|
401
|
+
// legacy layouts, from root and from a child folder.
|
|
402
|
+
const cases = [
|
|
403
|
+
{ web: `${podUri}profile/card.jsonld#me`, base: '', acl: `${podUri}.acl` },
|
|
404
|
+
{ web: `${podUri}profile/card.jsonld#me`, base: 'private/', acl: `${podUri}private/.acl` },
|
|
405
|
+
{ web: `${podUri}profile/card#me`, base: '', acl: `${podUri}.acl` },
|
|
406
|
+
{ web: `${podUri}profile/card#me`, base: 'private/', acl: `${podUri}private/.acl` },
|
|
407
|
+
{ web: `${podUri}me#me`, base: 'public/', acl: `${podUri}public/.acl` }
|
|
408
|
+
];
|
|
409
|
+
for (const { web, base, acl } of cases) {
|
|
410
|
+
const rel = relativizeOwnerWebId(web, podUri, base);
|
|
411
|
+
const generated = generateOwnerAcl('./', rel, true);
|
|
412
|
+
const wire = serializeAcl(generated);
|
|
413
|
+
const auths = await parseAcl(wire, acl);
|
|
414
|
+
const owner = auths.find(a => a.id === '#owner');
|
|
415
|
+
assert.ok(
|
|
416
|
+
owner.agents.includes(web),
|
|
417
|
+
`Round-trip failed for ${web} from ${base}: relative=${rel}, resolved=${JSON.stringify(owner.agents)}`
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('round-trip: relative ownerWebId from a child folder resolves correctly (#430)', async () => {
|
|
424
|
+
// /pod/private/.acl with agent '../profile/card.jsonld#me'
|
|
425
|
+
// should resolve to /pod/profile/card.jsonld#me, not into the
|
|
426
|
+
// pod root or escape it.
|
|
427
|
+
const generated = generatePrivateAcl('./', '../profile/card.jsonld#me');
|
|
428
|
+
const wire = serializeAcl(generated);
|
|
429
|
+
const auths = await parseAcl(wire, 'http://localhost:4444/alice/private/.acl');
|
|
430
|
+
const owner = auths.find(a => a.id === '#owner');
|
|
431
|
+
assert.ok(owner.agents.includes('http://localhost:4444/alice/profile/card.jsonld#me'),
|
|
432
|
+
`Expected resolution to /alice/profile/card.jsonld#me, got: ${JSON.stringify(owner.agents)}`);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('round-trip: relative "./" resolves to the .acl base URL on parse', async () => {
|
|
436
|
+
const generated = generateOwnerAcl('./', webId, true);
|
|
437
|
+
const wire = serializeAcl(generated);
|
|
438
|
+
|
|
439
|
+
// Parse the same .acl document under two different host URLs and
|
|
440
|
+
// assert accessTo resolves to whichever host asked. This is what
|
|
441
|
+
// makes the on-disk pod portable across interfaces.
|
|
442
|
+
const auths1 = await parseAcl(wire, 'http://localhost:4444/.acl');
|
|
443
|
+
const auths2 = await parseAcl(wire, 'http://0.0.0.0:4444/.acl');
|
|
444
|
+
|
|
445
|
+
const pub1 = auths1.find(a => a.agentClasses.includes('foaf:Agent'));
|
|
446
|
+
const pub2 = auths2.find(a => a.agentClasses.includes('foaf:Agent'));
|
|
447
|
+
assert.ok(pub1.accessTo.includes('http://localhost:4444/'),
|
|
448
|
+
`Expected localhost resolution, got: ${JSON.stringify(pub1.accessTo)}`);
|
|
449
|
+
assert.ok(pub2.accessTo.includes('http://0.0.0.0:4444/'),
|
|
450
|
+
`Expected 0.0.0.0 resolution, got: ${JSON.stringify(pub2.accessTo)}`);
|
|
451
|
+
});
|
|
452
|
+
});
|
|
241
453
|
});
|
|
242
454
|
|
|
243
455
|
describe('WAC Checker', () => {
|
|
@@ -325,6 +537,27 @@ describe('WAC Integration', () => {
|
|
|
325
537
|
});
|
|
326
538
|
});
|
|
327
539
|
|
|
540
|
+
describe('Cross-host ACL portability (#428)', () => {
|
|
541
|
+
// The .acl is written with a relative `./` so the public-read rule
|
|
542
|
+
// matches whichever host the request comes in on. Before #428, the
|
|
543
|
+
// .acl baked the bind-time host into accessTo and any other host
|
|
544
|
+
// returned 401. We exercise this by varying the Host: header.
|
|
545
|
+
it('serves public-read resources regardless of Host header', async () => {
|
|
546
|
+
// Profile is public-read by default (#427 Phase 1).
|
|
547
|
+
const baseHost = new URL(getBaseUrl()).host;
|
|
548
|
+
const profileUrl = `${getBaseUrl()}/wactest/profile/`;
|
|
549
|
+
const hostsToTry = [baseHost, 'localhost:9999', 'pod.example:443', 'pod.invalid'];
|
|
550
|
+
|
|
551
|
+
for (const host of hostsToTry) {
|
|
552
|
+
const res = await fetch(profileUrl, { headers: { Host: host } });
|
|
553
|
+
assert.strictEqual(
|
|
554
|
+
res.status, 200,
|
|
555
|
+
`Public-read should succeed for Host: ${host} (got ${res.status})`
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
|
|
328
561
|
describe('WAC-Allow Header', () => {
|
|
329
562
|
it('should return WAC-Allow header for public container', async () => {
|
|
330
563
|
const res = await request('/wactest/public/');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"sessionId":"a05da419-92b7-4056-93b8-e97b2035d4ae","pid":3932382,"procStart":"114094236","acquiredAt":1778317500161}
|