mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Make integration test names consistent.
This commit is contained in:
89
test/integration/ServerWithAuth.test.ts
Normal file
89
test/integration/ServerWithAuth.test.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import type { MockResponse } from 'node-mocks-http';
|
||||
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||
import { AclTestHelper } from '../util/TestHelpers';
|
||||
import { call } from '../util/Util';
|
||||
import { BASE, instantiateFromConfig } from './Config';
|
||||
|
||||
describe('A server with authorization', (): void => {
|
||||
let handler: HttpHandler;
|
||||
let aclHelper: AclTestHelper;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Set up the internal store
|
||||
const variables: Record<string, any> = {
|
||||
'urn:solid-server:default:variable:baseUrl': BASE,
|
||||
};
|
||||
const internalStore = await instantiateFromConfig(
|
||||
'urn:solid-server:default:MemoryResourceStore',
|
||||
'ldp-with-auth.json',
|
||||
variables,
|
||||
) as ResourceStore;
|
||||
variables['urn:solid-server:default:variable:store'] = internalStore;
|
||||
|
||||
// Create and initialize the HTTP handler and related components
|
||||
let initializer: Initializer;
|
||||
let store: ResourceStore;
|
||||
const instances = await instantiateFromConfig(
|
||||
'urn:solid-server:test:Instances',
|
||||
'ldp-with-auth.json',
|
||||
variables,
|
||||
) as Record<string, any>;
|
||||
({ handler, store, initializer } = instances);
|
||||
await initializer.handleSafe();
|
||||
|
||||
// Create test helpers for manipulating the components
|
||||
aclHelper = new AclTestHelper(store, BASE);
|
||||
});
|
||||
|
||||
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('cannot 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user