cdk-ecr-deployment 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,313 @@
1
+ 'use strict'
2
+
3
+ const https = require('https')
4
+ const test = require('ava')
5
+ const { createSecureServer, createSecureProxy } = require('./utils')
6
+ const { HttpsProxyAgent } = require('../')
7
+
8
+ function request (opts) {
9
+ return new Promise((resolve, reject) => {
10
+ const req = https.request(opts, resolve)
11
+ req.on('error', reject)
12
+ req.end(opts.body)
13
+ })
14
+ }
15
+
16
+ test('Basic', async t => {
17
+ const server = await createSecureServer()
18
+ const proxy = await createSecureProxy()
19
+ server.on('request', (req, res) => res.end('ok'))
20
+
21
+ const response = await request({
22
+ method: 'GET',
23
+ hostname: server.address().address,
24
+ port: server.address().port,
25
+ path: '/',
26
+ agent: new HttpsProxyAgent({
27
+ keepAlive: true,
28
+ keepAliveMsecs: 1000,
29
+ maxSockets: 256,
30
+ maxFreeSockets: 256,
31
+ scheduling: 'lifo',
32
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
33
+ })
34
+ })
35
+
36
+ let body = ''
37
+ response.setEncoding('utf8')
38
+ for await (const chunk of response) {
39
+ body += chunk
40
+ }
41
+
42
+ t.is(body, 'ok')
43
+ t.is(response.statusCode, 200)
44
+
45
+ server.close()
46
+ proxy.close()
47
+ })
48
+
49
+ test('Connection header (keep-alive)', async t => {
50
+ const server = await createSecureServer()
51
+ const proxy = await createSecureProxy()
52
+ server.on('request', (req, res) => res.end('ok'))
53
+
54
+ proxy.authenticate = function (req, fn) {
55
+ t.is(req.headers.connection, 'keep-alive')
56
+ fn(null, true)
57
+ }
58
+
59
+ const response = await request({
60
+ method: 'GET',
61
+ hostname: server.address().address,
62
+ port: server.address().port,
63
+ path: '/',
64
+ agent: new HttpsProxyAgent({
65
+ keepAlive: true,
66
+ keepAliveMsecs: 1000,
67
+ maxSockets: 256,
68
+ maxFreeSockets: 256,
69
+ scheduling: 'lifo',
70
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
71
+ })
72
+ })
73
+
74
+ let body = ''
75
+ response.setEncoding('utf8')
76
+ for await (const chunk of response) {
77
+ body += chunk
78
+ }
79
+
80
+ t.is(body, 'ok')
81
+ t.is(response.statusCode, 200)
82
+
83
+ server.close()
84
+ proxy.close()
85
+ })
86
+
87
+ test('Connection header (close)', async t => {
88
+ const server = await createSecureServer()
89
+ const proxy = await createSecureProxy()
90
+ server.on('request', (req, res) => res.end('ok'))
91
+
92
+ proxy.authenticate = function (req, fn) {
93
+ t.is(req.headers.connection, 'close')
94
+ fn(null, true)
95
+ }
96
+
97
+ const response = await request({
98
+ method: 'GET',
99
+ hostname: server.address().address,
100
+ port: server.address().port,
101
+ path: '/',
102
+ agent: new HttpsProxyAgent({
103
+ keepAlive: false,
104
+ keepAliveMsecs: 1000,
105
+ maxSockets: Infinity,
106
+ maxFreeSockets: 256,
107
+ scheduling: 'lifo',
108
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
109
+ })
110
+ })
111
+
112
+ let body = ''
113
+ response.setEncoding('utf8')
114
+ for await (const chunk of response) {
115
+ body += chunk
116
+ }
117
+
118
+ t.is(body, 'ok')
119
+ t.is(response.statusCode, 200)
120
+
121
+ server.close()
122
+ proxy.close()
123
+ })
124
+
125
+ test('Proxy authentication (empty)', async t => {
126
+ const server = await createSecureServer()
127
+ const proxy = await createSecureProxy()
128
+ server.on('request', (req, res) => res.end('ok'))
129
+
130
+ proxy.authenticate = function (req, fn) {
131
+ fn(null, req.headers['proxy-authorization'] === undefined)
132
+ }
133
+
134
+ const response = await request({
135
+ method: 'GET',
136
+ hostname: server.address().address,
137
+ port: server.address().port,
138
+ path: '/',
139
+ agent: new HttpsProxyAgent({
140
+ keepAlive: true,
141
+ keepAliveMsecs: 1000,
142
+ maxSockets: 256,
143
+ maxFreeSockets: 256,
144
+ scheduling: 'lifo',
145
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
146
+ })
147
+ })
148
+
149
+ let body = ''
150
+ response.setEncoding('utf8')
151
+ for await (const chunk of response) {
152
+ body += chunk
153
+ }
154
+
155
+ t.is(body, 'ok')
156
+ t.is(response.statusCode, 200)
157
+
158
+ server.close()
159
+ proxy.close()
160
+ })
161
+
162
+ test('Proxy authentication', async t => {
163
+ const server = await createSecureServer()
164
+ const proxy = await createSecureProxy()
165
+ server.on('request', (req, res) => res.end('ok'))
166
+
167
+ proxy.authenticate = function (req, fn) {
168
+ fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
169
+ }
170
+
171
+ const response = await request({
172
+ method: 'GET',
173
+ hostname: server.address().address,
174
+ port: server.address().port,
175
+ path: '/',
176
+ agent: new HttpsProxyAgent({
177
+ keepAlive: true,
178
+ keepAliveMsecs: 1000,
179
+ maxSockets: 256,
180
+ maxFreeSockets: 256,
181
+ scheduling: 'lifo',
182
+ proxy: `https://hello:world@${proxy.address().address}:${proxy.address().port}`
183
+ })
184
+ })
185
+
186
+ let body = ''
187
+ response.setEncoding('utf8')
188
+ for await (const chunk of response) {
189
+ body += chunk
190
+ }
191
+
192
+ t.is(body, 'ok')
193
+ t.is(response.statusCode, 200)
194
+
195
+ server.close()
196
+ proxy.close()
197
+ })
198
+
199
+ test('Configure the agent to reuse sockets', async t => {
200
+ const server = await createSecureServer()
201
+ const proxy = await createSecureProxy()
202
+ server.on('request', (req, res) => res.end('ok'))
203
+
204
+ let count = 0
205
+ proxy.on('connection', () => {
206
+ count += 1
207
+ t.is(count, 1)
208
+ })
209
+
210
+ const agent = new HttpsProxyAgent({
211
+ keepAlive: true,
212
+ keepAliveMsecs: 1000,
213
+ maxSockets: 256,
214
+ maxFreeSockets: 256,
215
+ scheduling: 'lifo',
216
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
217
+ })
218
+
219
+ let response = await request({
220
+ method: 'GET',
221
+ hostname: server.address().address,
222
+ port: server.address().port,
223
+ path: '/',
224
+ agent
225
+ })
226
+
227
+ let body = ''
228
+ response.setEncoding('utf8')
229
+ for await (const chunk of response) {
230
+ body += chunk
231
+ }
232
+
233
+ t.is(body, 'ok')
234
+ t.is(response.statusCode, 200)
235
+
236
+ response = await request({
237
+ method: 'GET',
238
+ hostname: server.address().address,
239
+ port: server.address().port,
240
+ path: '/',
241
+ agent
242
+ })
243
+
244
+ body = ''
245
+ response.setEncoding('utf8')
246
+ for await (const chunk of response) {
247
+ body += chunk
248
+ }
249
+
250
+ t.is(body, 'ok')
251
+ t.is(response.statusCode, 200)
252
+
253
+ server.close()
254
+ proxy.close()
255
+ })
256
+
257
+ test('Configure the agent to NOT reuse sockets', async t => {
258
+ const server = await createSecureServer()
259
+ const proxy = await createSecureProxy()
260
+ server.on('request', (req, res) => res.end('ok'))
261
+
262
+ const ports = []
263
+ proxy.on('connection', socket => {
264
+ t.false(ports.includes(socket.remotePort))
265
+ ports.push(socket.remotePort)
266
+ })
267
+
268
+ const agent = new HttpsProxyAgent({
269
+ keepAlive: false,
270
+ keepAliveMsecs: 1000,
271
+ maxSockets: Infinity,
272
+ maxFreeSockets: 256,
273
+ scheduling: 'lifo',
274
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
275
+ })
276
+
277
+ let response = await request({
278
+ method: 'GET',
279
+ hostname: server.address().address,
280
+ port: server.address().port,
281
+ path: '/',
282
+ agent
283
+ })
284
+
285
+ let body = ''
286
+ response.setEncoding('utf8')
287
+ for await (const chunk of response) {
288
+ body += chunk
289
+ }
290
+
291
+ t.is(body, 'ok')
292
+ t.is(response.statusCode, 200)
293
+
294
+ response = await request({
295
+ method: 'GET',
296
+ hostname: server.address().address,
297
+ port: server.address().port,
298
+ path: '/',
299
+ agent
300
+ })
301
+
302
+ body = ''
303
+ response.setEncoding('utf8')
304
+ for await (const chunk of response) {
305
+ body += chunk
306
+ }
307
+
308
+ t.is(body, 'ok')
309
+ t.is(response.statusCode, 200)
310
+
311
+ server.close()
312
+ proxy.close()
313
+ })
@@ -0,0 +1,45 @@
1
+ import * as http from 'http'
2
+ import * as https from 'https'
3
+ import { expectType } from 'tsd'
4
+ import {
5
+ HttpProxyAgent,
6
+ HttpProxyAgentOptions,
7
+ HttpsProxyAgent,
8
+ HttpsProxyAgentOptions
9
+ } from '../'
10
+
11
+ {
12
+ const agent = new HttpProxyAgent({
13
+ keepAlive: true,
14
+ keepAliveMsecs: 1000,
15
+ maxSockets: 256,
16
+ maxFreeSockets: 256,
17
+ proxy: 'http://localhost:8080'
18
+ })
19
+
20
+ expectType<HttpProxyAgent>(agent)
21
+ http.request({
22
+ method: 'GET',
23
+ hostname: 'localhost',
24
+ port: 9200,
25
+ agent
26
+ })
27
+ }
28
+
29
+ {
30
+ const agent = new HttpsProxyAgent({
31
+ keepAlive: true,
32
+ keepAliveMsecs: 1000,
33
+ maxSockets: 256,
34
+ maxFreeSockets: 256,
35
+ proxy: 'http://localhost:8080'
36
+ })
37
+
38
+ expectType<HttpsProxyAgent>(agent)
39
+ https.request({
40
+ method: 'GET',
41
+ hostname: 'localhost',
42
+ port: 9200,
43
+ agent
44
+ })
45
+ }
@@ -0,0 +1,103 @@
1
+ 'use strict'
2
+
3
+ const needle = require('needle')
4
+ const test = require('ava')
5
+ const {
6
+ createServer,
7
+ createSecureServer,
8
+ createProxy,
9
+ createSecureProxy
10
+ } = require('./utils')
11
+ const { HttpProxyAgent, HttpsProxyAgent } = require('../')
12
+
13
+ test('http to http', async t => {
14
+ const server = await createServer()
15
+ const proxy = await createProxy()
16
+ server.on('request', (req, res) => res.end('ok'))
17
+
18
+ const response = await needle('get', `http://${server.address().address}:${server.address().port}`, {
19
+ agent: new HttpProxyAgent({
20
+ keepAlive: true,
21
+ keepAliveMsecs: 1000,
22
+ maxSockets: 256,
23
+ maxFreeSockets: 256,
24
+ scheduling: 'lifo',
25
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
26
+ })
27
+ })
28
+
29
+ t.is(response.body.toString(), 'ok')
30
+ t.is(response.statusCode, 200)
31
+
32
+ server.close()
33
+ proxy.close()
34
+ })
35
+
36
+ test('https to http', async t => {
37
+ const server = await createServer()
38
+ const proxy = await createSecureProxy()
39
+ server.on('request', (req, res) => res.end('ok'))
40
+
41
+ const response = await needle('get', `http://${server.address().address}:${server.address().port}`, {
42
+ agent: new HttpProxyAgent({
43
+ keepAlive: true,
44
+ keepAliveMsecs: 1000,
45
+ maxSockets: 256,
46
+ maxFreeSockets: 256,
47
+ scheduling: 'lifo',
48
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
49
+ })
50
+ })
51
+
52
+ t.is(response.body.toString(), 'ok')
53
+ t.is(response.statusCode, 200)
54
+
55
+ server.close()
56
+ proxy.close()
57
+ })
58
+
59
+ test('http to https', async t => {
60
+ const server = await createSecureServer()
61
+ const proxy = await createProxy()
62
+ server.on('request', (req, res) => res.end('ok'))
63
+
64
+ const response = await needle('get', `https://${server.address().address}:${server.address().port}`, {
65
+ agent: new HttpsProxyAgent({
66
+ keepAlive: true,
67
+ keepAliveMsecs: 1000,
68
+ maxSockets: 256,
69
+ maxFreeSockets: 256,
70
+ scheduling: 'lifo',
71
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
72
+ })
73
+ })
74
+
75
+ t.is(response.body.toString(), 'ok')
76
+ t.is(response.statusCode, 200)
77
+
78
+ server.close()
79
+ proxy.close()
80
+ })
81
+
82
+ test('https to https', async t => {
83
+ const server = await createSecureServer()
84
+ const proxy = await createSecureProxy()
85
+ server.on('request', (req, res) => res.end('ok'))
86
+
87
+ const response = await needle('get', `https://${server.address().address}:${server.address().port}`, {
88
+ agent: new HttpsProxyAgent({
89
+ keepAlive: true,
90
+ keepAliveMsecs: 1000,
91
+ maxSockets: 256,
92
+ maxFreeSockets: 256,
93
+ scheduling: 'lifo',
94
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
95
+ })
96
+ })
97
+
98
+ t.is(response.body.toString(), 'ok')
99
+ t.is(response.statusCode, 200)
100
+
101
+ server.close()
102
+ proxy.close()
103
+ })
@@ -0,0 +1,103 @@
1
+ 'use strict'
2
+
3
+ const fetch = require('node-fetch')
4
+ const test = require('ava')
5
+ const {
6
+ createServer,
7
+ createSecureServer,
8
+ createProxy,
9
+ createSecureProxy
10
+ } = require('./utils')
11
+ const { HttpProxyAgent, HttpsProxyAgent } = require('../')
12
+
13
+ test('http to http', async t => {
14
+ const server = await createServer()
15
+ const proxy = await createProxy()
16
+ server.on('request', (req, res) => res.end('ok'))
17
+
18
+ const response = await fetch(`http://${server.address().address}:${server.address().port}`, {
19
+ agent: new HttpProxyAgent({
20
+ keepAlive: true,
21
+ keepAliveMsecs: 1000,
22
+ maxSockets: 256,
23
+ maxFreeSockets: 256,
24
+ scheduling: 'lifo',
25
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
26
+ })
27
+ })
28
+
29
+ t.is(await response.text(), 'ok')
30
+ t.is(response.status, 200)
31
+
32
+ server.close()
33
+ proxy.close()
34
+ })
35
+
36
+ test('https to http', async t => {
37
+ const server = await createServer()
38
+ const proxy = await createSecureProxy()
39
+ server.on('request', (req, res) => res.end('ok'))
40
+
41
+ const response = await fetch(`http://${server.address().address}:${server.address().port}`, {
42
+ agent: new HttpProxyAgent({
43
+ keepAlive: true,
44
+ keepAliveMsecs: 1000,
45
+ maxSockets: 256,
46
+ maxFreeSockets: 256,
47
+ scheduling: 'lifo',
48
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
49
+ })
50
+ })
51
+
52
+ t.is(await response.text(), 'ok')
53
+ t.is(response.status, 200)
54
+
55
+ server.close()
56
+ proxy.close()
57
+ })
58
+
59
+ test('http to https', async t => {
60
+ const server = await createSecureServer()
61
+ const proxy = await createProxy()
62
+ server.on('request', (req, res) => res.end('ok'))
63
+
64
+ const response = await fetch(`https://${server.address().address}:${server.address().port}`, {
65
+ agent: new HttpsProxyAgent({
66
+ keepAlive: true,
67
+ keepAliveMsecs: 1000,
68
+ maxSockets: 256,
69
+ maxFreeSockets: 256,
70
+ scheduling: 'lifo',
71
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
72
+ })
73
+ })
74
+
75
+ t.is(await response.text(), 'ok')
76
+ t.is(response.status, 200)
77
+
78
+ server.close()
79
+ proxy.close()
80
+ })
81
+
82
+ test('https to https', async t => {
83
+ const server = await createSecureServer()
84
+ const proxy = await createSecureProxy()
85
+ server.on('request', (req, res) => res.end('ok'))
86
+
87
+ const response = await fetch(`https://${server.address().address}:${server.address().port}`, {
88
+ agent: new HttpsProxyAgent({
89
+ keepAlive: true,
90
+ keepAliveMsecs: 1000,
91
+ maxSockets: 256,
92
+ maxFreeSockets: 256,
93
+ scheduling: 'lifo',
94
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
95
+ })
96
+ })
97
+
98
+ t.is(await response.text(), 'ok')
99
+ t.is(response.status, 200)
100
+
101
+ server.close()
102
+ proxy.close()
103
+ })
@@ -0,0 +1,139 @@
1
+ 'use strict'
2
+
3
+ const sget = require('simple-get')
4
+ const test = require('ava')
5
+ const {
6
+ createServer,
7
+ createSecureServer,
8
+ createProxy,
9
+ createSecureProxy
10
+ } = require('./utils')
11
+ const { HttpProxyAgent, HttpsProxyAgent } = require('..')
12
+
13
+ test('http to http', async t => {
14
+ const server = await createServer()
15
+ const proxy = await createProxy()
16
+ server.on('request', (req, res) => res.end('ok'))
17
+
18
+ const response = await new Promise((resolve, reject) => {
19
+ sget.concat({
20
+ url: `http://${server.address().address}:${server.address().port}`,
21
+ agent: new HttpProxyAgent({
22
+ keepAlive: true,
23
+ keepAliveMsecs: 1000,
24
+ maxSockets: 256,
25
+ maxFreeSockets: 256,
26
+ scheduling: 'lifo',
27
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
28
+ })
29
+ }, function (err, response, data) {
30
+ if (err) {
31
+ return reject(err)
32
+ }
33
+ t.is(data.toString(), 'ok')
34
+
35
+ return resolve(response)
36
+ })
37
+ })
38
+
39
+ t.is(response.statusCode, 200)
40
+
41
+ server.close()
42
+ proxy.close()
43
+ })
44
+
45
+ test('https to http', async t => {
46
+ const server = await createServer()
47
+ const proxy = await createSecureProxy()
48
+ server.on('request', (req, res) => res.end('ok'))
49
+
50
+ const response = await new Promise((resolve, reject) => {
51
+ sget.concat({
52
+ url: `http://${server.address().address}:${server.address().port}`,
53
+ agent: new HttpProxyAgent({
54
+ keepAlive: true,
55
+ keepAliveMsecs: 1000,
56
+ maxSockets: 256,
57
+ maxFreeSockets: 256,
58
+ scheduling: 'lifo',
59
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
60
+ })
61
+ }, function (err, response, data) {
62
+ if (err) {
63
+ return reject(err)
64
+ }
65
+ t.is(data.toString(), 'ok')
66
+
67
+ return resolve(response)
68
+ })
69
+ })
70
+
71
+ t.is(response.statusCode, 200)
72
+
73
+ server.close()
74
+ proxy.close()
75
+ })
76
+
77
+ test('http to https', async t => {
78
+ const server = await createSecureServer()
79
+ const proxy = await createProxy()
80
+ server.on('request', (req, res) => res.end('ok'))
81
+
82
+ const response = await new Promise((resolve, reject) => {
83
+ sget.concat({
84
+ url: `https://${server.address().address}:${server.address().port}`,
85
+ agent: new HttpsProxyAgent({
86
+ keepAlive: true,
87
+ keepAliveMsecs: 1000,
88
+ maxSockets: 256,
89
+ maxFreeSockets: 256,
90
+ scheduling: 'lifo',
91
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
92
+ })
93
+ }, function (err, response, data) {
94
+ if (err) {
95
+ return reject(err)
96
+ }
97
+ t.is(data.toString(), 'ok')
98
+
99
+ return resolve(response)
100
+ })
101
+ })
102
+
103
+ t.is(response.statusCode, 200)
104
+
105
+ server.close()
106
+ proxy.close()
107
+ })
108
+
109
+ test('https to https', async t => {
110
+ const server = await createSecureServer()
111
+ const proxy = await createSecureProxy()
112
+ server.on('request', (req, res) => res.end('ok'))
113
+
114
+ const response = await new Promise((resolve, reject) => {
115
+ sget.concat({
116
+ url: `https://${server.address().address}:${server.address().port}`,
117
+ agent: new HttpsProxyAgent({
118
+ keepAlive: true,
119
+ keepAliveMsecs: 1000,
120
+ maxSockets: 256,
121
+ maxFreeSockets: 256,
122
+ scheduling: 'lifo',
123
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
124
+ })
125
+ }, function (err, response, data) {
126
+ if (err) {
127
+ return reject(err)
128
+ }
129
+ t.is(data.toString(), 'ok')
130
+
131
+ return resolve(response)
132
+ })
133
+ })
134
+
135
+ t.is(response.statusCode, 200)
136
+
137
+ server.close()
138
+ proxy.close()
139
+ })