Skip to content

Commit f9b8efa

Browse files
authored
Merge pull request #21 from michielbdejong/trusted-apps-with-default-owners
also get trusted apps from default owners of resource container
2 parents 7271cd6 + 844bd5e commit f9b8efa

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/acl-check.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,19 @@ function accessDenied (kb, doc, directory, aclDoc, agent, modesRequired, origin,
4444
return ok
4545
}
4646

47-
async function getTrustedModesForOrigin (kb, aclDoc, doc, origin, fetch) {
48-
const docAuths = kb.each(null, ACL('accessTo'), doc, aclDoc)
49-
const ownerAuths = docAuths.filter(auth => kb.holds(auth, ACL('mode'), ACL('Control'), aclDoc))
47+
async function getTrustedModesForOrigin (kb, doc, directory, aclDoc, origin, fetch) {
48+
// FIXME: this is duplicate code from the modesAllowed function, will refactor,
49+
// see https://github.com/solid/acl-check/issues/22
50+
var auths
51+
if (!directory) { // Normal case, ACL for a file
52+
auths = kb.each(null, ACL('accessTo'), doc, aclDoc)
53+
log(` ${auths.length} direct authentications about ${doc}`)
54+
} else {
55+
auths = kb.each(null, ACL('default'), directory, null)
56+
auths = auths.concat(kb.each(null, ACL('defaultForNew'), directory, null)) // Deprecated but keep for ages
57+
log(` ${auths.length} default authentications about ${directory} in ${aclDoc}`)
58+
}
59+
const ownerAuths = auths.filter(auth => kb.holds(auth, ACL('mode'), ACL('Control'), aclDoc))
5060
const owners = ownerAuths.reduce((acc, auth) => acc.concat(kb.each(auth, ACL('agent'))), []) // owners
5161
let result
5262
try {

test/unit/get-trusted-modes-for-origin-test.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const prefixes = `
1515
@prefix alice: ${ALICE('#')} .
1616
`
1717

18-
test('aclCheck getTrustedModesForOrigin() getting trusted modes from publisherStore', t => {
18+
test('aclCheck getTrustedModesForOrigin() getting trusted modes from publisherStore (acl:accessTo on resource)', t => {
1919
const origin = $rdf.sym('https://apps.example.com')
2020
const doc = ALICE('some/doc.txt')
2121
const aclDoc = ALICE('some/doc.txt.acl')
@@ -36,7 +36,35 @@ test('aclCheck getTrustedModesForOrigin() getting trusted modes from publisherSt
3636
`
3737
$rdf.parse(publisherText, publisherStore, publisher.uri, 'text/turtle')
3838

39-
aclLogic.getTrustedModesForOrigin(publisherStore, aclDoc, doc, origin, Promise.resolve.bind(Promise)).then(result => {
39+
aclLogic.getTrustedModesForOrigin(publisherStore, doc, null, aclDoc, origin, Promise.resolve.bind(Promise)).then(result => {
40+
t.deepEqual(result, [ACL('Read'), ACL('Write')], 'Should get a list of modes')
41+
t.end()
42+
})
43+
})
44+
45+
test('aclCheck getTrustedModesForOrigin() getting trusted modes from publisherStore (acl:accessTo on container)', t => {
46+
const origin = $rdf.sym('https://apps.example.com')
47+
const container = ALICE('some/')
48+
const doc = ALICE('some/doc.txt')
49+
const aclDoc = ALICE('some/doc.txt.acl')
50+
const publisher = alice
51+
const requester = bob
52+
const publisherStore = $rdf.graph()
53+
const aclFileText = `${prefixes}
54+
<#owner>
55+
a acl:Authorization;
56+
acl:agent ${publisher};
57+
acl:default ${container};
58+
acl:mode acl:Control.
59+
`
60+
$rdf.parse(aclFileText, publisherStore, aclDoc.uri, 'text/turtle')
61+
const publisherText = `${prefixes}
62+
${publisher} acl:trustedApp [ acl:origin ${origin};
63+
acl:mode acl:Read, acl:Write].
64+
`
65+
$rdf.parse(publisherText, publisherStore, publisher.uri, 'text/turtle')
66+
67+
aclLogic.getTrustedModesForOrigin(publisherStore, doc, container, aclDoc, origin, Promise.resolve.bind(Promise)).then(result => {
4068
t.deepEqual(result, [ACL('Read'), ACL('Write')], 'Should get a list of modes')
4169
t.end()
4270
})

0 commit comments

Comments
 (0)