@@ -23,12 +23,14 @@ import (
23
23
"testing"
24
24
"time"
25
25
26
+ "github.com/google/go-cmp/cmp"
26
27
"github.com/google/go-sev-guest/abi"
27
28
"github.com/google/go-sev-guest/client"
28
29
spb "github.com/google/go-sev-guest/proto/sevsnp"
29
30
test "github.com/google/go-sev-guest/testing"
30
31
"google.golang.org/protobuf/encoding/prototext"
31
32
"google.golang.org/protobuf/proto"
33
+ "google.golang.org/protobuf/testing/protocmp"
32
34
)
33
35
34
36
var qp client.QuoteProvider
@@ -170,24 +172,53 @@ func TestReadAttestation(t *testing.T) {
170
172
}
171
173
}
172
174
175
+ func protoAttestationDiff (left , right []byte ) string {
176
+ leftp := & spb.Attestation {}
177
+ rightp := & spb.Attestation {}
178
+ if err := proto .Unmarshal (left , leftp ); err != nil {
179
+ return fmt .Sprintf ("left parse: %v" , err )
180
+ }
181
+ if err := proto .Unmarshal (right , rightp ); err != nil {
182
+ return fmt .Sprintf ("right parse: %v" , err )
183
+ }
184
+ return cmp .Diff (leftp , rightp , protocmp .Transform ())
185
+ }
186
+
187
+ func binAttestationDiff (left , right []byte ) string {
188
+ if diff := cmp .Diff (left [:abi .ReportSize ], right [:abi .ReportSize ]); diff != "" {
189
+ return fmt .Sprintf ("Report diff: %s" , diff )
190
+ }
191
+ leftcerts := left [abi .ReportSize :]
192
+ rightcerts := right [abi .ReportSize :]
193
+ leftt := new (abi.CertTable )
194
+ rightt := new (abi.CertTable )
195
+ if err := leftt .Unmarshal (leftcerts ); err != nil {
196
+ return "bad left"
197
+ }
198
+ if err := rightt .Unmarshal (rightcerts ); err != nil {
199
+ return "bad right"
200
+ }
201
+ return cmp .Diff (leftt .Proto (), rightt .Proto (), protocmp .Transform ())
202
+ }
203
+
173
204
func TestTransform (t * testing.T ) {
174
205
mu .Do (initDevice )
175
206
t .Run ("bin" , func (t * testing.T ) {
176
207
binout , err := Transform (input .attestation , "bin" )
177
208
if err != nil {
178
209
t .Fatalf ("Transform(_, \" bin\" ) = _, %v. Expect nil." , err )
179
210
}
180
- if ! bytes . Equal (binout , input .bincerts ) {
181
- t .Fatalf ("Transform(_, \" bin\" ) = %v, nil. Expect %v." , binout , input .bincerts )
211
+ if diff := binAttestationDiff (binout , input .bincerts ); diff != "" {
212
+ t .Fatalf ("Transform(_, \" bin\" ) = %v, nil. Expect %v.\n Diff: %s " , binout , input .bincerts , diff )
182
213
}
183
214
})
184
215
t .Run ("proto" , func (t * testing.T ) {
185
216
protoout , err := Transform (input .attestation , "proto" )
186
217
if err != nil {
187
218
t .Fatalf ("Transform(_, \" proto\" ) = _, %v. Expect nil." , err )
188
219
}
189
- if ! bytes . Equal (protoout , input .protocerts ) {
190
- t .Fatalf ("Transform(_, \" proto\" ) = %v, nil. Expect %v." , protoout , input .protocerts )
220
+ if diff := protoAttestationDiff (protoout , input .protocerts ); diff != "" {
221
+ t .Fatalf ("Transform(_, \" proto\" ) = %v, nil. Expect %v.\n Diff: %s " , protoout , input .protocerts , diff )
191
222
}
192
223
})
193
224
t .Run ("textproto" , func (t * testing.T ) {
0 commit comments