Skip to content

Commit 2199f49

Browse files
authored
[fix] Windows linter errors (#577)
* Fix windows-linter-errors
1 parent e318e5d commit 2199f49

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
*.go text eol=lf

commands/permissions_fix_windows_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@ import (
1111
"github.com/openpubkey/opkssh/policy"
1212
"github.com/openpubkey/opkssh/policy/files"
1313
"github.com/spf13/afero"
14+
"github.com/stretchr/testify/require"
1415
)
1516

1617
func TestRunPermissionsFix_AppliesRequiredACEs_Windows(t *testing.T) {
1718
// Setup in-memory fs with system policy file
1819
mem := afero.NewMemMapFs()
1920
systemPolicy := policy.SystemDefaultPolicyPath
20-
afero.WriteFile(mem, systemPolicy, []byte("x"), 0o644)
21+
err := afero.WriteFile(mem, systemPolicy, []byte("x"), 0o644)
22+
require.NoError(t, err, "Failed to write system policy file")
23+
2124
// ensure plugins dir exists but no ACEs present
2225
pluginsDir := policy.GetSystemConfigBasePath() + "/policy.d"
23-
mem.MkdirAll(pluginsDir, 0o750)
24-
afero.WriteFile(mem, pluginsDir+"/plugin.yml", []byte("a"), 0o644)
26+
err = mem.MkdirAll(pluginsDir, 0o750)
27+
if err != nil {
28+
t.Fatalf("Failed to create plugins dir: %v", err)
29+
}
30+
err = afero.WriteFile(mem, pluginsDir+"/plugin.yml", []byte("a"), 0o644)
31+
require.NoError(t, err, "Failed to write plugin file")
2532

2633
mfs := &mockFileSystem{
2734
fs: mem,
@@ -37,7 +44,7 @@ func TestRunPermissionsFix_AppliesRequiredACEs_Windows(t *testing.T) {
3744
Yes: true,
3845
}
3946

40-
err := p.Fix()
47+
err = p.Fix()
4148
if err != nil {
4249
t.Fatalf("Fix failed: %v", err)
4350
}
@@ -68,7 +75,8 @@ func TestRunPermissionsFix_SkipsExistingACEs_Windows(t *testing.T) {
6875
// Setup in-memory fs with system policy file, ACEs already present
6976
mem := afero.NewMemMapFs()
7077
systemPolicy := policy.SystemDefaultPolicyPath
71-
afero.WriteFile(mem, systemPolicy, []byte("x"), 0o644)
78+
err := afero.WriteFile(mem, systemPolicy, []byte("x"), 0o644)
79+
require.NoError(t, err, "Failed to write system policy file")
7280

7381
mfs := &mockFileSystem{
7482
fs: mem,
@@ -91,7 +99,7 @@ func TestRunPermissionsFix_SkipsExistingACEs_Windows(t *testing.T) {
9199
Yes: true,
92100
}
93101

94-
err := p.Fix()
102+
err = p.Fix()
95103
if err != nil {
96104
t.Fatalf("Fix failed: %v", err)
97105
}
@@ -108,7 +116,8 @@ func TestRunPermissionsFix_NoSystemACE_Windows(t *testing.T) {
108116
// Verify that SYSTEM:F ACE is never applied
109117
mem := afero.NewMemMapFs()
110118
systemPolicy := policy.SystemDefaultPolicyPath
111-
afero.WriteFile(mem, systemPolicy, []byte("x"), 0o644)
119+
err := afero.WriteFile(mem, systemPolicy, []byte("x"), 0o644)
120+
require.NoError(t, err, "Failed to write system policy file")
112121

113122
mfs := &mockFileSystem{
114123
fs: mem,
@@ -124,7 +133,7 @@ func TestRunPermissionsFix_NoSystemACE_Windows(t *testing.T) {
124133
Yes: true,
125134
}
126135

127-
err := p.Fix()
136+
err = p.Fix()
128137
if err != nil {
129138
t.Fatalf("Fix failed: %v", err)
130139
}

policy/files/acl_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (w *WindowsACLVerifier) VerifyACL(path string, expected ExpectedACL) (ACLRe
150150
}
151151
// Ensure security descriptor memory is freed
152152
if pSD != 0 {
153-
defer procLocalFree.Call(pSD)
153+
defer procLocalFree.Call(pSD) //nolint:errcheck // free failure not worth handling
154154
}
155155

156156
// Lookup owner name if available

policy/files/fileperms_ops_windows_acl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (w *WindowsACLFilePermsOps) ApplyACE(path string, ace ACE) error {
224224
return fmt.Errorf("GetNamedSecurityInfoW failed: %d", ret)
225225
}
226226
if pSD != 0 {
227-
defer procLocalFree.Call(pSD)
227+
defer procLocalFree.Call(pSD) //nolint:errcheck // free failure not worth handling
228228
}
229229

230230
// Build EXPLICIT_ACCESS
@@ -284,7 +284,7 @@ func (w *WindowsACLFilePermsOps) ApplyACE(path string, ace ACE) error {
284284
if pNewAcl == 0 {
285285
return fmt.Errorf("SetEntriesInAclW returned nil ACL")
286286
}
287-
defer procLocalFree.Call(pNewAcl)
287+
defer procLocalFree.Call(pNewAcl) //nolint:errcheck // free failure not worth handling
288288

289289
// Apply new DACL to the file
290290
ret3, _, err := procSetNamedSecurityInfo.Call(

0 commit comments

Comments
 (0)