Skip to content

Commit 3d7aa10

Browse files
committed
Add a test case for ExecLabel/SetExecLabel
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent d373fd1 commit 3d7aa10

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

go-selinux/selinux_linux_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,35 @@ func TestSocketLabel(t *testing.T) {
211211
}
212212
}
213213

214+
func TestExecLabel(t *testing.T) {
215+
if !GetEnabled() {
216+
t.Skip("SELinux not enabled, skipping.")
217+
}
218+
219+
// Ensure the thread stays the same for duration of the test.
220+
// Otherwise Go runtime can switch this to a different thread,
221+
// which results in EACCES in call to SetExecLabel.
222+
runtime.LockOSThread()
223+
defer runtime.UnlockOSThread()
224+
225+
const label = "system_u:object_r:container_t:s0:c1,c2"
226+
if err := SetExecLabel(label); err != nil {
227+
t.Fatal(err)
228+
}
229+
defer func() {
230+
if err := SetExecLabel(""); err != nil {
231+
t.Fatal(err)
232+
}
233+
}()
234+
nlabel, err := ExecLabel()
235+
if err != nil {
236+
t.Fatal(err)
237+
}
238+
if label != nlabel {
239+
t.Errorf("ExecLabel: want %q, got %q", label, nlabel)
240+
}
241+
}
242+
214243
func TestKeyLabel(t *testing.T) {
215244
if !GetEnabled() {
216245
t.Skip("SELinux not enabled, skipping.")

0 commit comments

Comments
 (0)