From 4748e6a865bfa44487b16271fae32089bf4ead06 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Wed, 27 Mar 2024 18:01:03 +1100 Subject: [PATCH] Updated tests to match corrected `isValidPath()` behaviour --- test/main-execute.test.js | 4 ++-- test/main-payloadverify.test.js | 22 +++++++++++++++------- test/main-property.test.js | 10 +++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/main-execute.test.js b/test/main-execute.test.js index 9c1bf9e..6f6419a 100644 --- a/test/main-execute.test.js +++ b/test/main-execute.test.js @@ -158,7 +158,7 @@ runner.add(async function testExecuteOriginRequest() { customHeaders: {}, domainName: 'domain.tld', keepaliveTimeout: 1, - path: '/', + path: '', port: 443, protocol: 'https', readTimeout: 4, @@ -194,7 +194,7 @@ runner.add(async function testExecuteOriginRequest() { customHeaders: {}, domainName: 'domain.tld', keepaliveTimeout: 1, - path: '/', + path: '', port: 443, protocol: 'https', readTimeout: 4, diff --git a/test/main-payloadverify.test.js b/test/main-payloadverify.test.js index 57aa499..031b30c 100644 --- a/test/main-payloadverify.test.js +++ b/test/main-payloadverify.test.js @@ -41,7 +41,7 @@ function testPayloadVerifyRequest(inst,withMockOrigin = false) { customHeaders: {}, domainName: 'example.org', keepaliveTimeout: 1, - path: '/', + path: '', port: 443, protocol: 'https', readTimeout: 4, @@ -356,7 +356,7 @@ function testPayloadVerifyRequestOrigin(inst) { }, domainName: 'example.org', keepaliveTimeout: 1, - path: '/', + path: '', port: 443, protocol: 'https', readTimeout: 4, @@ -383,7 +383,7 @@ function testPayloadVerifyRequestOrigin(inst) { ], }, domainName: 'bucket.s3.us-east-1.amazonaws.com', - path: '/', + path: '', region: 'us-east-1', }, }, @@ -423,6 +423,10 @@ function testPayloadVerifyRequestOrigin(inst) { // test: passing valid payload callVerify(makePayloadWithOriginCustom()); + callVerify(makePayloadWithOriginCustom(function(payload) { + payload.origin.custom.path = '/valid/path'; + })); + callVerify(makePayloadWithOriginCustom(function(payload) { payload.origin.custom.port = 80; })); @@ -578,13 +582,13 @@ function testPayloadVerifyRequestOrigin(inst) { assert.throws(function() { callVerify(makePayloadWithOriginCustom(function(payload) { - payload.origin.custom.path = 'invalid'; + payload.origin.custom.path = 'invalid/path'; })); }); assert.throws(function() { callVerify(makePayloadWithOriginCustom(function(payload) { - payload.origin.custom.path = '/invalid/'; + payload.origin.custom.path = '/invalid/path/'; })); }); @@ -675,6 +679,10 @@ function testPayloadVerifyRequestOrigin(inst) { payload.origin.s3.authMethod = 'origin-access-identity'; })); + callVerify(makePayloadWithOriginS3(function(payload) { + payload.origin.s3.path = '/valid/path'; + })); + // test: payload missing/invalid property values assert.throws(function() { callVerify(makePayloadWithOriginS3(function(payload) { @@ -808,13 +816,13 @@ function testPayloadVerifyRequestOrigin(inst) { assert.throws(function() { callVerify(makePayloadWithOriginS3(function(payload) { - payload.origin.s3.path = 'invalid'; + payload.origin.s3.path = 'invalid/path'; })); }); assert.throws(function() { callVerify(makePayloadWithOriginS3(function(payload) { - payload.origin.s3.path = '/invalid/'; + payload.origin.s3.path = '/invalid/path/'; })); }); } diff --git a/test/main-property.test.js b/test/main-property.test.js index 5d6bb45..5ac3a2e 100644 --- a/test/main-property.test.js +++ b/test/main-property.test.js @@ -323,14 +323,14 @@ function testPropertyRequestOrigin(inst) { // test: origin [custom] - inst.setOriginCustom('my-hostname.tld'); // note: `path` defaults to `/` + inst.setOriginCustom('my-hostname.tld'); // note: `path` defaults to empty string assert.deepEqual(cfEventData(inst).request.origin, { custom: { customHeaders: {}, domainName: 'my-hostname.tld', keepaliveTimeout: 1, - path: '/', + path: '', port: 443, protocol: 'https', readTimeout: 4, @@ -426,21 +426,21 @@ function testPropertyRequestOrigin(inst) { // test: origin [S3] - inst.setOriginS3('my-bucket.s3.ap-southeast-2.amazonaws.com'); // note: `path` defaults to `/` + inst.setOriginS3('my-bucket.s3.ap-southeast-2.amazonaws.com'); // note: `path` defaults to empty string assert.deepEqual(cfEventData(inst).request.origin, { s3: { authMethod: 'none', customHeaders: {}, domainName: 'my-bucket.s3.ap-southeast-2.amazonaws.com', - path: '/', + path: '', region: '', }, } ); inst.setOriginS3('my-bucket.s3.ap-southeast-2.amazonaws.com','ap-southeast-2'); - assert.equal(cfEventData(inst).request.origin.s3.path,'/'); + assert.equal(cfEventData(inst).request.origin.s3.path,''); assert.equal(cfEventData(inst).request.origin.s3.region,'ap-southeast-2'); inst.setOriginS3('my-bucket.s3.ap-southeast-2.amazonaws.com','ap-southeast-2','/my/path'); assert.equal(cfEventData(inst).request.origin.s3.path,'/my/path');