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

Commit

Permalink
failing test for #42
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed May 24, 2019
1 parent f8a8fa5 commit 865de49
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/auth/appIsTrustedForMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export interface OriginCheckTask {
}

async function checkOwnerProfile (webId: URL, origin: string, mode: string, graphFetcher: RdfFetcher): Promise<boolean> {
// TODO: move this cache into a decorator pattern, see #81
if (!ownerProfilesCache[webId.toString()]) {
ownerProfilesCache[webId.toString()] = await graphFetcher.fetchGraph(webId)
}
return Promise.resolve(false)
}

export async function appIsTrustedForMode (task: OriginCheckTask, graphFetcher: RdfFetcher): Promise<boolean> {
return Promise.resolve(true) // FIXME
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(false)
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/owner-profile.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

@prefix : <https://michielbdejong.com/profile/card#>.
@prefix acl: <http://www.w3.org/ns/auth/acl#>.

:me
acl:trustedApp
[
acl:mode acl:Append, acl:Read, acl:Write;
acl:origin <https://pheyvaer.github.io>
].
31 changes: 31 additions & 0 deletions test/unit/auth/trustedApps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import rdf from 'rdf-ext'
import N3Parser from 'rdf-parser-n3'
import fs from 'fs'
import { appIsTrustedForMode, OriginCheckTask } from '../../../src/lib/auth/appIsTrustedForMode'
import { RdfFetcher } from '../../../src/lib/rdf/RdfFetcher'
import { ACL } from '../../../src/lib/rdf/rdf-constants'

function readFixture (filename: string): Promise<any> {
const bodyStream = fs.createReadStream(filename)
let parser = new N3Parser({
factory: rdf
})
let quadStream = parser.import(bodyStream)
return rdf.dataset().import(quadStream)

}
test('finds acl:trustedApps nodes and their modes for a given owners list', async () => {
const task = {
origin: 'https://pheyvaer.github.io',
mode: ACL.Read,
resourceOwners: [ new URL('https://michielbdejong.com/profile/card#me')]
} as OriginCheckTask

const rdfFetcher: unknown = {
fetchGraph: jest.fn(() => {
return readFixture('test/fixtures/owner-profile.ttl')
})
}
const result = await appIsTrustedForMode(task, rdfFetcher as RdfFetcher)
expect(result).toEqual(true)
})

0 comments on commit 865de49

Please sign in to comment.