mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Only check DataAccessor canHandle call for Documents
This commit is contained in:
parent
0271133d33
commit
a1c3633a25
@ -141,9 +141,6 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
Promise<ResourceIdentifier> {
|
||||
this.validateIdentifier(container);
|
||||
|
||||
// Ensure the representation is supported by the accessor
|
||||
await this.accessor.canHandle(representation);
|
||||
|
||||
const parentMetadata = await this.getSafeNormalizedMetadata(container);
|
||||
|
||||
// Solid, §5.3: "When a POST method request targets a resource without an existing representation,
|
||||
@ -168,9 +165,16 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
// Clients who want the server to assign a URI of a resource, MUST use the POST request."
|
||||
// https://solid.github.io/specification/protocol#resource-type-heuristics
|
||||
const newID = await this.createSafeUri(container, representation.metadata);
|
||||
const isContainer = isContainerIdentifier(newID);
|
||||
|
||||
// Ensure the representation is supported by the accessor
|
||||
// Containers are not checked because uploaded representations are treated as metadata
|
||||
if (!isContainer) {
|
||||
await this.accessor.canHandle(representation);
|
||||
}
|
||||
|
||||
// Write the data. New containers should never be made for a POST request.
|
||||
await this.writeData(newID, representation, isContainerIdentifier(newID), false, false);
|
||||
await this.writeData(newID, representation, isContainer, false, false);
|
||||
|
||||
return newID;
|
||||
}
|
||||
@ -179,9 +183,6 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
this.validateIdentifier(identifier);
|
||||
|
||||
// Ensure the representation is supported by the accessor
|
||||
await this.accessor.canHandle(representation);
|
||||
|
||||
// Check if the resource already exists
|
||||
const oldMetadata = await this.getSafeNormalizedMetadata(identifier);
|
||||
|
||||
@ -202,6 +203,12 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
throw new BadRequestHttpError('Containers should have a `/` at the end of their path, resources should not.');
|
||||
}
|
||||
|
||||
// Ensure the representation is supported by the accessor
|
||||
// Containers are not checked because uploaded representations are treated as metadata
|
||||
if (!isContainer) {
|
||||
await this.accessor.canHandle(representation);
|
||||
}
|
||||
|
||||
this.validateConditions(conditions, oldMetadata);
|
||||
|
||||
// Potentially have to create containers if it didn't exist yet
|
||||
|
@ -214,12 +214,6 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
.rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
|
||||
it('checks if the DataAccessor supports the data.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
representation.binary = false;
|
||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('will 404 if the target does not exist.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(NotFoundHttpError);
|
||||
@ -241,6 +235,12 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
await expect(result).rejects.toThrow('The given path is not a container.');
|
||||
});
|
||||
|
||||
it('checks if the DataAccessor supports the data.', async(): Promise<void> => {
|
||||
const resourceID = { path: root };
|
||||
representation.binary = false;
|
||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('throws a 412 if the conditions are not matched.', async(): Promise<void> => {
|
||||
const resourceID = { path: root };
|
||||
const conditions = new BasicConditions({ notMatchesETag: [ '*' ]});
|
||||
|
Loading…
x
Reference in New Issue
Block a user