Skip to content

Commit 9ab6f7a

Browse files
committed
make testzip take extract args so they can be tested
1 parent 484dcb2 commit 9ab6f7a

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

main.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ var (
7474
slurpContentDisposition = slurpCmd.Flag("content-disposition", "Content disposition header").String()
7575

7676
// Testzip command (serves a local zip file via HTTP for debugging)
77-
testzipCmd = app.Command("testzip", "Extract and serve a local zip file via HTTP for debugging")
78-
testzipFile = testzipCmd.Arg("file", "Path to zip file").Required().String()
77+
testzipCmd = app.Command("testzip", "Extract and serve a local zip file via HTTP for debugging")
78+
testzipFile = testzipCmd.Arg("file", "Path to zip file").Required().String()
79+
testzipMaxFileSize = testzipCmd.Flag("max-file-size", "Maximum size per file in bytes").Uint64()
80+
testzipMaxTotalSize = testzipCmd.Flag("max-total-size", "Maximum total extracted size in bytes").Uint64()
81+
testzipMaxNumFiles = testzipCmd.Flag("max-num-files", "Maximum number of files").Int()
82+
testzipFilter = testzipCmd.Flag("filter", "Glob pattern to filter extracted files").String()
7983

8084
// Dump command
8185
dumpCmd = app.Command("dump", "Dump parsed config and exit")
@@ -306,5 +310,18 @@ func runSlurp(config *zipserver.Config) {
306310
}
307311

308312
func runTestzip(config *zipserver.Config) {
309-
must(zipserver.ServeZip(config, *testzipFile))
313+
limits := zipserver.DefaultExtractLimits(config)
314+
if *testzipMaxFileSize > 0 {
315+
limits.MaxFileSize = *testzipMaxFileSize
316+
}
317+
if *testzipMaxTotalSize > 0 {
318+
limits.MaxTotalSize = *testzipMaxTotalSize
319+
}
320+
if *testzipMaxNumFiles > 0 {
321+
limits.MaxNumFiles = *testzipMaxNumFiles
322+
}
323+
if *testzipFilter != "" {
324+
limits.IncludeGlob = *testzipFilter
325+
}
326+
must(zipserver.ServeZip(config, *testzipFile, limits))
310327
}

zipserver/serve_zip.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (mhh *memoryHttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
7070

7171
// ServeZip takes the path to zip file in the local fs and serves
7272
// it as http
73-
func ServeZip(config *Config, serve string) error {
73+
func ServeZip(config *Config, serve string, limits *ExtractLimits) error {
7474
config.Bucket = "local"
7575

7676
storage, err := NewMemStorage()
@@ -101,7 +101,7 @@ func ServeZip(config *Config, serve string) error {
101101
archiver := &ArchiveExtractor{Storage: storage, Config: config}
102102

103103
prefix := "extracted"
104-
extractedFiles, err := archiver.ExtractZip(ctx, key, prefix, DefaultExtractLimits(config))
104+
extractedFiles, err := archiver.ExtractZip(ctx, key, prefix, limits)
105105
if err != nil {
106106
return err
107107
}

0 commit comments

Comments
 (0)