| 1 |
package client |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto/x509" |
| 5 |
"net/http" |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/google/go-tpm-tools/internal" |
| 9 |
"github.com/google/go-tpm-tools/internal/test" |
| 10 |
pb "github.com/google/go-tpm-tools/proto/attest" |
| 11 |
"google.golang.org/protobuf/proto" |
| 12 |
) |
| 13 |
|
| 14 |
var externalClient = http.DefaultClient |
| 15 |
|
| 16 |
func TestNetworkFetchIssuingCertificate(t *testing.T) { |
| 17 |
attestBytes := test.COS85Nonce9009 |
| 18 |
att := &pb.Attestation{} |
| 19 |
if err := proto.Unmarshal(attestBytes, att); err != nil { |
| 20 |
t.Fatalf("Failed to unmarshal test attestation: %v", err) |
| 21 |
} |
| 22 |
|
| 23 |
akCert, err := x509.ParseCertificate(att.AkCert) |
| 24 |
if err != nil { |
| 25 |
t.Fatalf("Error parsing AK Cert: %v", err) |
| 26 |
} |
| 27 |
|
| 28 |
certChain, err := internal.GetCertificateChain(akCert, externalClient) |
| 29 |
if err != nil { |
| 30 |
t.Error(err) |
| 31 |
} |
| 32 |
if len(certChain) == 0 { |
| 33 |
t.Error("Did not retrieve any certificates.") |
| 34 |
} |
| 35 |
} |