Skip to content

Commit

Permalink
i/builtin: mock apparmor consistently for the tests (canonical#14376)
Browse files Browse the repository at this point in the history
also add a "allow all" test as there wasn't one afaict
  • Loading branch information
pedronis authored Aug 16, 2024
1 parent e53cf32 commit 552151e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions interfaces/builtin/lxd_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ apps:
}

func (s *LxdSupportInterfaceSuite) TestAppArmorSpec(c *C) {
r := apparmor_sandbox.MockFeatures(nil, nil, nil, nil)
defer r()
appSet, err := interfaces.NewSnapAppSet(s.plug.Snap(), nil)
c.Assert(err, IsNil)
spec := apparmor.NewSpecification(appSet)
Expand All @@ -115,6 +117,19 @@ func (s *LxdSupportInterfaceSuite) TestAppArmorSpecUserNS(c *C) {
c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "userns,\n")
}

func (s *LxdSupportInterfaceSuite) TestAppArmorSpecAllowAll(c *C) {
r := apparmor_sandbox.MockLevel(apparmor_sandbox.Full)
defer r()
r = apparmor_sandbox.MockFeatures(nil, nil, []string{"allow-all"}, nil)
defer r()
appSet, err := interfaces.NewSnapAppSet(s.plug.Snap(), nil)
c.Assert(err, IsNil)
spec := apparmor.NewSpecification(appSet)
c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "allow all,\n")
}

func (s *LxdSupportInterfaceSuite) TestAppArmorSpecUnconfined(c *C) {
appSet, err := interfaces.NewSnapAppSet(s.plugInfo.Snap, nil)
c.Assert(err, IsNil)
Expand Down

0 comments on commit 552151e

Please sign in to comment.