4 var http = require('http')
5 var https = require('https')
6 var test = require('tape')
7 var install = require('../lib/install')
9 test('download over http', function (t) {
12 var server = http.createServer(function (req, res) {
13 t.strictEqual(req.headers['user-agent'],
14 'node-gyp v42 (node ' + process.version + ')')
19 var host = '127.0.0.1'
20 server.listen(0, host, function () {
21 var port = this.address().port
26 var url = 'http://' + host + ':' + port
27 var req = install.test.download(gyp, {}, url)
28 req.on('response', function (res) {
30 res.setEncoding('utf8')
31 res.on('data', function(data) {
34 res.on('end', function() {
35 t.strictEqual(body, 'ok')
41 test('download over https with custom ca', function (t) {
44 var cert = fs.readFileSync(__dirname + '/fixtures/server.crt', 'utf8')
45 var key = fs.readFileSync(__dirname + '/fixtures/server.key', 'utf8')
47 var cafile = __dirname + '/fixtures/ca.crt'
48 var ca = install.test.readCAFile(cafile)
49 t.strictEqual(ca.length, 1)
51 var options = { ca: ca, cert: cert, key: key }
52 var server = https.createServer(options, function (req, res) {
53 t.strictEqual(req.headers['user-agent'],
54 'node-gyp v42 (node ' + process.version + ')')
59 server.on('clientError', function (err) {
63 var host = '127.0.0.1'
64 server.listen(8000, host, function () {
65 var port = this.address().port
67 opts: { cafile: cafile },
70 var url = 'https://' + host + ':' + port
71 var req = install.test.download(gyp, {}, url)
72 req.on('response', function (res) {
74 res.setEncoding('utf8')
75 res.on('data', function(data) {
78 res.on('end', function() {
79 t.strictEqual(body, 'ok')
85 test('download with missing cafile', function (t) {
88 opts: { cafile: 'no.such.file' },
91 install.test.download(gyp, {}, 'http://bad/')
93 t.ok(/no.such.file/.test(e.message))
97 test('check certificate splitting', function (t) {
98 var cas = install.test.readCAFile(__dirname + '/fixtures/ca-bundle.crt')
100 t.strictEqual(cas.length, 2)
101 t.notStrictEqual(cas[0], cas[1])