summaryrefslogtreecommitdiff
path: root/file_test.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-08-15 00:06:40 +0800
committerxuri <xuri.me@gmail.com>2021-08-15 00:06:40 +0800
commit48c16de8bf74df0fa94a30d29e2e7e3446d48433 (patch)
tree329a2e4ab896982581bd348a1700d75aeb40a517 /file_test.go
parentf6f14f507ee1adf4883cb1b12f27932a63afb286 (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 'file_test.go')
-rw-r--r--file_test.go12
1 files changed, 3 insertions, 9 deletions
diff --git a/file_test.go b/file_test.go
index d86ce53..956ff92 100644
--- a/file_test.go
+++ b/file_test.go
@@ -37,9 +37,7 @@ func BenchmarkWrite(b *testing.B) {
func TestWriteTo(t *testing.T) {
// Test WriteToBuffer err
{
- f := File{}
- buf := bytes.Buffer{}
- f.Pkg = sync.Map{}
+ f, buf := File{Pkg: sync.Map{}}, bytes.Buffer{}
f.Pkg.Store("/d/", []byte("s"))
_, err := f.WriteTo(bufio.NewWriter(&buf))
assert.EqualError(t, err, "zip: write to directory")
@@ -47,9 +45,7 @@ func TestWriteTo(t *testing.T) {
}
// Test file path overflow
{
- f := File{}
- buf := bytes.Buffer{}
- f.Pkg = sync.Map{}
+ f, buf := File{Pkg: sync.Map{}}, bytes.Buffer{}
const maxUint16 = 1<<16 - 1
f.Pkg.Store(strings.Repeat("s", maxUint16+1), nil)
_, err := f.WriteTo(bufio.NewWriter(&buf))
@@ -57,9 +53,7 @@ func TestWriteTo(t *testing.T) {
}
// Test StreamsWriter err
{
- f := File{}
- buf := bytes.Buffer{}
- f.Pkg = sync.Map{}
+ f, buf := File{Pkg: sync.Map{}}, bytes.Buffer{}
f.Pkg.Store("s", nil)
f.streams = make(map[string]*StreamWriter)
file, _ := os.Open("123")