Skip to content

Commit c99b434

Browse files
committed
bf(UTAPI-113): Support POST based auth in Vault mock
1 parent 5c0de32 commit c99b434

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

tests/utils/mock/Vault.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,29 @@ class Vault {
1919
return;
2020
}
2121

22-
const reqCtx = JSON.parse(query.requestContext);
23-
if (reqCtx.headers['x-amz-security-token'] && !query.securityToken) {
24-
res.writeHead(400, { 'Content-Type': 'application/json' });
25-
res.write(JSON.stringify({ code: 'InvalidSecurityToken', message: 'Security token is missing' }));
26-
res.end();
22+
if (req.method == 'GET') {
23+
const reqCtx = JSON.parse(query.requestContext);
24+
if (reqCtx.headers['x-amz-security-token'] && !query.securityToken) {
25+
res.writeHead(400, { 'Content-Type': 'application/json' });
26+
res.write(JSON.stringify({ code: 'InvalidSecurityToken', message: 'Security token is missing' }));
27+
res.end();
28+
return;
29+
}
30+
} else if (req.method == 'POST') {
31+
const body = [];
32+
req.on('data', chunk => {
33+
body.push(chunk);
34+
});
35+
req.on('end', () => {
36+
const bodyString = Buffer.concat(body).toString();
37+
const bodyJson = JSON.parse(bodyString);
38+
if (bodyJson.requestContext.headers['x-amz-security-token'] && !query.securityToken) {
39+
res.writeHead(400, { 'Content-Type': 'application/json' });
40+
res.write(JSON.stringify({ code: 'InvalidSecurityToken', message: 'Security token is missing' }));
41+
res.end();
42+
return;
43+
}
44+
});
2745
return;
2846
}
2947

0 commit comments

Comments
 (0)