【问题标题】:Added cert and key files in newman js file but still i could see error messages在 newman js 文件中添加了证书和密钥文件,但我仍然可以看到错误消息
【发布时间】:2020-03-04 17:59:54
【问题描述】:

我需要在 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

在我用过的sn-p收藏中,

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

提前致谢。

【问题讨论】:

    标签: node.js postman newman postman-collection-runner


    【解决方案1】:

    您需要在 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!');
        });
    

    【讨论】:

    • 嗨,丹尼,正如建议的那样,我已经尝试过了。现在我可以看到第一个请求正在通过,并且我在正文报告中看不到任何响应。但是,当我从邮递员那里打到相同的请求时,即使我在 newman 中运行(不生成报告),请求也会通过。仅当使用 .js(上面的代码)失败时。没有按预期工作。请指教
    • 我已经修改了内容并提供了更多数据。能否请您调查一下并提供建议。
    猜你喜欢
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 2022-12-02
    相关资源
    最近更新 更多