/
index.spec.ts
764 lines (742 loc) · 24 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
import * as _AWS from '@aws-sdk/client-ecr';
import { getDigest, getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName, mocked, partial } from '../../../test/util';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import * as _hostRules from '../../util/host-rules';
import { MediaType } from './types';
import * as docker from '.';
const hostRules = mocked(_hostRules);
jest.mock('@aws-sdk/client-ecr');
jest.mock('../../util/host-rules');
type ECR = _AWS.ECR;
type GetAuthorizationTokenCommandOutput = _AWS.GetAuthorizationTokenCommandOutput;
const AWS = mocked(_AWS);
const baseUrl = 'https://index.docker.io/v2';
const authUrl = 'https://auth.docker.io';
const amazonUrl = 'https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2';
function mockEcrAuthResolve(
res: Partial<GetAuthorizationTokenCommandOutput> = {}
) {
AWS.ECR.mockImplementationOnce(() =>
partial<ECR>({
getAuthorizationToken: () =>
Promise.resolve<GetAuthorizationTokenCommandOutput>(
partial<GetAuthorizationTokenCommandOutput>(res)
),
})
);
}
function mockEcrAuthReject(msg: string) {
AWS.ECR.mockImplementationOnce(() =>
partial<ECR>({
getAuthorizationToken: jest.fn().mockRejectedValue(new Error(msg)),
})
);
}
describe(getName(), () => {
beforeEach(() => {
httpMock.setup();
hostRules.find.mockReturnValue({
username: 'some-username',
password: 'some-password',
});
hostRules.hosts.mockReturnValue([]);
});
afterEach(() => {
jest.resetAllMocks();
httpMock.reset();
});
describe('getRegistryRepository', () => {
it('handles local registries', () => {
const res = docker.getRegistryRepository(
'registry:5000/org/package',
'https://index.docker.io'
);
expect(res).toMatchSnapshot();
});
it('supports registryUrls', () => {
const res = docker.getRegistryRepository(
'my.local.registry/prefix/image',
'https://my.local.registry/prefix'
);
expect(res).toMatchSnapshot();
});
it('supports http registryUrls', () => {
const res = docker.getRegistryRepository(
'my.local.registry/prefix/image',
'http://my.local.registry/prefix'
);
expect(res).toMatchSnapshot();
});
it('supports schemeless registryUrls', () => {
const res = docker.getRegistryRepository(
'my.local.registry/prefix/image',
'my.local.registry/prefix'
);
expect(res).toMatchSnapshot();
});
});
describe('getDigest', () => {
it('returns null if no token', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {})
.get('/library/some-dep/manifests/some-new-value')
.reply(401);
const res = await getDigest(
{ datasource: 'docker', depName: 'some-dep' },
'some-new-value'
);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null if errored', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, { token: 'some-token' })
.get('/library/some-dep/manifests/some-new-value')
.replyWithError('error');
const res = await getDigest(
{ datasource: 'docker', depName: 'some-dep' },
'some-new-value'
);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null if empty header', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, { token: 'some-token' })
.get('/library/some-dep/manifests/some-new-value')
.reply(200, undefined, { 'docker-content-digest': '' });
const res = await getDigest(
{ datasource: 'docker', depName: 'some-dep' },
'some-new-value'
);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns digest', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'www-authenticate':
'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull "',
})
.get('/library/some-dep/manifests/latest')
.reply(200, {}, { 'docker-content-digest': 'some-digest' });
httpMock
.scope(authUrl)
.get(
'/token?service=registry.docker.io&scope=repository:library/some-dep:pull'
)
.reply(200, { token: 'some-token' });
hostRules.find.mockReturnValue({});
const res = await getDigest({
datasource: 'docker',
depName: 'some-dep',
});
expect(res).toBe('some-digest');
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('falls back to body for digest', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'www-authenticate':
'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull "',
})
.get('/library/some-dep/manifests/some-new-value')
.reply(
200,
`{
"signatures": [
{
"header": {
"jwk": {
"crv": "P-256",
"kid": "DB2X:GSG2:72H3:AE3R:KCMI:Y77E:W7TF:ERHK:V5HR:JJ2Y:YMS6:HFGJ",
"kty": "EC",
"x": "jyr9-xZBorSC9fhqNsmfU_Ud31wbaZ-bVGz0HmySvbQ",
"y": "vkE6qZCCvYRWjSUwgAOvibQx_s8FipYkAiHS0VnAFNs"
},
"alg": "ES256"
},
"signature": "yUXzEiPzg_SlQlqGW43H6oMgYuz30zSkj2qauQc_kbyI9RQHucYAKs_lBSFaQdDrtgW-1iDZSP9eExKP8ANSyA",
"protected": "eyJmb3JtYXRMZW5ndGgiOjgzMDAsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAxOC0wMi0wNVQxNDoyMDoxOVoifQ"
}
]
}`,
{
'content-type': 'text/plain',
}
);
httpMock
.scope(authUrl)
.get(
'/token?service=registry.docker.io&scope=repository:library/some-dep:pull'
)
.reply(200, { token: 'some-token' });
const res = await getDigest(
{ datasource: 'docker', depName: 'some-dep' },
'some-new-value'
);
expect(res).toBe(
'sha256:b3d6068234f3a18ebeedd2dab81e67b6a192e81192a099df4112ecfc7c3be84f'
);
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('supports docker insecure registry', async () => {
httpMock
.scope(baseUrl.replace('https', 'http'))
.get('/')
.reply(200, '', {})
.get('/library/some-dep/manifests/latest')
.reply(200, '', { 'docker-content-digest': 'some-digest' });
hostRules.find.mockReturnValueOnce({ insecureRegistry: true });
const res = await getDigest({
datasource: 'docker',
depName: 'some-dep',
});
expect(res).toBe('some-digest');
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('supports basic authentication', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.get('/')
.reply(200)
.get('/library/some-dep/manifests/some-tag')
.reply(200, '', { 'docker-content-digest': 'some-digest' });
const res = await getDigest(
{ datasource: 'docker', depName: 'some-dep' },
'some-tag'
);
const trace = httpMock.getTrace();
expect(res).toBe('some-digest');
expect(trace[1].headers.authorization).toBe(
'Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk'
);
expect(trace).toMatchSnapshot();
});
it('returns null for 403 with basic authentication', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.get('/')
.reply(403);
const res = await getDigest(
{ datasource: 'docker', depName: 'some-dep' },
'some-tag'
);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('passes credentials to ECR client', async () => {
httpMock
.scope(amazonUrl)
.get('/')
.reply(200, '', {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.get('/')
.reply(200)
.get('/node/manifests/some-tag')
.reply(200, '', { 'docker-content-digest': 'some-digest' });
mockEcrAuthResolve({
authorizationData: [{ authorizationToken: 'abcdef' }],
});
await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
);
const trace = httpMock.getTrace();
expect(trace).toMatchSnapshot();
expect(AWS.ECR).toHaveBeenCalledWith({
credentials: {
accessKeyId: 'some-username',
secretAccessKey: 'some-password',
},
region: 'us-east-1',
});
});
it('supports ECR authentication', async () => {
httpMock
.scope(amazonUrl)
.get('/')
.reply(200, '', {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.get('/')
.reply(200)
.get('/node/manifests/some-tag')
.reply(200, '', { 'docker-content-digest': 'some-digest' });
mockEcrAuthResolve({
authorizationData: [{ authorizationToken: 'abcdef' }],
});
const res = await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
);
const trace = httpMock.getTrace();
expect(res).toBe('some-digest');
expect(trace[1].headers.authorization).toBe('Basic abcdef');
expect(trace).toMatchSnapshot();
});
it('continues without token if ECR authentication could not be extracted', async () => {
httpMock
.scope(amazonUrl)
.get('/')
.reply(200, '', {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.get('/')
.reply(403);
mockEcrAuthResolve();
const res = await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('continues without token if ECR authentication fails', async () => {
hostRules.find.mockReturnValue({});
httpMock
.scope(amazonUrl)
.get('/')
.reply(200, '', {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.get('/')
.reply(403);
mockEcrAuthReject('some error');
const res = await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('continues without token, when no header is present', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'content-type': 'text/plain',
})
.get('/library/some-dep/manifests/some-new-value')
.reply(200, {}, { 'docker-content-digest': 'some-digest' });
const res = await getDigest(
{ datasource: 'docker', depName: 'some-dep' },
'some-new-value'
);
expect(res).toBe('some-digest');
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('supports scoped names', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'www-authenticate':
'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull "',
})
.get('/library/some-other-dep/manifests/8.0.0-alpine')
.reply(200, {}, { 'docker-content-digest': 'some-digest' });
httpMock
.scope(authUrl)
.get(
'/token?service=registry.docker.io&scope=repository:library/some-other-dep:pull'
)
.reply(200, { access_token: 'some-token' });
const res = await getDigest(
{ datasource: 'docker', depName: 'some-other-dep' },
'8.0.0-alpine'
);
expect(res).toBe('some-digest');
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('should throw error for 429', async () => {
httpMock.scope(baseUrl).get('/').replyWithError({ statusCode: 429 });
await expect(
getDigest({ datasource: 'docker', depName: 'some-dep' }, 'latest')
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
it('should throw error for 5xx', async () => {
httpMock.scope(baseUrl).get('/').replyWithError({ statusCode: 504 });
await expect(
getDigest({ datasource: 'docker', depName: 'some-dep' }, 'latest')
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
});
describe('getReleases', () => {
it('returns null if no token', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {})
.get('/library/node/tags/list?n=10000')
.reply(403);
const res = await getPkgReleases({
datasource: docker.id,
depName: 'node',
});
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('uses custom registry with registryUrls', async () => {
const tags = ['1.0.0'];
httpMock
.scope('https://registry.company.com/v2')
.get('/')
.reply(200, '', {})
.get('/node/tags/list?n=10000')
.reply(
200,
{ tags },
{
link:
'<https://api.github.com/user/9287/repos?page=3&per_page=100>; rel="next", ',
}
)
.get('/')
.reply(200)
.get('/node/manifests/latest')
.reply(200);
httpMock
.scope('https://api.github.com')
.get('/user/9287/repos?page=3&per_page=100')
.reply(200, { tags: ['latest'] }, {});
const config = {
datasource: docker.id,
depName: 'node',
registryUrls: ['https://registry.company.com'],
};
const res = await getPkgReleases(config);
expect(res.releases).toHaveLength(1);
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('uses custom registry in depName', async () => {
const tags = ['1.0.0'];
httpMock
.scope('https://registry.company.com/v2')
.get('/')
.reply(200, '', {})
.get('/node/tags/list?n=10000')
.reply(200, { tags }, {})
.get('/')
.reply(200, '', {})
.get('/node/manifests/1.0.0')
.reply(200, '', {});
const res = await getPkgReleases({
datasource: docker.id,
depName: 'registry.company.com/node',
});
expect(res.releases).toHaveLength(1);
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('uses lower tag limit for ECR deps', async () => {
httpMock
.scope(amazonUrl)
.get('/')
.reply(200, '', {})
// The tag limit parameter `n` needs to be limited to 1000 for ECR
// See https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html#ECR-DescribeRepositories-request-maxResults
.get('/node/tags/list?n=1000')
.reply(200, {}, {})
.get('/')
.reply(200, '', {})
.get('/node/manifests/undefined')
.reply(200);
await getPkgReleases({
datasource: docker.id,
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
});
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('adds library/ prefix for Docker Hub (implicit)', async () => {
const tags = ['1.0.0'];
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'www-authenticate':
'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/node:pull "',
})
.get('/library/node/tags/list?n=10000')
.reply(200, { tags }, {})
.get('/')
.reply(200)
.get('/library/node/manifests/1.0.0')
.reply(200);
httpMock
.scope(authUrl)
.get(
'/token?service=registry.docker.io&scope=repository:library/node:pull'
)
.reply(200, { token: 'some-token ' });
const res = await getPkgReleases({
datasource: docker.id,
depName: 'node',
});
expect(res.releases).toHaveLength(1);
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('adds library/ prefix for Docker Hub (explicit)', async () => {
const tags = ['1.0.0'];
httpMock
.scope(baseUrl)
.get('/')
.reply(200, '', {
'www-authenticate':
'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/node:pull "',
})
.get('/library/node/tags/list?n=10000')
.reply(200, { tags }, {})
.get('/')
.reply(200)
.get('/library/node/manifests/1.0.0')
.reply(200);
httpMock
.scope(authUrl)
.get(
'/token?service=registry.docker.io&scope=repository:library/node:pull'
)
.reply(200, { token: 'some-token ' });
const res = await getPkgReleases({
datasource: docker.id,
depName: 'docker.io/node',
});
expect(res.releases).toHaveLength(1);
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('adds no library/ prefix for other registries', async () => {
const tags = ['1.0.0'];
httpMock
.scope('https://k8s.gcr.io/v2/')
.get('/')
.reply(200, '', {
'www-authenticate':
'Bearer realm="https://k8s.gcr.io/v2/token",service="k8s.gcr.io"',
})
.get(
'/token?service=k8s.gcr.io&scope=repository:kubernetes-dashboard-amd64:pull'
)
.reply(200, { token: 'some-token ' })
.get('/kubernetes-dashboard-amd64/tags/list?n=10000')
.reply(200, { tags }, {})
.get('/')
.reply(200)
.get('/kubernetes-dashboard-amd64/manifests/1.0.0')
.reply(200);
const res = await getPkgReleases({
datasource: docker.id,
depName: 'k8s.gcr.io/kubernetes-dashboard-amd64',
});
expect(res.releases).toHaveLength(1);
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null on error', async () => {
httpMock
.scope(baseUrl)
.get('/')
.reply(200, null)
.get('/my/node/tags/list?n=10000')
.replyWithError('error');
const res = await getPkgReleases({
datasource: docker.id,
depName: 'my/node',
});
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null if no auth', async () => {
hostRules.find.mockReturnValue({});
httpMock
.scope(baseUrl)
.get('/')
.reply(200, undefined, {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.get('/')
.reply(403);
const res = await getPkgReleases({
datasource: docker.id,
depName: 'node',
});
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('supports labels', async () => {
httpMock
.scope('https://registry.company.com/v2')
.get('/')
.times(3)
.reply(200)
.get('/node/tags/list?n=10000')
.reply(200, { tags: ['latest'] })
.get('/node/manifests/latest')
.reply(200, {
schemaVersion: 2,
mediaType: MediaType.manifestV2,
config: { digest: 'some-config-digest' },
})
.get('/node/blobs/some-config-digest')
.reply(200, {
config: {
Labels: {
'org.opencontainers.image.source':
'https://github.com/renovatebot/renovate',
},
},
});
const res = await getPkgReleases({
datasource: docker.id,
depName: 'registry.company.com/node',
});
const trace = httpMock.getTrace();
expect(res).toMatchSnapshot();
expect(trace).toMatchSnapshot();
});
it('supports manifest lists', async () => {
httpMock
.scope('https://registry.company.com/v2')
.get('/')
.times(4)
.reply(200)
.get('/node/tags/list?n=10000')
.reply(200, { tags: ['latest'] })
.get('/node/manifests/latest')
.reply(200, {
schemaVersion: 2,
mediaType: MediaType.manifestListV2,
manifests: [{ digest: 'some-image-digest' }],
})
.get('/node/manifests/some-image-digest')
.reply(200, {
schemaVersion: 2,
mediaType: MediaType.manifestV2,
config: { digest: 'some-config-digest' },
})
.get('/node/blobs/some-config-digest')
.reply(200, {
config: {
Labels: {
'org.opencontainers.image.source':
'https://github.com/renovatebot/renovate',
},
},
});
const res = await getPkgReleases({
datasource: docker.id,
depName: 'registry.company.com/node',
});
const trace = httpMock.getTrace();
expect(res).toMatchSnapshot();
expect(trace).toMatchSnapshot();
});
it('ignores unsupported manifest', async () => {
httpMock
.scope('https://registry.company.com/v2')
.get('/')
.times(2)
.reply(200)
.get('/node/tags/list?n=10000')
.reply(200, { tags: ['latest'] })
.get('/node/manifests/latest')
.reply(200, {
schemaVersion: 2,
mediaType: MediaType.manifestV1,
});
const res = await getPkgReleases({
datasource: docker.id,
depName: 'registry.company.com/node',
});
const trace = httpMock.getTrace();
expect(res).toMatchSnapshot();
expect(trace).toMatchSnapshot();
});
it('ignores unsupported schema version', async () => {
httpMock
.scope('https://registry.company.com/v2')
.get('/')
.times(2)
.reply(200)
.get('/node/tags/list?n=10000')
.reply(200, { tags: ['latest'] })
.get('/node/manifests/latest')
.reply(200, {});
const res = await getPkgReleases({
datasource: docker.id,
depName: 'registry.company.com/node',
});
const trace = httpMock.getTrace();
expect(res).toMatchSnapshot();
expect(trace).toMatchSnapshot();
});
it('supports redirect', async () => {
httpMock
.scope('https://registry.company.com/v2')
.get('/')
.times(3)
.reply(200)
.get('/node/tags/list?n=10000')
.reply(200, { tags: ['latest'] })
.get('/node/manifests/latest')
.reply(200, {
schemaVersion: 2,
mediaType: MediaType.manifestV2,
config: { digest: 'some-config-digest' },
})
.get('/node/blobs/some-config-digest')
.reply(302, undefined, {
location:
'https://abc.s3.amazon.com/some-config-digest?X-Amz-Algorithm=xxxx',
});
httpMock
.scope('https://abc.s3.amazon.com')
.get('/some-config-digest')
.query({ 'X-Amz-Algorithm': 'xxxx' })
.reply(200, {
config: {},
});
const res = await getPkgReleases({
datasource: docker.id,
depName: 'registry.company.com/node',
});
const trace = httpMock.getTrace();
expect(res).toMatchSnapshot();
expect(trace).toMatchSnapshot();
expect(trace[1].headers.authorization).toBe(
'Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk'
);
expect(trace[trace.length - 1].headers.authorization).toBeUndefined();
});
});
});