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

Commit

Permalink
70 tests green
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed May 28, 2019
1 parent c80a214 commit eb29ffa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/lib/core/checkAccess.ts
Expand Up @@ -39,8 +39,8 @@ async function modeAllowed (mode: URL, allowedAgentsForModes: AccessModes, webId
const agents = (allowedAgentsForModes as any)[mode.toString()].map((url: URL) => url.toString())
const webIdAsString: string | undefined = (webId ? webId.toString() : undefined)
debug(mode, agents, webId)
if ((agents.indexOf(AGENT_CLASS_ANYBODY) === -1) &&
(agents.indexOf(AGENT_CLASS_ANYBODY_LOGGED_IN) === -1) &&
if ((agents.indexOf(AGENT_CLASS_ANYBODY.toString()) === -1) &&
(agents.indexOf(AGENT_CLASS_ANYBODY_LOGGED_IN.toString()) === -1) &&
(!webIdAsString || agents.indexOf(webIdAsString) === -1)) {
debug('agent check returning false')
return false
Expand Down
4 changes: 2 additions & 2 deletions test/integration/app.test.ts
Expand Up @@ -12,13 +12,13 @@ beforeEach(async () => {
const publicContainerAclDocData = await objectToStream(makeResourceData('text/turtle', aclDoc.toString()))
await storage.getBlob(urlToPath(new URL('http://localhost:8080/foo/.acl'))).setData(publicContainerAclDocData)

// src/rdf/_mocks_/node-fetch.ts will use test/fixtures/web/michielbdejong.com/443/profile/card
// src/__mocks__/node-fetch.ts will use test/fixtures/web/michielbdejong.com/443/profile/card
// Which says origin https://pheyvaer.github.io is trusted by owner https://michielbdejong.com/profile/card#me
})

const handler = makeHandler(storage, 'http://localhost:8080', false)

test.only('handles a GET request for a public resource', async () => {
test('handles a GET request for a public resource', async () => {
let streamed = false
let endCallback: () => void
let httpReq: any = toChunkStream('')
Expand Down
11 changes: 8 additions & 3 deletions test/integration/glob-read.test.ts
Expand Up @@ -8,10 +8,13 @@ import { urlToPath } from '../../src/lib/storage/BlobTree'

const storage = new BlobTreeInMem()
beforeEach(async () => {
const aclDoc = fs.readFileSync('test/fixtures/aclDoc-read-and-container-read.ttl')
const aclDoc = fs.readFileSync('test/fixtures/aclDoc-read-rel-path-parent-container-with-owner.ttl')
const publicContainerAclDocData = await objectToStream(makeResourceData('text/turtle', aclDoc.toString()))
await storage.getBlob(urlToPath(new URL('http://localhost:8080/foo/.acl'))).setData(publicContainerAclDocData)

// src/__mocks__/node-fetch.ts will use test/fixtures/web/michielbdejong.com/443/profile/card
// Which says origin https://pheyvaer.github.io is trusted by owner https://michielbdejong.com/profile/card#me

const ldpRs1 = fs.readFileSync('test/fixtures/ldpRs1.ttl')
const ldpRs1Data = await objectToStream(makeResourceData('text/turtle', ldpRs1.toString()))
await storage.getBlob(urlToPath(new URL('http://localhost:8080/foo/ldp-rs1.ttl'))).setData(ldpRs1Data)
Expand All @@ -23,12 +26,14 @@ beforeEach(async () => {

const handler = makeHandler(storage, 'http://localhost:8080', false)

test('handles a GET /* request (glob read)', async () => {
test.only('handles a GET /* request (glob read)', async () => {
const expectedTurtle = fs.readFileSync('test/fixtures/ldpRs1-2-merge.ttl').toString()
let streamed = false
let endCallback: () => void
let httpReq: any = toChunkStream('')
httpReq.headers = {} as http.IncomingHttpHeaders
httpReq.headers = {
origin: 'https://pheyvaer.github.io'
} as http.IncomingHttpHeaders
httpReq.url = '/foo/*' as string
httpReq.method = 'GET'
httpReq = httpReq as http.IncomingMessage
Expand Down
15 changes: 10 additions & 5 deletions test/integration/sparql-query-get.test.ts
Expand Up @@ -8,13 +8,16 @@ import { urlToPath } from '../../src/lib/storage/BlobTree'

const storage = new BlobTreeInMem()
beforeEach(async () => {
const aclDoc = fs.readFileSync('test/fixtures/aclDoc-readwrite.ttl')
const aclDoc = fs.readFileSync('test/fixtures/aclDoc-read-rel-path-parent-container-with-owner.ttl')
const publicContainerAclDocData = await objectToStream(makeResourceData('text/turtle', aclDoc.toString()))
await storage.getBlob(urlToPath(new URL('http://localhost:8080/public/.acl'))).setData(publicContainerAclDocData)
await storage.getBlob(urlToPath(new URL('http://localhost:8080/foo/.acl'))).setData(publicContainerAclDocData)

// src/__mocks__/node-fetch.ts will use test/fixtures/web/michielbdejong.com/443/profile/card
// Which says origin https://pheyvaer.github.io is trusted by owner https://michielbdejong.com/profile/card#me

const ldpRs1 = fs.readFileSync('test/fixtures/ldpRs1.ttl')
const ldpRs1Data = await objectToStream(makeResourceData('text/turtle', ldpRs1.toString()))
await storage.getBlob(urlToPath(new URL('http://localhost:8080/public/ldp-rs1.ttl'))).setData(ldpRs1Data)
await storage.getBlob(urlToPath(new URL('http://localhost:8080/foo/ldp-rs1.ttl'))).setData(ldpRs1Data)
})

const handler = makeHandler(storage, 'http://localhost:8080', false)
Expand All @@ -25,8 +28,10 @@ test('handles a SPARQL query in the GET query parameter', async () => {
let streamed = false
let endCallback: () => void
let httpReq: any = toChunkStream('')
httpReq.headers = {} as http.IncomingHttpHeaders
httpReq.url = `/public/ldp-rs1.ttl?query=${encodeURIComponent(sparqlQuery)}`
httpReq.headers = {
origin: 'https://pheyvaer.github.io'
} as http.IncomingHttpHeaders
httpReq.url = `/foo/ldp-rs1.ttl?query=${encodeURIComponent(sparqlQuery)}`
httpReq.method = 'GET'
httpReq = httpReq as http.IncomingMessage
const httpRes = {
Expand Down

0 comments on commit eb29ffa

Please sign in to comment.