]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/initialize.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npm-registry-client / test / initialize.js
1 var test = require('tap').test
2 var url = require('url')
3
4 // var server = require('./lib/server.js')
5 var Client = require('../')
6
7 test('defaulted initialization', function (t) {
8   var client = new Client()
9   var options = client.initialize(
10     'http://localhost:1337/',
11     'GET',
12     'application/json',
13     {}
14   )
15
16   t.equal(options.url, 'http://localhost:1337/', 'URLs match')
17   t.equal(options.method, 'GET', 'methods match')
18   t.equal(options.proxy, undefined, "proxy won't overwrite environment")
19   t.equal(options.localAddress, undefined, 'localAddress has no default value')
20   t.equal(options.strictSSL, true, 'SSL is strict by default')
21
22   t.equal(options.headers.accept, 'application/json', 'accept header set')
23   t.equal(
24     options.headers.version,
25     require('../package.json').version,
26     'npm-registry-client version is present in headers'
27   )
28   t.ok(options.headers['npm-session'], 'request ID generated')
29   t.ok(options.headers['user-agent'], 'user-agent preset')
30
31   var HttpAgent = require('http').Agent
32   t.ok(options.agent instanceof HttpAgent, 'got an HTTP agent for an HTTP URL')
33   t.equal(options.agent.maxSockets, 50, 'maxSockets set to a reasonable default')
34
35   t.end()
36 })
37
38 test('intializing with maxSockets set works for http', function (t) {
39   var client = new Client({ maxSockets: Infinity })
40   var options = client.initialize(
41     url.parse('http://localhost:1337/'),
42     'GET',
43     'application/json',
44     {}
45   )
46
47   var HttpAgent = require('http').Agent
48   t.ok(options.agent instanceof HttpAgent, 'got an HTTP agent for an HTTP URL')
49   t.equal(options.agent.maxSockets, Infinity, 'request uses configured value for maxSockets')
50
51   t.end()
52 })
53
54 test('intializing with maxSockets set works for https', function (t) {
55   var client = new Client({ maxSockets: Infinity })
56   var options = client.initialize(
57     url.parse('https://localhost:1337/'),
58     'GET',
59     'application/json',
60     {}
61   )
62
63   var HttpsAgent = require('https').Agent
64   t.ok(options.agent instanceof HttpsAgent, 'got an HTTPS agent for an HTTPS URL')
65   t.equal(options.agent.maxSockets, Infinity, 'request uses configured value for maxSockets')
66
67   t.end()
68 })
69
70 test('referer set on client', function (t) {
71   var client = new Client()
72   client.refer = 'xtestx'
73   var options = client.initialize(
74     'http://localhost:1337/',
75     'GET',
76     'application/json',
77     {}
78   )
79
80   t.equal(options.headers.referer, 'xtestx', 'referer header set')
81
82   t.end()
83 })
84
85 test('initializing with proxy explicitly disabled', function (t) {
86   var client = new Client({ proxy: { http: false } })
87   var options = client.initialize(
88     'http://localhost:1337/',
89     'GET',
90     'application/json',
91     {}
92   )
93   t.ok('proxy' in options, 'proxy overridden by explicitly setting to false')
94   t.equal(options.proxy, null, 'request will override proxy when empty proxy passed in')
95   t.end()
96 })
97
98 test('initializing with proxy undefined', function (t) {
99   var client = new Client({ proxy: { http: undefined } })
100   var options = client.initialize(
101     'http://localhost:1337/',
102     'GET',
103     'application/json',
104     {}
105   )
106   t.notOk('proxy' in options, 'proxy can be read from env.PROXY by request')
107   t.end()
108 })
109
110 test('initializing with a certificate should map down to the https agent', function (t) {
111   var certificate = '-----BEGIN CERTIFICATE----- TEST\nTEST -----END CERTIFICATE-----\n'
112   var client = new Client({
113     ssl: {
114       certificate: certificate
115     }
116   })
117   var options = client.initialize(
118     { protocol: 'https:' },
119     'GET',
120     'application/json',
121     {}
122   )
123   t.equal(options.agent.options.cert, certificate, 'certificate will be saved properly on agent')
124   t.end()
125 })