-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain_test.go
More file actions
47 lines (40 loc) · 1.03 KB
/
main_test.go
File metadata and controls
47 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2026 Edgeless Systems GmbH
// SPDX-License-Identifier: BUSL-1.1
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAllowInsecureAttestation(t *testing.T) {
oldKernelCmdlinePath := kernelCmdlinePath
t.Cleanup(func() { kernelCmdlinePath = oldKernelCmdlinePath })
testCases := map[string]struct {
cmdline string
want bool
}{
"absent": {
cmdline: "console=hvc0",
want: false,
},
"disabled": {
cmdline: "console=hvc0 contrast.allow_insecure_attestation=0",
want: false,
},
"enabled": {
cmdline: "console=hvc0 contrast.allow_insecure_attestation=1 quiet",
want: true,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
kernelCmdlinePath = filepath.Join(t.TempDir(), "cmdline")
require.NoError(t, os.WriteFile(kernelCmdlinePath, []byte(tc.cmdline), 0o644))
got, err := allowInsecureAttestation()
require.NoError(t, err)
assert.Equal(t, tc.want, got)
})
}
}