Skip to content

Commit f4d6932

Browse files
committed
test(secureperm): force seed mode independent of umask
Address review feedback from coderabbitai on pkg/secureperm/secureperm_unix_test.go: TestLockDown_Mode0600_Unix and TestWriteFile_OverwriteDowngrades_Unix seed a 0o644 file via os.WriteFile, but that mode is filtered by the process umask. On a developer machine with a restrictive umask such as 0o077, the seed lands at 0o600 and the tests pass without exercising the downgrade path. Chmod the seed to 0o644 explicitly after the write so the lax-mode precondition is deterministic. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
1 parent a1a71ed commit f4d6932

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

pkg/secureperm/secureperm_unix_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func TestLockDown_Mode0600_Unix(t *testing.T) {
4848
if err := os.WriteFile(path, []byte("data"), 0o644); err != nil {
4949
t.Fatalf("seed: %v", err)
5050
}
51+
// os.WriteFile is subject to the process umask; force 0o644 so the
52+
// lax-mode precondition is deterministic regardless of the host
53+
// umask (a restrictive 0o077 would otherwise make the seed 0o600
54+
// and the test pass without proving LockDown tightened anything).
55+
if err := os.Chmod(path, 0o644); err != nil {
56+
t.Fatalf("chmod seed: %v", err)
57+
}
5158
if err := secureperm.LockDown(path); err != nil {
5259
t.Fatalf("LockDown: %v", err)
5360
}
@@ -72,6 +79,12 @@ func TestWriteFile_OverwriteDowngrades_Unix(t *testing.T) {
7279
if err := os.WriteFile(path, []byte("old"), 0o644); err != nil {
7380
t.Fatalf("seed: %v", err)
7481
}
82+
// Force the seed mode so the lax precondition survives a
83+
// restrictive umask; otherwise the test can pass without actually
84+
// verifying that WriteFile downgraded 0o644 to 0o600.
85+
if err := os.Chmod(path, 0o644); err != nil {
86+
t.Fatalf("chmod seed: %v", err)
87+
}
7588
if err := secureperm.WriteFile(path, []byte("new")); err != nil {
7689
t.Fatalf("WriteFile: %v", err)
7790
}

0 commit comments

Comments
 (0)