Beispiel #1
0
func (s *storageSuite) TestClientTLS(c *gc.C) {
	listener, _, storageDir := startServerTLS(c)
	defer listener.Close()
	stor, err := httpstorage.ClientTLS(listener.Addr().String(), coretesting.CACert, testAuthkey)
	c.Assert(err, gc.IsNil)

	data := []byte("hello")
	err = ioutil.WriteFile(filepath.Join(storageDir, "filename"), data, 0644)
	c.Assert(err, gc.IsNil)
	names, err := storage.List(stor, "filename")
	c.Assert(err, gc.IsNil)
	c.Assert(names, gc.DeepEquals, []string{"filename"})
	checkFileHasContents(c, stor, "filename", data)

	// Put, Remove and RemoveAll should all succeed.
	checkPutFile(c, stor, "filenamethesecond", data)
	checkFileHasContents(c, stor, "filenamethesecond", data)
	c.Assert(stor.Remove("filenamethesecond"), gc.IsNil)
	c.Assert(stor.RemoveAll(), gc.IsNil)
}
Beispiel #2
0
func (s *storageSuite) TestClientTLSInvalidAuth(c *gc.C) {
	listener, _, storageDir := startServerTLS(c)
	defer listener.Close()
	const invalidAuthkey = testAuthkey + "!"
	stor, err := httpstorage.ClientTLS(listener.Addr().String(), coretesting.CACert, invalidAuthkey)
	c.Assert(err, gc.IsNil)

	// Get and List should succeed.
	data := []byte("hello")
	err = ioutil.WriteFile(filepath.Join(storageDir, "filename"), data, 0644)
	c.Assert(err, gc.IsNil)
	names, err := storage.List(stor, "filename")
	c.Assert(err, gc.IsNil)
	c.Assert(names, gc.DeepEquals, []string{"filename"})
	checkFileHasContents(c, stor, "filename", data)

	// Put, Remove and RemoveAll should all fail.
	const authErrorPattern = ".*401 Unauthorized"
	err = putFile(c, stor, "filenamethesecond", data)
	c.Assert(err, gc.ErrorMatches, authErrorPattern)
	c.Assert(stor.Remove("filenamethesecond"), gc.ErrorMatches, authErrorPattern)
	c.Assert(stor.RemoveAll(), gc.ErrorMatches, authErrorPattern)
}