forked from vpulim/node-soap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-authentication-test.js
148 lines (128 loc) · 4.35 KB
/
server-authentication-test.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"use strict";
var fs = require('fs'),
soap = require('..'),
assert = require('assert'),
request = require('request'),
http = require('http'),
lastReqAddress;
var test = {};
test.server = null;
test.authenticate = null;
test.authenticateProxy = function authenticate(security, callback) {
return test.authenticate(security, callback);
};
test.service = {
StockQuoteService: {
StockQuotePort: {
GetLastTradePrice: function(args, cb, soapHeader) {
return { price: 19.56 };
}
}
}
};
describe('SOAP Server', function() {
before(function(done) {
fs.readFile(__dirname + '/wsdl/strict/stockquote.wsdl', 'utf8', function(err, data) {
assert.ifError(err);
test.wsdl = data;
done();
});
});
beforeEach(function(done) {
test.server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, '/stockquote', test.service, test.wsdl);
test.soapServer.authenticate = test.authenticateProxy;
test.baseUrl =
'http://' + test.server.address().address + ":" + test.server.address().port;
//windows return 0.0.0.0 as address and that is not
//valid to use in a request
if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') {
test.baseUrl =
'http://127.0.0.1:' + test.server.address().port;
}
done();
});
});
afterEach(function(done) {
test.server.close(function() {
test.server = null;
test.authenticate = null;
delete test.soapServer;
test.soapServer = null;
done();
});
});
it('should succeed on valid synchronous authentication', function(done) {
test.authenticate = function(security, callback) {
setTimeout(function delayed() {
callback(false); // Ignored
}, 10);
return true;
};
soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'AAPL'}, function(err, result) {
assert.ifError(err);
assert.equal(19.56, parseFloat(result.price));
done();
});
});
});
it('should succeed on valid asynchronous authentication', function(done) {
test.authenticate = function(security, callback) {
setTimeout(function delayed() {
callback(true);
}, 10);
return null; // Ignored
};
soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'AAPL'}, function(err, result) {
assert.ifError(err);
assert.equal(19.56, parseFloat(result.price));
done();
});
});
});
it('should fail on invalid synchronous authentication', function(done) {
test.authenticate = function(security, callback) {
setTimeout(function delayed() {
callback(true); // Ignored
}, 10);
return false;
};
soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'AAPL'}, function (err, result) {
assert.ok(err);
assert.ok(err.root.Envelope.Body.Fault.Code.Value);
assert.equal(err.root.Envelope.Body.Fault.Code.Value, 'SOAP-ENV:Client');
assert.ok(err.root.Envelope.Body.Fault.Code.Subcode.value);
assert.equal(err.root.Envelope.Body.Fault.Code.Subcode.value, 'AuthenticationFailure');
done();
});
});
});
it('should fail on invalid asynchronous authentication', function(done) {
test.authenticate = function(security, callback) {
setTimeout(function delayed() {
callback(false);
}, 10);
};
soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'AAPL'}, function (err, result) {
assert.ok(err);
assert.ok(err.root.Envelope.Body.Fault.Code.Value);
assert.equal(err.root.Envelope.Body.Fault.Code.Value, 'SOAP-ENV:Client');
assert.ok(err.root.Envelope.Body.Fault.Code.Subcode.value);
assert.equal(err.root.Envelope.Body.Fault.Code.Subcode.value, 'AuthenticationFailure');
done();
});
});
});
});