diff options
author | xuri <xuri.me@gmail.com> | 2021-08-15 00:06:40 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-08-15 00:06:40 +0800 |
commit | 48c16de8bf74df0fa94a30d29e2e7e3446d48433 (patch) | |
tree | 329a2e4ab896982581bd348a1700d75aeb40a517 /excelize_test.go | |
parent | f6f14f507ee1adf4883cb1b12f27932a63afb286 (diff) |
Improve security and simplify code
- Make variable name more semantic
- Reduce cyclomatic complexities for the formula calculate function
- Support specified unzip size limit on open file options, avoid zip bombs vulnerability attack
- Typo fix for documentation and error message
Diffstat (limited to 'excelize_test.go')
-rw-r--r-- | excelize_test.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/excelize_test.go b/excelize_test.go index cc3a1b2..918279b 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -184,13 +184,9 @@ func TestSaveFile(t *testing.T) { func TestSaveAsWrongPath(t *testing.T) { f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) - if assert.NoError(t, err) { - // Test write file to not exist directory. - err = f.SaveAs("") - if assert.Error(t, err) { - assert.True(t, os.IsNotExist(err), "Error: %v: Expected os.IsNotExists(err) == true", err) - } - } + assert.NoError(t, err) + // Test write file to not exist directory. + assert.EqualError(t, f.SaveAs(""), "open .: is a directory") } func TestCharsetTranscoder(t *testing.T) { @@ -204,6 +200,10 @@ func TestOpenReader(t *testing.T) { _, err = OpenReader(bytes.NewReader(oleIdentifier), Options{Password: "password"}) assert.EqualError(t, err, "decrypted file failed") + // Test open spreadsheet with unzip size limit. + _, err = OpenFile(filepath.Join("test", "Book1.xlsx"), Options{UnzipSizeLimit: 100}) + assert.EqualError(t, err, newUnzipSizeLimitError(100).Error()) + // Test open password protected spreadsheet created by Microsoft Office Excel 2010. f, err := OpenFile(filepath.Join("test", "encryptSHA1.xlsx"), Options{Password: "password"}) assert.NoError(t, err) @@ -1226,6 +1226,7 @@ func TestWorkSheetReader(t *testing.T) { f.Pkg.Store("xl/worksheets/sheet1.xml", MacintoshCyrillicCharset) _, err := f.workSheetReader("Sheet1") assert.EqualError(t, err, "xml decode error: XML syntax error on line 1: invalid UTF-8") + assert.EqualError(t, f.UpdateLinkedValue(), "xml decode error: XML syntax error on line 1: invalid UTF-8") // Test on no checked worksheet. f = NewFile() |