Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 3 | import ( |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 4 | "bytes" |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 5 | "fmt" |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 6 | "github.com/onsi/gomega/gmeasure" |
| 7 | "io" |
Matus Fabian | d086a36 | 2024-06-27 13:20:10 +0200 | [diff] [blame] | 8 | "net" |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 9 | "net/http" |
Matus Fabian | d086a36 | 2024-06-27 13:20:10 +0200 | [diff] [blame] | 10 | "net/http/httptrace" |
| 11 | "os" |
Matus Fabian | 5c4c1b6 | 2024-06-28 16:11:04 +0200 | [diff] [blame] | 12 | "sync" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 13 | "time" |
| 14 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 15 | . "fd.io/hs-test/infra" |
Matus Fabian | 5c4c1b6 | 2024-06-28 16:11:04 +0200 | [diff] [blame] | 16 | . "github.com/onsi/ginkgo/v2" |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 17 | ) |
| 18 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 19 | func init() { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 20 | RegisterVethTests(HttpCliTest, HttpCliConnectErrorTest) |
Matus Fabian | d086a36 | 2024-06-27 13:20:10 +0200 | [diff] [blame] | 21 | RegisterNoTopoTests(HeaderServerTest, HttpPersistentConnectionTest, HttpPipeliningTest, |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 22 | HttpStaticMovedTest, HttpStaticNotFoundTest, HttpCliMethodNotAllowedTest, |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 23 | HttpCliBadRequestTest, HttpStaticBuildInUrlGetIfStatsTest, HttpStaticBuildInUrlPostIfStatsTest, |
| 24 | HttpInvalidRequestLineTest, HttpMethodNotImplementedTest, HttpInvalidHeadersTest, |
| 25 | HttpContentLengthTest, HttpStaticBuildInUrlGetIfListTest, HttpStaticBuildInUrlGetVersionTest, |
| 26 | HttpStaticMacTimeTest, HttpStaticBuildInUrlGetVersionVerboseTest, HttpVersionNotSupportedTest, |
| 27 | HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest, |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 28 | HttpHeadersTest, HttpStaticFileHandler) |
Matus Fabian | c712de5 | 2024-07-24 12:56:14 +0200 | [diff] [blame] | 29 | RegisterNoTopoSoloTests(HttpStaticPromTest, HttpTpsTest, HttpTpsInterruptModeTest, PromConcurrentConnections, |
| 30 | PromMemLeakTest) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 33 | const wwwRootPath = "/tmp/www_root" |
| 34 | |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 35 | func httpDownloadBenchmark(s *HstSuite, experiment *gmeasure.Experiment, data interface{}) { |
| 36 | url, isValid := data.(string) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 37 | s.AssertEqual(true, isValid) |
| 38 | client := NewHttpClient() |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 39 | req, err := http.NewRequest("GET", url, nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 40 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 41 | t := time.Now() |
| 42 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 43 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 44 | defer resp.Body.Close() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 45 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 46 | _, err = io.ReadAll(resp.Body) |
| 47 | duration := time.Since(t) |
| 48 | experiment.RecordValue("Download Speed", (float64(resp.ContentLength)/1024/1024)/duration.Seconds(), gmeasure.Units("MB/s"), gmeasure.Precision(2)) |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Adrian Villin | 1fde999 | 2024-06-24 08:14:05 -0400 | [diff] [blame] | 51 | func HttpTpsInterruptModeTest(s *NoTopoSuite) { |
| 52 | HttpTpsTest(s) |
| 53 | } |
| 54 | |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 55 | func HttpTpsTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 56 | vpp := s.GetContainerByName("vpp").VppInstance |
| 57 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 58 | url := "http://" + serverAddress + ":8080/test_file_10M" |
| 59 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 60 | vpp.Vppctl("http tps uri tcp://0.0.0.0/8080") |
Matus Fabian | 2d1f0e6 | 2024-06-06 11:24:36 +0200 | [diff] [blame] | 61 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 62 | s.RunBenchmark("HTTP tps 10M", 10, 0, httpDownloadBenchmark, url) |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Matus Fabian | d086a36 | 2024-06-27 13:20:10 +0200 | [diff] [blame] | 65 | func HttpPersistentConnectionTest(s *NoTopoSuite) { |
| 66 | // testing url handler app do not support multi-thread |
| 67 | s.SkipIfMultiWorker() |
| 68 | vpp := s.GetContainerByName("vpp").VppInstance |
| 69 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 70 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) |
| 71 | s.Log(vpp.Vppctl("test-url-handler enable")) |
| 72 | |
| 73 | transport := http.DefaultTransport |
| 74 | transport.(*http.Transport).Proxy = nil |
| 75 | transport.(*http.Transport).DisableKeepAlives = false |
| 76 | client := &http.Client{ |
| 77 | Transport: transport, |
| 78 | Timeout: time.Second * 30, |
| 79 | CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 80 | return http.ErrUseLastResponse |
| 81 | }} |
| 82 | |
| 83 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/test1", nil) |
| 84 | s.AssertNil(err, fmt.Sprint(err)) |
| 85 | resp, err := client.Do(req) |
| 86 | s.AssertNil(err, fmt.Sprint(err)) |
| 87 | defer resp.Body.Close() |
| 88 | s.Log(DumpHttpResp(resp, true)) |
| 89 | s.AssertEqual(200, resp.StatusCode) |
| 90 | s.AssertEqual(false, resp.Close) |
| 91 | body, err := io.ReadAll(resp.Body) |
| 92 | s.AssertNil(err, fmt.Sprint(err)) |
| 93 | s.AssertEqual(string(body), "hello") |
| 94 | o1 := vpp.Vppctl("show session verbose proto http state ready") |
| 95 | s.Log(o1) |
| 96 | s.AssertContains(o1, "ESTABLISHED") |
| 97 | |
| 98 | req, err = http.NewRequest("GET", "http://"+serverAddress+":80/test2", nil) |
| 99 | s.AssertNil(err, fmt.Sprint(err)) |
| 100 | clientTrace := &httptrace.ClientTrace{ |
| 101 | GotConn: func(info httptrace.GotConnInfo) { |
| 102 | s.AssertEqual(true, info.Reused, "connection not reused") |
| 103 | }, |
| 104 | } |
| 105 | req = req.WithContext(httptrace.WithClientTrace(req.Context(), clientTrace)) |
| 106 | resp, err = client.Do(req) |
| 107 | s.AssertNil(err, fmt.Sprint(err)) |
| 108 | defer resp.Body.Close() |
| 109 | s.Log(DumpHttpResp(resp, true)) |
| 110 | s.AssertEqual(200, resp.StatusCode) |
| 111 | s.AssertEqual(false, resp.Close) |
| 112 | body, err = io.ReadAll(resp.Body) |
| 113 | s.AssertNil(err, fmt.Sprint(err)) |
| 114 | s.AssertEqual(string(body), "some data") |
| 115 | s.AssertNil(err, fmt.Sprint(err)) |
| 116 | o2 := vpp.Vppctl("show session verbose proto http state ready") |
| 117 | s.Log(o2) |
| 118 | s.AssertContains(o2, "ESTABLISHED") |
| 119 | s.AssertEqual(o1, o2) |
| 120 | } |
| 121 | |
| 122 | func HttpPipeliningTest(s *NoTopoSuite) { |
| 123 | // testing url handler app do not support multi-thread |
| 124 | s.SkipIfMultiWorker() |
| 125 | vpp := s.GetContainerByName("vpp").VppInstance |
| 126 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 127 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
| 128 | s.Log(vpp.Vppctl("test-url-handler enable")) |
| 129 | |
| 130 | req1 := "GET /test_delayed HTTP/1.1\r\nHost:" + serverAddress + ":80\r\nUser-Agent:test\r\n\r\n" |
| 131 | req2 := "GET /test1 HTTP/1.1\r\nHost:" + serverAddress + ":80\r\nUser-Agent:test\r\n\r\n" |
| 132 | |
| 133 | conn, err := net.DialTimeout("tcp", serverAddress+":80", time.Second*30) |
| 134 | s.AssertNil(err, fmt.Sprint(err)) |
| 135 | defer conn.Close() |
| 136 | err = conn.SetDeadline(time.Now().Add(time.Second * 15)) |
| 137 | s.AssertNil(err, fmt.Sprint(err)) |
| 138 | n, err := conn.Write([]byte(req1)) |
| 139 | s.AssertNil(err, fmt.Sprint(err)) |
| 140 | s.AssertEqual(n, len([]rune(req1))) |
| 141 | // send second request a bit later so first is already in progress |
| 142 | time.Sleep(500 * time.Millisecond) |
| 143 | n, err = conn.Write([]byte(req2)) |
| 144 | s.AssertNil(err, fmt.Sprint(err)) |
| 145 | s.AssertEqual(n, len([]rune(req2))) |
| 146 | reply := make([]byte, 1024) |
| 147 | n, err = conn.Read(reply) |
| 148 | s.AssertNil(err, fmt.Sprint(err)) |
| 149 | s.Log(string(reply)) |
| 150 | s.AssertContains(string(reply), "delayed data", "first request response not received") |
| 151 | s.AssertNotContains(string(reply), "hello", "second request response received") |
| 152 | // make sure response for second request is not received later |
| 153 | _, err = conn.Read(reply) |
| 154 | s.AssertMatchError(err, os.ErrDeadlineExceeded, "second request response received") |
| 155 | } |
| 156 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 157 | func HttpCliTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 158 | serverContainer := s.GetContainerByName("server-vpp") |
| 159 | clientContainer := s.GetContainerByName("client-vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 160 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 161 | serverVeth := s.GetInterfaceByName(ServerInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 162 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 163 | serverContainer.VppInstance.Vppctl("http cli server") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 164 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 165 | uri := "http://" + serverVeth.Ip4AddressString() + "/80" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 166 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 167 | o := clientContainer.VppInstance.Vppctl("http cli client" + |
Filip Tehlar | d894438 | 2023-11-27 13:28:36 +0100 | [diff] [blame] | 168 | " uri " + uri + " query /show/vlib/graph") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 169 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 170 | s.Log(o) |
| 171 | s.AssertContains(o, "<html>", "<html> not found in the result!") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 172 | } |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 173 | |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 174 | func HttpCliConnectErrorTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 175 | clientContainer := s.GetContainerByName("client-vpp") |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 176 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 177 | serverVeth := s.GetInterfaceByName(ServerInterfaceName) |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 178 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 179 | uri := "http://" + serverVeth.Ip4AddressString() + "/80" |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 180 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 181 | o := clientContainer.VppInstance.Vppctl("http cli client" + |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 182 | " uri " + uri + " query /show/vlib/graph") |
| 183 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 184 | s.Log(o) |
| 185 | s.AssertContains(o, "failed to connect") |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 188 | func HttpStaticPromTest(s *NoTopoSuite) { |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 189 | query := "stats.prom" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 190 | vpp := s.GetContainerByName("vpp").VppInstance |
| 191 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 192 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) |
| 193 | s.Log(vpp.Vppctl("prom enable")) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 194 | time.Sleep(time.Second * 5) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 195 | client := NewHttpClient() |
| 196 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/"+query, nil) |
| 197 | s.AssertNil(err, fmt.Sprint(err)) |
| 198 | resp, err := client.Do(req) |
| 199 | s.AssertNil(err, fmt.Sprint(err)) |
| 200 | defer resp.Body.Close() |
| 201 | s.Log(DumpHttpResp(resp, false)) |
| 202 | s.AssertEqual(200, resp.StatusCode) |
| 203 | s.AssertContains(resp.Header.Get("Content-Type"), "text") |
| 204 | s.AssertContains(resp.Header.Get("Content-Type"), "plain") |
| 205 | s.AssertNotEqual(int64(0), resp.ContentLength) |
| 206 | _, err = io.ReadAll(resp.Body) |
| 207 | } |
| 208 | |
Matus Fabian | c712de5 | 2024-07-24 12:56:14 +0200 | [diff] [blame] | 209 | func promReq(s *NoTopoSuite, url string) { |
Matus Fabian | 5c4c1b6 | 2024-06-28 16:11:04 +0200 | [diff] [blame] | 210 | client := NewHttpClient() |
| 211 | req, err := http.NewRequest("GET", url, nil) |
| 212 | s.AssertNil(err, fmt.Sprint(err)) |
| 213 | resp, err := client.Do(req) |
| 214 | s.AssertNil(err, fmt.Sprint(err)) |
| 215 | defer resp.Body.Close() |
| 216 | s.AssertEqual(200, resp.StatusCode) |
| 217 | _, err = io.ReadAll(resp.Body) |
| 218 | } |
| 219 | |
Matus Fabian | c712de5 | 2024-07-24 12:56:14 +0200 | [diff] [blame] | 220 | func promReqWg(s *NoTopoSuite, url string, wg *sync.WaitGroup) { |
| 221 | defer GinkgoRecover() |
| 222 | defer wg.Done() |
| 223 | promReq(s, url) |
| 224 | } |
| 225 | |
Matus Fabian | 5c4c1b6 | 2024-06-28 16:11:04 +0200 | [diff] [blame] | 226 | func PromConcurrentConnections(s *NoTopoSuite) { |
| 227 | vpp := s.GetContainerByName("vpp").VppInstance |
| 228 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 229 | url := "http://" + serverAddress + ":80/stats.prom" |
| 230 | |
| 231 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) |
| 232 | s.Log(vpp.Vppctl("prom enable")) |
| 233 | time.Sleep(time.Second * 5) |
| 234 | |
| 235 | var wg sync.WaitGroup |
| 236 | for i := 0; i < 20; i++ { |
| 237 | wg.Add(1) |
Matus Fabian | c712de5 | 2024-07-24 12:56:14 +0200 | [diff] [blame] | 238 | go promReqWg(s, url, &wg) |
Matus Fabian | 5c4c1b6 | 2024-06-28 16:11:04 +0200 | [diff] [blame] | 239 | } |
| 240 | wg.Wait() |
| 241 | s.Log(vpp.Vppctl("show session verbose proto http")) |
| 242 | } |
| 243 | |
Matus Fabian | c712de5 | 2024-07-24 12:56:14 +0200 | [diff] [blame] | 244 | func PromMemLeakTest(s *NoTopoSuite) { |
| 245 | s.SkipUnlessLeakCheck() |
| 246 | |
| 247 | vpp := s.GetContainerByName("vpp").VppInstance |
| 248 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 249 | url := "http://" + serverAddress + ":80/stats.prom" |
| 250 | |
| 251 | /* no goVPP less noise */ |
| 252 | vpp.Disconnect() |
| 253 | |
| 254 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) |
| 255 | s.Log(vpp.Vppctl("prom enable")) |
| 256 | time.Sleep(time.Second * 3) |
| 257 | |
| 258 | /* warmup request (FIB) */ |
| 259 | promReq(s, url) |
| 260 | |
| 261 | vpp.EnableMemoryTrace() |
| 262 | traces1, err := vpp.GetMemoryTrace() |
| 263 | s.AssertNil(err, fmt.Sprint(err)) |
| 264 | |
| 265 | /* collect stats couple of times */ |
| 266 | for i := 0; i < 5; i++ { |
| 267 | time.Sleep(time.Second * 1) |
| 268 | promReq(s, url) |
| 269 | } |
| 270 | |
| 271 | /* let's give it some time to clean up sessions */ |
| 272 | time.Sleep(time.Second * 5) |
| 273 | |
| 274 | traces2, err := vpp.GetMemoryTrace() |
| 275 | s.AssertNil(err, fmt.Sprint(err)) |
| 276 | vpp.MemLeakCheck(traces1, traces2) |
| 277 | } |
| 278 | |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 279 | func HttpStaticFileHandler(s *NoTopoSuite) { |
| 280 | content := "<http><body><p>Hello</p></body></http>" |
| 281 | content2 := "<http><body><p>Page</p></body></http>" |
| 282 | vpp := s.GetContainerByName("vpp").VppInstance |
| 283 | vpp.Container.Exec("mkdir -p " + wwwRootPath) |
| 284 | vpp.Container.CreateFile(wwwRootPath+"/index.html", content) |
| 285 | vpp.Container.CreateFile(wwwRootPath+"/page.html", content2) |
| 286 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 287 | s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug cache-size 2m")) |
| 288 | |
| 289 | client := NewHttpClient() |
| 290 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/index.html", nil) |
| 291 | s.AssertNil(err, fmt.Sprint(err)) |
| 292 | resp, err := client.Do(req) |
| 293 | s.AssertNil(err, fmt.Sprint(err)) |
| 294 | defer resp.Body.Close() |
| 295 | s.Log(DumpHttpResp(resp, true)) |
| 296 | s.AssertEqual(200, resp.StatusCode) |
| 297 | s.AssertContains(resp.Header.Get("Content-Type"), "html") |
| 298 | s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=") |
| 299 | s.AssertEqual(int64(len([]rune(content))), resp.ContentLength) |
| 300 | body, err := io.ReadAll(resp.Body) |
| 301 | s.AssertEqual(string(body), content) |
| 302 | o := vpp.Vppctl("show http static server cache verbose") |
| 303 | s.Log(o) |
| 304 | s.AssertContains(o, "index.html") |
| 305 | s.AssertNotContains(o, "page.html") |
| 306 | |
| 307 | resp, err = client.Do(req) |
| 308 | s.AssertNil(err, fmt.Sprint(err)) |
| 309 | defer resp.Body.Close() |
| 310 | s.Log(DumpHttpResp(resp, true)) |
| 311 | s.AssertEqual(200, resp.StatusCode) |
| 312 | s.AssertContains(resp.Header.Get("Content-Type"), "html") |
| 313 | s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=") |
| 314 | s.AssertEqual(int64(len([]rune(content))), resp.ContentLength) |
| 315 | body, err = io.ReadAll(resp.Body) |
| 316 | s.AssertEqual(string(body), content) |
| 317 | |
| 318 | req, err = http.NewRequest("GET", "http://"+serverAddress+":80/page.html", nil) |
| 319 | s.AssertNil(err, fmt.Sprint(err)) |
| 320 | resp, err = client.Do(req) |
| 321 | s.AssertNil(err, fmt.Sprint(err)) |
| 322 | defer resp.Body.Close() |
| 323 | s.Log(DumpHttpResp(resp, true)) |
| 324 | s.AssertEqual(200, resp.StatusCode) |
| 325 | s.AssertContains(resp.Header.Get("Content-Type"), "html") |
| 326 | s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=") |
| 327 | s.AssertEqual(int64(len([]rune(content2))), resp.ContentLength) |
| 328 | body, err = io.ReadAll(resp.Body) |
| 329 | s.AssertEqual(string(body), content2) |
| 330 | o = vpp.Vppctl("show http static server cache verbose") |
| 331 | s.Log(o) |
| 332 | s.AssertContains(o, "index.html") |
| 333 | s.AssertContains(o, "page.html") |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 336 | func HttpStaticPathTraversalTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 337 | vpp := s.GetContainerByName("vpp").VppInstance |
| 338 | vpp.Container.Exec("mkdir -p " + wwwRootPath) |
| 339 | vpp.Container.Exec("mkdir -p " + "/tmp/secret_folder") |
| 340 | vpp.Container.CreateFile("/tmp/secret_folder/secret_file.txt", "secret") |
| 341 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 342 | s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 343 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 344 | client := NewHttpClient() |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 345 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/../secret_folder/secret_file.txt", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 346 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 347 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 348 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 349 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 350 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 351 | s.AssertEqual(404, resp.StatusCode) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 352 | s.AssertEmpty(resp.Header.Get("Content-Type")) |
| 353 | s.AssertEmpty(resp.Header.Get("Cache-Control")) |
| 354 | s.AssertEqual(int64(0), resp.ContentLength) |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 357 | func HttpStaticMovedTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 358 | vpp := s.GetContainerByName("vpp").VppInstance |
| 359 | vpp.Container.Exec("mkdir -p " + wwwRootPath + "/tmp.aaa") |
| 360 | vpp.Container.CreateFile(wwwRootPath+"/tmp.aaa/index.html", "<http><body><p>Hello</p></body></http>") |
| 361 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 362 | s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 363 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 364 | client := NewHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 365 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/tmp.aaa", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 366 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 367 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 368 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 369 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 370 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 371 | s.AssertEqual(301, resp.StatusCode) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 372 | s.AssertEqual("http://"+serverAddress+"/tmp.aaa/index.html", resp.Header.Get("Location")) |
| 373 | s.AssertEmpty(resp.Header.Get("Content-Type")) |
| 374 | s.AssertEmpty(resp.Header.Get("Cache-Control")) |
| 375 | s.AssertEqual(int64(0), resp.ContentLength) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | func HttpStaticNotFoundTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 379 | vpp := s.GetContainerByName("vpp").VppInstance |
| 380 | vpp.Container.Exec("mkdir -p " + wwwRootPath) |
| 381 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 382 | s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 383 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 384 | client := NewHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 385 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/notfound.html", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 386 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 387 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 388 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 389 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 390 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 391 | s.AssertEqual(404, resp.StatusCode) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 392 | s.AssertEmpty(resp.Header.Get("Content-Type")) |
| 393 | s.AssertEmpty(resp.Header.Get("Cache-Control")) |
| 394 | s.AssertEqual(int64(0), resp.ContentLength) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | func HttpCliMethodNotAllowedTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 398 | vpp := s.GetContainerByName("vpp").VppInstance |
| 399 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 400 | vpp.Vppctl("http cli server") |
Matus Fabian | 616201a | 2024-05-02 11:17:15 +0200 | [diff] [blame] | 401 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 402 | client := NewHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 403 | req, err := http.NewRequest("POST", "http://"+serverAddress+":80/test", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 404 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 405 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 406 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 407 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 408 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 409 | s.AssertEqual(405, resp.StatusCode) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 410 | s.AssertNotEqual("", resp.Header.Get("Allow"), "server MUST generate an Allow header") |
| 411 | s.AssertEmpty(resp.Header.Get("Content-Type")) |
| 412 | s.AssertEqual(int64(0), resp.ContentLength) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | func HttpCliBadRequestTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 416 | vpp := s.GetContainerByName("vpp").VppInstance |
| 417 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 418 | vpp.Vppctl("http cli server") |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 419 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 420 | client := NewHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 421 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 422 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 423 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 424 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 425 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 426 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 427 | s.AssertEqual(400, resp.StatusCode) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 428 | s.AssertEmpty(resp.Header.Get("Content-Type")) |
| 429 | s.AssertEqual(int64(0), resp.ContentLength) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 432 | func HttpStaticBuildInUrlGetVersionTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 433 | vpp := s.GetContainerByName("vpp").VppInstance |
| 434 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 435 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 436 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 437 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 438 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/version.json", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 439 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 440 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 441 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 442 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 443 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 444 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 445 | data, err := io.ReadAll(resp.Body) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 446 | s.AssertNil(err, fmt.Sprint(err)) |
| 447 | s.AssertContains(string(data), "vpp_details") |
| 448 | s.AssertContains(string(data), "version") |
| 449 | s.AssertContains(string(data), "build_date") |
| 450 | s.AssertNotContains(string(data), "build_by") |
| 451 | s.AssertNotContains(string(data), "build_host") |
| 452 | s.AssertNotContains(string(data), "build_dir") |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 453 | s.AssertContains(resp.Header.Get("Content-Type"), "json") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | func HttpStaticBuildInUrlGetVersionVerboseTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 457 | vpp := s.GetContainerByName("vpp").VppInstance |
| 458 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 459 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 460 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 461 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 462 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/version.json?verbose=true", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 463 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 464 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 465 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 466 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 467 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 468 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 469 | data, err := io.ReadAll(resp.Body) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 470 | s.AssertNil(err, fmt.Sprint(err)) |
| 471 | s.AssertContains(string(data), "vpp_details") |
| 472 | s.AssertContains(string(data), "version") |
| 473 | s.AssertContains(string(data), "build_date") |
| 474 | s.AssertContains(string(data), "build_by") |
| 475 | s.AssertContains(string(data), "build_host") |
| 476 | s.AssertContains(string(data), "build_dir") |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 477 | s.AssertContains(resp.Header.Get("Content-Type"), "json") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | func HttpStaticBuildInUrlGetIfListTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 481 | vpp := s.GetContainerByName("vpp").VppInstance |
| 482 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 483 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 484 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 485 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 486 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/interface_list.json", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 487 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 488 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 489 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 490 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 491 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 492 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 493 | data, err := io.ReadAll(resp.Body) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 494 | s.AssertNil(err, fmt.Sprint(err)) |
| 495 | s.AssertContains(string(data), "interface_list") |
| 496 | s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).Peer.Name()) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 497 | s.AssertContains(resp.Header.Get("Content-Type"), "json") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | func HttpStaticBuildInUrlGetIfStatsTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 501 | vpp := s.GetContainerByName("vpp").VppInstance |
| 502 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 503 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 504 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 505 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 506 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/interface_stats.json", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 507 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 508 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 509 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 510 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 511 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 512 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 513 | data, err := io.ReadAll(resp.Body) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 514 | s.AssertNil(err, fmt.Sprint(err)) |
| 515 | s.AssertContains(string(data), "interface_stats") |
| 516 | s.AssertContains(string(data), "local0") |
| 517 | s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).Peer.Name()) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 518 | s.AssertContains(resp.Header.Get("Content-Type"), "json") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | func validatePostInterfaceStats(s *NoTopoSuite, data string) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 522 | s.AssertContains(data, "interface_stats") |
| 523 | s.AssertContains(data, s.GetInterfaceByName(TapInterfaceName).Peer.Name()) |
| 524 | s.AssertNotContains(data, "error") |
| 525 | s.AssertNotContains(data, "local0") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | func HttpStaticBuildInUrlPostIfStatsTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 529 | vpp := s.GetContainerByName("vpp").VppInstance |
| 530 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 531 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
| 532 | body := []byte(s.GetInterfaceByName(TapInterfaceName).Peer.Name()) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 533 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 534 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 535 | req, err := http.NewRequest("POST", |
| 536 | "http://"+serverAddress+":80/interface_stats.json", bytes.NewBuffer(body)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 537 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 538 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 539 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 540 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 541 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 542 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 543 | data, err := io.ReadAll(resp.Body) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 544 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 545 | validatePostInterfaceStats(s, string(data)) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 546 | s.AssertContains(resp.Header.Get("Content-Type"), "json") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | func HttpStaticMacTimeTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 550 | vpp := s.GetContainerByName("vpp").VppInstance |
| 551 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 552 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
| 553 | s.Log(vpp.Vppctl("mactime enable-disable " + s.GetInterfaceByName(TapInterfaceName).Peer.Name())) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 554 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 555 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 556 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/mactime.json", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 557 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 558 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 559 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 560 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 561 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 562 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 563 | data, err := io.ReadAll(resp.Body) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 564 | s.AssertNil(err, fmt.Sprint(err)) |
| 565 | s.AssertContains(string(data), "mactime") |
| 566 | s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).Ip4AddressString()) |
| 567 | s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).HwAddress.String()) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 568 | s.AssertContains(resp.Header.Get("Content-Type"), "json") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | func HttpInvalidRequestLineTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 572 | vpp := s.GetContainerByName("vpp").VppInstance |
| 573 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 574 | vpp.Vppctl("http cli server") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 575 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 576 | resp, err := TcpSendReceive(serverAddress+":80", "GET / HTTP/1.1") |
| 577 | s.AssertNil(err, fmt.Sprint(err)) |
| 578 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid framing not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 579 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 580 | resp, err = TcpSendReceive(serverAddress+":80", "GET / HTTP/1.1\r\n") |
| 581 | s.AssertNil(err, fmt.Sprint(err)) |
| 582 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid framing not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 583 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 584 | resp, err = TcpSendReceive(serverAddress+":80", "GET /\r\n\r\n") |
| 585 | s.AssertNil(err, fmt.Sprint(err)) |
| 586 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "HTTP-version must be present") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 587 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 588 | resp, err = TcpSendReceive(serverAddress+":80", "GET HTTP/1.1\r\n\r\n") |
| 589 | s.AssertNil(err, fmt.Sprint(err)) |
| 590 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "request-target must be present") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 591 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 592 | resp, err = TcpSendReceive(serverAddress+":80", "GET HTTP/1.1\r\n\r\n") |
| 593 | s.AssertNil(err, fmt.Sprint(err)) |
| 594 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "request-target must be present") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 595 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 596 | resp, err = TcpSendReceive(serverAddress+":80", "GET / HTTP/x\r\n\r\n") |
| 597 | s.AssertNil(err, fmt.Sprint(err)) |
| 598 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'HTTP/x' invalid http version not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 599 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 600 | resp, err = TcpSendReceive(serverAddress+":80", "GET / HTTP1.1\r\n\r\n") |
| 601 | s.AssertNil(err, fmt.Sprint(err)) |
| 602 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'HTTP1.1' invalid http version not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | func HttpInvalidTargetSyntaxTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 606 | vpp := s.GetContainerByName("vpp").VppInstance |
| 607 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 608 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 609 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 610 | resp, err := TcpSendReceive(serverAddress+":80", "GET /interface|stats.json HTTP/1.1\r\n\r\n") |
| 611 | s.AssertNil(err, fmt.Sprint(err)) |
| 612 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'|' not allowed in target path") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 613 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 614 | resp, err = TcpSendReceive(serverAddress+":80", "GET /interface#stats.json HTTP/1.1\r\n\r\n") |
| 615 | s.AssertNil(err, fmt.Sprint(err)) |
| 616 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'#' not allowed in target path") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 617 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 618 | resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%stats.json HTTP/1.1\r\n\r\n") |
| 619 | s.AssertNil(err, fmt.Sprint(err)) |
| 620 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 621 | "after '%' there must be two hex-digit characters in target path") |
| 622 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 623 | resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%1stats.json HTTP/1.1\r\n\r\n") |
| 624 | s.AssertNil(err, fmt.Sprint(err)) |
| 625 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 626 | "after '%' there must be two hex-digit characters in target path") |
| 627 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 628 | resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%Bstats.json HTTP/1.1\r\n\r\n") |
| 629 | s.AssertNil(err, fmt.Sprint(err)) |
| 630 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 631 | "after '%' there must be two hex-digit characters in target path") |
| 632 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 633 | resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%stats.json%B HTTP/1.1\r\n\r\n") |
| 634 | s.AssertNil(err, fmt.Sprint(err)) |
| 635 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 636 | "after '%' there must be two hex-digit characters in target path") |
| 637 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 638 | resp, err = TcpSendReceive(serverAddress+":80", "GET /version.json?verbose>true HTTP/1.1\r\n\r\n") |
| 639 | s.AssertNil(err, fmt.Sprint(err)) |
| 640 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'>' not allowed in target query") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 641 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 642 | resp, err = TcpSendReceive(serverAddress+":80", "GET /version.json?verbose%true HTTP/1.1\r\n\r\n") |
| 643 | s.AssertNil(err, fmt.Sprint(err)) |
| 644 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 645 | "after '%' there must be two hex-digit characters in target query") |
| 646 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 647 | resp, err = TcpSendReceive(serverAddress+":80", "GET /version.json?verbose=%1 HTTP/1.1\r\n\r\n") |
| 648 | s.AssertNil(err, fmt.Sprint(err)) |
| 649 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 650 | "after '%' there must be two hex-digit characters in target query") |
| 651 | } |
| 652 | |
| 653 | func HttpInvalidContentLengthTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 654 | vpp := s.GetContainerByName("vpp").VppInstance |
| 655 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 656 | vpp.Vppctl("http cli server") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 657 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 658 | resp, err := TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nContent-Length:\r\n\r\n") |
| 659 | s.AssertNil(err, fmt.Sprint(err)) |
| 660 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "Content-Length value must be present") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 661 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 662 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nContent-Length: \r\n\r\n") |
| 663 | s.AssertNil(err, fmt.Sprint(err)) |
| 664 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "Content-Length value must be present") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 665 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 666 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nContent-Length: a\r\n\r\n") |
| 667 | s.AssertNil(err, fmt.Sprint(err)) |
| 668 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 669 | "Content-Length value other than digit not allowed") |
| 670 | } |
| 671 | |
| 672 | func HttpContentLengthTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 673 | vpp := s.GetContainerByName("vpp").VppInstance |
| 674 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 675 | s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) |
| 676 | ifName := s.GetInterfaceByName(TapInterfaceName).Peer.Name() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 677 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 678 | resp, err := TcpSendReceive(serverAddress+":80", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 679 | "POST /interface_stats.json HTTP/1.1\r\nContent-Length:4\r\n\r\n"+ifName) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 680 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 681 | validatePostInterfaceStats(s, resp) |
| 682 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 683 | resp, err = TcpSendReceive(serverAddress+":80", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 684 | "POST /interface_stats.json HTTP/1.1\r\n Content-Length: 4 \r\n\r\n"+ifName) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 685 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 686 | validatePostInterfaceStats(s, resp) |
| 687 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 688 | resp, err = TcpSendReceive(serverAddress+":80", |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 689 | "POST /interface_stats.json HTTP/1.1\r\n\tContent-Length:\t\t4\r\n\r\n"+ifName) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 690 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 691 | validatePostInterfaceStats(s, resp) |
| 692 | } |
| 693 | |
| 694 | func HttpMethodNotImplementedTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 695 | vpp := s.GetContainerByName("vpp").VppInstance |
| 696 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 697 | vpp.Vppctl("http cli server") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 698 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 699 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 700 | req, err := http.NewRequest("OPTIONS", "http://"+serverAddress+":80/show/version", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 701 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 702 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 703 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 704 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 705 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 706 | s.AssertEqual(501, resp.StatusCode) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 707 | s.AssertEmpty(resp.Header.Get("Content-Type")) |
| 708 | s.AssertEqual(int64(0), resp.ContentLength) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | func HttpVersionNotSupportedTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 712 | vpp := s.GetContainerByName("vpp").VppInstance |
| 713 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 714 | vpp.Vppctl("http cli server") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 715 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 716 | resp, err := TcpSendReceive(serverAddress+":80", "GET / HTTP/2\r\n\r\n") |
| 717 | s.AssertNil(err, fmt.Sprint(err)) |
| 718 | s.AssertContains(resp, "HTTP/1.1 505 HTTP Version Not Supported") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | func HttpUriDecodeTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 722 | vpp := s.GetContainerByName("vpp").VppInstance |
| 723 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 724 | vpp.Vppctl("http cli server") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 725 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 726 | client := NewHttpClient() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 727 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/sh%6fw%20versio%6E%20verbose", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 728 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 729 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 730 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 731 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 732 | s.Log(DumpHttpResp(resp, true)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 733 | s.AssertEqual(200, resp.StatusCode) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 734 | data, err := io.ReadAll(resp.Body) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 735 | s.AssertNil(err, fmt.Sprint(err)) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 736 | s.AssertNotContains(string(data), "unknown input") |
| 737 | s.AssertContains(string(data), "Compiler") |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 738 | s.AssertContains(resp.Header.Get("Content-Type"), "html") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | func HttpHeadersTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 742 | vpp := s.GetContainerByName("vpp").VppInstance |
| 743 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 744 | vpp.Vppctl("http cli server") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 745 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 746 | resp, err := TcpSendReceive( |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 747 | serverAddress+":80", |
| 748 | "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser-Agent:test\r\nAccept:text/xml\r\nAccept:\ttext/plain\t \r\nAccept:text/html\r\n\r\n") |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 749 | s.AssertNil(err, fmt.Sprint(err)) |
| 750 | s.AssertContains(resp, "HTTP/1.1 200 OK") |
| 751 | s.AssertContains(resp, "Content-Type: text / plain") |
| 752 | s.AssertNotContains(resp, "<html>", "html content received instead of plain text") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | func HttpInvalidHeadersTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 756 | vpp := s.GetContainerByName("vpp").VppInstance |
| 757 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 758 | vpp.Vppctl("http cli server") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 759 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 760 | resp, err := TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nUser-Agent: test\r\n") |
| 761 | s.AssertNil(err, fmt.Sprint(err)) |
| 762 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "Header section must end with CRLF CRLF") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 763 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 764 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser@Agent:test\r\n\r\n") |
| 765 | s.AssertNil(err, fmt.Sprint(err)) |
| 766 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'@' not allowed in field name") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 767 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 768 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser-Agent\r\n\r\n") |
| 769 | s.AssertNil(err, fmt.Sprint(err)) |
| 770 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "incomplete field line not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 771 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 772 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\n: test\r\n\r\n") |
| 773 | s.AssertNil(err, fmt.Sprint(err)) |
| 774 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "empty field name not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 775 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 776 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\rUser-Agent:test\r\n\r\n") |
| 777 | s.AssertNil(err, fmt.Sprint(err)) |
| 778 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid field line end not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 779 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 780 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\nUser-Agent:test\r\n\r\n") |
| 781 | s.AssertNil(err, fmt.Sprint(err)) |
| 782 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid field line end not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 783 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 784 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser-Agent:\r\n\r\n") |
| 785 | s.AssertNil(err, fmt.Sprint(err)) |
| 786 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "empty field value not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 787 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 788 | resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser-Agent: \r\n\r\n") |
| 789 | s.AssertNil(err, fmt.Sprint(err)) |
| 790 | s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "empty field value not allowed") |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 791 | } |
| 792 | |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 793 | func HeaderServerTest(s *NoTopoSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 794 | vpp := s.GetContainerByName("vpp").VppInstance |
| 795 | serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() |
| 796 | vpp.Vppctl("http cli server") |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 797 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 798 | client := NewHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 799 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/show/version", nil) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 800 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 801 | resp, err := client.Do(req) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 802 | s.AssertNil(err, fmt.Sprint(err)) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 803 | defer resp.Body.Close() |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 804 | s.Log(DumpHttpResp(resp, true)) |
| 805 | s.AssertEqual(200, resp.StatusCode) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 806 | s.AssertEqual("http_cli_server", resp.Header.Get("Server")) |
Matus Fabian | 8ca6ce6 | 2024-06-20 17:08:26 +0200 | [diff] [blame] | 807 | s.AssertContains(resp.Header.Get("Content-Type"), "html") |
Matus Fabian | 616201a | 2024-05-02 11:17:15 +0200 | [diff] [blame] | 808 | } |