diff --git a/src/wac/parser.js b/src/wac/parser.js index 92faec0..b0b3727 100644 --- a/src/wac/parser.js +++ b/src/wac/parser.js @@ -144,8 +144,9 @@ function parseAuthorization(node, aclUrl) { auth.default = parseUriArray(node['acl:default'] || node['default']) .map(uri => resolveUri(uri, baseUrl)); - // Parse agents (WebIDs can be relative too) - auth.agents = parseUriArray(node['acl:agent'] || node['agent']); + // Parse agents (WebIDs can be relative too) - resolve against ACL URL + auth.agents = parseUriArray(node['acl:agent'] || node['agent']) + .map(uri => resolveUri(uri, aclUrl)); // Parse agentClass auth.agentClasses = parseUriArray(node['acl:agentClass'] || node['agentClass']); diff --git a/test/wac.test.js b/test/wac.test.js index 81cc1a8..477ab84 100644 --- a/test/wac.test.js +++ b/test/wac.test.js @@ -187,6 +187,23 @@ describe('WAC Parser', () => { `Expected accessTo to include 'https://alice.example/other/', got: ${auths[0].accessTo}`); }); + it('should resolve relative agent URIs against ACL URL', async () => { + const acl = { + '@context': { 'acl': 'http://www.w3.org/ns/auth/acl#' }, + '@id': '#owner', + '@type': 'acl:Authorization', + 'acl:agent': { '@id': './#me' }, + 'acl:accessTo': { '@id': './' }, + 'acl:mode': [{ '@id': 'acl:Read' }] + }; + + const auths = await parseAcl(JSON.stringify(acl), 'https://alice.example/.acl'); + + assert.strictEqual(auths.length, 1); + assert.ok(auths[0].agents.includes('https://alice.example/#me'), + `Expected agents to include 'https://alice.example/#me', got: ${auths[0].agents}`); + }); + it('should keep absolute URLs unchanged', async () => { const acl = { '@context': { 'acl': 'http://www.w3.org/ns/auth/acl#' },