mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Let AclInitializer throw internal error in case of problems
This commit is contained in:
@@ -5,6 +5,8 @@ import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifie
|
||||
import { getLoggerFor } from '../logging/LogUtil';
|
||||
import type { ResourceStore } from '../storage/ResourceStore';
|
||||
import { TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { createErrorMessage } from '../util/errors/ErrorUtil';
|
||||
import { InternalServerError } from '../util/errors/InternalServerError';
|
||||
import { ensureTrailingSlash, joinFilePath } from '../util/PathUtil';
|
||||
import { Initializer } from './Initializer';
|
||||
|
||||
@@ -43,7 +45,13 @@ export class AclInitializer extends Initializer {
|
||||
} else {
|
||||
this.logger.debug(`Installing root ACL document at ${rootAcl.path}`);
|
||||
const aclDocument = createReadStream(this.aclPath, 'utf8');
|
||||
await this.store.setRepresentation(rootAcl, new BasicRepresentation(aclDocument, rootAcl, TEXT_TURTLE));
|
||||
try {
|
||||
await this.store.setRepresentation(rootAcl, new BasicRepresentation(aclDocument, rootAcl, TEXT_TURTLE));
|
||||
} catch (error: unknown) {
|
||||
const msg = `There was an issue initializing the root .acl resource: ${createErrorMessage(error)}`;
|
||||
this.logger.error(msg);
|
||||
throw new InternalServerError(msg, { cause: error });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { AclInitializer } from '../../../src/init/AclInitializer';
|
||||
import type { AuxiliaryIdentifierStrategy } from '../../../src/ldp/auxiliary/AuxiliaryIdentifierStrategy';
|
||||
import { BasicRepresentation } from '../../../src/ldp/representation/BasicRepresentation';
|
||||
import type { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
import { InternalServerError } from '../../../src/util/errors/InternalServerError';
|
||||
import { joinFilePath } from '../../../src/util/PathUtil';
|
||||
|
||||
const createReadStream = jest.spyOn(fs, 'createReadStream').mockReturnValue('file contents' as any);
|
||||
@@ -72,9 +73,11 @@ describe('AclInitializer', (): void => {
|
||||
});
|
||||
|
||||
it('errors when the root ACL check errors.', async(): Promise<void> => {
|
||||
store.resourceExists.mockRejectedValueOnce(new Error('Fatal'));
|
||||
store.setRepresentation.mockRejectedValueOnce(new Error('Fatal'));
|
||||
|
||||
const initializer = new AclInitializer({ baseUrl, store, aclStrategy });
|
||||
await expect(initializer.handle()).rejects.toThrow('Fatal');
|
||||
const prom = initializer.handle();
|
||||
await expect(prom).rejects.toThrow('There was an issue initializing the root .acl resource: Fatal');
|
||||
await expect(prom).rejects.toThrow(InternalServerError);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user