src: don't error at startup when cwd doesn't exist
[platform/upstream/nodejs.git] / test / parallel / test-http-url.parse-https.request.js
1 var common = require('../common');
2 var assert = require('assert');
3
4 if (!common.hasCrypto) {
5   console.log('1..0 # Skipped: missing crypto');
6   process.exit();
7 }
8 var https = require('https');
9
10 var url = require('url');
11 var fs = require('fs');
12 var clientRequest;
13
14 // https options
15 var httpsOptions = {
16   key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
17   cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
18 };
19
20 var testURL = url.parse('https://localhost:' + common.PORT);
21 testURL.rejectUnauthorized = false;
22
23 function check(request) {
24   // assert that I'm https
25   assert.ok(request.socket._secureEstablished);
26 }
27
28 var server = https.createServer(httpsOptions, function(request, response) {
29   // run the check function
30   check.call(this, request, response);
31   response.writeHead(200, {});
32   response.end('ok');
33   server.close();
34 });
35
36 server.listen(common.PORT, function() {
37   // make the request
38   var clientRequest = https.request(testURL);
39   // since there is a little magic with the agent
40   // make sure that the request uses the https.Agent
41   assert.ok(clientRequest.agent instanceof https.Agent);
42   clientRequest.end();
43 });