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 { mkdirSync } from 'fs';
|
||||||
import * as rimraf from 'rimraf';
|
import * as rimraf from 'rimraf';
|
||||||
import { RootContainerInitializer } from '../../src/init/RootContainerInitializer';
|
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||||
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 { LDP } from '../../src/util/UriConstants';
|
import { LDP } from '../../src/util/UriConstants';
|
||||||
import { DataAccessorBasedConfig } from '../configs/DataAccessorBasedConfig';
|
import { BASE, getRootFilePath, instantiateFromConfig } from '../configs/Util';
|
||||||
import type { ServerConfig } from '../configs/ServerConfig';
|
|
||||||
import { BASE, getRootFilePath } from '../configs/Util';
|
|
||||||
import { FileTestHelper } from '../util/TestHelpers';
|
import { FileTestHelper } from '../util/TestHelpers';
|
||||||
|
|
||||||
const fileDataAccessorStore: [string, (rootFilePath: string) => ServerConfig] = [
|
const rootFilePath = getRootFilePath('full-config-no-auth');
|
||||||
'FileDataAccessorBasedStore',
|
const stores: [string, any][] = [
|
||||||
(rootFilePath: string): ServerConfig => new DataAccessorBasedConfig(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(),
|
||||||
'InMemoryDataAccessorBasedStore',
|
}],
|
||||||
(): ServerConfig => new DataAccessorBasedConfig(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 });
|
||||||
|
},
|
||||||
|
}],
|
||||||
];
|
];
|
||||||
|
|
||||||
const configs = [ fileDataAccessorStore, inMemoryDataAccessorStore ];
|
describe.each(stores)('A server using %s', (name, { storeUrn, setup, teardown }): void => {
|
||||||
|
|
||||||
describe.each(configs)('A server using a %s', (name, configFn): void => {
|
|
||||||
describe('without acl', (): void => {
|
describe('without acl', (): void => {
|
||||||
let rootFilePath: string;
|
|
||||||
let config: ServerConfig;
|
|
||||||
let handler: HttpHandler;
|
let handler: HttpHandler;
|
||||||
let fileHelper: FileTestHelper;
|
let fileHelper: FileTestHelper;
|
||||||
|
|
||||||
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> = {
|
||||||
handler = config.getHttpHandler();
|
'urn:solid-server:default:variable:baseUrl': BASE,
|
||||||
fileHelper = new FileTestHelper(handler, new URL(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
|
// Create and initialize the HTTP handler and related components
|
||||||
const initializer = new RootContainerInitializer(BASE, config.store);
|
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();
|
await initializer.handleSafe();
|
||||||
|
|
||||||
|
// Create test helpers for manipulating the components
|
||||||
|
fileHelper = new FileTestHelper(handler, new URL(BASE));
|
||||||
});
|
});
|
||||||
|
|
||||||
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.', async():
|
it('can add a file to the store, read it and delete it.', async():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user