mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-20 23:20:35 -04:00

keyservice joinservice upgrade-agent measurement-reader debugd disk-mapper rewrote joinservice main rewrote some unit tests rewrote upgrade-agent + some grpc functions rewrote measurement-reader rewrote debugd removed unused import removed forgotten zap reference in measurements reader rewrote disk-mapper + tests rewrote packages verify disk-mapper malicious join bootstrapper attestationconfigapi versionapi internal/cloud/azure disk-mapper tests image/upload/internal/cmd rewrote verify (WIP with loglevel increase) rewrote forgotten zap references in disk-mapper rewrote malicious join rewrote bootstrapper rewrote parts of internal/ rewrote attestationconfigapi (WIP) rewrote versionapi cli rewrote internal/cloud/azure rewrote disk-mapper tests (untested by me rn) rewrote image/upload/internal/cmd removed forgotten zap references in verify/cmd rewrote packages hack/oci-pin hack/qemu-metadata-api debugd/internal/debugd/deploy hack/bazel-deps-mirror cli/internal/cmd cli-k8s-compatibility rewrote hack/qemu-metadata-api/server rewrote debugd/internal/debugd/deploy rewrote hack/bazel-deps-mirror rewrote rest of hack/qemu-metadata-api rewrote forgotten zap references in joinservice server rewrote cli/internal/cmd rewrote cli-k8s-compatibility rewrote packages internal/staticupload e2d/internal/upgrade internal/constellation/helm internal/attestation/aws/snp internal/attestation/azure/trustedlaunch joinservice/internal/certcache/amkds some missed unit tests rewrote e2e/internal/upgrade rewrote internal/constellation/helm internal/attestation/aws/snp internal/attestation/azure/trustedlaunch joinservice/internal/certcache/amkds search and replace test logging over all left *_test.go
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package amdkds
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"log/slog"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
|
"github.com/edgelesssys/constellation/v2/joinservice/internal/certcache/amdkds/testdata"
|
|
"github.com/google/go-sev-guest/abi"
|
|
"github.com/google/go-sev-guest/verify/trust"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCertChain(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
getter *stubGetter
|
|
wantErr bool
|
|
}{
|
|
"success": {
|
|
getter: &stubGetter{
|
|
log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)),
|
|
ret: testdata.CertChain,
|
|
},
|
|
},
|
|
"getter error": {
|
|
getter: &stubGetter{
|
|
log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)),
|
|
err: assert.AnError,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
"empty cert chain": {
|
|
getter: &stubGetter{
|
|
log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)),
|
|
ret: nil,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
// Clear the product cert cache to ensure that the test cases are independent.
|
|
trust.ClearProductCertCache()
|
|
|
|
assert := assert.New(t)
|
|
|
|
kdsClient := NewKDSClient(tc.getter)
|
|
|
|
_, _, err := kdsClient.CertChain(abi.NoneReportSigner)
|
|
if tc.wantErr {
|
|
assert.Error(err)
|
|
} else {
|
|
assert.NoError(err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
type stubGetter struct {
|
|
log *slog.Logger
|
|
ret []byte
|
|
err error
|
|
}
|
|
|
|
func (s *stubGetter) Get(url string) ([]byte, error) {
|
|
s.log.Debug(fmt.Sprintf("Request to %s", url))
|
|
return s.ret, s.err
|
|
}
|