Skip to content

Commit 338ba2b

Browse files
committed
test: fix test-https-foafssl
1 parent 93390ff commit 338ba2b

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

test/simple/test-https-foafssl.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22-
if (!process.versions.openssl) {
23-
console.error('Skipping because node compiled without OpenSSL.');
22+
var common = require('../common');
23+
24+
if (!common.opensslCli) {
25+
console.error('Skipping because node compiled without OpenSSL CLI.');
2426
process.exit(0);
2527
}
2628

27-
var common = require('../common');
2829
var assert = require('assert');
2930
var join = require('path').join;
3031

3132
var fs = require('fs');
32-
var exec = require('child_process').exec;
33+
var spawn = require('child_process').spawn;
3334

3435
var https = require('https');
3536

@@ -40,6 +41,7 @@ var options = {
4041
};
4142

4243
var reqCount = 0;
44+
var CRLF = '\r\n';
4345
var body = 'hello world\n';
4446
var cert;
4547
var subjectaltname;
@@ -62,17 +64,26 @@ var server = https.createServer(options, function(req, res) {
6264

6365

6466
server.listen(common.PORT, function() {
65-
var cmd = 'curl --insecure https://127.0.0.1:' + common.PORT + '/';
66-
cmd += ' --cert ' + join(common.fixturesDir, 'foafssl.crt');
67-
cmd += ' --key ' + join(common.fixturesDir, 'foafssl.key');
68-
console.error('executing %j', cmd);
69-
exec(cmd, function(err, stdout, stderr) {
70-
if (err) throw err;
71-
common.error(common.inspect(stdout));
72-
assert.equal(body, stdout);
67+
var args = ['s_client',
68+
'-quiet',
69+
'-connect', '127.0.0.1:' + common.PORT,
70+
'-cert', join(common.fixturesDir, 'foafssl.crt'),
71+
'-key', join(common.fixturesDir, 'foafssl.key')];
72+
73+
var client = spawn(common.opensslCli, args);
74+
75+
client.stdout.on('data', function(data) {
76+
var message = data.toString();
77+
var contents = message.split(CRLF + CRLF).pop();
78+
assert.equal(body, contents);
7379
server.close();
7480
});
7581

82+
client.stdin.write('GET /\n\n');
83+
84+
client.on('error', function(error) {
85+
throw error;
86+
});
7687
});
7788

7889
process.on('exit', function() {

0 commit comments

Comments
 (0)