-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp tests for v0.2.2 add more fixtures
This commit udpates and improves the project's tests to work with the new spec v0.2.0. It also adds various new documents to widen the test cases and ensure compatibility with the previous spec version. Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
- Loading branch information
Showing
14 changed files
with
12,840 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ SPDX-License-Identifier: Apache-2.0 | |
package ctl | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
intoto "github.com/in-toto/in-toto-golang/in_toto" | ||
|
@@ -106,11 +107,15 @@ func TestListDocumentProducts(t *testing.T) { | |
}, | ||
}, | ||
{ | ||
"testdata/document1.vex.json", | ||
"testdata/v001-1.vex.json", | ||
[]string{"pkg:apk/wolfi/[email protected]"}, | ||
}, | ||
{ | ||
"testdata/v020-1.vex.json", | ||
[]string{"pkg:apk/wolfi/[email protected]"}, | ||
}, | ||
} { | ||
doc, err := vex.OpenJSON(tc.path) | ||
doc, err := vex.Open(tc.path) | ||
require.NoError(t, err) | ||
prods, err := impl.ListDocumentProducts(doc) | ||
require.NoError(t, err) | ||
|
@@ -155,7 +160,18 @@ func TestVerifyImageSubjects(t *testing.T) { | |
doc := vex.New() | ||
for _, p := range tc.products { | ||
doc.Statements = append( | ||
doc.Statements, vex.Statement{Products: []string{p}}, | ||
doc.Statements, vex.Statement{ | ||
Products: []vex.Product{ | ||
{ | ||
Component: vex.Component{ | ||
ID: p, | ||
Hashes: map[vex.Algorithm]vex.Hash{}, | ||
Identifiers: map[vex.IdentifierType]string{}, | ||
}, | ||
Subcomponents: []vex.Subcomponent{}, | ||
}, | ||
}, | ||
}, | ||
) | ||
} | ||
err := impl.VerifyImageSubjects(att, &doc) | ||
|
@@ -166,3 +182,90 @@ func TestVerifyImageSubjects(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestMerge(t *testing.T) { | ||
ctx := context.Background() | ||
doc1, err := vex.Open("testdata/v001-1.vex.json") | ||
require.NoError(t, err) | ||
doc2, err := vex.Open("testdata/v001-2.vex.json") | ||
require.NoError(t, err) | ||
|
||
doc3, err := vex.Open("testdata/v020-1.vex.json") | ||
require.NoError(t, err) | ||
doc4, err := vex.Open("testdata/v020-2.vex.json") | ||
require.NoError(t, err) | ||
|
||
impl := defaultVexCtlImplementation{} | ||
for _, tc := range []struct { | ||
opts MergeOptions | ||
docs []*vex.VEX | ||
expectedDoc *vex.VEX | ||
shouldErr bool | ||
}{ | ||
// Zero docs should fail | ||
{ | ||
opts: MergeOptions{}, | ||
docs: []*vex.VEX{}, | ||
expectedDoc: &vex.VEX{}, | ||
shouldErr: true, | ||
}, | ||
// One doc results in the same doc | ||
{ | ||
opts: MergeOptions{}, | ||
docs: []*vex.VEX{doc1}, | ||
expectedDoc: doc1, | ||
shouldErr: false, | ||
}, | ||
// Two docs, as they are | ||
{ | ||
opts: MergeOptions{}, | ||
docs: []*vex.VEX{doc1, doc2}, | ||
expectedDoc: &vex.VEX{ | ||
Metadata: vex.Metadata{}, | ||
Statements: []vex.Statement{ | ||
doc1.Statements[0], | ||
doc2.Statements[0], | ||
}, | ||
}, | ||
shouldErr: false, | ||
}, | ||
// Two docs, filter product | ||
{ | ||
opts: MergeOptions{ | ||
Products: []string{"pkg:apk/wolfi/[email protected]"}, | ||
}, | ||
docs: []*vex.VEX{doc3, doc4}, | ||
expectedDoc: &vex.VEX{ | ||
Metadata: vex.Metadata{}, | ||
Statements: []vex.Statement{ | ||
doc4.Statements[0], | ||
}, | ||
}, | ||
shouldErr: false, | ||
}, | ||
// Two docs, filter vulnerability | ||
{ | ||
opts: MergeOptions{ | ||
Vulnerabilities: []string{"CVE-9876-54321"}, | ||
}, | ||
docs: []*vex.VEX{doc3, doc4}, | ||
expectedDoc: &vex.VEX{ | ||
Metadata: vex.Metadata{}, | ||
Statements: []vex.Statement{ | ||
doc3.Statements[0], | ||
}, | ||
}, | ||
shouldErr: false, | ||
}, | ||
} { | ||
doc, err := impl.Merge(ctx, &tc.opts, tc.docs) | ||
if tc.shouldErr { | ||
require.Error(t, err) | ||
continue | ||
} | ||
|
||
// Check doc | ||
require.Len(t, doc.Statements, len(tc.expectedDoc.Statements)) | ||
require.Equal(t, doc.Statements, tc.expectedDoc.Statements) | ||
} | ||
} |
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
Oops, something went wrong.