https.js
2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*eslint-env mocha*/
/*eslint no-invalid-this:0*/
/*jshint -W100*/
var assert = require('power-assert');
var typeOf = require('type-of');
var constants = require('constants');
var helper = require('./_helper');
var cli = require('../index');
// オレオレ証明書のサーバーにアクセスできるようにする
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
describe('https', function () {
it('agentOptions未設定 => TLS1.2 Onlyのサーバーに接続可能', function (done) {
cli.fetch(helper.url('%https%'), function (err, $, res, body) {
assert(! err);
assert(typeOf(res) === 'object');
assert(typeOf($) === 'function');
assert(typeOf(body) === 'string');
assert(body === 'hello, https');
done();
});
});
it('agentOptions: TLS1.2強制 => TLS1.2 Onlyのサーバーに接続可能', function (done) {
cli.set('agentOptions', {
secureProtocol: 'TLSv1_2_method'
});
cli.fetch(helper.url('%https%'), function (err, $, res, body) {
assert(! err);
assert(typeOf(res) === 'object');
assert(typeOf($) === 'function');
assert(typeOf(body) === 'string');
assert(body === 'hello, https');
done();
});
});
it('agentOptions: TLS1.2強制 => httpのサーバーにも接続可能', function (done) {
cli.set('agentOptions', {
secureProtocol: 'TLSv1_2_method'
});
cli.fetch(helper.url('~info'), function (err, $, res, body) {
assert(! err);
assert(typeOf(res) === 'object');
assert(typeOf($) === 'function');
assert(typeOf(body) === 'string');
done();
});
});
it('agentOptions: TLS1.1強制 => TLS1.2 Onlyのサーバーに接続不可', function (done) {
cli.set('agentOptions', {
secureProtocol: 'TLSv1_1_method'
});
var url = helper.url('%https%');
cli.fetch(url, function (err, $, res, body) {
assert(err.errno === 'EPROTO');
assert(err.code === 'EPROTO');
assert(err.message.indexOf('SSL routines:') !== -1);
assert(err.url === url);
assert(! res);
assert(! $);
assert(! body);
done();
});
});
it('agentOptions: TLS1.2無効 => TLS1.2 Onlyのサーバーに接続不可', function (done) {
cli.set('agentOptions', {
secureOptions: constants.SSL_OP_NO_TLSv1_2
});
var url = helper.url('%https%');
cli.fetch(url, function (err, $, res, body) {
assert(err.errno === 'EPROTO');
assert(err.code === 'EPROTO');
assert(err.message.indexOf('SSL routines:') !== -1);
assert(err.url === url);
assert(! res);
assert(! $);
assert(! body);
done();
});
});
});