@@ -528,3 +528,52 @@ func TestInTotoRecord(t *testing.T) {
528
528
assert .Equal (t , table .stopResult , stopResult , "result from record stop did not match expected result" )
529
529
}
530
530
}
531
+
532
+ // TestRecordArtifactWithBlobs ensures that we calculate the same hash for blobs
533
+ func TestRecordArtifactWithBlobs (t * testing.T ) {
534
+ type args struct {
535
+ path string
536
+ hashAlgorithms []string
537
+ }
538
+ tests := []struct {
539
+ name string
540
+ args args
541
+ want map [string ]interface {}
542
+ wantErr error
543
+ }{
544
+ {
545
+ name : "test binary blob without line normalization segments" ,
546
+ args : args {
547
+ path : "foo.tar.gz" ,
548
+ hashAlgorithms : []string {"sha256" , "sha384" , "sha512" },
549
+ },
550
+ want : map [string ]interface {}{"sha256" : "52947cb78b91ad01fe81cd6aef42d1f6817e92b9e6936c1e5aabb7c98514f355" ,
551
+ "sha384" : "ce17464027a7d7c15b15032b404fc76fdbadfa1fa566d7f7747020df2542a293b3098873a98dbbda6e461f7767b8ff6c" ,
552
+ "sha512" : "bb040966a5a6aefb646909f636f7f99c9e16b684a1f0e83a87dc30c3ab4d9dec2f9b0091d8be74bbc78ba29cb0c2dd027c223579028cf9822b0bccc49d493a6d" },
553
+ wantErr : nil ,
554
+ },
555
+ {
556
+ name : "test binary blob with windows-like line breaks as byte segments" ,
557
+ args : args {
558
+ path : "helloworld" ,
559
+ hashAlgorithms : []string {"sha256" , "sha384" , "sha512" },
560
+ },
561
+ want : map [string ]interface {}{"sha256" : "fd895747460401ca62d81f310538110734ff5401f8ef86c3ab27168598225db8" ,
562
+ "sha384" : "ddc3ac40ca8d04929e13c42d555a5a6774d35bfac9e2f4cde5847ab3f12f36831faa3baf1b33922b53d288b352ae4b9a" ,
563
+ "sha512" : "46f0e37e72879843f95ddecc4d511c9ba90241c34b471c2f2caca2784abe185da50ddc5252562b2a911b7cfedafa3e878f0e6b7aa843c136915da5306061e501" },
564
+ wantErr : nil ,
565
+ },
566
+ }
567
+ for _ , tt := range tests {
568
+ t .Run (tt .name , func (t * testing.T ) {
569
+ got , err := RecordArtifact (tt .args .path , tt .args .hashAlgorithms )
570
+ if err != tt .wantErr {
571
+ t .Errorf ("RecordArtifact() error = %v, wantErr %v" , err , tt .wantErr )
572
+ return
573
+ }
574
+ if ! reflect .DeepEqual (got , tt .want ) {
575
+ t .Errorf ("RecordArtifact() got = %v, want %v" , got , tt .want )
576
+ }
577
+ })
578
+ }
579
+ }
0 commit comments