Skip to content

Commit 1bfc56a

Browse files
committed
Add test for root + SignaturePolicyPath.
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
1 parent eb63702 commit 1bfc56a

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

image/signature/policy_config_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ func TestDefaultPolicy(t *testing.T) {
147147
require.NoError(t, os.WriteFile(path, []byte(contents), 0o600))
148148
}
149149

150+
signaturePathWithRootSys := &types.SystemContext{}
151+
150152
for _, test := range []tc{
151153
{
152154
name: "signature policy path override success",
@@ -230,7 +232,8 @@ func TestDefaultPolicy(t *testing.T) {
230232
t.Setenv("CONTAINERS_POLICY_JSON", base)
231233
},
232234
sys: &types.SystemContext{},
233-
expectPolicy: &prInsecureAcceptAnything{},
235+
useRootPrefix: true,
236+
expectPolicy: &prInsecureAcceptAnything{},
234237
},
235238
{
236239
name: "containers policy conf read error",
@@ -252,6 +255,26 @@ func TestDefaultPolicy(t *testing.T) {
252255
sys: &types.SystemContext{},
253256
expectErr: true,
254257
},
258+
{
259+
name: "signature policy path wins over root for implicit absolute paths",
260+
setup: func(t *testing.T, rootPrefix string) {
261+
tempHome := t.TempDir()
262+
t.Setenv("XDG_CONFIG_HOME", tempHome)
263+
264+
// If SignaturePolicyPath were ignored, this would be used due to RootForImplicitAbsolutePaths.
265+
mustWritePolicy(t, filepath.Join(rootPrefix, "etc", "containers", "policy.json"), rejectJSON)
266+
267+
// SignaturePolicyPath is used as-is (not interpreted relative to RootForImplicitAbsolutePaths).
268+
sigPath := filepath.Join(t.TempDir(), "signature-policy.json")
269+
mustWritePolicy(t, sigPath, insecureJSON)
270+
271+
signaturePathWithRootSys.RootForImplicitAbsolutePaths = rootPrefix
272+
signaturePathWithRootSys.SignaturePolicyPath = sigPath
273+
},
274+
sys: signaturePathWithRootSys,
275+
useRootPrefix: true,
276+
expectPolicy: &prInsecureAcceptAnything{},
277+
},
255278
{
256279
name: "root for implicit absolute paths is honored",
257280
setup: func(t *testing.T, rootPrefix string) {
@@ -293,7 +316,6 @@ func TestDefaultPolicy(t *testing.T) {
293316

294317
require.NoError(t, err)
295318
require.NotNil(t, policy)
296-
require.NotEmpty(t, policy.Default)
297319

298320
switch expected := test.expectPolicy.(type) {
299321
case *Policy:

0 commit comments

Comments
 (0)