Добавлены файлы сертификатов и ключей в js-файле newman, но все равно я мог видеть сообщения об ошибках - PullRequest
0 голосов
/ 08 ноября 2019

Мне нужно добавить сертификат и ключ в файл .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-отчете, но оно хорошо работает в 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);

Заранее спасибо.

1 Ответ

0 голосов
/ 08 ноября 2019

Вам необходимо использовать следующие параметры (sslClientCert и sslClientKey) в объекте запуска 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!');
    });
...