]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
Adds incomplete test for http range file
authorPhilippe Antoine <contact@catenacyber.fr>
Fri, 6 Dec 2019 14:58:09 +0000 (15:58 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 27 Sep 2021 21:09:52 +0000 (23:09 +0200)
tests/http-range-file/README.md [new file with mode: 0644]
tests/http-range-file/client.go [new file with mode: 0644]
tests/http-range-file/input.pcap [new file with mode: 0644]
tests/http-range-file/test.yaml [new file with mode: 0644]

diff --git a/tests/http-range-file/README.md b/tests/http-range-file/README.md
new file mode 100644 (file)
index 0000000..4b6ad34
--- /dev/null
@@ -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 (file)
index 0000000..61a2df3
--- /dev/null
@@ -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 (file)
index 0000000..4cae52d
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 (file)
index 0000000..fcb5b4d
--- /dev/null
@@ -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