mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
import type { MockResponse } from 'node-mocks-http';
|
|
import { BasicHandlersWithAclConfig } from '../configs/BasicHandlersWithAclConfig';
|
|
import { AclTestHelper } from '../util/TestHelpers';
|
|
import { call } from '../util/Util';
|
|
|
|
describe('A server with authorization', (): void => {
|
|
const config = new BasicHandlersWithAclConfig();
|
|
const handler = config.getHttpHandler();
|
|
const { store } = config;
|
|
const aclHelper = new AclTestHelper(store, 'http://test.com/');
|
|
|
|
it('can create new entries.', async(): Promise<void> => {
|
|
await aclHelper.setSimpleAcl({ read: true, write: true, append: true }, 'agent');
|
|
|
|
// POST
|
|
let requestUrl = new URL('http://test.com/');
|
|
let response: MockResponse<any> = await call(
|
|
handler,
|
|
requestUrl,
|
|
'POST',
|
|
{ 'content-type': 'text/turtle', 'transfer-encoding': 'chunked' },
|
|
[ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ],
|
|
);
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
// PUT
|
|
requestUrl = new URL('http://test.com/foo/bar');
|
|
response = await call(
|
|
handler,
|
|
requestUrl,
|
|
'PUT',
|
|
{ 'content-type': 'text/turtle', 'transfer-encoding': 'chunked' },
|
|
[ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ],
|
|
);
|
|
expect(response.statusCode).toBe(205);
|
|
});
|
|
|
|
it('can not create new entries if not allowed.', async(): Promise<void> => {
|
|
await aclHelper.setSimpleAcl({ read: true, write: true, append: true }, 'authenticated');
|
|
|
|
// POST
|
|
let requestUrl = new URL('http://test.com/');
|
|
let response: MockResponse<any> = await call(
|
|
handler,
|
|
requestUrl,
|
|
'POST',
|
|
{ 'content-type': 'text/turtle', 'transfer-encoding': 'chunked' },
|
|
[ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ],
|
|
);
|
|
expect(response.statusCode).toBe(401);
|
|
|
|
// PUT
|
|
requestUrl = new URL('http://test.com/foo/bar');
|
|
response = await call(
|
|
handler,
|
|
requestUrl,
|
|
'PUT',
|
|
{ 'content-type': 'text/turtle', 'transfer-encoding': 'chunked' },
|
|
[ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ],
|
|
);
|
|
expect(response.statusCode).toBe(401);
|
|
});
|
|
});
|