From 05a3bcf75e2363ab8cd17ef928e8382f42e28a03 Mon Sep 17 00:00:00 2001 From: alexmullins Date: Thu, 29 Oct 2015 16:44:18 -0500 Subject: [PATCH] add another test case for reading multiple encrypted files. --- reader_test.go | 36 +++++++++++++++++++++++++++++------- testdata/world-aes.zip | Bin 0 -> 392 bytes 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 testdata/world-aes.zip diff --git a/reader_test.go b/reader_test.go index 6eba4cf..751e965 100644 --- a/reader_test.go +++ b/reader_test.go @@ -614,23 +614,17 @@ func TestSimplePassword(t *testing.T) { t.Errorf("Expected %s to open: %v.", file, err) } defer r.Close() - if len(r.File) != 1 { t.Errorf("Expected %s to contain one file.", file) } - f := r.File[0] - if f.FileInfo().Name() != "hello.txt" { t.Errorf("Expected %s to have a file named hello.txt", file) } - if f.Method != 0 { t.Errorf("Expected %s to have its Method set to 0.", file) } - f.SetPassword([]byte("golang")) - rc, err := f.Open() if err != nil { t.Errorf("Expected to open the readcloser: %v.", err) @@ -639,8 +633,36 @@ func TestSimplePassword(t *testing.T) { if err != nil { t.Errorf("Expected to copy bytes: %v.", err) } - if !bytes.Contains(buf.Bytes(), []byte("Hello World\r\n")) { t.Errorf("Expected contents were not found.") } } + +func TestHelloWorldAes(t *testing.T) { + file := "world-aes.zip" + expecting := "helloworld" + r, err := OpenReader(filepath.Join("testdata", file)) + if err != nil { + t.Errorf("Expected %s to open: %v", file, err) + } + defer r.Close() + if len(r.File) != 2 { + t.Errorf("Expected %s to contain two files.", file) + } + var b bytes.Buffer + for _, f := range r.File { + if !f.IsEncrypted() { + t.Errorf("Expected %s to be encrypted.", f.FileInfo().Name) + } + f.SetPassword([]byte("golang")) + rc, err := f.Open() + if err != nil { + t.Errorf("Expected to open readcloser: %v", err) + } + defer rc.Close() + io.Copy(&b, rc) + } + if !bytes.Equal([]byte(expecting), b.Bytes()) { + t.Errorf("Expected ending content to be %s instead of %s", expecting, b.Bytes()) + } +} diff --git a/testdata/world-aes.zip b/testdata/world-aes.zip new file mode 100644 index 0000000000000000000000000000000000000000..ac0b7294745c58cb85ff641232b4d976c8054685 GIT binary patch literal 392 zcmWIWW@a&FU}Q*Uc-Iu`&Hx08K+FonoDAFy8L2rr`FbT4C5$uK8JHLxU6~meazcdK z|Ap--h_n31D%O@{rIots`vVcKI9*ALUiba#et!bsMt;I#WO;s3P70clwHwa&_62S9 z;x%|0bmsX{Q;yo#9L0QA5sY(W1=Kt?UHBg0&B$cWfXkiwAZG)C0+?h#xS9(p#K<7Q z5G$+4J3;6oqsV6?RuH|*{OZLFfs2etK0~$z)9J{z1Osh?dj#2*4Z3QAAk#IT^Kv5F UhGGjV8_1zdKzIg7F9UHH03