85
85
func (s *configSuite) TestNamespaceRootNoSudo(c *gc.C) {
86
restore := local.SetRootCheckFunction(func() bool { return true })
86
88
err := os.Setenv("USER", "root")
87
89
c.Assert(err, gc.IsNil)
88
90
testConfig := minimalConfig(c)
92
94
func (s *configSuite) TestNamespaceRootWithSudo(c *gc.C) {
95
restore := local.SetRootCheckFunction(func() bool { return true })
93
97
err := os.Setenv("USER", "root")
94
98
c.Assert(err, gc.IsNil)
95
99
err = os.Setenv("SUDO_USER", "tester")
99
103
c.Assert(local.ConfigNamespace(testConfig), gc.Equals, "tester-test")
106
func (s *configSuite) TestSudoCallerIds(c *gc.C) {
107
defer os.Setenv("SUDO_UID", os.Getenv("SUDO_UID"))
108
defer os.Setenv("SUDO_GID", os.Getenv("SUDO_GID"))
109
for _, test := range []struct {
126
errString: `invalid value "foo" for SUDO_GID`,
130
errString: `invalid value "foo" for SUDO_UID`,
132
os.Setenv("SUDO_UID", test.uid)
133
os.Setenv("SUDO_GID", test.gid)
134
uid, gid, err := local.SudoCallerIds()
135
if test.errString == "" {
136
c.Assert(err, gc.IsNil)
137
c.Assert(uid, gc.Equals, test.expectedUid)
138
c.Assert(gid, gc.Equals, test.expectedGid)
140
c.Assert(err, gc.ErrorMatches, test.errString)
141
c.Assert(uid, gc.Equals, 0)
142
c.Assert(gid, gc.Equals, 0)
102
147
type configRootSuite struct {
103
148
baseProviderSuite