mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
fix(media config): expect HD_MEDIA_BACKEND_S3_ENDPOINT to be an uri
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
3c2f59c382
commit
baaa41b1e5
2 changed files with 44 additions and 2 deletions
|
@ -15,7 +15,7 @@ describe('mediaConfig', () => {
|
|||
const accessKeyId = 'accessKeyId';
|
||||
const secretAccessKey = 'secretAccessKey';
|
||||
const bucket = 'bucket';
|
||||
const endPoint = 'endPoint';
|
||||
const endPoint = 'https://endPoint';
|
||||
// Azure
|
||||
const azureConnectionString = 'connectionString';
|
||||
const container = 'container';
|
||||
|
@ -231,6 +231,46 @@ describe('mediaConfig', () => {
|
|||
);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_S3_ENDPOINT is not an URI', async () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_MEDIA_BACKEND: BackendType.S3,
|
||||
HD_MEDIA_BACKEND_S3_ACCESS_KEY: accessKeyId,
|
||||
HD_MEDIA_BACKEND_S3_SECRET_KEY: secretAccessKey,
|
||||
HD_MEDIA_BACKEND_S3_BUCKET: bucket,
|
||||
HD_MEDIA_BACKEND_S3_ENDPOINT: 'wrong-uri',
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
'"HD_MEDIA_BACKEND_S3_ENDPOINT" must be a valid uri with a scheme matching the ^https? pattern',
|
||||
);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_S3_ENDPOINT is an URI with a non-http(s) protocol', async () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_MEDIA_BACKEND: BackendType.S3,
|
||||
HD_MEDIA_BACKEND_S3_ACCESS_KEY: accessKeyId,
|
||||
HD_MEDIA_BACKEND_S3_SECRET_KEY: secretAccessKey,
|
||||
HD_MEDIA_BACKEND_S3_BUCKET: bucket,
|
||||
HD_MEDIA_BACKEND_S3_ENDPOINT: 'ftps://example.org',
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
'"HD_MEDIA_BACKEND_S3_ENDPOINT" must be a valid uri with a scheme matching the ^https? pattern',
|
||||
);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('for backend azure', () => {
|
||||
|
|
|
@ -56,7 +56,9 @@ const mediaSchema = Joi.object({
|
|||
accessKeyId: Joi.string().label('HD_MEDIA_BACKEND_S3_ACCESS_KEY'),
|
||||
secretAccessKey: Joi.string().label('HD_MEDIA_BACKEND_S3_SECRET_KEY'),
|
||||
bucket: Joi.string().label('HD_MEDIA_BACKEND_S3_BUCKET'),
|
||||
endPoint: Joi.string().uri().label('HD_MEDIA_BACKEND_S3_ENDPOINT'),
|
||||
endPoint: Joi.string()
|
||||
.uri({ scheme: /^https?/ })
|
||||
.label('HD_MEDIA_BACKEND_S3_ENDPOINT'),
|
||||
}),
|
||||
otherwise: Joi.optional(),
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue