Skip to content

Commit

Permalink
o/c/configcore,s/apparmor: mock aa root path in prompting tests
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Calder <[email protected]>
  • Loading branch information
olivercalder committed Sep 10, 2024
1 parent ca78825 commit 094a2c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions overlord/configstate/configcore/prompting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import (
"fmt"
"os"
"os/user"
"path/filepath"
"time"

. "gopkg.in/check.v1"
"gopkg.in/tomb.v2"

"github.com/snapcore/snapd/boot"
"github.com/snapcore/snapd/client"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/features"
"github.com/snapcore/snapd/interfaces"
"github.com/snapcore/snapd/interfaces/builtin"
Expand Down Expand Up @@ -69,6 +71,10 @@ func (s *promptingSuite) SetUpTest(c *C) {
))
// mock the presence of the notification socket
os.MkdirAll(notify.SysPath, 0o755)
// mock the presence of permstable32_version with supported version
s.AddCleanup(apparmor.MockFsRootPath(dirs.GlobalRootDir))
os.MkdirAll(filepath.Join(dirs.GlobalRootDir, "sys/kernel/security/apparmor/features/policy"), 0o755)
os.WriteFile(filepath.Join(dirs.GlobalRootDir, "sys/kernel/security/apparmor/features/policy/permstable32_version"), []byte("0x000002"), 0o644)

s.overlord = overlord.MockWithState(nil)
// override state set up by configcoreSuite
Expand Down
8 changes: 8 additions & 0 deletions sandbox/apparmor/apparmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,11 @@ func MockParserSearchPath(new string) (restore func()) {
parserSearchPath = oldAppArmorParserSearchPath
}
}

func MockFsRootPath(path string) (restorer func()) {
old := rootPath
rootPath = path
return func() {
rootPath = old
}
}
10 changes: 1 addition & 9 deletions sandbox/apparmor/export_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2014-2015 Canonical Ltd
* Copyright (C) 2014-2024 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
Expand Down Expand Up @@ -78,14 +78,6 @@ func MockProfilesPath(t *testutil.BaseTest, profiles string) {
})
}

func MockFsRootPath(path string) (restorer func()) {
old := rootPath
rootPath = path
return func() {
rootPath = old
}
}

func MockSnapdAppArmorSupportsReexec(new func() bool) (restore func()) {
restore = testutil.Backup(&snapdAppArmorSupportsReexec)
snapdAppArmorSupportsReexec = new
Expand Down

0 comments on commit 094a2c7

Please sign in to comment.