-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: verify sourceURI for npm packages (#521)
* update Signed-off-by: laurentsimon <[email protected]> * update Signed-off-by: laurentsimon <[email protected]> * update Signed-off-by: laurentsimon <[email protected]> * update Signed-off-by: laurentsimon <[email protected]> * Update verifiers/internal/gha/provenance.go Co-authored-by: Ian Lewis <[email protected]> Signed-off-by: laurentsimon <[email protected]> * update Signed-off-by: laurentsimon <[email protected]> --------- Signed-off-by: laurentsimon <[email protected]> Signed-off-by: laurentsimon <[email protected]> Co-authored-by: Ian Lewis <[email protected]>
- Loading branch information
1 parent
5a77b25
commit ae38103
Showing
3 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,10 +160,11 @@ func Test_VerifyDigest(t *testing.T) { | |
func Test_verifySourceURI(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
prov *intoto.ProvenanceStatement | ||
sourceURI string | ||
expected error | ||
name string | ||
prov *intoto.ProvenanceStatement | ||
sourceURI string | ||
allowNoMaterialRef bool | ||
expected error | ||
// v1 provenance does not include materials | ||
skipv1 bool | ||
}{ | ||
|
@@ -288,6 +289,45 @@ func Test_verifySourceURI(t *testing.T) { | |
}, | ||
sourceURI: "https://github.com/some/repo", | ||
}, | ||
{ | ||
name: "match source no git no material ref", | ||
prov: &intoto.ProvenanceStatement{ | ||
Predicate: slsa02.ProvenancePredicate{ | ||
Invocation: slsa02.ProvenanceInvocation{ | ||
ConfigSource: slsa02.ConfigSource{ | ||
URI: "git+https://github.com/some/[email protected]", | ||
}, | ||
}, | ||
Materials: []slsacommon.ProvenanceMaterial{ | ||
{ | ||
URI: "git+https://github.com/some/repo", | ||
}, | ||
}, | ||
}, | ||
}, | ||
allowNoMaterialRef: true, | ||
sourceURI: "https://github.com/some/repo", | ||
}, | ||
{ | ||
name: "match source no git no material ref ref not allowed", | ||
prov: &intoto.ProvenanceStatement{ | ||
Predicate: slsa02.ProvenancePredicate{ | ||
Invocation: slsa02.ProvenanceInvocation{ | ||
ConfigSource: slsa02.ConfigSource{ | ||
URI: "git+https://github.com/some/[email protected]", | ||
}, | ||
}, | ||
Materials: []slsacommon.ProvenanceMaterial{ | ||
{ | ||
URI: "git+https://github.com/some/repo", | ||
}, | ||
}, | ||
}, | ||
}, | ||
sourceURI: "https://github.com/some/repo", | ||
expected: serrors.ErrorMalformedURI, | ||
skipv1: true, | ||
}, | ||
{ | ||
name: "match source no git+https", | ||
prov: &intoto.ProvenanceStatement{ | ||
|
@@ -412,7 +452,7 @@ func Test_verifySourceURI(t *testing.T) { | |
ProvenanceStatement: tt.prov, | ||
} | ||
|
||
err := verifySourceURI(prov02, tt.sourceURI, true) | ||
err := verifySourceURI(prov02, tt.sourceURI, tt.allowNoMaterialRef) | ||
if !errCmp(err, tt.expected) { | ||
t.Errorf(cmp.Diff(err, tt.expected)) | ||
} | ||
|
@@ -433,7 +473,7 @@ func Test_verifySourceURI(t *testing.T) { | |
}, | ||
}, | ||
} | ||
err = verifySourceURI(prov1, tt.sourceURI, true) | ||
err = verifySourceURI(prov1, tt.sourceURI, tt.allowNoMaterialRef) | ||
if !errCmp(err, tt.expected) { | ||
t.Errorf(cmp.Diff(err, tt.expected)) | ||
} | ||
|