1
1
package main
2
2
3
3
import (
4
+ "errors"
4
5
"io/ioutil"
5
6
"path/filepath"
6
7
"testing"
7
8
8
9
"github.com/jfrog/jfrog-cli/inttestutils"
10
+ "github.com/jfrog/jfrog-cli/utils/cliutils"
11
+ "github.com/jfrog/jfrog-cli/utils/config"
9
12
"github.com/jfrog/jfrog-cli/utils/tests"
13
+ "github.com/jfrog/jfrog-client-go/auth"
10
14
"github.com/jfrog/jfrog-client-go/utils"
11
15
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
16
+ "github.com/jfrog/jfrog-client-go/utils/io/httputils"
12
17
"github.com/stretchr/testify/assert"
13
18
)
14
19
15
20
const bundleVersion = "10"
16
21
22
+ var (
23
+ distributionDetails * config.ArtifactoryDetails
24
+ distAuth auth.ServiceDetails
25
+ distHttpDetails httputils.HttpClientDetails
26
+ // JFrog CLI for Distribution commands
27
+ distributionCli * tests.JfrogCli
28
+ )
29
+
17
30
func InitDistributionTests () {
18
- * tests .RtDistributionUrl = utils .AddTrailingSlashIfNeeded (* tests .RtDistributionUrl )
19
- initArtifactoryCli ()
20
- inttestutils .CleanUpOldBundles (artHttpDetails , bundleVersion , artifactoryCli )
21
31
InitArtifactoryTests ()
22
- inttestutils .SendGpgKeys (artHttpDetails )
32
+ initDistributionCli ()
33
+ inttestutils .CleanUpOldBundles (distHttpDetails , bundleVersion , distributionCli )
34
+ inttestutils .SendGpgKeys (artHttpDetails , distHttpDetails )
23
35
}
24
36
25
37
func CleanDistributionTests () {
26
38
deleteCreatedRepos ()
27
39
}
28
40
41
+ func authenticateDistribution () string {
42
+ distributionDetails = & config.ArtifactoryDetails {DistributionUrl : * tests .RtDistributionUrl }
43
+ cred := "--dist-url=" + * tests .RtDistributionUrl
44
+ if * tests .RtAccessToken != "" {
45
+ distributionDetails .AccessToken = * tests .RtDistributionAccessToken
46
+ cred += " --access-token=" + * tests .RtDistributionAccessToken
47
+ } else {
48
+ distributionDetails .User = * tests .RtUser
49
+ distributionDetails .Password = * tests .RtPassword
50
+ cred += " --user=" + * tests .RtUser + " --password=" + * tests .RtPassword
51
+ }
52
+
53
+ var err error
54
+ if distAuth , err = distributionDetails .CreateDistAuthConfig (); err != nil {
55
+ cliutils .ExitOnErr (errors .New ("Failed while attempting to authenticate with Artifactory: " + err .Error ()))
56
+ }
57
+ distributionDetails .DistributionUrl = distAuth .GetUrl ()
58
+ distHttpDetails = distAuth .CreateHttpClientDetails ()
59
+ return cred
60
+ }
61
+
62
+ func initDistributionCli () {
63
+ if distributionCli != nil {
64
+ return
65
+ }
66
+ * tests .RtDistributionUrl = utils .AddTrailingSlashIfNeeded (* tests .RtDistributionUrl )
67
+ cred := authenticateDistribution ()
68
+ distributionCli = tests .NewJfrogCli (execMain , "jfrog rt" , cred )
69
+ }
70
+
29
71
func initDistributionTest (t * testing.T ) {
30
72
if ! * tests .TestDistribution {
31
73
t .Skip ("Skipping distribution test. To run distribution test add the '-test.distribution=true' option." )
32
74
}
33
75
}
34
76
35
77
func cleanDistributionTest (t * testing.T ) {
36
- artifactoryCli .Exec ("rbdel" , tests .BundleName , bundleVersion , "--site=*" , "--delete-from-dist" , "--quiet" )
37
- inttestutils .WaitForDeletion (t , tests .BundleName , bundleVersion , artHttpDetails )
78
+ distributionCli .Exec ("rbdel" , tests .BundleName , bundleVersion , "--site=*" , "--delete-from-dist" , "--quiet" )
79
+ inttestutils .WaitForDeletion (t , tests .BundleName , bundleVersion , distHttpDetails )
38
80
inttestutils .CleanDistributionRepositories (t , artifactoryDetails )
39
81
tests .CleanFileSystem ()
40
82
}
@@ -48,9 +90,9 @@ func TestBundleAsyncDistDownload(t *testing.T) {
48
90
artifactoryCli .Exec ("u" , "--spec=" + specFile )
49
91
50
92
// Create and distribute release bundle
51
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
52
- artifactoryCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" )
53
- inttestutils .WaitForDistribution (t , tests .BundleName , bundleVersion , artHttpDetails )
93
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
94
+ distributionCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" )
95
+ inttestutils .WaitForDistribution (t , tests .BundleName , bundleVersion , distHttpDetails )
54
96
55
97
// Download by bundle version, b2 and b3 should not be downloaded, b1 should
56
98
artifactoryCli .Exec ("dl " + tests .DistRepo1 + "/data/* " + tests .Out + fileutils .GetFileSeparator ()+ "download" + fileutils .GetFileSeparator ()+ "simple_by_build" + fileutils .GetFileSeparator (), "--bundle=" + tests .BundleName + "/" + bundleVersion )
@@ -71,13 +113,12 @@ func TestBundleDownloadUsingSpec(t *testing.T) {
71
113
specFile , err := tests .CreateSpec (tests .DistributionUploadSpecB )
72
114
assert .NoError (t , err )
73
115
artifactoryCli .Exec ("u" , "--spec=" + specFile )
74
- inttestutils .WaitForDeletion (t , tests .BundleName , bundleVersion , artHttpDetails )
75
116
76
117
// Create release bundle
77
118
distributionRules , err := tests .CreateSpec (tests .DistributionRules )
78
119
assert .NoError (t , err )
79
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
80
- artifactoryCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--dist-rules=" + distributionRules , "--sync" )
120
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
121
+ distributionCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--dist-rules=" + distributionRules , "--sync" )
81
122
82
123
// Download by bundle version, b2 and b3 should not be downloaded, b1 should
83
124
specFile , err = tests .CreateSpec (tests .BundleDownloadSpec )
@@ -102,8 +143,8 @@ func TestBundleDownloadNoPattern(t *testing.T) {
102
143
artifactoryCli .Exec ("u" , "--spec=" + specFile )
103
144
104
145
// Create release bundle
105
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
106
- artifactoryCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
146
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
147
+ distributionCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
107
148
108
149
// Download by bundle name and version with pattern "*", b2 and b3 should not be downloaded, b1 should
109
150
artifactoryCli .Exec ("dl" , "*" , "out/download/simple_by_build/data/" , "--bundle=" + tests .BundleName + "/" + bundleVersion , "--flat" )
@@ -136,8 +177,8 @@ func TestBundleExclusions(t *testing.T) {
136
177
artifactoryCli .Exec ("u" , "--spec=" + specFile )
137
178
138
179
// Create release bundle. Include b1.in and b2.in. Exclude b3.in.
139
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b*.in" , "--sign" , "--exclusions=*b3.in" )
140
- artifactoryCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
180
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b*.in" , "--sign" , "--exclusions=*b3.in" )
181
+ distributionCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
141
182
142
183
// Download by bundle version, b2 and b3 should not be downloaded, b1 should
143
184
artifactoryCli .Exec ("dl " + tests .DistRepo1 + "/data/* " + tests .Out + fileutils .GetFileSeparator ()+ "download" + fileutils .GetFileSeparator ()+ "simple_by_build" + fileutils .GetFileSeparator (), "--bundle=" + tests .BundleName + "/" + bundleVersion , "--exclusions=*b2.in" )
@@ -163,8 +204,8 @@ func TestBundleCopy(t *testing.T) {
163
204
artifactoryCli .Exec ("u" , "--spec=" + specFileB )
164
205
165
206
// Create release bundle
166
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/a*" , "--sign" )
167
- artifactoryCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
207
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/a*" , "--sign" )
208
+ distributionCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
168
209
169
210
// Copy by bundle name and version
170
211
specFile , err := tests .CreateSpec (tests .CopyByBundleSpec )
@@ -187,8 +228,8 @@ func TestBundleSetProperties(t *testing.T) {
187
228
artifactoryCli .Exec ("u" , "testsdata/a/a1.in" , tests .DistRepo1 + "/a.in" )
188
229
189
230
// Create release bundle
190
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/a.in" , "--sign" )
191
- artifactoryCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
231
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/a.in" , "--sign" )
232
+ distributionCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
192
233
193
234
// Set the 'prop=red' property to the file.
194
235
artifactoryCli .Exec ("sp" , tests .DistRepo1 + "/a.*" , "prop=red" , "--bundle=" + tests .BundleName + "/" + bundleVersion )
@@ -222,16 +263,17 @@ func TestSignReleaseBundle(t *testing.T) {
222
263
artifactoryCli .Exec ("u" , "--spec=" + specFile )
223
264
224
265
// Create a release bundle without --sign and make sure it is not signed
225
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" )
226
- distributableResponse := inttestutils .GetLocalBundle (t , tests .BundleName , bundleVersion , artHttpDetails )
266
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" )
267
+ distributableResponse := inttestutils .GetLocalBundle (t , tests .BundleName , bundleVersion , distHttpDetails )
227
268
assert .NotNil (t , distributableResponse )
228
269
assert .Equal (t , inttestutils .Open , distributableResponse .State )
229
270
230
271
// Sign the release bundle and make sure it is signed
231
- artifactoryCli .Exec ("rbs" , tests .BundleName , bundleVersion )
232
- distributableResponse = inttestutils .GetLocalBundle (t , tests .BundleName , bundleVersion , artHttpDetails )
272
+ distributionCli .Exec ("rbs" , tests .BundleName , bundleVersion )
273
+ distributableResponse = inttestutils .GetLocalBundle (t , tests .BundleName , bundleVersion , distHttpDetails )
233
274
assert .NotNil (t , distributableResponse )
234
- assert .Equal (t , inttestutils .Signed , distributableResponse .State )
275
+
276
+ assert .True (t , distributableResponse .State == inttestutils .Signed || distributableResponse .State == inttestutils .ReadyForDistribution )
235
277
236
278
// Cleanup
237
279
cleanDistributionTest (t )
@@ -246,12 +288,12 @@ func TestBundleDeleteLocal(t *testing.T) {
246
288
artifactoryCli .Exec ("u" , "--spec=" + specFile )
247
289
248
290
// Create a release bundle
249
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
250
- inttestutils .VerifyLocalBundleExistence (t , tests .BundleName , bundleVersion , true , artHttpDetails )
291
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
292
+ inttestutils .VerifyLocalBundleExistence (t , tests .BundleName , bundleVersion , true , distHttpDetails )
251
293
252
294
// Delete release bundle locally
253
- artifactoryCli .Exec ("rbdel" , tests .BundleName , bundleVersion , "--site=*" , "--delete-from-dist" , "--quiet" )
254
- inttestutils .VerifyLocalBundleExistence (t , tests .BundleName , bundleVersion , false , artHttpDetails )
295
+ distributionCli .Exec ("rbdel" , tests .BundleName , bundleVersion , "--site=*" , "--delete-from-dist" , "--quiet" )
296
+ inttestutils .VerifyLocalBundleExistence (t , tests .BundleName , bundleVersion , false , distHttpDetails )
255
297
256
298
// Cleanup
257
299
cleanDistributionTest (t )
@@ -266,14 +308,14 @@ func TestUpdateReleaseBundle(t *testing.T) {
266
308
artifactoryCli .Exec ("u" , "--spec=" + specFile )
267
309
268
310
// Create a release bundle with b2.in
269
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b2.in" )
270
- inttestutils .VerifyLocalBundleExistence (t , tests .BundleName , bundleVersion , true , artHttpDetails )
311
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b2.in" )
312
+ inttestutils .VerifyLocalBundleExistence (t , tests .BundleName , bundleVersion , true , distHttpDetails )
271
313
272
314
// Update release bundle to have b1.in
273
- artifactoryCli .Exec ("rbu" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
315
+ distributionCli .Exec ("rbu" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/b1.in" , "--sign" )
274
316
275
317
// Distribute release bundle
276
- artifactoryCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
318
+ distributionCli .Exec ("rbd" , tests .BundleName , bundleVersion , "--site=*" , "--sync" )
277
319
278
320
// Download by bundle version, b2 and b3 should not be downloaded, b1 should
279
321
artifactoryCli .Exec ("dl " + tests .DistRepo1 + "/data/* " + tests .Out + fileutils .GetFileSeparator ()+ "download" + fileutils .GetFileSeparator ()+ "simple_by_build" + fileutils .GetFileSeparator (), "--bundle=" + tests .BundleName + "/" + bundleVersion )
@@ -298,10 +340,10 @@ func TestCreateBundleText(t *testing.T) {
298
340
// Create a release bundle with release notes and description
299
341
releaseNotesPath := filepath .Join (tests .GetTestResourcesPath (), "distribution" , "releasenotes.md" )
300
342
description := "thisIsADescription"
301
- artifactoryCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/*" , "--release-notes-path=" + releaseNotesPath , "--desc=" + description )
343
+ distributionCli .Exec ("rbc" , tests .BundleName , bundleVersion , tests .DistRepo1 + "/data/*" , "--release-notes-path=" + releaseNotesPath , "--desc=" + description )
302
344
303
345
// Validate release notes and description
304
- distributableResponse := inttestutils .GetLocalBundle (t , tests .BundleName , bundleVersion , artHttpDetails )
346
+ distributableResponse := inttestutils .GetLocalBundle (t , tests .BundleName , bundleVersion , distHttpDetails )
305
347
if distributableResponse != nil {
306
348
assert .Equal (t , description , distributableResponse .Description )
307
349
releaseNotes , err := ioutil .ReadFile (releaseNotesPath )
0 commit comments