2023-05-25 12:43:44 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
2023-06-07 10:16:32 -04:00
|
|
|
package attestationconfigapi
|
2023-05-25 12:43:44 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-11-14 04:03:01 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
2023-06-05 06:33:22 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-05-25 12:43:44 -04:00
|
|
|
)
|
|
|
|
|
2023-06-05 06:33:22 -04:00
|
|
|
func TestUploadAzureSEVSNP(t *testing.T) {
|
|
|
|
sut := Client{
|
|
|
|
bucketID: "bucket",
|
|
|
|
signer: fakeSigner{},
|
|
|
|
}
|
2023-11-14 04:03:01 -05:00
|
|
|
version := SEVSNPVersion{}
|
2023-06-05 06:33:22 -04:00
|
|
|
date := time.Date(2023, 1, 1, 1, 1, 1, 1, time.UTC)
|
2023-11-14 04:03:01 -05:00
|
|
|
ops := sut.constructUploadCmd(variant.AzureSEVSNP{}, version, SEVSNPVersionList{list: []string{"2021-01-01-01-01.json", "2019-01-01-01-01.json"}, variant: variant.AzureSEVSNP{}}, date)
|
2023-06-05 06:33:22 -04:00
|
|
|
dateStr := "2023-01-01-01-01.json"
|
2023-08-25 09:10:24 -04:00
|
|
|
assert := assert.New(t)
|
2023-06-05 06:33:22 -04:00
|
|
|
assert.Contains(ops, putCmd{
|
2023-11-14 04:03:01 -05:00
|
|
|
apiObject: SEVSNPVersionAPI{
|
|
|
|
Variant: variant.AzureSEVSNP{},
|
|
|
|
Version: dateStr,
|
|
|
|
SEVSNPVersion: version,
|
2023-06-05 06:33:22 -04:00
|
|
|
},
|
2023-08-25 09:10:24 -04:00
|
|
|
signer: fakeSigner{},
|
2023-06-05 06:33:22 -04:00
|
|
|
})
|
|
|
|
assert.Contains(ops, putCmd{
|
2023-11-14 04:03:01 -05:00
|
|
|
apiObject: SEVSNPVersionList{variant: variant.AzureSEVSNP{}, list: []string{"2023-01-01-01-01.json", "2021-01-01-01-01.json", "2019-01-01-01-01.json"}},
|
2023-08-25 09:10:24 -04:00
|
|
|
signer: fakeSigner{},
|
2023-06-05 06:33:22 -04:00
|
|
|
})
|
|
|
|
}
|
2023-06-01 07:55:46 -04:00
|
|
|
|
2023-06-05 06:33:22 -04:00
|
|
|
func TestDeleteAzureSEVSNPVersions(t *testing.T) {
|
|
|
|
sut := Client{
|
|
|
|
bucketID: "bucket",
|
|
|
|
}
|
2023-11-14 04:03:01 -05:00
|
|
|
versions := SEVSNPVersionList{list: []string{"2023-01-01.json", "2021-01-01.json", "2019-01-01.json"}}
|
2023-06-01 07:55:46 -04:00
|
|
|
|
2023-11-14 04:03:01 -05:00
|
|
|
ops, err := sut.deleteSEVSNPVersion(versions, "2021-01-01")
|
2023-05-25 12:43:44 -04:00
|
|
|
|
2023-06-05 06:33:22 -04:00
|
|
|
assert := assert.New(t)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Contains(ops, deleteCmd{
|
2023-11-14 04:03:01 -05:00
|
|
|
apiObject: SEVSNPVersionAPI{
|
2023-06-05 06:33:22 -04:00
|
|
|
Version: "2021-01-01.json",
|
|
|
|
},
|
|
|
|
})
|
2023-05-25 12:43:44 -04:00
|
|
|
|
2023-06-05 06:33:22 -04:00
|
|
|
assert.Contains(ops, putCmd{
|
2023-11-14 04:03:01 -05:00
|
|
|
apiObject: SEVSNPVersionList{list: []string{"2023-01-01.json", "2019-01-01.json"}},
|
2023-06-05 06:33:22 -04:00
|
|
|
})
|
2023-05-25 12:43:44 -04:00
|
|
|
}
|
|
|
|
|
2023-06-05 06:33:22 -04:00
|
|
|
type fakeSigner struct{}
|
|
|
|
|
|
|
|
func (fakeSigner) Sign(_ []byte) ([]byte, error) {
|
|
|
|
return []byte("signature"), nil
|
2023-05-25 12:43:44 -04:00
|
|
|
}
|