Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn the signing key to be optional in RBC #2759

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions lifecycle/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ func validateCreateReleaseBundleContext(c *cli.Context) error {
return cliutils.WrongNumberOfArgumentsHandler(c)
}

if err := assertSigningKeyProvided(c); err != nil {
return err
}

return assertValidCreationMethod(c)
}

Expand Down Expand Up @@ -188,10 +184,6 @@ func promote(c *cli.Context) error {
return cliutils.WrongNumberOfArgumentsHandler(c)
}

if err := assertSigningKeyProvided(c); err != nil {
return err
}

lcDetails, err := createLifecycleDetailsByFlags(c)
if err != nil {
return err
Expand Down Expand Up @@ -358,13 +350,6 @@ func validateDistributeCommand(c *cli.Context) error {
return nil
}

func assertSigningKeyProvided(c *cli.Context) error {
if c.String(cliutils.SigningKey) == "" {
return errorutils.CheckErrorf("the --%s option is mandatory", cliutils.SigningKey)
}
return nil
}

func createLifecycleDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) {
lcDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, commonCliUtils.Platform)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions lifecycle/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestValidateCreateReleaseBundleContext(t *testing.T) {
{"extraArgs", []string{"one", "two", "three", "four"}, []string{}, true},
{"bothSources", []string{"one", "two", "three"}, []string{cliutils.Builds + "=/path/to/file", cliutils.ReleaseBundles + "=/path/to/file"}, true},
{"noSources", []string{"one", "two", "three"}, []string{}, true},
{"builds without signing key", []string{"name", "version"}, []string{cliutils.Builds + "=/path/to/file"}, true},
{"builds without signing key", []string{"name", "version"}, []string{cliutils.Builds + "=/path/to/file"}, false},
{"builds correct", []string{"name", "version"}, []string{
cliutils.Builds + "=/path/to/file", cliutils.SigningKey + "=key"}, false},
{"releaseBundles without signing key", []string{"name", "version", "env"}, []string{cliutils.ReleaseBundles + "=/path/to/file"}, true},
{"releaseBundles without signing key", []string{"name", "version"}, []string{cliutils.ReleaseBundles + "=/path/to/file"}, false},
{"releaseBundles correct", []string{"name", "version"}, []string{
cliutils.ReleaseBundles + "=/path/to/file", cliutils.SigningKey + "=key"}, false},
{"spec without signing key", []string{"name", "version", "env"}, []string{"spec=/path/to/file"}, true},
Expand Down
32 changes: 20 additions & 12 deletions lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ func compareRbArtifacts(t *testing.T, actual services.ReleaseBundleSpecResponse,
}

func TestReleaseBundleCreationFromAql(t *testing.T) {
testReleaseBundleCreation(t, tests.UploadDevSpecA, tests.LifecycleAql, tests.GetExpectedLifecycleCreationByAql())
testReleaseBundleCreation(t, tests.UploadDevSpecA, tests.LifecycleAql, tests.GetExpectedLifecycleCreationByAql(), false)
}

func TestReleaseBundleCreationFromArtifacts(t *testing.T) {
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts())
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), false)
}

func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string) {
func TestReleaseBundleCreationFromArtifactsWithoutSigningKey(t *testing.T) {
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), true)
}

func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string, withoutKey bool) {
cleanCallback := initLifecycleTest(t)
defer cleanCallback()
lcManager := getLcServiceManager(t)
Expand All @@ -103,7 +107,7 @@ func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, ex
assert.NoError(t, err)
runRt(t, "upload", "--spec="+specFile)

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

assertRbArtifacts(t, lcManager, tests.LcRbName1, number1, expected)
Expand All @@ -119,17 +123,17 @@ func TestLifecycleFullFlow(t *testing.T) {
defer deleteBuilds()

// Create release bundle from builds synchronously.
createRbFromSpec(t, tests.LifecycleBuilds12, tests.LcRbName1, number1, true)
createRbFromSpec(t, tests.LifecycleBuilds12, tests.LcRbName1, number1, true, false)
defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1)

// Create release bundle from a build asynchronously and assert status.
// This build has dependencies which are included in the release bundle.
createRbFromSpec(t, tests.LifecycleBuilds3, tests.LcRbName2, number2, false)
createRbFromSpec(t, tests.LifecycleBuilds3, tests.LcRbName2, number2, false, false)
defer deleteReleaseBundle(t, lcManager, tests.LcRbName2, number2)
assertStatusCompleted(t, lcManager, tests.LcRbName2, number2, "")

// Create a combined release bundle from the two previous release bundle.
createRbFromSpec(t, tests.LifecycleReleaseBundles, tests.LcRbName3, number3, true)
createRbFromSpec(t, tests.LifecycleReleaseBundles, tests.LcRbName3, number3, true, false)
defer deleteReleaseBundle(t, lcManager, tests.LcRbName3, number3)

// Promote the last release bundle to prod repo 1.
Expand Down Expand Up @@ -195,23 +199,27 @@ func uploadBuilds(t *testing.T) func() {
func createRbBackwardCompatible(t *testing.T, specName, sourceOption, rbName, rbVersion string, sync bool) {
specFile, err := getSpecFile(specName)
assert.NoError(t, err)
createRb(t, specFile, sourceOption, rbName, rbVersion, sync)
createRb(t, specFile, sourceOption, rbName, rbVersion, sync, false)
}

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

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

if !withoutKey {
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
Loading