diff options
Diffstat (limited to 'crypt_test.go')
-rw-r--r-- | crypt_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/crypt_test.go b/crypt_test.go index 2df5af2..d2fba35 100644 --- a/crypt_test.go +++ b/crypt_test.go @@ -12,6 +12,7 @@ package excelize import ( + "io/ioutil" "path/filepath" "strings" "testing" @@ -30,6 +31,13 @@ func TestEncrypt(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "SECRET", cell) assert.NoError(t, f.Close()) + // Test decrypt spreadsheet with unsupported encrypt mechanism + raw, err := ioutil.ReadFile(filepath.Join("test", "encryptAES.xlsx")) + assert.NoError(t, err) + raw[2050] = 3 + _, err = Decrypt(raw, &Options{Password: "password"}) + assert.EqualError(t, err, ErrUnsupportedEncryptMechanism.Error()) + // Test encrypt spreadsheet with invalid password assert.EqualError(t, f.SaveAs(filepath.Join("test", "Encryption.xlsx"), Options{Password: strings.Repeat("*", MaxFieldLength+1)}), ErrPasswordLengthInvalid.Error()) // Test encrypt spreadsheet with new password @@ -51,6 +59,11 @@ func TestEncryptionMechanism(t *testing.T) { assert.EqualError(t, err, ErrUnknownEncryptMechanism.Error()) } +func TestEncryptionWriteDirectoryEntry(t *testing.T) { + cfb := cfb{} + assert.Equal(t, 1536, len(cfb.writeDirectoryEntry(0, 0, -1))) +} + func TestHashing(t *testing.T) { assert.Equal(t, hashing("unsupportedHashAlgorithm", []byte{}), []byte(nil)) } |