Skip to content

Commit

Permalink
use safer path for stub tests
Browse files Browse the repository at this point in the history
While these stubs shouldn't make actual changes, it's better to not
 use `/etc` in the tests, as they may be run as `root`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Nov 14, 2022
1 parent 41ff4c2 commit bc94efc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions go-selinux/label/label_stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ func TestCheckLabelCompile(t *testing.T) {
t.Fatal(err)
}

if _, err := FileLabel("/etc"); err != nil {
tmpDir := t.TempDir()
if _, err := FileLabel(tmpDir); err != nil {
t.Fatal(err)
}

if err := SetFileLabel("/etc", "foobar"); err != nil {
if err := SetFileLabel(tmpDir, "foobar"); err != nil {
t.Fatal(err)
}

Expand Down
5 changes: 3 additions & 2 deletions go-selinux/selinux_stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ func TestSELinuxStubs(t *testing.T) {
t.Error("SELinux enabled on non-linux.")
}

if _, err := FileLabel("/etc"); err != nil {
tmpDir := t.TempDir()
if _, err := FileLabel(tmpDir); err != nil {
t.Error(err)
}

if err := SetFileLabel("/etc", testLabel); err != nil {
if err := SetFileLabel(tmpDir, testLabel); err != nil {
t.Error(err)
}

Expand Down

0 comments on commit bc94efc

Please sign in to comment.