From 5f831f3aee50c426804e2920f657bbd23dc0cf13 Mon Sep 17 00:00:00 2001 From: lifubang Date: Sun, 13 Oct 2024 17:17:35 +0800 Subject: [PATCH] add test for apply bounding or ambient caps for other process Signed-off-by: lifubang --- capability/capability_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/capability/capability_test.go b/capability/capability_test.go index 81b27e5..b5d6c4d 100644 --- a/capability/capability_test.go +++ b/capability/capability_test.go @@ -5,6 +5,7 @@ package capability_test import ( + "errors" "runtime" "testing" @@ -151,3 +152,35 @@ func TestAmbientCapSet(t *testing.T) { } } } + +func TestApplyAmbientCapsForOtherProcess(t *testing.T) { + if runtime.GOOS != "linux" { + return + } + requirePCapSet(t) + + pid, err := NewPid(1) + if err != nil { + t.Fatal(err) + } + err = pid.Apply(AMBIENT) + if !errors.Is(err, ErrAmbientNotMine) { + t.Fatalf("expected not support error when rasing ambient caps for other process, but got: %v", err) + } +} + +func TestApplyBoundingCapsForOtherProcess(t *testing.T) { + if runtime.GOOS != "linux" { + return + } + requirePCapSet(t) + + pid, err := NewPid(1) + if err != nil { + t.Fatal(err) + } + err = pid.Apply(BOUNDING) + if !errors.Is(err, ErrBoundingNotMine) { + t.Fatalf("expected not support error when drop bounding caps for other process, but got: %v", err) + } +}