Skip to content

Commit ef8d7d6

Browse files
authored
chore: refactoring the signing test to make it more robust (#657)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it #### Which issue(s) this PR fixes <!-- Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Signed-off-by: Gergely Brautigam <[email protected]>
1 parent c0b9d07 commit ef8d7d6

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

e2e/create_test_component.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ func createTestComponentVersionUnsigned(t *testing.T, componentNameIdentifier st
3535
Setup(setup.AddComponentVersions(podinfo(t, nil, "", componentNameIdentifier, testPath, version)))
3636
}
3737

38-
func createTestComponentVersionSigned(t *testing.T, featureString string, privateKey []byte, keyName string, publicKey []byte, componentNameIdentifier string, testPath string, version string) *features.FeatureBuilder {
38+
func createTestComponentVersionSigned(t *testing.T, featureString string, privateKey []byte, keyName string, componentNameIdentifier string, testPath string, version string) *features.FeatureBuilder {
3939
t.Helper()
40-
secretData := map[string][]byte{
41-
keyName: publicKey,
42-
}
4340
return features.New(featureString).
44-
WithStep("create secret", 1, shared.CreateSecret(keyName, secretData, nil, "")).
4541
WithStep("", 2, setup.AddComponentVersions(podinfoBackend(t, privateKey, keyName, componentNameIdentifier, testPath, version))).
4642
WithStep("", 2, setup.AddComponentVersions(podinfoFrontend(t, privateKey, keyName, componentNameIdentifier, testPath, version))).
4743
WithStep("", 2, setup.AddComponentVersions(podinfoRedis(t, privateKey, keyName, componentNameIdentifier, testPath, version))).

e2e/main_test.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,8 @@ func TestSignedComponentUploadToLocalOCIRegistry(t *testing.T) {
120120
t.Fatal(err)
121121
}
122122

123-
_, invalidPublicKey, err := createRSAKeys()
124-
if err != nil {
125-
t.Fatal(err)
126-
}
127-
128-
setupComponent := createTestComponentVersionSigned(t, "Add signed components to component-version", privateKey, keyName, invalidPublicKey, componentNameIdentifier, testSignedComponentsPath, version1)
123+
createSigningSecret := features.New("Create signing secret").WithStep("create valid rsa key secret", 1, shared.CreateSecret(keyName, map[string][]byte{keyName: publicKey}, nil, ""))
124+
setupComponent := createTestComponentVersionSigned(t, "Add signed components to component-version", privateKey, keyName, componentNameIdentifier, testSignedComponentsPath, version1)
129125
validation := features.New("Validate if signed OCM Components are present in OCI Registry").
130126
Setup(setup.AddScheme(v1alpha1.AddToScheme)).
131127
Setup(setup.AddScheme(sourcev1.AddToScheme)).
@@ -136,16 +132,14 @@ func TestSignedComponentUploadToLocalOCIRegistry(t *testing.T) {
136132
Assess("Validate Component "+podinfoComponentName, checkRepositoryExistsInRegistry(componentNamePrefix+componentNameIdentifier+podinfoComponentName)).
137133
Assess("Validate Component "+podinfoBackendComponentName, checkRepositoryExistsInRegistry(componentNamePrefix+componentNameIdentifier+podinfoBackendComponentName)).
138134
Assess("Validate Component "+podinfoFrontendComponentName, checkRepositoryExistsInRegistry(componentNamePrefix+componentNameIdentifier+podinfoFrontendComponentName)).
139-
Assess("Validate Component "+redisComponentName, checkRepositoryExistsInRegistry(componentNamePrefix+componentNameIdentifier+redisComponentName)).
140-
Teardown(shared.DeleteSecret(keyName))
135+
Assess("Validate Component "+redisComponentName, checkRepositoryExistsInRegistry(componentNamePrefix+componentNameIdentifier+redisComponentName))
141136

142137
signatureVerification := features.New("Validate if signed Component Versions of OCM Components exist").
143-
WithStep("create valid rsa key secret", 1, shared.CreateSecret(keyName, map[string][]byte{keyName: publicKey}, nil, "")).
144-
Assess("Check that component version "+cvName+" is ready and signature was verified", checkIsComponentVersionReady(cvName, ocmNamespace)).
145-
Teardown(shared.DeleteSecret(keyName))
138+
Assess("Check that component version "+cvName+" is ready and signature was verified", checkIsComponentVersionReady(cvName, ocmNamespace))
146139

147140
testEnv.Test(t,
148141
setupComponent.Feature(),
142+
createSigningSecret.Feature(),
149143
validation.Feature(),
150144
signatureVerification.Feature(),
151145
)

0 commit comments

Comments
 (0)