mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Use Components.js in FullConfig.noAuth.
This commit is contained in:
parent
7c1f4e9d6f
commit
27910aaf73
@ -1,67 +0,0 @@
|
||||
import type {
|
||||
DataAccessor,
|
||||
HttpHandler,
|
||||
ResourceStore,
|
||||
} from '../../src/index';
|
||||
import {
|
||||
AuthenticatedLdpHandler,
|
||||
EmptyCredentialsExtractor,
|
||||
MethodPermissionsExtractor,
|
||||
RdfToQuadConverter,
|
||||
QuadToRdfConverter,
|
||||
WaterfallHandler,
|
||||
} from '../../src/index';
|
||||
import type { ServerConfig } from './ServerConfig';
|
||||
import {
|
||||
getConvertingStore,
|
||||
getBasicRequestParser,
|
||||
getOperationHandler,
|
||||
getWebAclAuthorizer,
|
||||
getDataAccessorStore,
|
||||
getResponseWriter,
|
||||
} from './Util';
|
||||
|
||||
/**
|
||||
* AuthenticatedFileResourceStoreConfig works with
|
||||
* - a WebAclAuthorizer
|
||||
* - a FileResourceStore wrapped in a converting store (rdf to quad & quad to rdf)
|
||||
* - GET, POST, PUT & DELETE operation handlers
|
||||
*/
|
||||
export class AuthenticatedDataAccessorBasedConfig implements ServerConfig {
|
||||
public base: string;
|
||||
public store: ResourceStore;
|
||||
|
||||
public constructor(base: string, dataAccessor: DataAccessor) {
|
||||
this.base = base;
|
||||
this.store = getConvertingStore(
|
||||
getDataAccessorStore(base, dataAccessor),
|
||||
[ new QuadToRdfConverter(),
|
||||
new RdfToQuadConverter() ],
|
||||
);
|
||||
}
|
||||
|
||||
public getHttpHandler(): HttpHandler {
|
||||
const requestParser = getBasicRequestParser();
|
||||
|
||||
const credentialsExtractor = new EmptyCredentialsExtractor();
|
||||
const permissionsExtractor = new WaterfallHandler([
|
||||
new MethodPermissionsExtractor(),
|
||||
]);
|
||||
|
||||
const operationHandler = getOperationHandler(this.store);
|
||||
|
||||
const responseWriter = getResponseWriter();
|
||||
const authorizer = getWebAclAuthorizer(this.store);
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
credentialsExtractor,
|
||||
permissionsExtractor,
|
||||
authorizer,
|
||||
operationHandler,
|
||||
responseWriter,
|
||||
});
|
||||
|
||||
return handler;
|
||||
}
|
||||
}
|
@ -1,49 +1,63 @@
|
||||
import { mkdirSync } from 'fs';
|
||||
import * as rimraf from 'rimraf';
|
||||
import { RootContainerInitializer } from '../../src/init/RootContainerInitializer';
|
||||
import type { HttpHandler } from '../../src/server/HttpHandler';
|
||||
import { FileDataAccessor } from '../../src/storage/accessors/FileDataAccessor';
|
||||
import { InMemoryDataAccessor } from '../../src/storage/accessors/InMemoryDataAccessor';
|
||||
import { ExtensionBasedMapper } from '../../src/storage/mapping/ExtensionBasedMapper';
|
||||
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||
import { LDP } from '../../src/util/UriConstants';
|
||||
import { DataAccessorBasedConfig } from '../configs/DataAccessorBasedConfig';
|
||||
import type { ServerConfig } from '../configs/ServerConfig';
|
||||
import { BASE, getRootFilePath } from '../configs/Util';
|
||||
import { BASE, getRootFilePath, instantiateFromConfig } from '../configs/Util';
|
||||
import { FileTestHelper } from '../util/TestHelpers';
|
||||
|
||||
const fileDataAccessorStore: [string, (rootFilePath: string) => ServerConfig] = [
|
||||
'FileDataAccessorBasedStore',
|
||||
(rootFilePath: string): ServerConfig => new DataAccessorBasedConfig(BASE,
|
||||
new FileDataAccessor(new ExtensionBasedMapper(BASE, rootFilePath))),
|
||||
];
|
||||
const inMemoryDataAccessorStore: [string, (rootFilePath: string) => ServerConfig] = [
|
||||
'InMemoryDataAccessorBasedStore',
|
||||
(): ServerConfig => new DataAccessorBasedConfig(BASE, new InMemoryDataAccessor(BASE)),
|
||||
const rootFilePath = getRootFilePath('full-config-no-auth');
|
||||
const stores: [string, any][] = [
|
||||
[ 'in-memory storage', {
|
||||
storeUrn: 'urn:solid-server:default:MemoryResourceStore',
|
||||
setup: jest.fn(),
|
||||
teardown: jest.fn(),
|
||||
}],
|
||||
[ 'on-disk storage', {
|
||||
storeUrn: 'urn:solid-server:default:FileResourceStore',
|
||||
setup(): void {
|
||||
mkdirSync(rootFilePath, { recursive: true });
|
||||
},
|
||||
teardown(): void {
|
||||
rimraf.sync(rootFilePath, { glob: false });
|
||||
},
|
||||
}],
|
||||
];
|
||||
|
||||
const configs = [ fileDataAccessorStore, inMemoryDataAccessorStore ];
|
||||
|
||||
describe.each(configs)('A server using a %s', (name, configFn): void => {
|
||||
describe.each(stores)('A server using %s', (name, { storeUrn, setup, teardown }): void => {
|
||||
describe('without acl', (): void => {
|
||||
let rootFilePath: string;
|
||||
let config: ServerConfig;
|
||||
let handler: HttpHandler;
|
||||
let fileHelper: FileTestHelper;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
rootFilePath = getRootFilePath(name);
|
||||
mkdirSync(rootFilePath, { recursive: true });
|
||||
config = configFn(rootFilePath);
|
||||
handler = config.getHttpHandler();
|
||||
fileHelper = new FileTestHelper(handler, new URL(BASE));
|
||||
// Set up the internal store
|
||||
await setup();
|
||||
const variables: Record<string, any> = {
|
||||
'urn:solid-server:default:variable:baseUrl': 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;
|
||||
|
||||
// Initialize store
|
||||
const initializer = new RootContainerInitializer(BASE, config.store);
|
||||
// Create and initialize the HTTP handler and related components
|
||||
let initializer: Initializer;
|
||||
const instances = await instantiateFromConfig(
|
||||
'urn:solid-server:test:Instances',
|
||||
'auth-ldp-handler.json',
|
||||
variables,
|
||||
) as Record<string, any>;
|
||||
({ handler, initializer } = instances);
|
||||
await initializer.handleSafe();
|
||||
|
||||
// Create test helpers for manipulating the components
|
||||
fileHelper = new FileTestHelper(handler, new URL(BASE));
|
||||
});
|
||||
|
||||
afterAll(async(): Promise<void> => {
|
||||
rimraf.sync(rootFilePath, { glob: false });
|
||||
await teardown();
|
||||
});
|
||||
|
||||
it('can add a file to the store, read it and delete it.', async():
|
||||
|
Loading…
x
Reference in New Issue
Block a user