Exemple #1
0
func (s *FingerprintSuite) TestNewValidFingerprint(c *gc.C) {
	expected, _ := newFingerprint(c, "spamspamspam")
	s.hash.ReturnSum = expected

	fp := hash.NewValidFingerprint(s.hash)
	sum := fp.Bytes()

	s.stub.CheckCallNames(c, "Sum")
	c.Check(sum, jc.DeepEquals, expected)
}
Exemple #2
0
func (s *HashSuite) TestHashingWriter(c *gc.C) {
	data := "some data"
	newHash, _ := hash.SHA384()
	expected, err := hash.GenerateFingerprint(strings.NewReader(data), newHash)
	c.Assert(err, jc.ErrorIsNil)
	var writer bytes.Buffer

	h := newHash()
	hashingWriter := io.MultiWriter(&writer, h)
	_, err = hashingWriter.Write([]byte(data))
	c.Assert(err, jc.ErrorIsNil)
	fp := hash.NewValidFingerprint(h)

	c.Check(fp, jc.DeepEquals, expected)
	c.Check(writer.String(), gc.Equals, data)
}
Exemple #3
0
func (s *HashSuite) TestHashingReader(c *gc.C) {
	expected := "some data"
	stub := &testing.Stub{}
	reader := &filetesting.StubReader{
		Stub: stub,
		ReturnRead: &fakeStream{
			data: expected,
		},
	}

	newHash, validate := hash.SHA384()
	h := newHash()
	hashingReader := io.TeeReader(reader, h)
	data, err := ioutil.ReadAll(hashingReader)
	c.Assert(err, jc.ErrorIsNil)
	fp := hash.NewValidFingerprint(h)
	hexSum := fp.Hex()
	fpAgain, err := hash.ParseHexFingerprint(hexSum, validate)
	c.Assert(err, jc.ErrorIsNil)

	stub.CheckCallNames(c, "Read") // The EOF was mixed with the data.
	c.Check(string(data), gc.Equals, expected)
	c.Check(fpAgain, jc.DeepEquals, fp)
}