Esempio n. 1
0
func (s *ZipSuite) TestExtractAllSymlinkErrors(c *gc.C) {
	for i, test := range []struct {
		content []ft.Entry
		error   string
	}{{
		content: []ft.Entry{
			ft.Symlink{"symlink", "/blah"},
		},
		error: `cannot extract "symlink": symlink "/blah" is absolute`,
	}, {
		content: []ft.Entry{
			ft.Symlink{"symlink", "../blah"},
		},
		error: `cannot extract "symlink": symlink "../blah" leads out of scope`,
	}, {
		content: []ft.Entry{
			ft.Dir{"dir", 0755},
			ft.Symlink{"dir/symlink", "../../blah"},
		},
		error: `cannot extract "dir/symlink": symlink "../../blah" leads out of scope`,
	}} {
		c.Logf("test %d: %s", i, test.error)
		targetPath := c.MkDir()
		reader := s.makeZip(c, test.content...)
		err := zip.ExtractAll(reader, targetPath)
		c.Check(err, gc.ErrorMatches, test.error)
	}
}
Esempio n. 2
0
func (s *ZipSuite) TestExtractAllMergeDirs(c *gc.C) {
	targetPath := c.MkDir()
	ft.Dir{"dir", 0755}.Create(c, targetPath)
	originals := []ft.Entry{
		ft.Dir{"dir/original-dir", 0751},
		ft.File{"dir/original-file", "content 1", 0600},
		ft.Symlink{"dir/original-symlink", "original-file"},
	}
	for _, entry := range originals {
		entry.Create(c, targetPath)
	}
	merges := []ft.Entry{
		ft.Dir{"dir", 0751},
		ft.Dir{"dir/merge-dir", 0750},
		ft.File{"dir/merge-file", "content 2", 0640},
		ft.Symlink{"dir/merge-symlink", "merge-file"},
	}
	reader := s.makeZip(c, merges...)
	err := zip.ExtractAll(reader, targetPath)
	c.Assert(err, gc.IsNil)

	for i, test := range append(originals, merges...) {
		c.Logf("test %d: %#v", i, test)
		test.Check(c, targetPath)
	}
}
Esempio n. 3
0
func (s *ZipSuite) TestClosesFile(c *gc.C) {
	reader := s.makeZip(c, ft.File{"f", "echo hullo!", 0755})
	targetPath := c.MkDir()
	err := zip.ExtractAll(reader, targetPath)
	c.Assert(err, gc.IsNil)
	cmd := exec.Command("/bin/sh", "-c", filepath.Join(targetPath, "f"))
	var buffer bytes.Buffer
	cmd.Stdout = &buffer
	err = cmd.Run()
	c.Assert(err, gc.IsNil)
	c.Assert(buffer.String(), gc.Equals, "hullo!\n")
}
Esempio n. 4
0
func (s *ZipSuite) TestExtractAllOverwriteDirs(c *gc.C) {
	name := "some-dir"
	for i, test := range []ft.Entry{
		ft.File{name, "content", 0644},
		ft.Dir{name, 0751},
		ft.Symlink{name, "wherever"},
	} {
		c.Logf("test %d: %#v", i, test)
		targetPath := c.MkDir()
		ft.Dir{name, 0}.Create(c, targetPath)
		reader := s.makeZip(c, test)
		err := zip.ExtractAll(reader, targetPath)
		c.Check(err, gc.IsNil)
		test.Check(c, targetPath)
	}
}
Esempio n. 5
0
func (s *ZipSuite) TestExtractAll(c *gc.C) {
	entries := []ft.Entry{
		ft.File{"some-file", "content 1", 0644},
		ft.File{"another-file", "content 2", 0640},
		ft.Symlink{"some-symlink", "some-file"},
		ft.Dir{"some-dir", 0750},
		ft.File{"some-dir/another-file", "content 3", 0644},
		ft.Dir{"some-dir/another-dir", 0755},
		ft.Symlink{"some-dir/another-dir/another-symlink", "../../another-file"},
	}
	reader := s.makeZip(c, entries...)
	targetPath := c.MkDir()
	err := zip.ExtractAll(reader, targetPath)
	c.Assert(err, gc.IsNil)
	for i, entry := range entries {
		c.Logf("test %d: %#v", i, entry)
		entry.Check(c, targetPath)
	}
}