-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter out unsupported systems at runtime rather than compilation tim…
…e for the `/etc/passwd` CIS checks' unit tests. PiperOrigin-RevId: 652436006
- Loading branch information
1 parent
0878179
commit 7a87679
Showing
4 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
detector/cis/generic_linux/etcpasswdpermissions/detector_dummy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build !linux | ||
|
||
package etcpasswdpermissions_test | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
"time" | ||
) | ||
|
||
func (f *fakeFS) Open(name string) (fs.File, error) { return nil, errors.New("unsupported system") } | ||
|
||
func (f *fakeFile) Stat() (fs.FileInfo, error) { return nil, errors.New("unsupported system") } | ||
func (fakeFile) Read([]byte) (int, error) { return 0, errors.New("unsupported system") } | ||
func (fakeFile) Close() error { return nil } | ||
|
||
func (fakeFileInfo) Name() string { return "unsupported" } | ||
func (fakeFileInfo) Size() int64 { return 0 } | ||
func (i *fakeFileInfo) Mode() fs.FileMode { return 0 } | ||
func (fakeFileInfo) ModTime() time.Time { return time.Now() } | ||
func (i *fakeFileInfo) IsDir() bool { return false } | ||
func (i *fakeFileInfo) Sys() any { return nil } |
48 changes: 48 additions & 0 deletions
48
detector/cis/generic_linux/etcpasswdpermissions/detector_linux_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build linux | ||
|
||
package etcpasswdpermissions_test | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
"os" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func (f *fakeFS) Open(name string) (fs.File, error) { | ||
if name == "etc/passwd" { | ||
if f.exists { | ||
return &fakeFile{perms: f.perms, uid: f.uid, gid: f.gid}, nil | ||
} | ||
return nil, os.ErrNotExist | ||
} | ||
return nil, errors.New("failed to open") | ||
} | ||
|
||
func (f *fakeFile) Stat() (fs.FileInfo, error) { | ||
return &fakeFileInfo{perms: f.perms, uid: f.uid, gid: f.gid}, nil | ||
} | ||
func (fakeFile) Read([]byte) (int, error) { return 0, errors.New("failed to read") } | ||
func (fakeFile) Close() error { return nil } | ||
|
||
func (fakeFileInfo) Name() string { return "/etc/passwd" } | ||
func (fakeFileInfo) Size() int64 { return 1 } | ||
func (i *fakeFileInfo) Mode() fs.FileMode { return i.perms } | ||
func (fakeFileInfo) ModTime() time.Time { return time.Now() } | ||
func (i *fakeFileInfo) IsDir() bool { return false } | ||
func (i *fakeFileInfo) Sys() any { return &syscall.Stat_t{Uid: i.uid, Gid: i.gid} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters