在 newman js 文件中添加了证书和密钥文件,但我仍然可以看到错误消息

Added cert and key files in newman js file but still i could see error messages

我需要在 newman 的 .js 文件中添加证书和密钥。请指教

下面是我的示例(修改后的)代码,

var https = require('https');
var fs = require('fs');
const newman = require('newman');
    newman.run({
        collection: require("/Users/cloud/Documents/sample.json"), // can also provide a URL or path to a local JSON file.
        environment: require("/Users/cloud/Documents/env.json"),
        insecure: true,
        sslClientCert: fs.readFileSync("/Users/cloud/Documents/certs/test.crt"),
        sslClientKey: fs.readFileSync("/Users/cloud/Documents/certs/test.key"),
        reporters: 'htmlextra',
        reporter: {
            htmlextra: {
                export: '/Users/cloud/Documents/report', // If not specified, the file will be written to `newman/` in the current working directory.
                darkTheme: true, // optional, tells the reporter to use the `Dark Theme` template
                title: 'My new report title'
            }
        }
    }, function (err) {
        if (err) {throw err;}
        console.log('collection run 8 complete!');
    });

我已经添加了证书和密钥文件,但仍然出现 SSL 握手错误。但是当我 运行 在 newman 中使用下面的命令时它起作用了。我无法在 js 文件中传递客户端密钥和客户端证书

newman run "collectio.json" -e "env.json" --insecure --ssl-client-key <keypath> --ssl-client-cert <cert path>

下面是我在 html 报告中看到的错误消息,但它在 newman CLI 中运行良好,

Assertion: 

write EPROTO 4514592192:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1536:SSL alert number 40

Unexpected token u in JSON at position 0

在我使用的 collection 片段中,

var jsonData = JSON.parse(responseBody);
console.log(jsonData);
pm.globals.set("JWT", jsonData.access_token);

提前致谢。

您需要在 Newman 运行 对象中使用以下选项(sslClientCertsslClientKey):

newman.run({
        collection: require("/Users/cloud/Documents/sample.json"), // can also provide a URL or path to a local JSON file.
        environment: require("/Users/cloud/Documents/env.json"),
        insecure: true,
        sslClientCert: fs.readFileSync("/Users/cloud/Documents/certs/test.crt"),
        sslClientKey: fs.readFileSync("/Users/cloud/Documents/certs/test.key"),
        reporters: 'htmlextra',
        reporter: {
            htmlextra: {
                export: '/Users/cloud/Documents/report', // If not specified, the file will be written to `newman/` in the current working directory.
                darkTheme: true, // optional, tells the reporter to use the `Dark Theme` template
                title: 'My new report title'
            }
        }
    }, function (err) {
        if (err) {throw err;}
        console.log('collection run 8 complete!');
    });