add test for failing corrupt input into flate

This commit is contained in:
alexmullins 2015-10-29 23:12:02 -05:00
parent 17e26cdce5
commit a4e475ab56
4 changed files with 33 additions and 2 deletions

View File

@ -11,7 +11,7 @@ hello.txt -> compress -> encrypt -> .zip -> decrypt -> decompress -> hello.txt
Roadmap
==============================================================================
Reading - Almost done (TODO: check for AE-2 and skip CRC).
Reading - Working on it. Some bugs to work out (TODO: check for AE-2 and skip CRC).
Writing - Not started.
Testing - Needs more.

View File

@ -244,6 +244,7 @@ func decryptStream(ciphertext, key, iv []byte) io.Reader {
return nil
}
stream := cipher.NewCTR(block, iv)
// Not decrypting stream correctly if the number of bytes being read is >16
reader := cipher.StreamReader{S: stream, R: bytes.NewReader(ciphertext)}
return reader
}

View File

@ -660,9 +660,39 @@ func TestHelloWorldAes(t *testing.T) {
t.Errorf("Expected to open readcloser: %v", err)
}
defer rc.Close()
io.Copy(&b, rc)
if _, err := io.Copy(&b, rc); err != nil {
t.Errorf("Expected to copy bytes to buffer: %v", err)
}
}
if !bytes.Equal([]byte(expecting), b.Bytes()) {
t.Errorf("Expected ending content to be %s instead of %s", expecting, b.Bytes())
}
}
func TestMacbethAct1(t *testing.T) {
file := "macbeth-act1.zip"
expecting := "Exeunt"
var b bytes.Buffer
r, err := OpenReader(filepath.Join("testdata", file))
if err != nil {
t.Errorf("Expected %s to open: %v", file, err)
}
defer r.Close()
for _, f := range r.File {
if !f.IsEncrypted() {
t.Errorf("Expected %s to be encrypted.", f.Name)
}
f.SetPassword([]byte("golang"))
rc, err := f.Open()
if err != nil {
t.Errorf("Expected to open readcloser: %v", err)
}
defer rc.Close()
if _, err := io.Copy(&b, rc); err != nil {
t.Errorf("Expected to copy bytes to buffer: %v", err)
}
}
if !bytes.Contains(b.Bytes(), []byte(expecting)) {
t.Errorf("Expected to find %s in the buffer %v", expecting, b.Bytes())
}
}

BIN
testdata/macbeth-act1.zip vendored Normal file

Binary file not shown.