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-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-06-07 10:16:32 -04:00
|
|
|
version := AzureSEVSNPVersion{}
|
2023-06-05 06:33:22 -04:00
|
|
|
date := time.Date(2023, 1, 1, 1, 1, 1, 1, time.UTC)
|
2023-08-25 09:10:24 -04:00
|
|
|
ops := sut.constructUploadCmd(version, []string{"2021-01-01-01-01.json", "2019-01-01-01-01.json"}, 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-06-07 10:16:32 -04:00
|
|
|
apiObject: AzureSEVSNPVersionAPI{
|
2023-06-05 06:33:22 -04:00
|
|
|
Version: dateStr,
|
|
|
|
AzureSEVSNPVersion: version,
|
|
|
|
},
|
2023-08-25 09:10:24 -04:00
|
|
|
signer: fakeSigner{},
|
2023-06-05 06:33:22 -04:00
|
|
|
})
|
|
|
|
assert.Contains(ops, putCmd{
|
2023-06-07 10:16:32 -04:00
|
|
|
apiObject: AzureSEVSNPVersionList([]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-06-07 10:16:32 -04:00
|
|
|
versions := AzureSEVSNPVersionList([]string{"2023-01-01.json", "2021-01-01.json", "2019-01-01.json"})
|
2023-06-01 07:55:46 -04:00
|
|
|
|
2023-06-05 06:33:22 -04:00
|
|
|
ops, err := sut.deleteAzureSEVSNPVersion(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-06-07 10:16:32 -04:00
|
|
|
apiObject: AzureSEVSNPVersionAPI{
|
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-06-07 10:16:32 -04:00
|
|
|
apiObject: AzureSEVSNPVersionList([]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
|
|
|
}
|