cdk-ecr-deployment 2.1.3 → 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,351 @@
1
+ 'use strict'
2
+
3
+ const http = require('http')
4
+ const test = require('ava')
5
+ const { createServer, createProxy } = require('./utils')
6
+ const { HttpProxyAgent } = require('../')
7
+
8
+ function request (opts) {
9
+ return new Promise((resolve, reject) => {
10
+ const req = http.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 createServer()
18
+ const proxy = await createProxy()
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 HttpProxyAgent({
27
+ keepAlive: true,
28
+ keepAliveMsecs: 1000,
29
+ maxSockets: 256,
30
+ maxFreeSockets: 256,
31
+ scheduling: 'lifo',
32
+ proxy: `http://${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 createServer()
51
+ const proxy = await createProxy()
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 HttpProxyAgent({
65
+ keepAlive: true,
66
+ keepAliveMsecs: 1000,
67
+ maxSockets: 256,
68
+ maxFreeSockets: 256,
69
+ scheduling: 'lifo',
70
+ proxy: `http://${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 createServer()
89
+ const proxy = await createProxy()
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 HttpProxyAgent({
103
+ keepAlive: false,
104
+ keepAliveMsecs: 1000,
105
+ maxSockets: Infinity,
106
+ maxFreeSockets: 256,
107
+ scheduling: 'lifo',
108
+ proxy: `http://${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 createServer()
127
+ const proxy = await createProxy()
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 HttpProxyAgent({
140
+ keepAlive: true,
141
+ keepAliveMsecs: 1000,
142
+ maxSockets: 256,
143
+ maxFreeSockets: 256,
144
+ scheduling: 'lifo',
145
+ proxy: `http://${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 createServer()
164
+ const proxy = await createProxy()
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 HttpProxyAgent({
177
+ keepAlive: true,
178
+ keepAliveMsecs: 1000,
179
+ maxSockets: 256,
180
+ maxFreeSockets: 256,
181
+ scheduling: 'lifo',
182
+ proxy: `http://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 createServer()
201
+ const proxy = await createProxy()
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 HttpProxyAgent({
211
+ keepAlive: true,
212
+ keepAliveMsecs: 1000,
213
+ maxSockets: 256,
214
+ maxFreeSockets: 256,
215
+ scheduling: 'lifo',
216
+ proxy: `http://${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 createServer()
259
+ const proxy = await createProxy()
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 HttpProxyAgent({
269
+ keepAlive: false,
270
+ keepAliveMsecs: 1000,
271
+ maxSockets: Infinity,
272
+ maxFreeSockets: 256,
273
+ scheduling: 'lifo',
274
+ proxy: `http://${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
+ })
314
+
315
+ test('Test Host Header', async t => {
316
+ const server = await createServer()
317
+ const proxy = await createProxy()
318
+ server.on('request', (req, res) => res.end('ok'))
319
+
320
+ proxy.authenticate = function (req, fn) {
321
+ t.is(req.headers.host, `${server.address().address}:${server.address().port}`)
322
+ fn(null, true)
323
+ }
324
+
325
+ const response = await request({
326
+ method: 'GET',
327
+ hostname: server.address().address,
328
+ port: server.address().port,
329
+ path: '/',
330
+ agent: new HttpProxyAgent({
331
+ keepAlive: true,
332
+ keepAliveMsecs: 1000,
333
+ maxSockets: 256,
334
+ maxFreeSockets: 256,
335
+ scheduling: 'lifo',
336
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
337
+ })
338
+ })
339
+
340
+ let body = ''
341
+ response.setEncoding('utf8')
342
+ for await (const chunk of response) {
343
+ body += chunk
344
+ }
345
+
346
+ t.is(body, 'ok')
347
+ t.is(response.statusCode, 200)
348
+
349
+ server.close()
350
+ proxy.close()
351
+ })
@@ -0,0 +1,313 @@
1
+ 'use strict'
2
+
3
+ const https = require('https')
4
+ const test = require('ava')
5
+ const { createSecureServer, createProxy } = 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 createProxy()
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: `http://${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 createProxy()
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: `http://${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 createProxy()
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: `http://${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 createProxy()
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: `http://${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 createProxy()
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: `http://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 createProxy()
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: `http://${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 createProxy()
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: `http://${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
+ })