@@ -1029,6 +1029,7 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignature(t *testing.T) {
1029
1029
wantErr bool
1030
1030
wantErrMsg string
1031
1031
shouldSign bool
1032
+ beforeFunc func (obj * sourcev1.OCIRepository )
1032
1033
assertConditions []metav1.Condition
1033
1034
}{
1034
1035
{
@@ -1060,6 +1061,49 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignature(t *testing.T) {
1060
1061
* conditions .FalseCondition (sourcev1 .SourceVerifiedCondition , sourcev1 .VerificationError , "failed to verify the signature using provider '<provider>': no matching signatures were found for '<url>'" ),
1061
1062
},
1062
1063
},
1064
+ {
1065
+ name : "verify failed before, removed from spec, remove condition" ,
1066
+ reference : & sourcev1.OCIRepositoryRef {Tag : "6.1.4" },
1067
+ digest : img4 .digest .Hex ,
1068
+ beforeFunc : func (obj * sourcev1.OCIRepository ) {
1069
+ conditions .MarkFalse (obj , sourcev1 .SourceVerifiedCondition , "VerifyFailed" , "fail msg" )
1070
+ obj .Spec .Verify = nil
1071
+ obj .Status .Artifact = & sourcev1.Artifact {Revision : img4 .digest .Hex }
1072
+ },
1073
+ want : sreconcile .ResultSuccess ,
1074
+ },
1075
+ {
1076
+ name : "same artifact, verified before, change in obj gen verify again" ,
1077
+ reference : & sourcev1.OCIRepositoryRef {Tag : "6.1.4" },
1078
+ digest : img4 .digest .Hex ,
1079
+ shouldSign : true ,
1080
+ beforeFunc : func (obj * sourcev1.OCIRepository ) {
1081
+ obj .Status .Artifact = & sourcev1.Artifact {Revision : img4 .digest .Hex }
1082
+ // Set Verified with old observed generation and different reason/message.
1083
+ conditions .MarkTrue (obj , sourcev1 .SourceVerifiedCondition , "Verified" , "verified" )
1084
+ // Set new object generation.
1085
+ obj .SetGeneration (3 )
1086
+ },
1087
+ want : sreconcile .ResultSuccess ,
1088
+ assertConditions : []metav1.Condition {
1089
+ * conditions .TrueCondition (sourcev1 .SourceVerifiedCondition , meta .SucceededReason , "verified signature of digest <digest>" ),
1090
+ },
1091
+ },
1092
+ {
1093
+ name : "no verify for already verified, verified condition remains the same" ,
1094
+ reference : & sourcev1.OCIRepositoryRef {Tag : "6.1.4" },
1095
+ digest : img4 .digest .Hex ,
1096
+ shouldSign : true ,
1097
+ beforeFunc : func (obj * sourcev1.OCIRepository ) {
1098
+ // Artifact present and custom verified condition reason/message.
1099
+ obj .Status .Artifact = & sourcev1.Artifact {Revision : img4 .digest .Hex }
1100
+ conditions .MarkTrue (obj , sourcev1 .SourceVerifiedCondition , "Verified" , "verified" )
1101
+ },
1102
+ want : sreconcile .ResultSuccess ,
1103
+ assertConditions : []metav1.Condition {
1104
+ * conditions .TrueCondition (sourcev1 .SourceVerifiedCondition , "Verified" , "verified" ),
1105
+ },
1106
+ },
1063
1107
}
1064
1108
1065
1109
builder := fakeclient .NewClientBuilder ().WithScheme (testEnv .GetScheme ())
@@ -1147,6 +1191,10 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignature(t *testing.T) {
1147
1191
assertConditions [k ].Message = strings .ReplaceAll (assertConditions [k ].Message , "<provider>" , "cosign" )
1148
1192
}
1149
1193
1194
+ if tt .beforeFunc != nil {
1195
+ tt .beforeFunc (obj )
1196
+ }
1197
+
1150
1198
artifact := & sourcev1.Artifact {}
1151
1199
got , err := r .reconcileSource (ctx , obj , artifact , tmpDir )
1152
1200
if tt .wantErr {
0 commit comments