github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/monitor/extractors/ssh_test.go (about) 1 // +build !windows 2 3 package extractors 4 5 import ( 6 "strconv" 7 "testing" 8 9 . "github.com/smartystreets/goconvey/convey" 10 "go.aporeto.io/trireme-lib/common" 11 "go.aporeto.io/trireme-lib/policy" 12 ) 13 14 func testRuntime() *policy.PURuntime { 15 16 tags := policy.NewTagStore() 17 tags.AppendKeyValue("@user:ssh:app", "web") 18 tags.AppendKeyValue("$cert", "ss") 19 20 runtimeIps := policy.ExtendedMap{"bridge": "0.0.0.0/0"} 21 options := &policy.OptionsType{ 22 CgroupName: "/1234", 23 CgroupMark: strconv.FormatUint(104, 10), 24 } 25 26 return policy.NewPURuntime("curl", 1234, "", tags, runtimeIps, common.SSHSessionPU, options) 27 } 28 29 func TestSSHMetadataExtractor(t *testing.T) { 30 31 Convey("When I call the ssh metadata extrator", t, func() { 32 33 Convey("If all data are present", func() { 34 event := &common.EventInfo{ 35 Name: "curl", 36 PID: 1234, 37 PUID: "/1234", 38 PUType: common.SSHSessionPU, 39 Tags: []string{"app=web", "$cert=ss"}, 40 } 41 42 pu, err := SSHMetadataExtractor(event) 43 Convey("I should get no error and a valid PU runtime", func() { 44 So(err, ShouldBeNil) 45 So(pu, ShouldResemble, testRuntime()) 46 }) 47 }) 48 }) 49 }