11// Copyright (c) 2020, Control Command Inc. All rights reserved.
2- // Copyright (c) 2019, Sylabs Inc. All rights reserved.
2+ // Copyright (c) 2019-2025 , Sylabs Inc. All rights reserved.
33// Copyright (c) Contributors to the Apptainer project, established as
44// Apptainer a Series of LF Projects LLC.
55// This software is licensed under a 3-clause BSD license. Please consult the
@@ -174,7 +174,7 @@ func (c *ctx) singularityKeyNewpair(t *testing.T) {
174174 {
175175 name : "newpair help" ,
176176 args : []string {"newpair" , "--help" },
177- stdout : "^Create a new key pair" ,
177+ stdout : "^Create a new PGP key- pair" ,
178178 },
179179 {
180180 name : "newpair" ,
@@ -728,6 +728,70 @@ func (c ctx) singularityKeyCmd(t *testing.T) {
728728 c .singularityKeyRemove (t )
729729}
730730
731+ func (c * ctx ) generateCosignKeypair (t * testing.T ) {
732+ testDir := t .TempDir ()
733+
734+ tests := []struct {
735+ name string
736+ args []string
737+ consoleOps []string
738+ expectExit int
739+ expectPrivate string
740+ expectPublic string
741+ }{
742+ {
743+ name : "OK" ,
744+ args : []string {"generate-cosign-key-pair" },
745+ consoleOps : []string {
746+ "test123" ,
747+ "test123" ,
748+ },
749+ expectExit : 0 ,
750+ expectPrivate : filepath .Join (testDir , "singularity-cosign.key" ),
751+ expectPublic : filepath .Join (testDir , "singularity-cosign.pub" ),
752+ },
753+ {
754+ name : "FilesExist" ,
755+ args : []string {"generate-cosign-key-pair" },
756+ expectExit : 255 ,
757+ },
758+ {
759+ name : "Prefix" ,
760+ args : []string {"generate-cosign-key-pair" , "--output-key-prefix" , "test" },
761+ consoleOps : []string {
762+ "test123" ,
763+ "test123" ,
764+ },
765+ expectExit : 0 ,
766+ expectPrivate : filepath .Join (testDir , "test.key" ),
767+ expectPublic : filepath .Join (testDir , "test.pub" ),
768+ },
769+ }
770+
771+ for _ , tt := range tests {
772+ c .env .RunSingularity (
773+ t ,
774+ e2e .AsSubtest (tt .name ),
775+ e2e .WithProfile (e2e .UserProfile ),
776+ e2e .ConsoleRun (buildConsoleLines (tt .consoleOps ... )... ),
777+ e2e .WithDir (testDir ),
778+ e2e .WithCommand ("key" ),
779+ e2e .WithArgs (tt .args ... ),
780+ e2e .ExpectExit (tt .expectExit ),
781+ )
782+ if tt .expectPrivate != "" {
783+ if ! e2e .PathExists (t , tt .expectPrivate ) {
784+ t .Errorf ("Private key %q not found" , tt .expectPrivate )
785+ }
786+ }
787+ if tt .expectPublic != "" {
788+ if ! e2e .PathExists (t , tt .expectPublic ) {
789+ t .Errorf ("Public key %q not found" , tt .expectPublic )
790+ }
791+ }
792+ }
793+ }
794+
731795// E2ETests is the main func to trigger the test suite
732796func E2ETests (env e2e.TestEnv ) testhelper.Tests {
733797 c := ctx {
@@ -746,5 +810,6 @@ func E2ETests(env e2e.TestEnv) testhelper.Tests {
746810 t .Run ("keyCmd" , c .singularityKeyCmd ) // Run all the tests in order
747811 t .Run ("keyNewpairWithLen" , c .singularityKeyNewpairWithLen ) // We run a separate test for `key newpair --bit-length` because it requires handling a keyring a specific way
748812 },
813+ "cosign" : c .generateCosignKeypair ,
749814 }
750815}
0 commit comments