From 27910aaf73ba64e7e2538bdcf3cd4f093eff6040 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Mon, 21 Dec 2020 23:24:40 +0100 Subject: [PATCH] test: Use Components.js in FullConfig.noAuth. --- .../AuthenticatedDataAccessorBasedConfig.ts | 67 ----------------- test/integration/FullConfig.noAuth.test.ts | 72 +++++++++++-------- 2 files changed, 43 insertions(+), 96 deletions(-) delete mode 100644 test/configs/AuthenticatedDataAccessorBasedConfig.ts diff --git a/test/configs/AuthenticatedDataAccessorBasedConfig.ts b/test/configs/AuthenticatedDataAccessorBasedConfig.ts deleted file mode 100644 index 1c4ccd92b..000000000 --- a/test/configs/AuthenticatedDataAccessorBasedConfig.ts +++ /dev/null @@ -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; - } -} diff --git a/test/integration/FullConfig.noAuth.test.ts b/test/integration/FullConfig.noAuth.test.ts index 4b83a4ba1..757be451c 100644 --- a/test/integration/FullConfig.noAuth.test.ts +++ b/test/integration/FullConfig.noAuth.test.ts @@ -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 => { - 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 = { + '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; + ({ handler, initializer } = instances); await initializer.handleSafe(); + + // Create test helpers for manipulating the components + fileHelper = new FileTestHelper(handler, new URL(BASE)); }); afterAll(async(): Promise => { - rimraf.sync(rootFilePath, { glob: false }); + await teardown(); }); it('can add a file to the store, read it and delete it.', async():