LEFT | RIGHT |
1 // Copyright 2011, 2012, 2013 Canonical Ltd. | 1 // Copyright 2011, 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package environs_test | 4 package environs_test |
5 | 5 |
6 import ( | 6 import ( |
7 "os" | 7 "os" |
8 "path/filepath" | 8 "path/filepath" |
9 | 9 |
10 . "launchpad.net/gocheck" | 10 . "launchpad.net/gocheck" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 path := testing.HomePath(".juju", "environments.yaml") | 157 path := testing.HomePath(".juju", "environments.yaml") |
158 c.Assert(path, Equals, outfile) | 158 c.Assert(path, Equals, outfile) |
159 | 159 |
160 es, err := environs.ReadEnvirons("") | 160 es, err := environs.ReadEnvirons("") |
161 c.Assert(err, IsNil) | 161 c.Assert(err, IsNil) |
162 e, err := es.Open("") | 162 e, err := es.Open("") |
163 c.Assert(err, IsNil) | 163 c.Assert(err, IsNil) |
164 c.Assert(e.Name(), Equals, "only") | 164 c.Assert(e.Name(), Equals, "only") |
165 } | 165 } |
166 | 166 |
167 func (suite) TestConfigDirPerm(c *C) { | 167 func (suite) TestConfigPerm(c *C) { |
168 » defer testing.MakeEmptyFakeHomeWithoutJuju(c).Restore() | 168 » defer testing.MakeSampleHome(c).Restore() |
169 | 169 |
| 170 » path := testing.HomePath(".juju") |
| 171 » info, err := os.Lstat(path) |
| 172 » c.Assert(err, IsNil) |
| 173 » oldPerm := info.Mode().Perm() |
170 env := ` | 174 env := ` |
171 environments: | 175 environments: |
172 only: | 176 only: |
173 type: dummy | 177 type: dummy |
174 state-server: false | 178 state-server: false |
175 authorized-keys: i-am-a-key | 179 authorized-keys: i-am-a-key |
176 ` | 180 ` |
177 outfile, err := environs.WriteEnvirons("", env) | 181 outfile, err := environs.WriteEnvirons("", env) |
178 c.Assert(err, IsNil) | 182 c.Assert(err, IsNil) |
179 » path := testing.HomePath(".juju", "environments.yaml") | 183 |
180 » c.Assert(path, Equals, outfile) | 184 » info, err = os.Lstat(outfile) |
181 | 185 » c.Assert(err, IsNil) |
182 » info, err := os.Lstat(filepath.Dir(path)) | 186 » c.Assert(info.Mode().Perm(), Equals, os.FileMode(0600)) |
183 » c.Assert(err, IsNil) | 187 |
184 » c.Assert(uint32(info.Mode().Perm()), Equals, uint32(0700)) | 188 » info, err = os.Lstat(filepath.Dir(outfile)) |
185 } | 189 » c.Assert(err, IsNil) |
186 | 190 » c.Assert(info.Mode().Perm(), Equals, oldPerm) |
187 func (suite) TestConfigFilePerm(c *C) { | 191 |
188 » defer testing.MakeEmptyFakeHome(c).Restore() | |
189 | |
190 » env := ` | |
191 environments: | |
192 only: | |
193 type: dummy | |
194 state-server: false | |
195 authorized-keys: i-am-a-key | |
196 ` | |
197 » outfile, err := environs.WriteEnvirons("", env) | |
198 » c.Assert(err, IsNil) | |
199 » path := testing.HomePath(".juju", "environments.yaml") | |
200 » c.Assert(path, Equals, outfile) | |
201 | |
202 » info, err := os.Lstat(path) | |
203 » c.Assert(err, IsNil) | |
204 » c.Assert(uint32(info.Mode().Perm()), Equals, uint32(0600)) | |
205 } | 192 } |
206 | 193 |
207 func (suite) TestNamedConfigFile(c *C) { | 194 func (suite) TestNamedConfigFile(c *C) { |
208 defer testing.MakeFakeHomeNoEnvironments(c, "only").Restore() | 195 defer testing.MakeFakeHomeNoEnvironments(c, "only").Restore() |
209 | 196 |
210 env := ` | 197 env := ` |
211 environments: | 198 environments: |
212 only: | 199 only: |
213 type: dummy | 200 type: dummy |
214 state-server: false | 201 state-server: false |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 c.Assert(err, IsNil) | 248 c.Assert(err, IsNil) |
262 cfg1, err := environs.BootstrapConfig(cfg) | 249 cfg1, err := environs.BootstrapConfig(cfg) |
263 c.Assert(err, IsNil) | 250 c.Assert(err, IsNil) |
264 | 251 |
265 expect := cfg.AllAttrs() | 252 expect := cfg.AllAttrs() |
266 delete(expect, "secret") | 253 delete(expect, "secret") |
267 expect["admin-secret"] = "" | 254 expect["admin-secret"] = "" |
268 expect["ca-private-key"] = "" | 255 expect["ca-private-key"] = "" |
269 c.Assert(cfg1.AllAttrs(), DeepEquals, expect) | 256 c.Assert(cfg1.AllAttrs(), DeepEquals, expect) |
270 } | 257 } |
LEFT | RIGHT |