Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Add a test for AmberProvenanceMetadataVerifier
Browse files Browse the repository at this point in the history
  • Loading branch information
rbehjati committed Apr 14, 2022
1 parent b4a790c commit d75b0fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
9 changes: 7 additions & 2 deletions slsa/slsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ import (
const schemaExamplePath = "schema/amber-slsa-buildtype/v1/example.json"

func TestSlsaExampleProvenance(t *testing.T) {
// In the case of running tests bazel exposes data dependencies not in the
// current dir, but in the parent. Hence we need to move one level up.
// The path to provenance is specified relative to the root of the repo, so we need to go one level up.
// Get the current directory before that to restore the path at the end of the test.
currentDir, err := os.Getwd()
if err != nil {
t.Fatalf("couldn't get current directory: %v", err)
}
defer os.Chdir(currentDir)
os.Chdir("../")

// Parses the provenance and validates it against the schema.
Expand Down
28 changes: 24 additions & 4 deletions verify/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,34 @@ import (

const schemaExamplePath = "schema/amber-slsa-buildtype/v1/example.json"

func TestVerifyProvenanceFile(t *testing.T) {
// In the case of running tests bazel exposes data dependencies not in the
// current dir, but in the parent. Hence we need to move one level up.
func TestReproducibleProvenanceVerifier(t *testing.T) {
// The path to provenance is specified relative to the root of the repo, so we need to go one level up.
// Get the current directory before that to restore the path at the end of the test.
currentDir, err := os.Getwd()
if err != nil {
t.Fatalf("couldn't get current directory: %v", err)
}
defer os.Chdir(currentDir)
os.Chdir("../")

verifier := ReproducibleProvenanceVerifier{}

if err := verifier.Verify(schemaExamplePath); err != nil {
t.Fatalf("couldn't verify the provenance file: %v", err)
}
}

func TestAmberProvenanceMetadataVerifier(t *testing.T) {
// The path to provenance is specified relative to the root of the repo, so we need to go one level up.
// Get the current directory before that to restore the path at the end of the test.
currentDir, err := os.Getwd()
if err != nil {
t.Fatalf("couldn't get current directory: %v", err)
}
defer os.Chdir(currentDir)
os.Chdir("../")
verifier := AmberProvenanceMetadataVerifier{}

if err := verifier.Verify(schemaExamplePath); err != nil {
t.Fatalf("couldn't verify the provenance file: %v", err)
}
}

0 comments on commit d75b0fc

Please sign in to comment.