diff --git a/backend/src/config/media.config.spec.ts b/backend/src/config/media.config.spec.ts index e63085210..540c68f33 100644 --- a/backend/src/config/media.config.spec.ts +++ b/backend/src/config/media.config.spec.ts @@ -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', () => { diff --git a/backend/src/config/media.config.ts b/backend/src/config/media.config.ts index d6561a704..3411b7904 100644 --- a/backend/src/config/media.config.ts +++ b/backend/src/config/media.config.ts @@ -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(), }),