From: Philippe Antoine Date: Fri, 6 Dec 2019 14:58:09 +0000 (+0100) Subject: Adds incomplete test for http range file X-Git-Tag: suricata-6.0.4~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=518c18bfad75eef1769c440475f65fc09b8edbe8;p=thirdparty%2Fsuricata-verify.git Adds incomplete test for http range file --- diff --git a/tests/http-range-file/README.md b/tests/http-range-file/README.md new file mode 100644 index 000000000..4b6ad3421 --- /dev/null +++ b/tests/http-range-file/README.md @@ -0,0 +1,7 @@ +# Description + +Test http file extraction over multiple transactions with range header. + +# PCAP + +The pcap comes from running `go run client.go` diff --git a/tests/http-range-file/client.go b/tests/http-range-file/client.go new file mode 100644 index 000000000..61a2df315 --- /dev/null +++ b/tests/http-range-file/client.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + "io" + "io/ioutil" + "net" + "net/http" + "strconv" + "strings" + "time" +) + +func main() { + url := "http://i.imgur.com/z4d4kWk.jpg" + step := 10000 + + tr := &http.Transport{ + //may not be needed + MaxIdleConns: 10, + MaxIdleConnsPerHost: 10, + MaxConnsPerHost: 10, + IdleConnTimeout: 30 * time.Second, + DisableKeepAlives: false, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + } + client := &http.Client{Transport: tr} + + req, _ := http.NewRequest("GET", url, nil) + req.Header.Set("Range", fmt.Sprintf("bytes=0-%d", step-1)) + resp, err := client.Do(req) + filesize, _ := strconv.Atoi(strings.Split(resp.Header["Content-Range"][0], "/")[1]) + fmt.Printf("%#+v %#+v\n", filesize, err) + //cf https://github.com/golang/go/issues/26095 + io.Copy(ioutil.Discard, resp.Body) + resp.Body.Close() + + for start := step; start < filesize; start += step { + req2, _ := http.NewRequest("GET", url, nil) + req2.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", start, start+step-1)) + resp2, _ := client.Do(req2) + io.Copy(ioutil.Discard, resp2.Body) + resp2.Body.Close() + + fmt.Printf("%#+v %#+v\n", start, step) + } +} diff --git a/tests/http-range-file/input.pcap b/tests/http-range-file/input.pcap new file mode 100644 index 000000000..4cae52d43 Binary files /dev/null and b/tests/http-range-file/input.pcap differ diff --git a/tests/http-range-file/test.yaml b/tests/http-range-file/test.yaml new file mode 100644 index 000000000..fcb5b4dde --- /dev/null +++ b/tests/http-range-file/test.yaml @@ -0,0 +1,17 @@ +requires: + features: + - HAVE_LIBJANSSON + min-version: 7.0.0 + +# disables checksum verification +args: + - -k none + +checks: + + # Check that there is one file event with content range. + - filter: + count: 1 + match: + event_type: fileinfo + fileinfo.size: 146515