Skip to content

Commit

Permalink
Add unit test testEditHeadersWithAllowedPrefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gawsoftpl committed May 1, 2024
1 parent 8170509 commit 8690f15
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/unit/s3gateway_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,45 @@ function testEditHeaders() {
}
}

function testEditHeadersWithAllowedPrefixes() {
printHeader('testEditHeadersWithAllowedPrefixes');

process.env['HEADER_PREFIXES_ALLOWED'] = 'x-amz-'
const r = {
"headersOut": {
"Accept-Ranges": "bytes",
"Content-Length": 42,
"Content-Security-Policy": "block-all-mixed-content",
"Content-Type": "text/plain",
"X-Amz-Bucket-Region": "us-east-1",
"X-Amz-Request-Id": "166539E18A46500A",
"X-Xss-Protection": "1; mode=block"
},
"variables": {
"uri_path": "/a/c/ramen.jpg"
},
}

r.log = function(msg) {
console.log(msg);
}

s3gateway.editHeaders(r);

let found_headers_x_amz_ = 0
for (const key in r.headersOut) {
if (key.toLowerCase().indexOf("x-amz", 0) == 0) {
found_headers_x_amz_++;
}
}

if (found_headers_x_amz_ != 2)
throw "x-amz header stripped from headers, should allow those 2 headers";

delete process.env['HEADER_PREFIXES_ALLOWED']

}


function testEditHeadersHeadDirectory() {
printHeader('testEditHeadersHeadDirectory');
Expand Down

0 comments on commit 8690f15

Please sign in to comment.