Download this file
| 1 | package fakeopencode |
| 2 | |
| 3 | import ( |
| 4 | "crypto/tls" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // Security round finding 8: the fake Go records every request it is |
| 10 | // sent, whatever its path, before it routes it, so a test sees stray |
| 11 | // traffic on the one allowed host. |
| 12 | func TestGoRecordsEveryRequest(t *testing.T) { |
| 13 | g := StartGo(t) |
| 14 | c := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}} |
| 15 | for _, path := range []string{"/api/share", "/inference/go/v1/models", "/telemetry"} { |
| 16 | resp, err := c.Get("https://" + g.Addr + path) |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | resp.Body.Close() |
| 21 | } |
| 22 | seen := g.Seen() |
| 23 | if len(seen) != 3 || seen[0].Path != "/api/share" || seen[0].Method != "GET" || seen[2].Path != "/telemetry" { |
| 24 | t.Fatalf("seen %+v", seen) |
| 25 | } |
| 26 | } |
| 27 | |