我需要在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握手错误。但是当我使用以下命令在纽曼运行时,它可以工作。我无法在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
在我使用的收藏夹片段中,
var jsonData = JSON.parse(responseBody);
console.log(jsonData);
pm.globals.set("JWT",jsonData.access_token);
谢谢。