forked from jfrog/jfrog-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distribution_test.go
612 lines (487 loc) · 23.3 KB
/
distribution_test.go
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
package main
import (
"encoding/json"
"errors"
"fmt"
coreTestUtils "github.com/jfrog/jfrog-cli-core/v2/common/tests"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli/inttestutils"
"github.com/jfrog/jfrog-cli/utils/tests"
"github.com/jfrog/jfrog-client-go/auth"
distributionServices "github.com/jfrog/jfrog-client-go/distribution/services"
clientDistUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils"
clientUtils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/stretchr/testify/assert"
"net/http"
"os"
"path/filepath"
"strconv"
"testing"
)
const (
bundleVersion = "10"
distributionEndpoint = "distribution/"
)
var (
distributionDetails *config.ServerDetails
distAuth auth.ServiceDetails
distHttpDetails httputils.HttpClientDetails
// JFrog CLI for Distribution commands
distributionCli *tests.JfrogCli
)
func InitDistributionTests() {
initDistributionCli()
inttestutils.CleanUpOldBundles(distHttpDetails, bundleVersion, distributionCli)
InitArtifactoryTests()
inttestutils.SendGpgKeys(artHttpDetails, distHttpDetails)
}
func CleanDistributionTests() {
deleteCreatedRepos()
}
func authenticateDistribution() string {
*tests.JfrogUrl = clientUtils.AddTrailingSlashIfNeeded(*tests.JfrogUrl)
distributionDetails = &config.ServerDetails{DistributionUrl: *tests.JfrogUrl + distributionEndpoint}
cred := "--url=" + distributionDetails.DistributionUrl
if *tests.JfrogAccessToken != "" {
distributionDetails.AccessToken = *tests.JfrogAccessToken
cred += " --access-token=" + *tests.JfrogAccessToken
} else {
distributionDetails.Password = *tests.JfrogPassword
cred += " --password=" + *tests.JfrogPassword
}
// Due to a bug in distribution when authenticate with a multi-scope token,
// we must send a username as well as token or password.
distributionDetails.User = *tests.JfrogUser
cred += " --user=" + *tests.JfrogUser
var err error
if distAuth, err = distributionDetails.CreateDistAuthConfig(); err != nil {
coreutils.ExitOnErr(errors.New("Failed while attempting to authenticate with Distribution: " + err.Error()))
}
distributionDetails.DistributionUrl = distAuth.GetUrl()
distHttpDetails = distAuth.CreateHttpClientDetails()
return cred
}
func initDistributionCli() {
if distributionCli != nil {
return
}
cred := authenticateDistribution()
distributionCli = tests.NewJfrogCli(execMain, "jfrog ds", cred)
}
func initDistributionTest(t *testing.T) {
if !*tests.TestDistribution {
t.Skip("Skipping distribution test. To run distribution test add the '-test.distribution=true' option.")
}
}
func cleanDistributionTest(t *testing.T) {
err := distributionCli.Exec("rbdel", tests.BundleName, bundleVersion, "--site=*", "--delete-from-dist", "--quiet", "--sync")
if err != nil {
// If release bundle already deleted during the tests no need to fail here
assert.ErrorContains(t, err, fmt.Sprintf("Release Bundle Version '%s/%s' was not found", tests.BundleName, bundleVersion))
}
inttestutils.CleanDistributionRepositories(t, serverDetails)
tests.CleanFileSystem()
}
func TestBundleAsyncDistDownload(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create and distribute release bundle
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--create-repo")
inttestutils.WaitForDistribution(t, tests.BundleName, bundleVersion, distHttpDetails)
// Download by bundle version, b2 and b3 should not be downloaded, b1 should
runRt(t, "dl", tests.DistRepo1+"/data/*", tests.Out+fileutils.GetFileSeparator()+"download"+fileutils.GetFileSeparator()+"simple_by_build"+fileutils.GetFileSeparator(), "--bundle="+tests.BundleName+"/"+bundleVersion)
// Validate files are downloaded by bundle version
paths, _ := fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
err = tests.ValidateListsIdentical(tests.GetBuildSimpleDownload(), paths)
assert.NoError(t, err)
// Cleanup
cleanDistributionTest(t)
}
func TestBundleDownloadUsingSpec(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create release bundle
distributionRulesPath := filepath.Join(tests.GetTestResourcesPath(), "distribution", tests.DistributionRules)
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--dist-rules="+distributionRulesPath, "--sync", "--create-repo")
// Download by bundle version with gpg validation, b2 and b3 should not be downloaded, b1 should
specFile, err = tests.CreateSpec(tests.BundleDownloadGpgSpec)
assert.NoError(t, err)
runRt(t, "dl", "--spec="+specFile)
// Validate files are downloaded by bundle version
paths, _ := fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
err = tests.ValidateListsIdentical(tests.GetBuildSimpleDownload(), paths)
assert.NoError(t, err)
// Cleanup
cleanDistributionTest(t)
}
func TestBundleCreateByAql(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create release bundle by AQL
spec, err := tests.CreateSpec(tests.DistributionCreateByAql)
assert.NoError(t, err)
runDs(t, "rbc", tests.BundleName, bundleVersion, "--spec="+spec, "--sign")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// Download by bundle version, b2 and b3 should not be downloaded, b1 should
specFile, err = tests.CreateSpec(tests.BundleDownloadSpec)
assert.NoError(t, err)
runRt(t, "dl", "--spec="+specFile)
// Validate files are downloaded by bundle version
paths, _ := fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
err = tests.ValidateListsIdentical(tests.GetBuildSimpleDownload(), paths)
assert.NoError(t, err)
// Cleanup
cleanDistributionTest(t)
}
func TestBundleDownloadNoPattern(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create release bundle
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// Download by bundle name and version with pattern "*", b2 and b3 should not be downloaded, b1 should
runRt(t, "dl", "*", "out/download/simple_by_build/data/", "--bundle="+tests.BundleName+"/"+bundleVersion, "--flat")
// Validate files are downloaded by bundle version
paths, _ := fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
err = tests.ValidateListsIdentical(tests.GetBuildSimpleDownload(), paths)
assert.NoError(t, err)
// Download by bundle name and version without pattern, b2 and b3 should not be downloaded, b1 should
tests.CleanFileSystem()
specFile, err = tests.CreateSpec(tests.BundleDownloadSpecNoPattern)
assert.NoError(t, err)
runRt(t, "dl", "--spec="+specFile, "--flat")
// Validate files are downloaded by bundle version
paths, _ = fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
err = tests.ValidateListsIdentical(tests.GetBuildSimpleDownload(), paths)
assert.NoError(t, err)
// Cleanup
cleanDistributionTest(t)
}
func TestBundleExclusions(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create release bundle. Include b1.in and b2.in. Exclude b3.in.
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b*.in", "--sign", "--exclusions=*b3.in")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// Download by bundle version, b2 and b3 should not be downloaded, b1 should
runRt(t, "dl", tests.DistRepo1+"/data/*", tests.Out+fileutils.GetFileSeparator()+"download"+fileutils.GetFileSeparator()+"simple_by_build"+fileutils.GetFileSeparator(), "--bundle="+tests.BundleName+"/"+bundleVersion, "--exclusions=*b2.in")
// Validate files are downloaded by bundle version
paths, _ := fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
err = tests.ValidateListsIdentical(tests.GetBuildSimpleDownload(), paths)
assert.NoError(t, err)
// Cleanup
cleanDistributionTest(t)
}
func TestBundleCopy(t *testing.T) {
initDistributionTest(t)
// Upload files
specFileA, err := tests.CreateSpec(tests.DistributionUploadSpecA)
assert.NoError(t, err)
specFileB, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFileA)
runRt(t, "u", "--spec="+specFileB)
// Create release bundle
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/a*", "--sign")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// Copy by bundle name and version
specFile, err := tests.CreateSpec(tests.CopyByBundleSpec)
assert.NoError(t, err)
runRt(t, "cp", "--spec="+specFile)
// Validate files are copied by bundle version
spec, err := tests.CreateSpec(tests.CopyByBundleAssertSpec)
assert.NoError(t, err)
inttestutils.VerifyExistInArtifactory(tests.GetBundleCopyExpected(), spec, serverDetails, t)
// Cleanup
cleanDistributionTest(t)
}
func TestBundleSetProperties(t *testing.T) {
initDistributionTest(t)
// Upload a file.
runRt(t, "u", "testdata/a/a1.in", tests.DistRepo1+"/a.in")
// Create release bundle
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/a.in", "--sign")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// Set the 'prop=red' property to the file.
runRt(t, "sp", tests.DistRepo1+"/a.*", "prop=red", "--bundle="+tests.BundleName+"/"+bundleVersion)
// Now let's change the property value, by searching for the 'prop=red'.
specFile, err := tests.CreateSpec(tests.DistributionSetDeletePropsSpec)
assert.NoError(t, err)
runRt(t, "sp", "prop=green", "--spec="+specFile, "--bundle="+tests.BundleName+"/"+bundleVersion)
resultItems := searchItemsInArtifactory(t, tests.SearchDistRepoByInSuffix)
assert.NotZero(t, len(resultItems), "No artifacts were found.")
for _, item := range resultItems {
properties := item.Properties
assert.Equal(t, 2, len(properties), "Failed setting properties on item:", item.GetItemRelativePath())
for _, prop := range properties {
if prop.Key == "sha256" {
continue
}
assert.Equal(t, "prop", prop.Key, "Wrong property key")
assert.Equal(t, "green", prop.Value, "Wrong property value")
}
}
cleanDistributionTest(t)
}
func TestSignReleaseBundle(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create a release bundle without --sign and make sure it is not signed
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in")
distributableResponse := inttestutils.GetLocalBundle(t, tests.BundleName, bundleVersion, distHttpDetails)
inttestutils.AssertReleaseBundleOpen(t, distributableResponse)
// Sign the release bundle and make sure it is signed
runDs(t, "rbs", tests.BundleName, bundleVersion)
distributableResponse = inttestutils.GetLocalBundle(t, tests.BundleName, bundleVersion, distHttpDetails)
inttestutils.AssertReleaseBundleSigned(t, distributableResponse)
// Cleanup
cleanDistributionTest(t)
}
func TestBundleDeleteLocal(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create a release bundle
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
// Delete release bundle locally
runDs(t, "rbdel", tests.BundleName, bundleVersion, "--site=*", "--delete-from-dist", "--quiet")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, false, distHttpDetails)
// Cleanup
cleanDistributionTest(t)
}
func TestUpdateReleaseBundle(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create a release bundle with b2.in
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
// Update release bundle to have b1.in
runDs(t, "rbu", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign")
// Distribute release bundle
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// GPG validation for release bundle
keyPath := filepath.Join(tests.GetTestResourcesPath(), "distribution", "public.key.1")
wrongKeyPath := filepath.Join(tests.GetTestResourcesPath(), "distribution", "public.key.2")
// Flag --gpg-key with no --bundle flag - returns error
runRtCmdExpectError(t, "dl", tests.DistRepo1+"/data/*", tests.Out+fileutils.GetFileSeparator()+"download"+fileutils.GetFileSeparator()+"simple_by_build"+fileutils.GetFileSeparator(), "--gpg-key="+wrongKeyPath)
// Validate with the wrong key - returns error
runRtCmdExpectError(t, "dl", tests.DistRepo1+"/data/*", tests.Out+fileutils.GetFileSeparator()+"download"+fileutils.GetFileSeparator()+"simple_by_build"+fileutils.GetFileSeparator(), "--bundle="+tests.BundleName+"/"+bundleVersion, "--gpg-key="+wrongKeyPath)
// Download by bundle version with the correct key, b2 and b3 should not be downloaded, b1 should
runRt(t, "dl", tests.DistRepo1+"/data/*", tests.Out+fileutils.GetFileSeparator()+"download"+fileutils.GetFileSeparator()+"simple_by_build"+fileutils.GetFileSeparator(), "--bundle="+tests.BundleName+"/"+bundleVersion, "--gpg-key="+keyPath)
// Validate files are downloaded by bundle version
paths, _ := fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
err = tests.ValidateListsIdentical(tests.GetBuildSimpleDownload(), paths)
assert.NoError(t, err)
// Cleanup
cleanDistributionTest(t)
}
func TestCreateBundleText(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create a release bundle with release notes and description
releaseNotesPath := filepath.Join(tests.GetTestResourcesPath(), "distribution", "releasenotes.md")
description := "thisIsADescription"
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/*", "--release-notes-path="+releaseNotesPath, "--desc="+description)
// Validate release notes and description
distributableResponse := inttestutils.GetLocalBundle(t, tests.BundleName, bundleVersion, distHttpDetails)
if distributableResponse != nil {
assert.Equal(t, description, distributableResponse.Description)
releaseNotes, err := os.ReadFile(releaseNotesPath)
assert.NoError(t, err)
assert.Equal(t, string(releaseNotes), distributableResponse.ReleaseNotes.Content)
assert.Equal(t, clientDistUtils.Markdown, distributableResponse.ReleaseNotes.Syntax)
}
cleanDistributionTest(t)
}
func TestCreateBundleProps(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create and distribute release bundle with added props
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/*", "--target-props=key1=val1;key2=val2,val3", "--sign")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// Verify props are added to the distributes artifact
verifyExistInArtifactoryByProps(tests.GetBundlePropsExpected(), tests.DistRepo1+"/data/", "key1=val1;key2=val2;key2=val3", t)
cleanDistributionTest(t)
}
func TestUpdateBundleProps(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create, update and distribute release bundle with added props
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/*")
runDs(t, "rbu", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/*", "--target-props=key1=val1", "--sign")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync", "--create-repo")
// Verify props are added to the distributes artifact
verifyExistInArtifactoryByProps(tests.GetBundlePropsExpected(), tests.DistRepo1+"/data/", "key1=val1", t)
cleanDistributionTest(t)
}
func TestBundlePathMapping(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create and distribute release bundle with path mapping from <DistRepo1>/data/ to <DistRepo2>/target/
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/(*)", "--sign", "--target="+tests.DistRepo2+"/target/{1}")
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync")
// Validate files are distributed to the target mapping
spec, err := tests.CreateSpec(tests.DistributionMappingDownload)
assert.NoError(t, err)
inttestutils.VerifyExistInArtifactory(tests.GetBundleMappingExpected(), spec, serverDetails, t)
cleanDistributionTest(t)
}
func TestBundlePathMappingUsingSpec(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
// Create and distribute release bundle with path mapping from <DistRepo1>/data/ to <DistRepo2>/target/
spec, err := tests.CreateSpec(tests.DistributionCreateWithMapping)
assert.NoError(t, err)
runDs(t, "rbc", tests.BundleName, bundleVersion, "--sign", "--spec="+spec)
runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync")
// Validate files are distributed to the target mapping
spec, err = tests.CreateSpec(tests.DistributionMappingDownload)
assert.NoError(t, err)
inttestutils.VerifyExistInArtifactory(tests.GetBundleMappingExpected(), spec, serverDetails, t)
cleanDistributionTest(t)
}
func TestReleaseBundleCreateDetailedSummary(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
buffer, _, previousLog := coreTests.RedirectLogOutputToBuffer()
// Restore previous logger when the function returns
defer log.SetLogger(previousLog)
// Create a release bundle with b2.in
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in", "--sign", "--detailed-summary")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
tests.VerifySha256DetailedSummaryFromBuffer(t, buffer, previousLog)
// Cleanup
cleanDistributionTest(t)
}
func TestReleaseBundleUpdateDetailedSummary(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
buffer, _, previousLog := coreTests.RedirectLogOutputToBuffer()
// Restore previous logger when the function returns
defer log.SetLogger(previousLog)
// Create a release bundle with b2.in
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
// Update release bundle to have b1.in
runDs(t, "rbu", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign", "--detailed-summary")
tests.VerifySha256DetailedSummaryFromBuffer(t, buffer, previousLog)
// Cleanup
cleanDistributionTest(t)
}
func TestReleaseBundleSignDetailedSummary(t *testing.T) {
initDistributionTest(t)
// Upload files
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
assert.NoError(t, err)
runRt(t, "u", "--spec="+specFile)
buffer, _, previousLog := coreTests.RedirectLogOutputToBuffer()
// Restore previous logger when the function returns
defer log.SetLogger(previousLog)
// Create a release bundle with b2.in
runDs(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in")
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
// Update release bundle to have b1.in
runDs(t, "rbs", tests.BundleName, bundleVersion, "--detailed-summary")
tests.VerifySha256DetailedSummaryFromBuffer(t, buffer, previousLog)
// Cleanup
cleanDistributionTest(t)
}
func TestDistributeSyncTimeout(t *testing.T) {
initDistributionTest(t)
trackerId := "123"
statusRequestsReceived := 0
testServer, mockServerDetails, _ := coreTestUtils.CreateDsRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/api/v1/distribution/"+tests.BundleName+"/"+bundleVersion {
w.WriteHeader(http.StatusOK)
content, err := json.Marshal(distributionServices.DistributionResponseBody{TrackerId: json.Number(trackerId)})
assert.NoError(t, err)
_, err = w.Write(content)
assert.NoError(t, err)
return
}
if r.RequestURI == "/api/v1/release_bundle/"+tests.BundleName+"/"+bundleVersion+"/distribution/"+trackerId {
statusRequestsReceived++
w.WriteHeader(http.StatusOK)
content, err := json.Marshal(distributionServices.DistributionStatusResponse{Status: distributionServices.InProgress})
assert.NoError(t, err)
_, err = w.Write(content)
assert.NoError(t, err)
return
}
})
defer testServer.Close()
maxWaitMinutes := 1
distributionRulesPath := filepath.Join(tests.GetTestResourcesPath(), "distribution", tests.DistributionRules)
mockDsCli := tests.NewJfrogCli(execMain, "jfrog ds", "--url="+mockServerDetails.DistributionUrl)
err := mockDsCli.Exec("rbd", tests.BundleName, bundleVersion, "--dist-rules="+distributionRulesPath, "--sync", "--max-wait-minutes="+strconv.Itoa(maxWaitMinutes), "--create-repo")
assert.ErrorContains(t, err, "executor timeout after")
assert.ErrorAs(t, err, &clientUtils.RetryExecutorTimeoutError{})
expectedStatusRequests := (maxWaitMinutes * 60 / distributionServices.DefaultDistributeSyncSleepIntervalSeconds) + 1
assert.Equal(t, expectedStatusRequests, statusRequestsReceived)
// Cleanup
cleanDistributionTest(t)
}
// Run `jfrog ds` command`. The first arg is the distribution command, such as 'rbc', 'rbu', etc.
func runDs(t *testing.T, args ...string) {
err := distributionCli.Exec(args...)
assert.NoError(t, err)
}
// Run `jfrog rt` command and expected an error
func runRtCmdExpectError(t *testing.T, args ...string) {
err := artifactoryCli.Exec(args...)
assert.Error(t, err)
}