mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Use Components.js in FullConfig.acl.
This commit is contained in:
parent
1cf1167261
commit
7c1f4e9d6f
@ -12,6 +12,7 @@ module.exports = {
|
|||||||
'no-process-env': 'off',
|
'no-process-env': 'off',
|
||||||
|
|
||||||
// We are not using Mocha
|
// We are not using Mocha
|
||||||
|
'mocha/no-nested-tests': 'off',
|
||||||
'mocha/no-exports': 'off',
|
'mocha/no-exports': 'off',
|
||||||
'mocha/no-skipped-tests': 'off',
|
'mocha/no-skipped-tests': 'off',
|
||||||
'mocha/no-synchronous-tests': 'off',
|
'mocha/no-synchronous-tests': 'off',
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
"files-scs:config/presets/ldp/request-parser.json",
|
"files-scs:config/presets/ldp/request-parser.json",
|
||||||
"files-scs:config/presets/representation-conversion.json",
|
"files-scs:config/presets/representation-conversion.json",
|
||||||
"files-scs:config/presets/storage/backend/storage-memory.json",
|
"files-scs:config/presets/storage/backend/storage-memory.json",
|
||||||
|
"files-scs:config/presets/storage/backend/storage-filesystem.json",
|
||||||
"files-scs:config/presets/storage-wrapper.json",
|
"files-scs:config/presets/storage-wrapper.json",
|
||||||
"files-scs:config/presets/cli-params.json"
|
"files-scs:config/presets/cli-params.json"
|
||||||
],
|
],
|
||||||
@ -38,8 +39,12 @@
|
|||||||
"@id": "urn:solid-server:default:RoutingResourceStore",
|
"@id": "urn:solid-server:default:RoutingResourceStore",
|
||||||
"@type": "PassthroughStore",
|
"@type": "PassthroughStore",
|
||||||
"PassthroughStore:_source": {
|
"PassthroughStore:_source": {
|
||||||
"@id": "urn:solid-server:default:MemoryResourceStore"
|
"@id": "urn:solid-server:default:variable:store"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@id": "urn:solid-server:default:variable:store",
|
||||||
|
"@type": "Variable"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,29 @@ describe('A server with authorization', (): void => {
|
|||||||
let aclHelper: AclTestHelper;
|
let aclHelper: AclTestHelper;
|
||||||
|
|
||||||
beforeAll(async(): Promise<void> => {
|
beforeAll(async(): Promise<void> => {
|
||||||
let initializer: Initializer,
|
// Set up the internal store
|
||||||
store: ResourceStore;
|
const variables: Record<string, any> = {
|
||||||
const instances = await instantiateFromConfig('urn:solid-server:test:Instances', 'auth-ldp-handler.json', {
|
|
||||||
'urn:solid-server:default:variable:baseUrl': BASE,
|
'urn:solid-server:default:variable:baseUrl': BASE,
|
||||||
}) as Record<string, any>;
|
};
|
||||||
({ handler, store, initializer } = instances);
|
const internalStore = await instantiateFromConfig(
|
||||||
|
'urn:solid-server:default:MemoryResourceStore',
|
||||||
|
'auth-ldp-handler.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',
|
||||||
|
'auth-ldp-handler.json',
|
||||||
|
variables,
|
||||||
|
) as Record<string, any>;
|
||||||
|
({ handler, store, initializer } = instances);
|
||||||
await initializer.handleSafe();
|
await initializer.handleSafe();
|
||||||
|
|
||||||
|
// Create test helpers for manipulating the components
|
||||||
aclHelper = new AclTestHelper(store, BASE);
|
aclHelper = new AclTestHelper(store, BASE);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,52 +1,68 @@
|
|||||||
import { createReadStream, mkdirSync } from 'fs';
|
import { createReadStream, mkdirSync } from 'fs';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import * as rimraf from 'rimraf';
|
import * as rimraf from 'rimraf';
|
||||||
import { RootContainerInitializer } from '../../src/init/RootContainerInitializer';
|
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||||
import { RepresentationMetadata } from '../../src/ldp/representation/RepresentationMetadata';
|
import { RepresentationMetadata } from '../../src/ldp/representation/RepresentationMetadata';
|
||||||
import { FileDataAccessor } from '../../src/storage/accessors/FileDataAccessor';
|
|
||||||
import { InMemoryDataAccessor } from '../../src/storage/accessors/InMemoryDataAccessor';
|
|
||||||
import { ExtensionBasedMapper } from '../../src/storage/mapping/ExtensionBasedMapper';
|
|
||||||
import { guardStream } from '../../src/util/GuardedStream';
|
import { guardStream } from '../../src/util/GuardedStream';
|
||||||
import { ensureTrailingSlash } from '../../src/util/PathUtil';
|
|
||||||
import { CONTENT_TYPE, LDP } from '../../src/util/UriConstants';
|
import { CONTENT_TYPE, LDP } from '../../src/util/UriConstants';
|
||||||
import { AuthenticatedDataAccessorBasedConfig } from '../configs/AuthenticatedDataAccessorBasedConfig';
|
import { BASE, getRootFilePath, instantiateFromConfig } from '../configs/Util';
|
||||||
import type { ServerConfig } from '../configs/ServerConfig';
|
|
||||||
import { BASE, getRootFilePath } from '../configs/Util';
|
|
||||||
import { AclTestHelper, FileTestHelper } from '../util/TestHelpers';
|
import { AclTestHelper, FileTestHelper } from '../util/TestHelpers';
|
||||||
|
|
||||||
const dataAccessorStore: [string, (rootFilePath: string) => ServerConfig] = [
|
const rootFilePath = getRootFilePath('full-config-acl');
|
||||||
'AuthenticatedFileDataAccessorBasedStore',
|
const stores: [string, any][] = [
|
||||||
(rootFilePath: string): ServerConfig => new AuthenticatedDataAccessorBasedConfig(BASE,
|
[ 'in-memory storage', {
|
||||||
new FileDataAccessor(new ExtensionBasedMapper(BASE, rootFilePath))),
|
storeUrn: 'urn:solid-server:default:MemoryResourceStore',
|
||||||
];
|
setup: jest.fn(),
|
||||||
const inMemoryDataAccessorStore: [string, (rootFilePath: string) => ServerConfig] = [
|
teardown: jest.fn(),
|
||||||
'AuthenticatedInMemoryDataAccessorBasedStore',
|
}],
|
||||||
(): ServerConfig => new AuthenticatedDataAccessorBasedConfig(BASE, new InMemoryDataAccessor(BASE)),
|
[ 'on-disk storage', {
|
||||||
|
storeUrn: 'urn:solid-server:default:FileResourceStore',
|
||||||
|
setup(): void {
|
||||||
|
mkdirSync(rootFilePath, { recursive: true });
|
||||||
|
},
|
||||||
|
teardown(): void {
|
||||||
|
rimraf.sync(rootFilePath, { glob: false });
|
||||||
|
},
|
||||||
|
}],
|
||||||
];
|
];
|
||||||
|
|
||||||
describe.each([ dataAccessorStore, inMemoryDataAccessorStore ])('A server using a %s', (name, configFn): void => {
|
describe.each(stores)('A server using %s', (name, { storeUrn, setup, teardown }): void => {
|
||||||
describe('with acl', (): void => {
|
describe('with acl', (): void => {
|
||||||
let config: ServerConfig;
|
let handler: HttpHandler;
|
||||||
let aclHelper: AclTestHelper;
|
let aclHelper: AclTestHelper;
|
||||||
let fileHelper: FileTestHelper;
|
let fileHelper: FileTestHelper;
|
||||||
let rootFilePath: string;
|
|
||||||
|
|
||||||
beforeAll(async(): Promise<void> => {
|
beforeAll(async(): Promise<void> => {
|
||||||
rootFilePath = getRootFilePath(name);
|
// Set up the internal store
|
||||||
mkdirSync(rootFilePath, { recursive: true });
|
await setup();
|
||||||
config = configFn(rootFilePath);
|
const variables: Record<string, any> = {
|
||||||
aclHelper = new AclTestHelper(config.store, ensureTrailingSlash(BASE));
|
'urn:solid-server:default:variable:baseUrl': BASE,
|
||||||
fileHelper = new FileTestHelper(config.getHttpHandler(), new URL(ensureTrailingSlash(BASE)));
|
'urn:solid-server:default:variable:rootFilePath': rootFilePath,
|
||||||
|
};
|
||||||
|
const internalStore = await instantiateFromConfig(
|
||||||
|
storeUrn,
|
||||||
|
'auth-ldp-handler.json',
|
||||||
|
variables,
|
||||||
|
) as ResourceStore;
|
||||||
|
variables['urn:solid-server:default:variable:store'] = internalStore;
|
||||||
|
|
||||||
// Make sure the root directory exists
|
// Create and initialize the HTTP handler and related components
|
||||||
mkdirSync(rootFilePath, { recursive: true });
|
let initializer: Initializer;
|
||||||
|
let store: ResourceStore;
|
||||||
// Initialize store
|
const instances = await instantiateFromConfig(
|
||||||
const initializer = new RootContainerInitializer(BASE, config.store);
|
'urn:solid-server:test:Instances',
|
||||||
|
'auth-ldp-handler.json',
|
||||||
|
variables,
|
||||||
|
) as Record<string, any>;
|
||||||
|
({ handler, store, initializer } = instances);
|
||||||
await initializer.handleSafe();
|
await initializer.handleSafe();
|
||||||
|
|
||||||
// Use store instead of file access so tests also work for non-file backends
|
// Create test helpers for manipulating the components
|
||||||
await config.store.setRepresentation({ path: `${BASE}/permanent.txt` }, {
|
aclHelper = new AclTestHelper(store, BASE);
|
||||||
|
fileHelper = new FileTestHelper(handler, new URL(BASE));
|
||||||
|
|
||||||
|
// Write test resource
|
||||||
|
await store.setRepresentation({ path: `${BASE}/permanent.txt` }, {
|
||||||
binary: true,
|
binary: true,
|
||||||
data: guardStream(createReadStream(join(__dirname, '../assets/permanent.txt'))),
|
data: guardStream(createReadStream(join(__dirname, '../assets/permanent.txt'))),
|
||||||
metadata: new RepresentationMetadata({ [CONTENT_TYPE]: 'text/plain' }),
|
metadata: new RepresentationMetadata({ [CONTENT_TYPE]: 'text/plain' }),
|
||||||
@ -54,12 +70,11 @@ describe.each([ dataAccessorStore, inMemoryDataAccessorStore ])('A server using
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async(): Promise<void> => {
|
afterAll(async(): Promise<void> => {
|
||||||
rimraf.sync(rootFilePath, { glob: false });
|
await teardown();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can add a file to the store, read it and delete it if allowed.', async(): Promise<
|
it('can add a file to the store, read it and delete it if allowed.', async():
|
||||||
void
|
Promise<void> => {
|
||||||
> => {
|
|
||||||
// Set acl
|
// Set acl
|
||||||
await aclHelper.setSimpleAcl({ read: true, write: true, append: true }, 'agent');
|
await aclHelper.setSimpleAcl({ read: true, write: true, append: true }, 'agent');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user