javascript-solid-server 0.0.221 → 0.0.222
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/package.json +1 -1
- package/src/handlers/resource.js +27 -0
- package/src/rdf/turtle.js +0 -0
- package/src/wac/parser.js +96 -19
- package/test/wac.test.js +226 -4
package/package.json
CHANGED
package/src/handlers/resource.js
CHANGED
|
@@ -17,6 +17,10 @@ import { emitChange } from '../notifications/events.js';
|
|
|
17
17
|
import { checkIfMatch, checkIfNoneMatchForGet, checkIfNoneMatchForWrite } from '../utils/conditional.js';
|
|
18
18
|
import { generateDatabrowserHtml, generateModuleDatabrowserHtml, shouldServeMashlib, DATA_ISLAND_MAX_BYTES } from '../mashlib/index.js';
|
|
19
19
|
import { turtleToJsonLd } from '../rdf/turtle.js';
|
|
20
|
+
import { parseAcl, grantsAccess } from '../wac/parser.js';
|
|
21
|
+
|
|
22
|
+
// Shared by the PUT and PATCH guards for .acl resources (#631).
|
|
23
|
+
const ACL_GRANTS_NOTHING = 'ACL document has no authorization that grants a mode to an agent, agent class or group; refusing to store it, as it would grant nobody access.';
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Live reload script - injected into HTML when --live-reload is enabled
|
|
@@ -974,6 +978,24 @@ export async function handlePut(request, reply) {
|
|
|
974
978
|
});
|
|
975
979
|
}
|
|
976
980
|
|
|
981
|
+
// An ACL that parses to no authorizations would lock everyone out of the
|
|
982
|
+
// resource (and of the .acl itself, so it couldn't be repaired over HTTP).
|
|
983
|
+
// Refuse it up front instead of storing it. See #631.
|
|
984
|
+
if (urlPath.endsWith('.acl')) {
|
|
985
|
+
let aclDoc = request.body;
|
|
986
|
+
if (Buffer.isBuffer(aclDoc)) aclDoc = aclDoc.toString('utf8');
|
|
987
|
+
if (typeof aclDoc === 'string') {
|
|
988
|
+
try {
|
|
989
|
+
aclDoc = safeJsonParse(aclDoc);
|
|
990
|
+
} catch (e) {
|
|
991
|
+
return reply.code(400).send({ error: 'Bad Request', message: 'ACL body is not valid JSON: ' + e.message });
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
if (!grantsAccess(await parseAcl(aclDoc, resourceUrl))) {
|
|
995
|
+
return reply.code(400).send({ error: 'Bad Request', message: ACL_GRANTS_NOTHING });
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
|
|
977
999
|
// Check if we can accept this input type
|
|
978
1000
|
if (!canAcceptInput(contentType, connegEnabled)) {
|
|
979
1001
|
const acceptValue = connegEnabled
|
|
@@ -1385,6 +1407,11 @@ export async function handlePatch(request, reply) {
|
|
|
1385
1407
|
}
|
|
1386
1408
|
}
|
|
1387
1409
|
|
|
1410
|
+
// A patch must not leave an ACL that grants nobody access (#631).
|
|
1411
|
+
if (urlPath.endsWith('.acl') && !grantsAccess(await parseAcl(updatedDocument, resourceUrl))) {
|
|
1412
|
+
return reply.code(409).send({ error: 'Conflict', message: ACL_GRANTS_NOTHING });
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1388
1415
|
// Write updated document
|
|
1389
1416
|
let updatedContent;
|
|
1390
1417
|
if (htmlWrapper) {
|
package/src/rdf/turtle.js
CHANGED
|
Binary file
|
package/src/wac/parser.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Parses ACL files (JSON-LD or Turtle) into authorization rules
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { turtleToJsonLd } from '../rdf/turtle.js';
|
|
6
|
+
import { turtleToJsonLd, expandUri } from '../rdf/turtle.js';
|
|
7
7
|
import { safeJsonParse } from '../utils/url.js';
|
|
8
8
|
|
|
9
9
|
const ACL = 'http://www.w3.org/ns/auth/acl#';
|
|
@@ -57,9 +57,17 @@ export async function parseAcl(content, aclUrl) {
|
|
|
57
57
|
// Handle @graph array or single object
|
|
58
58
|
const nodes = Array.isArray(doc) ? doc : (doc['@graph'] || [doc]);
|
|
59
59
|
|
|
60
|
+
// The document's @context (plus any node-level @context) decides what the
|
|
61
|
+
// keys mean. Contexts are merged leniently across the whole document, as
|
|
62
|
+
// jsonLdToTurtle does; remote context URLs are never fetched (#389).
|
|
63
|
+
const docContext = mergeContext({}, Array.isArray(doc) ? undefined : doc['@context']);
|
|
64
|
+
|
|
60
65
|
for (const node of nodes) {
|
|
61
|
-
if (
|
|
62
|
-
|
|
66
|
+
if (!node || typeof node !== 'object') continue;
|
|
67
|
+
const context = mergeContext(docContext, node['@context']);
|
|
68
|
+
const expanded = expandNode(node, context);
|
|
69
|
+
if (isAuthorization(expanded, context)) {
|
|
70
|
+
const auth = parseAuthorization(expanded, context, aclUrl);
|
|
63
71
|
if (auth) {
|
|
64
72
|
authorizations.push(auth);
|
|
65
73
|
}
|
|
@@ -69,18 +77,89 @@ export async function parseAcl(content, aclUrl) {
|
|
|
69
77
|
return authorizations;
|
|
70
78
|
}
|
|
71
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Merge a JSON-LD @context value (object, or array of objects / strings) into
|
|
82
|
+
* an accumulated context object. String entries (remote contexts) are skipped
|
|
83
|
+
* on purpose — JSS never dereferences contexts at parse time (#389).
|
|
84
|
+
*/
|
|
85
|
+
function mergeContext(base, ctx) {
|
|
86
|
+
if (!ctx) return base;
|
|
87
|
+
const entries = Array.isArray(ctx) ? ctx : [ctx];
|
|
88
|
+
let merged = base;
|
|
89
|
+
for (const entry of entries) {
|
|
90
|
+
if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
|
|
91
|
+
merged = { ...merged, ...entry };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return merged;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Expand a property key or @type value to a full IRI. Falls back to @vocab
|
|
99
|
+
* for bare terms the context doesn't define.
|
|
100
|
+
*/
|
|
101
|
+
function expandTerm(term, context) {
|
|
102
|
+
if (typeof term !== 'string' || !term) return term;
|
|
103
|
+
const expanded = expandUri(term, context);
|
|
104
|
+
if (expanded === term && !term.includes(':') && typeof context['@vocab'] === 'string') {
|
|
105
|
+
return context['@vocab'] + term;
|
|
106
|
+
}
|
|
107
|
+
return expanded;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Return a view of the node keyed by full predicate IRIs (#631). Keyword
|
|
112
|
+
* entries (`@id`, `@type`, …) are kept as-is. Keys that expand to the same
|
|
113
|
+
* IRI (e.g. `acl:mode` and the expanded form in one node) are concatenated.
|
|
114
|
+
*/
|
|
115
|
+
function expandNode(node, context) {
|
|
116
|
+
const out = {};
|
|
117
|
+
for (const [key, value] of Object.entries(node)) {
|
|
118
|
+
const iri = key.startsWith('@') ? key : expandTerm(key, context);
|
|
119
|
+
if (iri in out && !key.startsWith('@')) {
|
|
120
|
+
out[iri] = [].concat(out[iri], value);
|
|
121
|
+
} else {
|
|
122
|
+
out[iri] = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Read an ACL property from an expanded node. The full IRI is what a
|
|
130
|
+
* correctly-expanded key becomes; the `acl:`-prefixed and bare forms are
|
|
131
|
+
* kept as fallbacks for documents without any usable context.
|
|
132
|
+
*/
|
|
133
|
+
function aclProp(node, term) {
|
|
134
|
+
return node[`${ACL}${term}`] ?? node[`acl:${term}`] ?? node[term];
|
|
135
|
+
}
|
|
136
|
+
|
|
72
137
|
/**
|
|
73
138
|
* Check if node is an Authorization
|
|
74
139
|
*/
|
|
75
|
-
function isAuthorization(node) {
|
|
140
|
+
function isAuthorization(node, context = {}) {
|
|
76
141
|
const type = node['@type'];
|
|
77
142
|
if (!type) return false;
|
|
78
143
|
|
|
79
144
|
const types = Array.isArray(type) ? type : [type];
|
|
80
|
-
return types.some(t =>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
145
|
+
return types.some(t => {
|
|
146
|
+
const full = expandTerm(t, context);
|
|
147
|
+
return full === `${ACL}Authorization` || t === 'Authorization';
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* True when at least one authorization can grant something: it names a mode
|
|
153
|
+
* and an agent, agent class or group. An ACL for which this is false grants
|
|
154
|
+
* nobody access, including the writer, so writes that would leave a resource
|
|
155
|
+
* with such an ACL are refused (#631).
|
|
156
|
+
* @param {Array<Authorization>} authorizations
|
|
157
|
+
* @returns {boolean}
|
|
158
|
+
*/
|
|
159
|
+
export function grantsAccess(authorizations) {
|
|
160
|
+
return authorizations.some(a =>
|
|
161
|
+
a.modes.length > 0 &&
|
|
162
|
+
(a.agents.length > 0 || a.agentClasses.length > 0 || a.agentGroups.length > 0)
|
|
84
163
|
);
|
|
85
164
|
}
|
|
86
165
|
|
|
@@ -123,8 +202,9 @@ function resolveUri(uri, baseUrl) {
|
|
|
123
202
|
/**
|
|
124
203
|
* Parse a single Authorization node
|
|
125
204
|
*/
|
|
126
|
-
function parseAuthorization(node, aclUrl) {
|
|
205
|
+
function parseAuthorization(node, context, aclUrl) {
|
|
127
206
|
const baseUrl = getBaseUrl(aclUrl);
|
|
207
|
+
const uris = term => parseUriArray(aclProp(node, term)).map(u => expandUri(u, context));
|
|
128
208
|
|
|
129
209
|
const auth = {
|
|
130
210
|
id: node['@id'],
|
|
@@ -138,28 +218,25 @@ function parseAuthorization(node, aclUrl) {
|
|
|
138
218
|
};
|
|
139
219
|
|
|
140
220
|
// Parse accessTo - resolve relative URLs
|
|
141
|
-
auth.accessTo =
|
|
142
|
-
.map(uri => resolveUri(uri, baseUrl));
|
|
221
|
+
auth.accessTo = uris('accessTo').map(uri => resolveUri(uri, baseUrl));
|
|
143
222
|
|
|
144
223
|
// Parse default (for containers) - resolve relative URLs
|
|
145
|
-
auth.default =
|
|
146
|
-
.map(uri => resolveUri(uri, baseUrl));
|
|
224
|
+
auth.default = uris('default').map(uri => resolveUri(uri, baseUrl));
|
|
147
225
|
|
|
148
226
|
// Parse agents (WebIDs can be relative too) - resolve against ACL URL
|
|
149
|
-
auth.agents =
|
|
150
|
-
.map(uri => resolveUri(uri, aclUrl));
|
|
227
|
+
auth.agents = uris('agent').map(uri => resolveUri(uri, aclUrl));
|
|
151
228
|
|
|
152
229
|
// Parse agentClass
|
|
153
|
-
auth.agentClasses =
|
|
230
|
+
auth.agentClasses = uris('agentClass');
|
|
154
231
|
|
|
155
232
|
// Parse agentGroup
|
|
156
|
-
auth.agentGroups =
|
|
233
|
+
auth.agentGroups = uris('agentGroup');
|
|
157
234
|
|
|
158
235
|
// Parse modes
|
|
159
|
-
auth.modes =
|
|
236
|
+
auth.modes = uris('mode').map(normalizeMode);
|
|
160
237
|
|
|
161
238
|
// Parse conditions
|
|
162
|
-
auth.conditions = parseConditions(node
|
|
239
|
+
auth.conditions = parseConditions(aclProp(node, 'condition'));
|
|
163
240
|
|
|
164
241
|
return auth;
|
|
165
242
|
}
|
package/test/wac.test.js
CHANGED
|
@@ -81,7 +81,7 @@ describe('WAC Parser', () => {
|
|
|
81
81
|
assert.ok(ownerAuth.modes.includes(AccessMode.WRITE));
|
|
82
82
|
assert.ok(ownerAuth.modes.includes(AccessMode.CONTROL));
|
|
83
83
|
// Check public authorization
|
|
84
|
-
const publicAuth = auths.find(a => a.agentClasses.includes('foaf
|
|
84
|
+
const publicAuth = auths.find(a => a.agentClasses.includes('http://xmlns.com/foaf/0.1/Agent'));
|
|
85
85
|
assert.ok(publicAuth, 'Should have public authorization');
|
|
86
86
|
assert.ok(publicAuth.modes.includes(AccessMode.READ));
|
|
87
87
|
});
|
|
@@ -101,7 +101,7 @@ describe('WAC Parser', () => {
|
|
|
101
101
|
const auths = await parseAcl(JSON.stringify(acl), 'https://alice.example/public/.acl');
|
|
102
102
|
|
|
103
103
|
assert.strictEqual(auths.length, 1);
|
|
104
|
-
assert.ok(auths[0].agentClasses.includes('foaf
|
|
104
|
+
assert.ok(auths[0].agentClasses.includes('http://xmlns.com/foaf/0.1/Agent'));
|
|
105
105
|
assert.ok(auths[0].modes.includes(AccessMode.READ));
|
|
106
106
|
});
|
|
107
107
|
|
|
@@ -444,8 +444,8 @@ describe('WAC Parser', () => {
|
|
|
444
444
|
const auths1 = await parseAcl(wire, 'http://localhost:4444/.acl');
|
|
445
445
|
const auths2 = await parseAcl(wire, 'http://0.0.0.0:4444/.acl');
|
|
446
446
|
|
|
447
|
-
const pub1 = auths1.find(a => a.agentClasses.includes('foaf
|
|
448
|
-
const pub2 = auths2.find(a => a.agentClasses.includes('foaf
|
|
447
|
+
const pub1 = auths1.find(a => a.agentClasses.includes('http://xmlns.com/foaf/0.1/Agent'));
|
|
448
|
+
const pub2 = auths2.find(a => a.agentClasses.includes('http://xmlns.com/foaf/0.1/Agent'));
|
|
449
449
|
assert.ok(pub1.accessTo.includes('http://localhost:4444/'),
|
|
450
450
|
`Expected localhost resolution, got: ${JSON.stringify(pub1.accessTo)}`);
|
|
451
451
|
assert.ok(pub2.accessTo.includes('http://0.0.0.0:4444/'),
|
|
@@ -788,3 +788,225 @@ describe('WAC PaymentCondition noDebit (secondary/guard checks must not charge)'
|
|
|
788
788
|
assert.strictEqual(await balanceNow(), 100, 'balance must be unchanged');
|
|
789
789
|
});
|
|
790
790
|
});
|
|
791
|
+
|
|
792
|
+
describe('WAC Parser: JSON-LD expansion (#631)', () => {
|
|
793
|
+
const ACL = 'http://www.w3.org/ns/auth/acl#';
|
|
794
|
+
const aclUrl = 'http://127.0.0.1:8732/me/public/doc.ttl.acl';
|
|
795
|
+
const webId = 'http://127.0.0.1:8732/me/profile/card.jsonld#me';
|
|
796
|
+
const target = 'http://127.0.0.1:8732/me/public/doc.ttl';
|
|
797
|
+
|
|
798
|
+
function expectOwner(auths) {
|
|
799
|
+
assert.strictEqual(auths.length, 1, `expected one authorization, got ${JSON.stringify(auths)}`);
|
|
800
|
+
assert.deepStrictEqual(auths[0].agents, [webId]);
|
|
801
|
+
assert.deepStrictEqual(auths[0].accessTo, [target]);
|
|
802
|
+
assert.deepStrictEqual(auths[0].modes.sort(), [AccessMode.CONTROL, AccessMode.READ, AccessMode.WRITE].sort());
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
it('reads an ACL in expanded form (full IRIs, no @context)', async () => {
|
|
806
|
+
const acl = [{
|
|
807
|
+
'@id': '#owner',
|
|
808
|
+
'@type': [`${ACL}Authorization`],
|
|
809
|
+
[`${ACL}agent`]: [{ '@id': webId }],
|
|
810
|
+
[`${ACL}accessTo`]: [{ '@id': target }],
|
|
811
|
+
[`${ACL}mode`]: [{ '@id': `${ACL}Read` }, { '@id': `${ACL}Write` }, { '@id': `${ACL}Control` }]
|
|
812
|
+
}];
|
|
813
|
+
expectOwner(await parseAcl(JSON.stringify(acl), aclUrl));
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
it('reads an ACL that uses a different prefix than acl:', async () => {
|
|
817
|
+
const acl = {
|
|
818
|
+
'@context': { wac: ACL },
|
|
819
|
+
'@graph': [{
|
|
820
|
+
'@id': '#owner',
|
|
821
|
+
'@type': 'wac:Authorization',
|
|
822
|
+
'wac:agent': { '@id': webId },
|
|
823
|
+
'wac:accessTo': { '@id': target },
|
|
824
|
+
'wac:mode': [{ '@id': 'wac:Read' }, { '@id': 'wac:Write' }, { '@id': 'wac:Control' }]
|
|
825
|
+
}]
|
|
826
|
+
};
|
|
827
|
+
expectOwner(await parseAcl(JSON.stringify(acl), aclUrl));
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
it('reads an ACL whose @context is an array with a remote entry', async () => {
|
|
831
|
+
const acl = {
|
|
832
|
+
'@context': ['https://www.w3.org/ns/solid/context', { auth: ACL }],
|
|
833
|
+
'@graph': [{
|
|
834
|
+
'@id': '#owner',
|
|
835
|
+
'@type': 'auth:Authorization',
|
|
836
|
+
'auth:agent': { '@id': webId },
|
|
837
|
+
'auth:accessTo': { '@id': target },
|
|
838
|
+
'auth:mode': [{ '@id': 'auth:Read' }, { '@id': 'auth:Write' }, { '@id': 'auth:Control' }]
|
|
839
|
+
}]
|
|
840
|
+
};
|
|
841
|
+
expectOwner(await parseAcl(JSON.stringify(acl), aclUrl));
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it('reads an ACL that relies on @vocab and term definitions', async () => {
|
|
845
|
+
const acl = {
|
|
846
|
+
'@context': {
|
|
847
|
+
'@vocab': ACL,
|
|
848
|
+
agent: { '@id': `${ACL}agent`, '@type': '@id' },
|
|
849
|
+
accessTo: { '@id': `${ACL}accessTo`, '@type': '@id' },
|
|
850
|
+
mode: { '@id': `${ACL}mode`, '@type': '@id' }
|
|
851
|
+
},
|
|
852
|
+
'@id': '#owner',
|
|
853
|
+
'@type': 'Authorization',
|
|
854
|
+
agent: webId,
|
|
855
|
+
accessTo: target,
|
|
856
|
+
mode: ['Read', 'Write', 'Control']
|
|
857
|
+
};
|
|
858
|
+
expectOwner(await parseAcl(JSON.stringify(acl), aclUrl));
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it('reads a Turtle ACL that declares a non-acl prefix', async () => {
|
|
862
|
+
const ttl = `@prefix wac: <${ACL}> .
|
|
863
|
+
<#owner> a wac:Authorization ;
|
|
864
|
+
wac:agent <${webId}> ;
|
|
865
|
+
wac:accessTo <${target}> ;
|
|
866
|
+
wac:mode wac:Read, wac:Write, wac:Control .`;
|
|
867
|
+
expectOwner(await parseAcl(ttl, aclUrl));
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
it('normalises agent classes to full IRIs', async () => {
|
|
871
|
+
const acl = {
|
|
872
|
+
'@context': { wac: ACL, people: 'http://xmlns.com/foaf/0.1/' },
|
|
873
|
+
'@id': '#public',
|
|
874
|
+
'@type': 'wac:Authorization',
|
|
875
|
+
'wac:agentClass': { '@id': 'people:Agent' },
|
|
876
|
+
'wac:accessTo': { '@id': target },
|
|
877
|
+
'wac:mode': { '@id': 'wac:Read' }
|
|
878
|
+
};
|
|
879
|
+
const auths = await parseAcl(JSON.stringify(acl), aclUrl);
|
|
880
|
+
assert.deepStrictEqual(auths[0].agentClasses, ['http://xmlns.com/foaf/0.1/Agent']);
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
describe('WAC Integration: ACL PUT guard (#631)', () => {
|
|
885
|
+
let baseUrl;
|
|
886
|
+
|
|
887
|
+
before(async () => {
|
|
888
|
+
const result = await startTestServer();
|
|
889
|
+
baseUrl = result.baseUrl;
|
|
890
|
+
await createTestPod('aclguard');
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
after(async () => {
|
|
894
|
+
await stopTestServer();
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
const ACL = 'http://www.w3.org/ns/auth/acl#';
|
|
898
|
+
|
|
899
|
+
it('accepts an expanded-form ACL and the owner keeps access', async () => {
|
|
900
|
+
const put = await request('/aclguard/public/exp.jsonld', {
|
|
901
|
+
method: 'PUT', auth: 'aclguard',
|
|
902
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
903
|
+
body: JSON.stringify({ '@id': '', 'http://schema.org/name': 'x' })
|
|
904
|
+
});
|
|
905
|
+
assert.ok(put.status === 201 || put.status === 204, `PUT resource: ${put.status}`);
|
|
906
|
+
|
|
907
|
+
const webId = `${baseUrl}/aclguard/profile/card.jsonld#me`;
|
|
908
|
+
const acl = [{
|
|
909
|
+
'@id': '#owner',
|
|
910
|
+
'@type': [`${ACL}Authorization`],
|
|
911
|
+
[`${ACL}agent`]: [{ '@id': webId }],
|
|
912
|
+
[`${ACL}accessTo`]: [{ '@id': `${baseUrl}/aclguard/public/exp.jsonld` }],
|
|
913
|
+
[`${ACL}mode`]: [{ '@id': `${ACL}Read` }, { '@id': `${ACL}Write` }, { '@id': `${ACL}Control` }]
|
|
914
|
+
}];
|
|
915
|
+
const putAcl = await request('/aclguard/public/exp.jsonld.acl', {
|
|
916
|
+
method: 'PUT', auth: 'aclguard',
|
|
917
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
918
|
+
body: JSON.stringify(acl)
|
|
919
|
+
});
|
|
920
|
+
assert.ok(putAcl.status === 201 || putAcl.status === 204, `PUT acl: ${putAcl.status}`);
|
|
921
|
+
|
|
922
|
+
assertStatus(await request('/aclguard/public/exp.jsonld', { auth: 'aclguard' }), 200);
|
|
923
|
+
assertStatus(await request('/aclguard/public/exp.jsonld.acl', { auth: 'aclguard' }), 200);
|
|
924
|
+
// The expanded ACL grants nothing to the public.
|
|
925
|
+
assertStatus(await request('/aclguard/public/exp.jsonld'), 401);
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
it('rejects an ACL document that yields no authorizations', async () => {
|
|
929
|
+
const res = await request('/aclguard/public/exp.jsonld.acl', {
|
|
930
|
+
method: 'PUT', auth: 'aclguard',
|
|
931
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
932
|
+
body: JSON.stringify({ '@context': { acl: ACL }, '@id': '#owner', 'acl:agent': { '@id': 'x' } })
|
|
933
|
+
});
|
|
934
|
+
assertStatus(res, 400);
|
|
935
|
+
const body = await res.json();
|
|
936
|
+
assert.match(body.message, /authorization/i);
|
|
937
|
+
// The previous ACL is still in place.
|
|
938
|
+
assertStatus(await request('/aclguard/public/exp.jsonld', { auth: 'aclguard' }), 200);
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
it('rejects an ACL whose authorizations name an agent but no mode', async () => {
|
|
942
|
+
const res = await request('/aclguard/public/exp.jsonld.acl', {
|
|
943
|
+
method: 'PUT', auth: 'aclguard',
|
|
944
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
945
|
+
body: JSON.stringify({
|
|
946
|
+
'@context': { acl: ACL },
|
|
947
|
+
'@id': '#owner',
|
|
948
|
+
'@type': 'acl:Authorization',
|
|
949
|
+
'acl:agent': { '@id': `${baseUrl}/aclguard/profile/card.jsonld#me` },
|
|
950
|
+
'acl:accessTo': { '@id': `${baseUrl}/aclguard/public/exp.jsonld` }
|
|
951
|
+
})
|
|
952
|
+
});
|
|
953
|
+
assertStatus(res, 400);
|
|
954
|
+
assertStatus(await request('/aclguard/public/exp.jsonld', { auth: 'aclguard' }), 200);
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
it('rejects an ACL whose authorizations name a mode but no agent', async () => {
|
|
958
|
+
const res = await request('/aclguard/public/exp.jsonld.acl', {
|
|
959
|
+
method: 'PUT', auth: 'aclguard',
|
|
960
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
961
|
+
body: JSON.stringify({
|
|
962
|
+
'@context': { acl: ACL },
|
|
963
|
+
'@id': '#owner',
|
|
964
|
+
'@type': 'acl:Authorization',
|
|
965
|
+
'acl:accessTo': { '@id': `${baseUrl}/aclguard/public/exp.jsonld` },
|
|
966
|
+
'acl:mode': [{ '@id': 'acl:Read' }, { '@id': 'acl:Control' }]
|
|
967
|
+
})
|
|
968
|
+
});
|
|
969
|
+
assertStatus(res, 400);
|
|
970
|
+
assertStatus(await request('/aclguard/public/exp.jsonld', { auth: 'aclguard' }), 200);
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
it('rejects a PATCH that would leave the ACL granting nobody access', async () => {
|
|
974
|
+
const webId = `${baseUrl}/aclguard/profile/card.jsonld#me`;
|
|
975
|
+
// Single expanded node (the N3 patch engine matches full-IRI keys and
|
|
976
|
+
// does not handle top-level arrays), so the delete below is applied.
|
|
977
|
+
const put = await request('/aclguard/public/exp.jsonld.acl', {
|
|
978
|
+
method: 'PUT', auth: 'aclguard',
|
|
979
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
980
|
+
body: JSON.stringify({
|
|
981
|
+
'@id': '#owner',
|
|
982
|
+
'@type': `${ACL}Authorization`,
|
|
983
|
+
[`${ACL}agent`]: { '@id': webId },
|
|
984
|
+
[`${ACL}accessTo`]: { '@id': `${baseUrl}/aclguard/public/exp.jsonld` },
|
|
985
|
+
[`${ACL}mode`]: [{ '@id': `${ACL}Read` }, { '@id': `${ACL}Write` }, { '@id': `${ACL}Control` }]
|
|
986
|
+
})
|
|
987
|
+
});
|
|
988
|
+
assertStatus(put, 204);
|
|
989
|
+
const patch = `
|
|
990
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
991
|
+
@prefix acl: <${ACL}>.
|
|
992
|
+
_:patch a solid:InsertDeletePatch;
|
|
993
|
+
solid:deletes { <#owner> acl:agent <${webId}> }.
|
|
994
|
+
`;
|
|
995
|
+
const res = await request('/aclguard/public/exp.jsonld.acl', {
|
|
996
|
+
method: 'PATCH', auth: 'aclguard',
|
|
997
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
998
|
+
body: patch
|
|
999
|
+
});
|
|
1000
|
+
assertStatus(res, 409);
|
|
1001
|
+
assertStatus(await request('/aclguard/public/exp.jsonld', { auth: 'aclguard' }), 200);
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
it('rejects an ACL body that is not valid JSON', async () => {
|
|
1005
|
+
const res = await request('/aclguard/public/exp.jsonld.acl', {
|
|
1006
|
+
method: 'PUT', auth: 'aclguard',
|
|
1007
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
1008
|
+
body: '{not json'
|
|
1009
|
+
});
|
|
1010
|
+
assertStatus(res, 400);
|
|
1011
|
+
});
|
|
1012
|
+
});
|