首页 > 解决方案 > 如何为 aws4 签名请求存根 sinon

问题描述

我是 sinon 和 aws 的新手。我需要为以下代码片段编写一个测试用例。我无法找到如何为 aws4.sign 存根。请帮忙

function signRequest(Parameter, creds, body) {
    console.log("***********  signRequest  *********************");
    var hostname = Parameter.Value.split('//', 2)[1].split('/', 2)[0];
    let request = {
        service: 'execute-api',
        region: REGION,
        host: hostname,
        method: 'POST',
        url: `${Parameter.Value}/api`,
        path: '/api',
        data: body, // object describing the mappedbody
        body: body,
        headers: {
            'content-type': 'application/json'
        }
    };
    var signedRequest = aws4.sign(request, creds);
    console.log("signRequest-->signedRequest: " + signedRequest)
    return signedRequest;
}

标签: aws-sdk-nodejssinon-chai

解决方案


推荐阅读