diff options
author | xuri <xuri.me@gmail.com> | 2022-05-29 19:37:10 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2022-05-29 19:37:10 +0800 |
commit | 7a6d5f5ebe5fa9b74ec58b79baf79b369d496e21 (patch) | |
tree | da761d89ba9c8eb4a78a69770532a1c87c255e4a /crypt_test.go | |
parent | 551b83afab85f2911410a6fa994fe5cc883d8804 (diff) |
This initialized support for encryption workbook by password, ref #199
- Remove exported variable `ErrEncrypt`
Diffstat (limited to 'crypt_test.go')
-rw-r--r-- | crypt_test.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/crypt_test.go b/crypt_test.go index d095176..2df5af2 100644 --- a/crypt_test.go +++ b/crypt_test.go @@ -13,18 +13,33 @@ package excelize import ( "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" ) func TestEncrypt(t *testing.T) { + // Test decrypt spreadsheet with incorrect password _, err := OpenFile(filepath.Join("test", "encryptSHA1.xlsx"), Options{Password: "passwd"}) assert.EqualError(t, err, ErrWorkbookPassword.Error()) - + // Test decrypt spreadsheet with password f, err := OpenFile(filepath.Join("test", "encryptSHA1.xlsx"), Options{Password: "password"}) assert.NoError(t, err) - assert.EqualError(t, f.SaveAs(filepath.Join("test", "BadEncrypt.xlsx"), Options{Password: "password"}), ErrEncrypt.Error()) + cell, err := f.GetCellValue("Sheet1", "A1") + assert.NoError(t, err) + assert.Equal(t, "SECRET", cell) + assert.NoError(t, f.Close()) + // 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 + assert.NoError(t, f.SaveAs(filepath.Join("test", "Encryption.xlsx"), Options{Password: "passwd"})) + assert.NoError(t, f.Close()) + f, err = OpenFile(filepath.Join("test", "Encryption.xlsx"), Options{Password: "passwd"}) + assert.NoError(t, err) + cell, err = f.GetCellValue("Sheet1", "A1") + assert.NoError(t, err) + assert.Equal(t, "SECRET", cell) assert.NoError(t, f.Close()) } |