mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
Fix tests and linting (#370)
* Fix license integration test * Fix build tags in lint config * Fix missing error checks * Fix use of MarkNodeAsInitialized * Fix attestation tests * Add license integration test to cmake list
This commit is contained in:
parent
397c9013ea
commit
0969ff4ac3
@ -1,13 +1,14 @@
|
||||
run:
|
||||
timeout: 5m
|
||||
|
||||
output:
|
||||
format: tab
|
||||
sort-results: true
|
||||
timeout: 10m
|
||||
build-tags:
|
||||
- integration
|
||||
- aws
|
||||
- gcp
|
||||
- azure
|
||||
|
||||
output:
|
||||
format: tab
|
||||
sort-results: true
|
||||
|
||||
linters:
|
||||
enable:
|
||||
|
@ -71,3 +71,4 @@ add_test(NAME unit-node-operator COMMAND go test -race -count=3 ./... WORKING_DI
|
||||
add_test(NAME integration-node-operator COMMAND make test WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/operators/constellation-node-operator)
|
||||
add_test(NAME integration-mount COMMAND bash -c "go test -tags integration -c ./test/ && sudo ./test.test -test.v -v 9" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/mount)
|
||||
add_test(NAME integration-dm COMMAND bash -c "go test -tags integration -c ./test/ && sudo ./test.test -test.v" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/state/internal)
|
||||
add_test(NAME integration-license COMMAND bash -c "go test -tags integration" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/internal/license)
|
||||
|
@ -22,7 +22,7 @@ func TestAttestation(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
issuer := NewIssuer()
|
||||
validator := NewValidator(map[uint32][]byte{}) // TODO: check for list of expected Azure PCRs
|
||||
validator := NewValidator(map[uint32][]byte{}, nil) // TODO: check for list of expected Azure PCRs
|
||||
|
||||
nonce := []byte{2, 3, 4}
|
||||
challenge := []byte("Constellation")
|
||||
@ -41,7 +41,7 @@ func TestAttestation(t *testing.T) {
|
||||
assert.Equal(challenge, out)
|
||||
|
||||
// Mark node as intialized. We should still be abe to validate
|
||||
assert.NoError(vtpm.MarkNodeAsInitialized(vtpm.OpenVTPM, []byte("Test"), []byte("Nonce")))
|
||||
assert.NoError(vtpm.MarkNodeAsBootstrapped(vtpm.OpenVTPM, []byte("Test")))
|
||||
|
||||
attDocRaw, err = issuer.Issue(challenge, nonce)
|
||||
assert.NoError(err)
|
||||
|
@ -20,9 +20,10 @@ func TestMain(m *testing.M) {
|
||||
func TestAttestation(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
PCR0 := []byte{0x0f, 0x35, 0xc2, 0x14, 0x60, 0x8d, 0x93, 0xc7, 0xa6, 0xe6, 0x8a, 0xe7, 0x35, 0x9b, 0x4a, 0x8b, 0xe5, 0xa0, 0xe9, 0x9e, 0xea, 0x91, 0x07, 0xec, 0xe4, 0x27, 0xc4, 0xde, 0xa4, 0xe4, 0x39, 0xcf}
|
||||
|
||||
issuer := NewIssuer()
|
||||
validator := NewValidator(map[uint32][]byte{0: PCR0})
|
||||
validator := NewValidator(map[uint32][]byte{0: PCR0}, nil)
|
||||
|
||||
nonce := []byte{2, 3, 4}
|
||||
challenge := []byte("Constellation")
|
||||
@ -41,7 +42,7 @@ func TestAttestation(t *testing.T) {
|
||||
assert.Equal(challenge, out)
|
||||
|
||||
// Mark node as intialized. We should still be abe to validate
|
||||
assert.NoError(vtpm.MarkNodeAsInitialized(vtpm.OpenVTPM, []byte("Test"), []byte("Nonce")))
|
||||
assert.NoError(vtpm.MarkNodeAsBootstrapped(vtpm.OpenVTPM, []byte("Test")))
|
||||
|
||||
attDocRaw, err = issuer.Issue(challenge, nonce)
|
||||
assert.NoError(err)
|
||||
|
@ -21,7 +21,7 @@ func (s simTPMNOPCloser) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestMarkNodeAsInitialized(t *testing.T) {
|
||||
func TestMarkNodeAsBootstrapped(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
package license
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
func TestCheckQuotaIntegration(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
license string
|
||||
action string
|
||||
action Action
|
||||
wantQuota int
|
||||
wantError bool
|
||||
}{
|
||||
@ -48,10 +49,11 @@ func TestCheckQuotaIntegration(t *testing.T) {
|
||||
|
||||
client := NewClient()
|
||||
|
||||
resp, err := client.CheckQuota(CheckQuotaRequest{
|
||||
req := CheckQuotaRequest{
|
||||
Action: tc.action,
|
||||
License: tc.license,
|
||||
})
|
||||
}
|
||||
resp, err := client.CheckQuota(context.Background(), req)
|
||||
|
||||
if tc.wantError {
|
||||
assert.Error(err)
|
||||
|
@ -106,16 +106,17 @@ func cleanUpBucket(ctx context.Context, require *require.Assertions, bucketID st
|
||||
objects = append(objects, *output.Contents[i].Key)
|
||||
}
|
||||
// Delete all objects of the bucket
|
||||
cleanUpObjects(ctx, client, bucketID, objects)
|
||||
require.NoError(cleanUpObjects(ctx, client, bucketID, objects))
|
||||
|
||||
// Delete the bucket
|
||||
deleteBucketInput := &s3.DeleteBucketInput{
|
||||
Bucket: &bucketID,
|
||||
}
|
||||
client.DeleteBucket(ctx, deleteBucketInput)
|
||||
_, err = client.DeleteBucket(ctx, deleteBucketInput)
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
func cleanUpObjects(ctx context.Context, client *s3.Client, bucketID string, objectsToDelete []string) {
|
||||
func cleanUpObjects(ctx context.Context, client *s3.Client, bucketID string, objectsToDelete []string) error {
|
||||
var objectsIdentifier []types.ObjectIdentifier
|
||||
for _, object := range objectsToDelete {
|
||||
objectsIdentifier = append(objectsIdentifier, types.ObjectIdentifier{Key: aws.String(object)})
|
||||
@ -124,7 +125,8 @@ func cleanUpObjects(ctx context.Context, client *s3.Client, bucketID string, obj
|
||||
Bucket: &bucketID,
|
||||
Delete: &types.Delete{Objects: objectsIdentifier},
|
||||
}
|
||||
client.DeleteObjects(ctx, deleteObjectsInput)
|
||||
_, err := client.DeleteObjects(ctx, deleteObjectsInput)
|
||||
return err
|
||||
}
|
||||
|
||||
func TestAwsKms(t *testing.T) {
|
||||
|
@ -23,11 +23,11 @@ const (
|
||||
)
|
||||
|
||||
func setup() {
|
||||
exec.Command("/bin/dd", "if=/dev/zero", fmt.Sprintf("of=%s", DevicePath), "bs=64M", "count=1").Run()
|
||||
_ = exec.Command("/bin/dd", "if=/dev/zero", fmt.Sprintf("of=%s", DevicePath), "bs=64M", "count=1").Run()
|
||||
}
|
||||
|
||||
func teardown(devicePath string) {
|
||||
exec.Command("/bin/rm", "-f", devicePath).Run()
|
||||
_ = exec.Command("/bin/rm", "-f", devicePath).Run()
|
||||
}
|
||||
|
||||
func copy(source, target string) error {
|
||||
@ -35,7 +35,7 @@ func copy(source, target string) error {
|
||||
}
|
||||
|
||||
func resize() {
|
||||
exec.Command("/bin/dd", "if=/dev/zero", fmt.Sprintf("of=%s", DevicePath), "bs=32M", "count=1", "oflag=append", "conv=notrunc").Run()
|
||||
_ = exec.Command("/bin/dd", "if=/dev/zero", fmt.Sprintf("of=%s", DevicePath), "bs=32M", "count=1", "oflag=append", "conv=notrunc").Run()
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
@ -85,7 +85,7 @@ func TestPrepareExistingDisk(t *testing.T) {
|
||||
openTPM: vtpm.OpenNOPTPM,
|
||||
wantErr: true,
|
||||
},
|
||||
"MarkNodeAsInitialized fails": {
|
||||
"MarkNodeAsBootstrapped fails": {
|
||||
fs: afero.Afero{Fs: afero.NewMemMapFs()},
|
||||
keyWaiter: &stubKeyWaiter{},
|
||||
mapper: &stubMapper{uuid: "test"},
|
||||
|
Loading…
Reference in New Issue
Block a user