diff --git a/test/assets/templates/.acl b/test/assets/templates/.acl new file mode 100644 index 000000000..f5072ada9 --- /dev/null +++ b/test/assets/templates/.acl @@ -0,0 +1,3 @@ +@prefix acl: . + +<#owner> acl:agent <{{webId}}>. diff --git a/test/assets/templates/profile/card$.ttl b/test/assets/templates/profile/card$.ttl new file mode 100644 index 000000000..3461b7e23 --- /dev/null +++ b/test/assets/templates/profile/card$.ttl @@ -0,0 +1,5 @@ +@prefix foaf: . + +<{{webId}}> + a foaf:Person ; + foaf:name "{{name}}". diff --git a/test/configs/websockets.json b/test/configs/auth-allow-all.json similarity index 100% rename from test/configs/websockets.json rename to test/configs/auth-allow-all.json diff --git a/test/integration/PodCreation.test.ts b/test/integration/PodCreation.test.ts new file mode 100644 index 000000000..f6737f384 --- /dev/null +++ b/test/integration/PodCreation.test.ts @@ -0,0 +1,70 @@ +import type { Server } from 'http'; +import { join } from 'path'; +import fetch from 'cross-fetch'; +import type { HttpServerFactory } from '../../src/server/HttpServerFactory'; +import { readableToString } from '../../src/util/StreamUtil'; +import { instantiateFromConfig } from '../configs/Util'; + +const port = 6003; +const baseUrl = `http://localhost:${port}/`; + +describe('A server with a pod handler', (): void => { + let server: Server; + const agent = { login: 'alice', webId: 'http://test.com/#alice', name: 'Alice Bob' }; + + beforeAll(async(): Promise => { + const factory = await instantiateFromConfig( + 'urn:solid-server:default:ServerFactory', 'auth-allow-all.json', { + 'urn:solid-server:default:variable:port': port, + 'urn:solid-server:default:variable:baseUrl': baseUrl, + 'urn:solid-server:default:variable:podTemplateFolder': join(__dirname, '../assets/templates'), + }, + ) as HttpServerFactory; + server = factory.startServer(port); + }); + + afterAll(async(): Promise => { + await new Promise((resolve, reject): void => { + server.close((error): void => error ? reject(error) : resolve()); + }); + }); + + it('creates a pod when posting an Agent to /pods.', async(): Promise => { + const pod = `${baseUrl}${agent.login}/`; + + // Pod should not exist yet + let res = await fetch(pod); + expect(res.status).toBe(404); + + // Create pod call should return the address of the new pod + res = await fetch(`${baseUrl}pods`, { + method: 'POST', + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify(agent), + }); + expect(res.status).toBe(201); + expect(res.headers.get('location')).toBe(`${baseUrl}${agent.login}/`); + + // Check if all resources are created + res = await fetch(`${pod}.acl`); + expect(res.status).toBe(200); + let body = await readableToString(res.body as any); + expect(body).toBe(`@prefix acl: . + +<#owner> acl:agent <${agent.webId}>. +`); + + res = await fetch(`${pod}profile/card`); + expect(res.status).toBe(200); + expect(res.headers.get('content-type')).toBe('text/turtle'); + body = await readableToString(res.body as any); + expect(body).toBe(`@prefix foaf: . + +<${agent.webId}> + a foaf:Person ; + foaf:name "${agent.name}". +`); + }); +}); diff --git a/test/integration/WebSocketsProtocol.test.ts b/test/integration/WebSocketsProtocol.test.ts index 064cfbee7..a118c9ce1 100644 --- a/test/integration/WebSocketsProtocol.test.ts +++ b/test/integration/WebSocketsProtocol.test.ts @@ -13,7 +13,7 @@ describe('A server with the Solid WebSockets API behind a proxy', (): void => { beforeAll(async(): Promise => { const factory = await instantiateFromConfig( - 'urn:solid-server:default:ServerFactory', 'websockets.json', { + 'urn:solid-server:default:ServerFactory', 'auth-allow-all.json', { 'urn:solid-server:default:variable:port': port, 'urn:solid-server:default:variable:baseUrl': 'https://example.pod/', 'urn:solid-server:default:variable:podTemplateFolder': 'templates',