From 7e65e0db19d715dc5cc7ad42a20287943cf014d5 Mon Sep 17 00:00:00 2001 From: Vadim Kovalenko Date: Fri, 28 Jul 2023 18:01:02 +0300 Subject: [PATCH] Add test for S3 region rejection --- test/unit/s3.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/s3.test.ts b/test/unit/s3.test.ts index 8589d711..cfa0cfce 100644 --- a/test/unit/s3.test.ts +++ b/test/unit/s3.test.ts @@ -42,4 +42,17 @@ describeIf('S3', () => { // Image doesnt exist in S3 expect(imageNotExist).toBeNull() }) + + test('Test whether the wrong region was set', async () => { + const wrongS3UrlObj = urlParser.parse('https://wrong-s3.region.com/?keyId=123&secretAccessKey=123&bucketName=kiwix', true) + + expect( + () => + new S3(`${wrongS3UrlObj.protocol}//${wrongS3UrlObj.host}/`, { + bucketName: wrongS3UrlObj.query.bucketName, + keyId: wrongS3UrlObj.query.keyId, + secretAccessKey: wrongS3UrlObj.query.secretAccessKey, + }), + ).toThrow('Unknown S3 region set') + }) })