test: Add integration test for intermediate containers

This commit is contained in:
Joachim Van Herwegen 2022-06-16 09:41:39 +02:00
parent d5bcec704c
commit 47c54abe22
2 changed files with 37 additions and 2 deletions

View File

@ -84,11 +84,14 @@ describe('A Solid server with IDP', (): void => {
acl:default <./>;
acl:mode acl:Read, acl:Write, acl:Control.
`;
await fetch(`${container}.acl`, {
const res = await fetch(`${container}.acl`, {
method: 'PUT',
headers: { 'content-type': 'text/turtle' },
body: aclTurtle,
});
if (res.status !== 201) {
throw new Error('Something went wrong initializing the test ACL');
}
});
afterAll(async(): Promise<void> => {

View File

@ -1,7 +1,7 @@
import { promises as fsPromises } from 'fs';
import fetch from 'cross-fetch';
import type { ResourceStore, App } from '../../src/';
import { BasicRepresentation, isSystemError, joinFilePath } from '../../src/';
import { BasicRepresentation, isSystemError, joinFilePath, joinUrl } from '../../src/';
import { AclHelper } from '../util/AclHelper';
import { deleteResource, getResource, postResource, putResource } from '../util/FetchUtil';
import { getPort } from '../util/Util';
@ -234,4 +234,36 @@ describe.each(stores)('An LDP handler with auth using %s', (name, { storeConfig,
const response = await getResource(identifier.path);
expect(await response.text()).toContain('valid data');
});
it('prevents creation of intermediate intermediate containers if they are not allowed.', async(): Promise<void> => {
const url = joinUrl(baseUrl, 'foo/bar/');
// Not allowed since there are no append permissions on the base container
await aclHelper.setSimpleAcl(baseUrl, {
permissions: { write: true },
agentClass: 'agent',
default: true,
});
let response = await fetch(url, { method: 'PUT' });
expect(response.status).toBe(401);
// Not allowed since there are no write permissions for the target
await aclHelper.setSimpleAcl(baseUrl, {
permissions: { append: true },
agentClass: 'agent',
accessTo: true,
});
response = await fetch(url, { method: 'PUT' });
expect(response.status).toBe(401);
// This covers all required permissions
await aclHelper.setSimpleAcl(baseUrl, [
{ permissions: { append: true },
agentClass: 'agent',
accessTo: true },
{ permissions: { write: true },
agentClass: 'agent',
default: true },
]);
await putResource(url, { contentType: 'text/plain', exists: false });
});
});