Skip to content

Commit 0aa6c4c

Browse files
committed
tests/*/luks: add blackbox tests for luks
Fixes #1554
1 parent 5c2cf95 commit 0aa6c4c

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

tests/negative/luks/creation.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2023 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package luks
16+
17+
import (
18+
"github.com/coreos/ignition/v2/tests/register"
19+
"github.com/coreos/ignition/v2/tests/types"
20+
)
21+
22+
func init() {
23+
register.Register(register.NegativeTest, LuksFailToEncryptFormatedDevice())
24+
}
25+
26+
// Fail to encrypt a device which is formatted without "WipeVolume"
27+
func LuksFailToEncryptFormatedDevice() types.Test {
28+
name := "luks.formatedDevice.noWipeVolume"
29+
in := types.GetBaseDisk()
30+
out := types.GetBaseDisk()
31+
mntDevices := []types.MntDevice{
32+
{
33+
Label: "OEM",
34+
Substitution: "$DEVICE",
35+
},
36+
}
37+
config := `{
38+
"ignition": { "version": "$version" },
39+
"storage": {
40+
"luks": [
41+
{
42+
"device": "$DEVICE",
43+
"name": "$UUID",
44+
"wipeVolume": false
45+
}
46+
]
47+
}
48+
}`
49+
configMinVersion := "3.2.0"
50+
51+
return types.Test{
52+
Name: name,
53+
In: in,
54+
Out: out,
55+
MntDevices: mntDevices,
56+
Config: config,
57+
ConfigMinVersion: configMinVersion,
58+
}
59+
}

tests/positive/luks/creation.go

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2023 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package luks
16+
17+
import (
18+
"github.com/coreos/ignition/v2/tests/register"
19+
"github.com/coreos/ignition/v2/tests/types"
20+
)
21+
22+
func init() {
23+
register.Register(register.PositiveTest, LuksWithKeyfileKey())
24+
register.Register(register.PositiveTest, LuksWithTPM2())
25+
26+
}
27+
28+
func LuksWithKeyfileKey() types.Test {
29+
name := "luks.formattedDevice.wipeVolume.keyfile"
30+
in := types.GetBaseDisk()
31+
out := types.GetBaseDisk()
32+
mntDevices := []types.MntDevice{
33+
{
34+
Label: "OEM",
35+
Substitution: "$DEVICE",
36+
},
37+
}
38+
config := `{
39+
"ignition": { "version": "$version" },
40+
"storage": {
41+
"luks": [
42+
{
43+
"device": "$DEVICE",
44+
"name": "$uuid2",
45+
"keyFile": {
46+
"compression": "",
47+
"source": "data:,REPLACE-THIS-WITH-YOUR-KEY-MATERIAL"
48+
},
49+
"wipeVolume": true
50+
}
51+
]
52+
}
53+
}`
54+
configMinVersion := "3.2.0"
55+
in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4"
56+
out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS"
57+
58+
return types.Test{
59+
Name: name,
60+
In: in,
61+
Out: out,
62+
MntDevices: mntDevices,
63+
Config: config,
64+
ConfigMinVersion: configMinVersion,
65+
}
66+
}
67+
68+
func LuksWithTPM2() types.Test {
69+
name := "luks.formattedDevice.wipeVolume.tpm2"
70+
in := types.GetBaseDisk()
71+
out := types.GetBaseDisk()
72+
mntDevices := []types.MntDevice{
73+
{
74+
Label: "OEM",
75+
Substitution: "$DEVICE",
76+
},
77+
}
78+
config := `{
79+
"ignition": { "version": "$version" },
80+
"storage": {
81+
"luks": [
82+
{
83+
"clevis": {
84+
"tpm2": true
85+
},
86+
"device": "$DEVICE",
87+
"name": "$uuid1",
88+
"wipeVolume": true
89+
}
90+
]
91+
}
92+
}`
93+
configMinVersion := "3.2.0"
94+
in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4"
95+
out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS"
96+
97+
return types.Test{
98+
Name: name,
99+
In: in,
100+
Out: out,
101+
MntDevices: mntDevices,
102+
Config: config,
103+
ConfigMinVersion: configMinVersion,
104+
}
105+
}

tests/registry/registry.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
_ "github.com/coreos/ignition/v2/tests/negative/files"
2020
_ "github.com/coreos/ignition/v2/tests/negative/filesystems"
2121
_ "github.com/coreos/ignition/v2/tests/negative/general"
22+
_ "github.com/coreos/ignition/v2/tests/negative/luks"
2223
_ "github.com/coreos/ignition/v2/tests/negative/partitions"
2324
_ "github.com/coreos/ignition/v2/tests/negative/proxy"
2425
_ "github.com/coreos/ignition/v2/tests/negative/regression"
@@ -27,6 +28,7 @@ import (
2728
_ "github.com/coreos/ignition/v2/tests/positive/files"
2829
_ "github.com/coreos/ignition/v2/tests/positive/filesystems"
2930
_ "github.com/coreos/ignition/v2/tests/positive/general"
31+
_ "github.com/coreos/ignition/v2/tests/positive/luks"
3032
_ "github.com/coreos/ignition/v2/tests/positive/partitions"
3133
_ "github.com/coreos/ignition/v2/tests/positive/passwd"
3234
_ "github.com/coreos/ignition/v2/tests/positive/proxy"

0 commit comments

Comments
 (0)