Skip to content

Commit

Permalink
Make the signing key optinal jf release-bundle-create (#2762)
Browse files Browse the repository at this point in the history
  • Loading branch information
oshratZairi committed Nov 27, 2024
1 parent cbf2b00 commit bb3329f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
55 changes: 31 additions & 24 deletions lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ import (
)

const (
artifactoryLifecycleMinVersion = "7.68.3"
gpgKeyPairName = "lc-tests-key-pair"
lcTestdataPath = "lifecycle"
releaseBundlesSpec = "release-bundles-spec.json"
buildsSpec12 = "builds-spec-1-2.json"
buildsSpec3 = "builds-spec-3.json"
prodEnvironment = "PROD"
number1, number2, number3 = "111", "222", "333"
artifactoryLifecycleMinVersion = "7.68.3"
signingKeyOptionalArtifactoryMinVersion = "7.101.1"
gpgKeyPairName = "lc-tests-key-pair"
lcTestdataPath = "lifecycle"
releaseBundlesSpec = "release-bundles-spec.json"
buildsSpec12 = "builds-spec-1-2.json"
buildsSpec3 = "builds-spec-3.json"
prodEnvironment = "PROD"
number1, number2, number3 = "111", "222", "333"
withoutSigningKey = true
)

var (
Expand All @@ -45,7 +47,7 @@ var (
)

func TestBackwardCompatibleReleaseBundleCreation(t *testing.T) {
cleanCallback := initLifecycleTest(t)
cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion)
defer cleanCallback()
lcManager := getLcServiceManager(t)

Expand Down Expand Up @@ -95,26 +97,31 @@ func TestReleaseBundleCreationFromArtifacts(t *testing.T) {
}

func TestReleaseBundleCreationFromArtifactsWithoutSigningKey(t *testing.T) {
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), true)
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), withoutSigningKey)
}

func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string, withoutKey bool) {
cleanCallback := initLifecycleTest(t)
defer cleanCallback()
lcManager := getLcServiceManager(t)
func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string, withoutSigningKey bool) {
if withoutSigningKey {
cleanCallback := initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion)
defer cleanCallback()
} else {
cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion)
defer cleanCallback()
}

lcManager := getLcServiceManager(t)
specFile, err := tests.CreateSpec(uploadSpec)
assert.NoError(t, err)
runRt(t, "upload", "--spec="+specFile)

createRbFromSpec(t, creationSpec, tests.LcRbName1, number1, true, withoutKey)
createRbFromSpec(t, creationSpec, tests.LcRbName1, number1, true, withoutSigningKey)
defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1)

assertRbArtifacts(t, lcManager, tests.LcRbName1, number1, expected)
}

func TestLifecycleFullFlow(t *testing.T) {
cleanCallback := initLifecycleTest(t)
cleanCallback := initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion)
defer cleanCallback()
lcManager := getLcServiceManager(t)

Expand Down Expand Up @@ -165,7 +172,7 @@ func TestLifecycleFullFlow(t *testing.T) {

// Import bundles only work on onPerm platforms
func TestImportReleaseBundle(t *testing.T) {
cleanCallback := initLifecycleTest(t)
cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion)
defer cleanCallback()
wd, err := os.Getwd()
assert.NoError(t, err)
Expand Down Expand Up @@ -202,24 +209,23 @@ func createRbBackwardCompatible(t *testing.T, specName, sourceOption, rbName, rb
createRb(t, specFile, sourceOption, rbName, rbVersion, sync, false)
}

func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync bool, withoutKey bool) {
func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync bool, withoutSigningKey bool) {
specFile, err := tests.CreateSpec(specName)
assert.NoError(t, err)
createRb(t, specFile, "spec", rbName, rbVersion, sync, withoutKey)
createRb(t, specFile, "spec", rbName, rbVersion, sync, withoutSigningKey)
}

func createRb(t *testing.T, specFilePath, sourceOption, rbName, rbVersion string, sync bool, withoutKey bool) {
func createRb(t *testing.T, specFilePath, sourceOption, rbName, rbVersion string, sync bool, withoutSigningKey bool) {
argsAndOptions := []string{
"rbc",
rbName,
rbVersion,
getOption(sourceOption, specFilePath),
}

if !withoutKey {
if !withoutSigningKey {
argsAndOptions = append(argsAndOptions, getOption(cliutils.SigningKey, gpgKeyPairName))
}

// Add the --sync option only if requested, to test the default value.
if sync {
argsAndOptions = append(argsAndOptions, getOption(cliutils.Sync, "true"))
Expand Down Expand Up @@ -371,11 +377,12 @@ func uploadBuildWithDeps(t *testing.T, buildName, buildNumber string) {
runRt(t, "build-publish", buildName, buildNumber)
}

func initLifecycleTest(t *testing.T) (cleanCallback func()) {
func initLifecycleTest(t *testing.T, minVersion string) (cleanCallback func()) {
if !*tests.TestLifecycle {
t.Skip("Skipping lifecycle test. To run release bundle test add the '-test.lc=true' option.")
}
validateArtifactoryVersion(t, artifactoryLifecycleMinVersion)

validateArtifactoryVersion(t, minVersion)

if !isLifecycleSupported(t) {
t.Skip("Skipping lifecycle test because the functionality is not enabled on the provided JPD.")
Expand Down
2 changes: 1 addition & 1 deletion utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ var flagsMap = map[string]cli.Flag{
},
lcSigningKey: cli.StringFlag{
Name: SigningKey,
Usage: "[Mandatory] The GPG/RSA key-pair name given in Artifactory.` `",
Usage: "[Optional] The GPG/RSA key-pair name given in Artifactory. If the key isn't provided, the command creates or uses the default key.` `",
},
lcPathMappingPattern: cli.StringFlag{
Name: PathMappingPattern,
Expand Down

0 comments on commit bb3329f

Please sign in to comment.