@@ -22,7 +22,6 @@ import (
2222 "bytes"
2323 "crypto/x509"
2424 "encoding/base64"
25- "encoding/json"
2625 "errors"
2726 "fmt"
2827 "io"
@@ -233,18 +232,53 @@ func TestSLSAProvenanceFromSignature(t *testing.T) {
233232 },
234233 err : errors .New ("unsupported attestation predicate type: kaboom" ),
235234 },
235+ {
236+ name : "schema validation fails - missing subject" ,
237+ setup : func (l * mockSignature ) {
238+ payload := encode (`{
239+ "_type": "https://in-toto.io/Statement/v0.1",
240+ "predicateType": "https://slsa.dev/provenance/v0.2",
241+ "predicate": {"builder": {"id": "https://my.builder"}, "buildType": "https://my.build.type"}
242+ }` )
243+ l .On ("MediaType" ).Return (types .MediaType (ct .DssePayloadType ), nil )
244+ l .On ("Uncompressed" ).Return (buffy (fmt .Sprintf (`{"payload":"%s"}` , payload )), nil )
245+ l .On ("Base64Signature" ).Return ("" , nil )
246+ l .On ("Cert" ).Return (& x509.Certificate {}, nil )
247+ l .On ("Chain" ).Return ([]* x509.Certificate {}, nil )
248+ },
249+ err : errors .New ("attestation does not conform to SLSA v0.2 schema: jsonschema: '' does not validate with https://slsa.dev/provenance/v0.2#/required: missing properties: 'subject'" ),
250+ },
251+ {
252+ name : "schema validation fails - missing builder" ,
253+ setup : func (l * mockSignature ) {
254+ payload := encode (`{
255+ "_type": "https://in-toto.io/Statement/v0.1",
256+ "subject": [{"name": "example.com/test", "digest": {"sha256": "abc123"}}],
257+ "predicateType": "https://slsa.dev/provenance/v0.2",
258+ "predicate": {"buildType": "https://my.build.type"}
259+ }` )
260+ l .On ("MediaType" ).Return (types .MediaType (ct .DssePayloadType ), nil )
261+ l .On ("Uncompressed" ).Return (buffy (fmt .Sprintf (`{"payload":"%s"}` , payload )), nil )
262+ l .On ("Base64Signature" ).Return ("" , nil )
263+ l .On ("Cert" ).Return (& x509.Certificate {}, nil )
264+ l .On ("Chain" ).Return ([]* x509.Certificate {}, nil )
265+ },
266+ err : errors .New ("attestation does not conform to SLSA v0.2 schema: jsonschema: '/predicate' does not validate with https://slsa.dev/provenance/v0.2#/properties/predicate/required: missing properties: 'builder'" ),
267+ },
236268 {
237269 name : "cannot create entity signature" ,
238270 data : `{
239271 "_type": "https://in-toto.io/Statement/v0.1",
272+ "subject": [{"name": "example.com/test", "digest": {"sha256": "abc123"}}],
240273 "predicateType": "https://slsa.dev/provenance/v0.2",
241- "predicate": {"buildType": "https://my.build.type"}
274+ "predicate": {"builder": {"id": "https://my.builder"}, " buildType": "https://my.build.type"}
242275 }` ,
243276 setup : func (l * mockSignature ) {
244277 payload := encode (`{
245278 "_type": "https://in-toto.io/Statement/v0.1",
279+ "subject": [{"name": "example.com/test", "digest": {"sha256": "abc123"}}],
246280 "predicateType": "https://slsa.dev/provenance/v0.2",
247- "predicate": {"buildType":"https://my.build.type"}
281+ "predicate": {"builder": {"id": "https://my.builder"}, " buildType":"https://my.build.type"}
248282 }` )
249283 l .On ("MediaType" ).Return (types .MediaType (ct .DssePayloadType ), nil )
250284 l .On ("Uncompressed" ).Return (buffy (fmt .Sprintf (`{"payload":"%s"}` , payload )), nil )
@@ -256,16 +290,18 @@ func TestSLSAProvenanceFromSignature(t *testing.T) {
256290 name : "valid with signature from payload" ,
257291 data : `{
258292 "_type": "https://in-toto.io/Statement/v0.1",
293+ "subject": [{"name": "example.com/test", "digest": {"sha256": "abc123"}}],
259294 "predicateType": "https://slsa.dev/provenance/v0.2",
260- "predicate": {"buildType": "https://my.build.type"}
295+ "predicate": {"builder": {"id": "https://my.builder"}, " buildType": "https://my.build.type"}
261296 }` ,
262297 setup : func (l * mockSignature ) {
263298 sig1 := `{"keyid": "key-id-1", "sig": "sig-1"}`
264299 sig2 := `{"keyid": "key-id-2", "sig": "sig-2"}`
265300 payload := encode (`{
266301 "_type": "https://in-toto.io/Statement/v0.1",
302+ "subject": [{"name": "example.com/test", "digest": {"sha256": "abc123"}}],
267303 "predicateType": "https://slsa.dev/provenance/v0.2",
268- "predicate": {"buildType": "https://my.build.type"}
304+ "predicate": {"builder": {"id": "https://my.builder"}, " buildType": "https://my.build.type"}
269305 }` )
270306 l .On ("MediaType" ).Return (types .MediaType (ct .DssePayloadType ), nil )
271307 l .On ("Uncompressed" ).Return (buffy (
@@ -280,16 +316,18 @@ func TestSLSAProvenanceFromSignature(t *testing.T) {
280316 name : "valid with signature from certificate" ,
281317 data : `{
282318 "_type": "https://in-toto.io/Statement/v0.1",
319+ "subject": [{"name": "example.com/test", "digest": {"sha256": "abc123"}}],
283320 "predicateType": "https://slsa.dev/provenance/v0.2",
284- "predicate": {"buildType": "https://my.build.type"}
321+ "predicate": {"builder": {"id": "https://my.builder"}, " buildType": "https://my.build.type"}
285322 }` ,
286323 setup : func (l * mockSignature ) {
287324 sig1 := `{"keyid": "ignored-1", "sig": "ignored-1"}`
288325 sig2 := `{"keyid": "ignored-2", "sig": "ignored-2"}`
289326 payload := encode (`{
290327 "_type": "https://in-toto.io/Statement/v0.1",
328+ "subject": [{"name": "example.com/test", "digest": {"sha256": "abc123"}}],
291329 "predicateType": "https://slsa.dev/provenance/v0.2",
292- "predicate": {"buildType": "https://my.build.type"}
330+ "predicate": {"builder": {"id": "https://my.builder"}, " buildType": "https://my.build.type"}
293331 }` )
294332 l .On ("MediaType" ).Return (types .MediaType (ct .DssePayloadType ), nil )
295333 l .On ("Uncompressed" ).Return (buffy (
0 commit comments