forked from vpulim/node-soap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientSSLSecurityPFX.js
129 lines (106 loc) · 3.95 KB
/
ClientSSLSecurityPFX.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
var fs = require('fs'),
join = require('path').join;
describe('ClientSSLSecurityPFX', function() {
var ClientSSLSecurityPFX = require('../../').ClientSSLSecurityPFX;
var pfx = __filename;
it('should be function', function() {
ClientSSLSecurityPFX.should.be.type('function');
});
describe('defaultOption param', function() {
it('should be accepted as the second param', function() {
new ClientSSLSecurityPFX(null, {});
});
it('should be used in addOptions', function() {
var options = {};
var defaultOptions = { foo: 5 };
var instance = new ClientSSLSecurityPFX(null, defaultOptions);
instance.addOptions(options);
options.should.have.property("foo", 5);
});
});
it('should throw if invalid pfk file is given', function () {
var instanceCert = null;
try {
instanceCert = new ClientSSLSecurityPFX({});
} catch (e) {
//should happen!
instanceCert = false;
}
if (instanceCert !== false) {
throw new Error('accepted wrong pfk');
}
});
xit('should be usable in a request', function (done) {
var https = require('https');
var pfkBuffer = fs.readFileSync(join(__dirname, '..', 'certs', 'client-password.pfx')),
instance;
instance = new ClientSSLSecurityPFX(pfkBuffer, 'test2test');
var soptions = {
host: 'localhost',
port: 1338,
requestCert: true,
rejectUnauthorized: false,
pfx: fs.readFileSync(join(__dirname, '..', 'certs', 'server-password.pfx')),
passphrase: 'test2test',
};
var options = {
port: 1338
};
instance.addOptions(options);
var server = https.createServer(soptions, function(req, res) {
req.socket.should.have.property('authorized', true);
// Doesn't work in older versions of nodejs
// req.socket.should.have.property('authorizationError', null);
res.writeHead(200);
res.end('OK');
});
server.listen(soptions.port, soptions.host, function() {
var data = '';
https.get(options, function(res) {
res.on('data', function(data_) { data += data_; });
res.on('end', function() {
server.close();
data.should.equal('OK');
done();
});
});
});
});
it('should accept a passphrase as argument for the pfx cert', function () {
var pfkBuffer = fs.readFileSync(join(__dirname, '..', 'certs', 'client-password.pfx')),
instance;
instance = new ClientSSLSecurityPFX(pfkBuffer, 'test2est');
instance.should.have.property("pfx", pfkBuffer);
instance.should.have.property("passphrase", 'test2est');
});
it('should accept a Buffer as argument for the pfx cert', function () {
var pfkBuffer = fs.readFileSync(join(__dirname, '..', 'certs', 'pfk-buffer.pfx')),
instance;
instance = new ClientSSLSecurityPFX(pfkBuffer);
instance.should.have.property("pfx", pfkBuffer);
});
it('should return a blank when toXML is called', function () {
var pfkBuffer = fs.readFileSync(join(__dirname, '..', 'certs', 'pfk-buffer.pfx')),
instance;
instance = new ClientSSLSecurityPFX(pfkBuffer);
var xml = instance.toXML();
xml.should.be.exactly('');
});
it('should accept a String as argument for the pfx cert', function () {
var pfkBuffer = fs.readFileSync(join(__dirname, '..', 'certs', 'pfk-buffer.pfx')),
instance;
instance = new ClientSSLSecurityPFX(join(__dirname, '..', 'certs', 'pfk-buffer.pfx'));
instance.should.have.property("pfx", pfkBuffer);
});
it('should have an options with addOptions', function () {
var pfkBuffer = fs.readFileSync(join(__dirname, '..', 'certs', 'client-password.pfx')),
instance;
instance = new ClientSSLSecurityPFX(pfkBuffer, 'test2est');
var options = { foo: 5 };
instance.addOptions(options);
options.should.have.property("pfx", pfkBuffer);
options.should.have.property("passphrase", 'test2est');
options.should.have.property("foo", 5);
});
});