1
// Copyright 2014 Canonical Ltd.
2
// Copyright 2014 Cloudbase Solutions SRL
3
// Licensed under the AGPLv3, see LICENCE file for details.
12
jc "github.com/juju/testing/checkers"
13
gc "gopkg.in/check.v1"
14
"gopkg.in/juju/names.v2"
16
"github.com/juju/juju/apiserver/params"
17
"github.com/juju/juju/testing"
18
jujuversion "github.com/juju/juju/version"
21
type identitySuite struct {
23
mongodConfigPath string
27
var _ = gc.Suite(&identitySuite{})
29
var attributeParams = AgentConfigParams{
30
Tag: names.NewMachineTag("1"),
31
UpgradedToVersion: jujuversion.Current,
34
StateAddresses: []string{"localhost:1234"},
35
APIAddresses: []string{"localhost:1235"},
37
Model: testing.ModelTag,
40
var servingInfo = params.StateServingInfo{
42
PrivateKey: "old key",
43
CAPrivateKey: "old ca key",
46
SharedSecret: "shared",
47
SystemIdentity: "identity",
50
func (s *identitySuite) TestWriteSystemIdentityFile(c *gc.C) {
51
params := attributeParams
52
params.Paths.DataDir = c.MkDir()
53
conf, err := NewStateMachineConfig(params, servingInfo)
54
c.Assert(err, jc.ErrorIsNil)
55
err = WriteSystemIdentityFile(conf)
56
c.Assert(err, jc.ErrorIsNil)
58
contents, err := ioutil.ReadFile(conf.SystemIdentityPath())
59
c.Assert(err, jc.ErrorIsNil)
60
c.Check(string(contents), gc.Equals, servingInfo.SystemIdentity)
62
fi, err := os.Stat(conf.SystemIdentityPath())
63
c.Assert(err, jc.ErrorIsNil)
65
// Windows is not fully POSIX compliant. Chmod() and Chown() have unexpected behavior
66
// compared to linux/unix
67
if runtime.GOOS != "windows" {
68
c.Check(fi.Mode().Perm(), gc.Equals, os.FileMode(0600))
70
// ensure that file is deleted when SystemIdentity is empty
72
info.SystemIdentity = ""
73
conf, err = NewStateMachineConfig(params, info)
74
c.Assert(err, jc.ErrorIsNil)
75
err = WriteSystemIdentityFile(conf)
76
c.Assert(err, jc.ErrorIsNil)
77
fi, err = os.Stat(conf.SystemIdentityPath())
78
c.Assert(err, jc.Satisfies, os.IsNotExist)