@@ -299,6 +299,113 @@ func TestEvaluateSourceProv_Failure(t *testing.T) {
299299 }
300300}
301301
302+ func createVsaSummary (ref string , verifiedLevels []slsa_types.ControlName ) attest.VsaSummary {
303+ return attest.VsaSummary {
304+ SourceRefs : []string {ref },
305+ VerifiedLevels : verifiedLevels ,
306+ }
307+ }
308+
309+ func TestEvaluateTagProv_Success (t * testing.T ) {
310+ // Controls for mock provenance
311+ tagHygieneEarlier := slsa_types.Control {Name : slsa_types .TagHygiene , Since : earlierFixedTime }
312+ origL2ReviewedSummary := createVsaSummary ("refs/heads/orig" , []slsa_types.ControlName {
313+ slsa_types .ControlName (slsa_types .SlsaSourceLevel2 ), slsa_types .ReviewEnforced })
314+ mainL3Summary := createVsaSummary ("refs/heads/main" , []slsa_types.ControlName {
315+ slsa_types .ControlName (slsa_types .SlsaSourceLevel3 )})
316+
317+ tests := []struct {
318+ name string
319+ protectedTagPolicy * ProtectedTag
320+ vsaSummaries []attest.VsaSummary
321+ expectedLevels slsa_types.SourceVerifiedLevels
322+ }{
323+ {
324+ name : "Policy has protected_tag setting, and enabled" ,
325+ protectedTagPolicy : & ProtectedTag {
326+ Since : fixedTime ,
327+ TagHygiene : true ,
328+ },
329+ vsaSummaries : []attest.VsaSummary {origL2ReviewedSummary },
330+ expectedLevels : slsa_types.SourceVerifiedLevels {slsa_types .ReviewEnforced , slsa_types .ControlName (slsa_types .SlsaSourceLevel2 )},
331+ },
332+ {
333+ name : "Policy has protected_tag setting, and multiple summaries" ,
334+ protectedTagPolicy : & ProtectedTag {
335+ Since : fixedTime ,
336+ TagHygiene : true ,
337+ },
338+ vsaSummaries : []attest.VsaSummary {origL2ReviewedSummary , mainL3Summary },
339+ // The spec says we MUST NOT return multiple levels per track in a VSA...
340+ expectedLevels : slsa_types.SourceVerifiedLevels {
341+ slsa_types .ReviewEnforced , slsa_types .ControlName (slsa_types .SlsaSourceLevel3 )},
342+ },
343+ {
344+ name : "Policy has protected_tag setting, and it's not enabled" ,
345+ protectedTagPolicy : & ProtectedTag {
346+ Since : fixedTime ,
347+ TagHygiene : false ,
348+ },
349+ vsaSummaries : []attest.VsaSummary {origL2ReviewedSummary },
350+ expectedLevels : slsa_types.SourceVerifiedLevels {slsa_types .ControlName (slsa_types .SlsaSourceLevel1 )},
351+ },
352+ {
353+ name : "Policy has protected_tag setting, and it's earlier than the control" ,
354+ protectedTagPolicy : & ProtectedTag {
355+ Since : earlierFixedTime ,
356+ TagHygiene : false ,
357+ },
358+ vsaSummaries : []attest.VsaSummary {origL2ReviewedSummary },
359+ expectedLevels : slsa_types.SourceVerifiedLevels {slsa_types .ControlName (slsa_types .SlsaSourceLevel1 )},
360+ },
361+ {
362+ name : "Policy has no protected_tag setting" ,
363+ protectedTagPolicy : nil ,
364+ vsaSummaries : []attest.VsaSummary {origL2ReviewedSummary },
365+ expectedLevels : slsa_types.SourceVerifiedLevels {slsa_types .ControlName (slsa_types .SlsaSourceLevel1 )},
366+ },
367+ }
368+
369+ for _ , tt := range tests {
370+ t .Run (tt .name , func (t * testing.T ) {
371+ // Valid Provenance Predicate (attest.SourceProvenancePred)
372+ tagProvPred := attest.TagProvenancePred {
373+ Controls : slsa_types.Controls {tagHygieneEarlier },
374+ VsaSummaries : tt .vsaSummaries ,
375+ }
376+
377+ provenanceStatement := createStatementForTest (t , tagProvPred , attest .TagProvPredicateType )
378+
379+ pb := ProtectedBranch {
380+ Name : "main" ,
381+ TargetSlsaSourceLevel : slsa_types .SlsaSourceLevel2 ,
382+ RequireReview : true ,
383+ Since : fixedTime ,
384+ }
385+ rp := createTestPolicy (pb )
386+ rp .ProtectedTag = tt .protectedTagPolicy
387+
388+ expectedPolicyFilePath := createTempPolicyFile (t , rp )
389+ defer os .Remove (expectedPolicyFilePath )
390+ pe := & PolicyEvaluator {UseLocalPolicy : expectedPolicyFilePath }
391+
392+ ghConn := newTestGhBranchConnection ("local" , "local" , "main" )
393+
394+ verifiedLevels , policyPath , err := pe .EvaluateTagProv (context .Background (), ghConn , provenanceStatement )
395+
396+ if err != nil {
397+ t .Errorf ("EvaluateTagProv() error = %v, want nil" , err )
398+ }
399+ if policyPath != expectedPolicyFilePath {
400+ t .Errorf ("EvaluateTagProv() policyPath = %q, want %q" , policyPath , expectedPolicyFilePath )
401+ }
402+ if ! slices .Equal (verifiedLevels , tt .expectedLevels ) {
403+ t .Errorf ("EvaluateTagProv() verifiedLevels = %v, want %v" , verifiedLevels , tt .expectedLevels )
404+ }
405+ })
406+ }
407+ }
408+
302409func TestEvaluateControl_Success (t * testing.T ) {
303410 // Controls
304411 continuityEnforcedEarlier := slsa_types.Control {Name : slsa_types .ContinuityEnforced , Since : earlierFixedTime }
@@ -555,7 +662,7 @@ func assertProtectedBranchEquals(t *testing.T, got *ProtectedBranch, expected Pr
555662 if ignoreSince && actual .Since != (time.Time {}) { // Add note only if Since was ignored AND original got.Since was not zero
556663 errorMessage .WriteString (fmt .Sprintf ("\n (Note: 'Since' field was ignored in comparison as requested. Original Expected.Since: %v, Original Got.Since: %v)" , expected .Since , actual .Since ))
557664 }
558- t .Errorf (errorMessage .String ())
665+ t .Error (errorMessage .String ())
559666 }
560667}
561668
0 commit comments