@@ -2,14 +2,18 @@ package actions
22
33import (
44 "context"
5+ "crypto/elliptic"
56 "testing"
67
78 "github.com/go-logr/logr"
89 . "github.com/onsi/gomega"
10+ "github.com/onsi/gomega/gstruct"
911 "github.com/securesign/operator/api/v1alpha1"
1012 common "github.com/securesign/operator/internal/action"
1113 "github.com/securesign/operator/internal/constants"
1214 "github.com/securesign/operator/internal/labels"
15+ cryptoutil "github.com/securesign/operator/internal/utils/crypto"
16+ fipsTest "github.com/securesign/operator/internal/utils/crypto/test"
1317 v1 "k8s.io/api/core/v1"
1418 "k8s.io/apimachinery/pkg/api/meta"
1519 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -171,3 +175,59 @@ func TestKeyDelete(t *testing.T) {
171175
172176 g .Expect (meta .IsStatusConditionTrue (instance .Status .Conditions , "ctfe.pub" )).To (BeTrue ())
173177}
178+
179+ func TestKeyValidationFailsInFIPS (t * testing.T ) {
180+ g := NewWithT (t )
181+ cryptoutil .FIPSEnabled = true
182+ t .Cleanup (func () {
183+ cryptoutil .FIPSEnabled = false
184+ })
185+
186+ invalidPub , _ , _ , err := fipsTest .GenerateECCertificatePEM (false , "" , elliptic .P224 ())
187+ g .Expect (err ).ToNot (HaveOccurred ())
188+
189+ g .Expect (testAction .Client .Create (testContext , & v1.Secret {
190+ ObjectMeta : metav1.ObjectMeta {
191+ Name : "invalid" ,
192+ Namespace : t .Name (),
193+ },
194+ Data : map [string ][]byte {"key" : invalidPub },
195+ })).To (Succeed ())
196+
197+ instance := & v1alpha1.Tuf {
198+ ObjectMeta : metav1.ObjectMeta {
199+ Name : "tuf" ,
200+ Namespace : t .Name (),
201+ },
202+ Spec : v1alpha1.TufSpec {
203+ Keys : []v1alpha1.TufKey {
204+ {
205+ Name : "rekor.pub" ,
206+ SecretRef : & v1alpha1.SecretKeySelector {
207+ LocalObjectReference : v1alpha1.LocalObjectReference {
208+ Name : "invalid" ,
209+ },
210+ Key : "key" ,
211+ },
212+ },
213+ },
214+ },
215+ Status : v1alpha1.TufStatus {
216+ Conditions : []metav1.Condition {{
217+ Type : constants .Ready ,
218+ Reason : constants .Pending ,
219+ Status : metav1 .ConditionFalse ,
220+ }},
221+ },
222+ }
223+
224+ testAction .Handle (testContext , instance )
225+
226+ g .Expect (meta .IsStatusConditionFalse (instance .Status .Conditions , "rekor.pub" )).To (BeTrue ())
227+ g .Expect (meta .FindStatusCondition (instance .Status .Conditions , "rekor.pub" )).To (
228+ gstruct .PointTo (SatisfyAll (
229+ HaveField ("Reason" , Equal (constants .Failure )),
230+ HaveField ("Message" , ContainSubstring ("FIPS" )),
231+ )),
232+ )
233+ }
0 commit comments