Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
appIsTrustedForMode - test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed May 24, 2019
1 parent 24d75cd commit 44f5793
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
46 changes: 45 additions & 1 deletion src/lib/auth/appIsTrustedForMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,51 @@ async function checkOwnerProfile (webId: URL, origin: string, mode: string, grap
} catch (err) {
debug('error looping over quads', err)
}
return false
const appNodes: { [indexer: string]: any } = {}
function ensure (str: string) {
if (!appNodes[str]) {
appNodes[str] = {}
}
}
quads.map((quad: any): void => {
debug('considering quad', quad)
switch (quad.predicate.value) {
case ACL.mode:
debug('mode predicate!', quad.predicate.value, mode)
if (mode === quad.object.value) {
ensure(quad.subject.value)
appNodes[quad.subject.value].modeMatches = true
}
break
case ACL.origin:
debug('origin predicate!', quad.predicate.value, origin)
if (origin === quad.object.value) {
ensure(quad.subject.value)
appNodes[quad.subject.value].originMatches = true
}
break
case ACL.trustedApp:
debug('trustedApp predicate!', quad.predicate.value, webId.toString())
if (webId.toString() === quad.subject.value) {
ensure(quad.object.value)
appNodes[quad.object.value].webIdMatches = true
}
break
default:
debug('unknown predicate!', quad.predicate.value)
}
})
debug('appNodes', appNodes)
let found = false
Object.keys(appNodes).map(nodeName => {
debug('considering', nodeName, appNodes[nodeName])
if (appNodes[nodeName].webIdMatches && appNodes[nodeName].originMatches && appNodes[nodeName].modeMatches) {
debug('found')
found = true
}
})
debug('returning', found)
return found
}

export async function appIsTrustedForMode (task: OriginCheckTask, graphFetcher: RdfFetcher): Promise<boolean> {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/rdf/rdf-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export const ACL = {
agent: PREFIX.ACL + 'agent',
agentGroup: PREFIX.ACL + 'agentGroup',
agentClass: PREFIX.ACL + 'agentClass',
mode: PREFIX.ACL + 'mode'
mode: PREFIX.ACL + 'mode',

origin: PREFIX.ACL + 'origin',
trustedApp: PREFIX.ACL + 'trustedApp'

}

export const FOAF = {
Expand Down

0 comments on commit 44f5793

Please sign in to comment.