mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Hide internal data by making it auxiliary
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createReadStream } from 'fs';
|
||||
import fetch from 'cross-fetch';
|
||||
import { DataFactory, Parser } from 'n3';
|
||||
import { DataFactory, Parser, Store } from 'n3';
|
||||
import { joinFilePath, PIM, RDF } from '../../src/';
|
||||
import type { App } from '../../src/';
|
||||
import { LDP } from '../../src/util/Vocabularies';
|
||||
@@ -90,9 +90,11 @@ describe.each(stores)('An LDP handler allowing all requests %s', (name, { storeC
|
||||
|
||||
const parser = new Parser({ baseIRI: baseUrl });
|
||||
const quads = parser.parse(await response.text());
|
||||
expect(quads.some((entry): boolean => entry.equals(
|
||||
quad(namedNode(baseUrl), RDF.terms.type, LDP.terms.Container),
|
||||
))).toBe(true);
|
||||
const store = new Store(quads);
|
||||
expect(store.countQuads(namedNode(baseUrl), RDF.terms.type, LDP.terms.Container, null)).toBe(1);
|
||||
const contains = store.getObjects(namedNode(baseUrl), LDP.terms.contains, null);
|
||||
expect(contains).toHaveLength(1);
|
||||
expect(contains[0].value).toBe(`${baseUrl}index.html`);
|
||||
});
|
||||
|
||||
it('can add a document to the store, read it and delete it.', async(): Promise<void> => {
|
||||
|
||||
@@ -45,8 +45,8 @@ describe('A ComposedAuxiliaryStrategy', (): void => {
|
||||
expect(identifierStrategy.isAuxiliaryIdentifier).toHaveBeenLastCalledWith(identifier);
|
||||
});
|
||||
|
||||
it('returns the injected value for isRootRequired.', async(): Promise<void> => {
|
||||
expect(strategy.isRootRequired()).toBe(true);
|
||||
it('returns the injected value for isRequiredInRoot.', async(): Promise<void> => {
|
||||
expect(strategy.isRequiredInRoot()).toBe(true);
|
||||
});
|
||||
|
||||
it('adds metadata through the MetadataGenerator.', async(): Promise<void> => {
|
||||
@@ -63,9 +63,9 @@ describe('A ComposedAuxiliaryStrategy', (): void => {
|
||||
expect(validator.handleSafe).toHaveBeenLastCalledWith(representation);
|
||||
});
|
||||
|
||||
it('defaults isRootRequired to false.', async(): Promise<void> => {
|
||||
it('defaults isRequiredInRoot to false.', async(): Promise<void> => {
|
||||
strategy = new ComposedAuxiliaryStrategy(identifierStrategy, metadataGenerator, validator);
|
||||
expect(strategy.isRootRequired()).toBe(false);
|
||||
expect(strategy.isRequiredInRoot()).toBe(false);
|
||||
});
|
||||
|
||||
it('does not add metadata or validate if the corresponding classes are not injected.', async(): Promise<void> => {
|
||||
|
||||
@@ -27,7 +27,7 @@ class SimpleSuffixStrategy implements AuxiliaryStrategy {
|
||||
return { path: identifier.path.slice(0, -this.suffix.length) };
|
||||
}
|
||||
|
||||
public isRootRequired(): boolean {
|
||||
public isRequiredInRoot(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ describe('A RoutingAuxiliaryStrategy', (): void => {
|
||||
expect(sources[1].addMetadata).toHaveBeenLastCalledWith(metadata);
|
||||
});
|
||||
|
||||
it('#isRootRequired returns the result of the correct source.', async(): Promise<void> => {
|
||||
sources[0].isRootRequired = jest.fn();
|
||||
sources[1].isRootRequired = jest.fn();
|
||||
strategy.isRootRequired(dummy2Id);
|
||||
expect(sources[0].isRootRequired).toHaveBeenCalledTimes(0);
|
||||
expect(sources[1].isRootRequired).toHaveBeenCalledTimes(1);
|
||||
expect(sources[1].isRootRequired).toHaveBeenLastCalledWith(dummy2Id);
|
||||
it('#isRequiredInRoot returns the result of the correct source.', async(): Promise<void> => {
|
||||
sources[0].isRequiredInRoot = jest.fn();
|
||||
sources[1].isRequiredInRoot = jest.fn();
|
||||
strategy.isRequiredInRoot(dummy2Id);
|
||||
expect(sources[0].isRequiredInRoot).toHaveBeenCalledTimes(0);
|
||||
expect(sources[1].isRequiredInRoot).toHaveBeenCalledTimes(1);
|
||||
expect(sources[1].isRequiredInRoot).toHaveBeenLastCalledWith(dummy2Id);
|
||||
});
|
||||
|
||||
it('#validates using the correct validator.', async(): Promise<void> => {
|
||||
|
||||
@@ -107,7 +107,7 @@ class SimpleSuffixStrategy implements AuxiliaryStrategy {
|
||||
return { path: identifier.path.slice(0, -this.suffix.length) };
|
||||
}
|
||||
|
||||
public isRootRequired(): boolean {
|
||||
public isRequiredInRoot(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
storageMetadata.add(RDF.type, PIM.terms.Storage);
|
||||
accessor.data[`${root}container/`] = new BasicRepresentation(representation.data, storageMetadata);
|
||||
accessor.data[`${root}container/.dummy`] = representation;
|
||||
auxiliaryStrategy.isRootRequired = jest.fn().mockReturnValue(true);
|
||||
auxiliaryStrategy.isRequiredInRoot = jest.fn().mockReturnValue(true);
|
||||
const result = store.deleteResource({ path: `${root}container/.dummy` });
|
||||
await expect(result).rejects.toThrow(MethodNotAllowedHttpError);
|
||||
await expect(result).rejects.toThrow(
|
||||
@@ -648,7 +648,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
const storageMetadata = new RepresentationMetadata(representation.metadata);
|
||||
accessor.data[`${root}container/`] = new BasicRepresentation(representation.data, storageMetadata);
|
||||
accessor.data[`${root}container/.dummy`] = representation;
|
||||
auxiliaryStrategy.isRootRequired = jest.fn().mockReturnValue(true);
|
||||
auxiliaryStrategy.isRequiredInRoot = jest.fn().mockReturnValue(true);
|
||||
await expect(store.deleteResource({ path: `${root}container/.dummy` })).resolves.toEqual([
|
||||
{ path: `${root}container/.dummy` },
|
||||
{ path: `${root}container/` },
|
||||
|
||||
Reference in New Issue
Block a user