Skip to content

Commit 7bb2720

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

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

tests/utils/mock/Vault.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const http = require('http');
22
const url = require('url');
3+
const querystring = require('querystring');
34

45
const config = require('../../../lib/Config');
56
const { CANONICAL_ID } = require('./values');
@@ -19,18 +20,40 @@ class Vault {
1920
return;
2021
}
2122

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();
23+
if (req.method === 'GET') {
24+
Vault._checkSecurityToken(query, res);
25+
return;
26+
} else if (req.method === 'POST') {
27+
const body = [];
28+
req.on('data', chunk => {
29+
body.push(chunk);
30+
});
31+
req.on('end', () => {
32+
const data = querystring.parse(Buffer.concat(body).toString());
33+
Vault._checkSecurityToken(data, res);
34+
});
2735
return;
2836
}
2937

3038
res.writeHead(200);
3139
res.end();
3240
}
3341

42+
static _checkSecurityToken(reqData, res) {
43+
if (reqData.requestContext) {
44+
const reqCtx = JSON.parse(reqData.requestContext);
45+
if (reqCtx?.headers['x-amz-security-token'] && !reqData.securityToken) {
46+
res.writeHead(400, { 'Content-Type': 'application/json' });
47+
res.write(JSON.stringify({ code: 'InvalidSecurityToken', message: 'Security token is missing' }));
48+
res.end();
49+
return;
50+
}
51+
}
52+
53+
res.writeHead(200);
54+
res.end();
55+
}
56+
3457
start() {
3558
const { port } = config.vaultd;
3659
this._server = http.createServer(this._onRequest).listen(port);

0 commit comments

Comments
 (0)