~themue/juju-core/049-prepare-ec2

« back to all changes in this revision

Viewing changes to utils/sudo_test.go

[r=thumper],[bug=1231724] Make local provider work.

lp:1231724 shows that if a local provider is bootstrapped,
the created directory $(JUJU_HOME)/environments is not readable
by the user that started the provider as the bootstrap is done
by root, and the files and directories created are owned by
root with 0600 permission, which means you can't even run
juju status on a bootstrapped local provider.

https://codereview.appspot.com/14258043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package utils_test
 
5
 
 
6
import (
 
7
        "os"
 
8
 
 
9
        gc "launchpad.net/gocheck"
 
10
 
 
11
        "launchpad.net/juju-core/testing/testbase"
 
12
        "launchpad.net/juju-core/utils"
 
13
)
 
14
 
 
15
type sudoSuite struct {
 
16
        testbase.LoggingSuite
 
17
}
 
18
 
 
19
func (s *sudoSuite) TestSudoCallerIds(c *gc.C) {
 
20
        s.PatchEnvironment("SUDO_UID", "0")
 
21
        s.PatchEnvironment("SUDO_GID", "0")
 
22
        for _, test := range []struct {
 
23
                uid         string
 
24
                gid         string
 
25
                errString   string
 
26
                expectedUid int
 
27
                expectedGid int
 
28
        }{{
 
29
                uid: "",
 
30
                gid: "",
 
31
        }, {
 
32
                uid:         "1001",
 
33
                gid:         "1002",
 
34
                expectedUid: 1001,
 
35
                expectedGid: 1002,
 
36
        }, {
 
37
                uid:       "1001",
 
38
                gid:       "foo",
 
39
                errString: `invalid value "foo" for SUDO_GID`,
 
40
        }, {
 
41
                uid:       "foo",
 
42
                gid:       "bar",
 
43
                errString: `invalid value "foo" for SUDO_UID`,
 
44
        }} {
 
45
                os.Setenv("SUDO_UID", test.uid)
 
46
                os.Setenv("SUDO_GID", test.gid)
 
47
                uid, gid, err := utils.SudoCallerIds()
 
48
                if test.errString == "" {
 
49
                        c.Assert(err, gc.IsNil)
 
50
                        c.Assert(uid, gc.Equals, test.expectedUid)
 
51
                        c.Assert(gid, gc.Equals, test.expectedGid)
 
52
                } else {
 
53
                        c.Assert(err, gc.ErrorMatches, test.errString)
 
54
                        c.Assert(uid, gc.Equals, 0)
 
55
                        c.Assert(gid, gc.Equals, 0)
 
56
                }
 
57
        }
 
58
}