blob: a5694bfb54ba3ed17026a789b1950c286f2dfea4 [file] [log] [blame]
Filip Tehlarb15a0002022-11-10 12:34:17 +01001package main
2
Filip Tehlarc204c872022-12-21 08:59:16 +01003import (
Matus Fabian82ad9662024-06-04 19:00:00 +02004 "bytes"
Filip Tehlar8df3de42023-01-27 13:14:34 +01005 "fmt"
Matus Fabian2d1f0e62024-06-06 11:24:36 +02006 "github.com/onsi/gomega/gmeasure"
7 "io"
Matus Fabianb7a9ed72024-05-10 16:20:40 +02008 "net/http"
Adrian Villincee15aa2024-03-14 11:42:55 -04009 "time"
10
Adrian Villin4677d922024-06-14 09:32:39 +020011 . "fd.io/hs-test/infra"
Adrian Villincee15aa2024-03-14 11:42:55 -040012 . "github.com/onsi/ginkgo/v2"
Filip Tehlarc204c872022-12-21 08:59:16 +010013)
14
Adrian Villincee15aa2024-03-14 11:42:55 -040015func init() {
Adrian Villin4677d922024-06-14 09:32:39 +020016 RegisterVethTests(HttpCliTest, HttpCliConnectErrorTest)
Matus Fabianed984382024-06-24 19:05:38 +020017 RegisterNoTopoTests(HeaderServerTest,
Matus Fabianb7a9ed72024-05-10 16:20:40 +020018 HttpStaticMovedTest, HttpStaticNotFoundTest, HttpCliMethodNotAllowedTest,
Matus Fabian82ad9662024-06-04 19:00:00 +020019 HttpCliBadRequestTest, HttpStaticBuildInUrlGetIfStatsTest, HttpStaticBuildInUrlPostIfStatsTest,
20 HttpInvalidRequestLineTest, HttpMethodNotImplementedTest, HttpInvalidHeadersTest,
21 HttpContentLengthTest, HttpStaticBuildInUrlGetIfListTest, HttpStaticBuildInUrlGetVersionTest,
22 HttpStaticMacTimeTest, HttpStaticBuildInUrlGetVersionVerboseTest, HttpVersionNotSupportedTest,
23 HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest,
24 HttpHeadersTest)
Adrian Villin1fde9992024-06-24 08:14:05 -040025 RegisterNoTopoSoloTests(HttpStaticPromTest, HttpTpsTest, HttpTpsInterruptModeTest)
Adrian Villincee15aa2024-03-14 11:42:55 -040026}
27
Matus Fabian5409d332024-05-28 13:39:13 +020028const wwwRootPath = "/tmp/www_root"
29
Matus Fabian2d1f0e62024-06-06 11:24:36 +020030func httpDownloadBenchmark(s *HstSuite, experiment *gmeasure.Experiment, data interface{}) {
31 url, isValid := data.(string)
Adrian Villin4677d922024-06-14 09:32:39 +020032 s.AssertEqual(true, isValid)
33 client := NewHttpClient()
Matus Fabian2d1f0e62024-06-06 11:24:36 +020034 req, err := http.NewRequest("GET", url, nil)
Adrian Villin4677d922024-06-14 09:32:39 +020035 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian2d1f0e62024-06-06 11:24:36 +020036 t := time.Now()
37 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +020038 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian2d1f0e62024-06-06 11:24:36 +020039 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +020040 s.AssertEqual(200, resp.StatusCode)
Matus Fabian2d1f0e62024-06-06 11:24:36 +020041 _, err = io.ReadAll(resp.Body)
42 duration := time.Since(t)
43 experiment.RecordValue("Download Speed", (float64(resp.ContentLength)/1024/1024)/duration.Seconds(), gmeasure.Units("MB/s"), gmeasure.Precision(2))
Matus Fabian2d1f0e62024-06-06 11:24:36 +020044}
45
Adrian Villin1fde9992024-06-24 08:14:05 -040046func HttpTpsInterruptModeTest(s *NoTopoSuite) {
47 HttpTpsTest(s)
48}
49
Matus Fabian2d1f0e62024-06-06 11:24:36 +020050func HttpTpsTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020051 vpp := s.GetContainerByName("vpp").VppInstance
52 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
Matus Fabian2d1f0e62024-06-06 11:24:36 +020053 url := "http://" + serverAddress + ":8080/test_file_10M"
54
Adrian Villin4677d922024-06-14 09:32:39 +020055 vpp.Vppctl("http tps uri tcp://0.0.0.0/8080")
Matus Fabian2d1f0e62024-06-06 11:24:36 +020056
Adrian Villin4677d922024-06-14 09:32:39 +020057 s.RunBenchmark("HTTP tps 10M", 10, 0, httpDownloadBenchmark, url)
Filip Tehlarb15a0002022-11-10 12:34:17 +010058}
59
Adrian Villincee15aa2024-03-14 11:42:55 -040060func HttpCliTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020061 serverContainer := s.GetContainerByName("server-vpp")
62 clientContainer := s.GetContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010063
Adrian Villin4677d922024-06-14 09:32:39 +020064 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010065
Adrian Villin4677d922024-06-14 09:32:39 +020066 serverContainer.VppInstance.Vppctl("http cli server")
Filip Tehlarb15a0002022-11-10 12:34:17 +010067
Adrian Villin4677d922024-06-14 09:32:39 +020068 uri := "http://" + serverVeth.Ip4AddressString() + "/80"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010069
Adrian Villin4677d922024-06-14 09:32:39 +020070 o := clientContainer.VppInstance.Vppctl("http cli client" +
Filip Tehlard8944382023-11-27 13:28:36 +010071 " uri " + uri + " query /show/vlib/graph")
Filip Tehlarb15a0002022-11-10 12:34:17 +010072
Adrian Villin4677d922024-06-14 09:32:39 +020073 s.Log(o)
74 s.AssertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010075}
Filip Tehlarc204c872022-12-21 08:59:16 +010076
Matus Fabian3d008932024-05-13 10:29:11 +020077func HttpCliConnectErrorTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020078 clientContainer := s.GetContainerByName("client-vpp")
Matus Fabian3d008932024-05-13 10:29:11 +020079
Adrian Villin4677d922024-06-14 09:32:39 +020080 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
Matus Fabian3d008932024-05-13 10:29:11 +020081
Adrian Villin4677d922024-06-14 09:32:39 +020082 uri := "http://" + serverVeth.Ip4AddressString() + "/80"
Matus Fabian3d008932024-05-13 10:29:11 +020083
Adrian Villin4677d922024-06-14 09:32:39 +020084 o := clientContainer.VppInstance.Vppctl("http cli client" +
Matus Fabian3d008932024-05-13 10:29:11 +020085 " uri " + uri + " query /show/vlib/graph")
86
Adrian Villin4677d922024-06-14 09:32:39 +020087 s.Log(o)
88 s.AssertContains(o, "failed to connect")
Matus Fabian3d008932024-05-13 10:29:11 +020089}
90
Adrian Villincee15aa2024-03-14 11:42:55 -040091func HttpStaticPromTest(s *NoTopoSuite) {
Filip Tehlarcc1475c2023-11-29 12:59:05 +010092 finished := make(chan error, 1)
93 query := "stats.prom"
Adrian Villin4677d922024-06-14 09:32:39 +020094 vpp := s.GetContainerByName("vpp").VppInstance
95 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
96 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers"))
97 s.Log(vpp.Vppctl("prom enable"))
Adrian Villincee15aa2024-03-14 11:42:55 -040098 time.Sleep(time.Second * 5)
99 go func() {
100 defer GinkgoRecover()
Adrian Villin4677d922024-06-14 09:32:39 +0200101 s.StartWget(finished, serverAddress, "80", query, "")
Adrian Villincee15aa2024-03-14 11:42:55 -0400102 }()
Filip Tehlarcc1475c2023-11-29 12:59:05 +0100103 err := <-finished
Adrian Villin4677d922024-06-14 09:32:39 +0200104 s.AssertNil(err)
Filip Tehlarcc1475c2023-11-29 12:59:05 +0100105}
106
Matus Fabian5409d332024-05-28 13:39:13 +0200107func HttpStaticPathTraversalTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200108 vpp := s.GetContainerByName("vpp").VppInstance
109 vpp.Container.Exec("mkdir -p " + wwwRootPath)
110 vpp.Container.Exec("mkdir -p " + "/tmp/secret_folder")
111 vpp.Container.CreateFile("/tmp/secret_folder/secret_file.txt", "secret")
112 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
113 s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug"))
Matus Fabian5409d332024-05-28 13:39:13 +0200114
Adrian Villin4677d922024-06-14 09:32:39 +0200115 client := NewHttpClient()
Matus Fabian5409d332024-05-28 13:39:13 +0200116 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/../secret_folder/secret_file.txt", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200117 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian5409d332024-05-28 13:39:13 +0200118 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200119 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian5409d332024-05-28 13:39:13 +0200120 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200121 s.AssertEqual(404, resp.StatusCode)
Matus Fabian5409d332024-05-28 13:39:13 +0200122}
123
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200124func HttpStaticMovedTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200125 vpp := s.GetContainerByName("vpp").VppInstance
126 vpp.Container.Exec("mkdir -p " + wwwRootPath + "/tmp.aaa")
127 vpp.Container.CreateFile(wwwRootPath+"/tmp.aaa/index.html", "<http><body><p>Hello</p></body></http>")
128 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
129 s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug"))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200130
Adrian Villin4677d922024-06-14 09:32:39 +0200131 client := NewHttpClient()
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200132 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/tmp.aaa", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200133 s.AssertNil(err, fmt.Sprint(err))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200134 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200135 s.AssertNil(err, fmt.Sprint(err))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200136 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200137 s.AssertEqual(301, resp.StatusCode)
138 s.AssertNotEqual("", resp.Header.Get("Location"))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200139}
140
141func HttpStaticNotFoundTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200142 vpp := s.GetContainerByName("vpp").VppInstance
143 vpp.Container.Exec("mkdir -p " + wwwRootPath)
144 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
145 s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug"))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200146
Adrian Villin4677d922024-06-14 09:32:39 +0200147 client := NewHttpClient()
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200148 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/notfound.html", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200149 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian595d8cb2024-05-17 11:28:43 +0200150 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200151 s.AssertNil(err, fmt.Sprint(err))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200152 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200153 s.AssertEqual(404, resp.StatusCode)
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200154}
155
156func HttpCliMethodNotAllowedTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200157 vpp := s.GetContainerByName("vpp").VppInstance
158 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
159 vpp.Vppctl("http cli server")
Matus Fabian616201a2024-05-02 11:17:15 +0200160
Adrian Villin4677d922024-06-14 09:32:39 +0200161 client := NewHttpClient()
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200162 req, err := http.NewRequest("POST", "http://"+serverAddress+":80/test", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200163 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian595d8cb2024-05-17 11:28:43 +0200164 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200165 s.AssertNil(err, fmt.Sprint(err))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200166 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200167 s.AssertEqual(405, resp.StatusCode)
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200168 // TODO: need to be fixed in http code
Adrian Villin4677d922024-06-14 09:32:39 +0200169 //s.AssertNotEqual("", resp.Header.Get("Allow"))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200170}
171
172func HttpCliBadRequestTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200173 vpp := s.GetContainerByName("vpp").VppInstance
174 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
175 vpp.Vppctl("http cli server")
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200176
Adrian Villin4677d922024-06-14 09:32:39 +0200177 client := NewHttpClient()
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200178 req, err := http.NewRequest("GET", "http://"+serverAddress+":80", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200179 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian595d8cb2024-05-17 11:28:43 +0200180 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200181 s.AssertNil(err, fmt.Sprint(err))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200182 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200183 s.AssertEqual(400, resp.StatusCode)
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200184}
185
Matus Fabian82ad9662024-06-04 19:00:00 +0200186func HttpStaticBuildInUrlGetVersionTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200187 vpp := s.GetContainerByName("vpp").VppInstance
188 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
189 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
Matus Fabian82ad9662024-06-04 19:00:00 +0200190
Adrian Villin4677d922024-06-14 09:32:39 +0200191 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200192 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/version.json", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200193 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200194 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200195 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200196 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200197 s.AssertEqual(200, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200198 data, err := io.ReadAll(resp.Body)
Adrian Villin4677d922024-06-14 09:32:39 +0200199 s.AssertNil(err, fmt.Sprint(err))
200 s.AssertContains(string(data), "vpp_details")
201 s.AssertContains(string(data), "version")
202 s.AssertContains(string(data), "build_date")
203 s.AssertNotContains(string(data), "build_by")
204 s.AssertNotContains(string(data), "build_host")
205 s.AssertNotContains(string(data), "build_dir")
Matus Fabian82ad9662024-06-04 19:00:00 +0200206}
207
208func HttpStaticBuildInUrlGetVersionVerboseTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200209 vpp := s.GetContainerByName("vpp").VppInstance
210 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
211 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
Matus Fabian82ad9662024-06-04 19:00:00 +0200212
Adrian Villin4677d922024-06-14 09:32:39 +0200213 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200214 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/version.json?verbose=true", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200215 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200216 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200217 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200218 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200219 s.AssertEqual(200, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200220 data, err := io.ReadAll(resp.Body)
Adrian Villin4677d922024-06-14 09:32:39 +0200221 s.AssertNil(err, fmt.Sprint(err))
222 s.AssertContains(string(data), "vpp_details")
223 s.AssertContains(string(data), "version")
224 s.AssertContains(string(data), "build_date")
225 s.AssertContains(string(data), "build_by")
226 s.AssertContains(string(data), "build_host")
227 s.AssertContains(string(data), "build_dir")
Matus Fabian82ad9662024-06-04 19:00:00 +0200228}
229
230func HttpStaticBuildInUrlGetIfListTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200231 vpp := s.GetContainerByName("vpp").VppInstance
232 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
233 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
Matus Fabian82ad9662024-06-04 19:00:00 +0200234
Adrian Villin4677d922024-06-14 09:32:39 +0200235 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200236 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/interface_list.json", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200237 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200238 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200239 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200240 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200241 s.AssertEqual(200, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200242 data, err := io.ReadAll(resp.Body)
Adrian Villin4677d922024-06-14 09:32:39 +0200243 s.AssertNil(err, fmt.Sprint(err))
244 s.AssertContains(string(data), "interface_list")
245 s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).Peer.Name())
Matus Fabian82ad9662024-06-04 19:00:00 +0200246}
247
248func HttpStaticBuildInUrlGetIfStatsTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200249 vpp := s.GetContainerByName("vpp").VppInstance
250 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
251 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
Matus Fabian82ad9662024-06-04 19:00:00 +0200252
Adrian Villin4677d922024-06-14 09:32:39 +0200253 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200254 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/interface_stats.json", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200255 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200256 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200257 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200258 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200259 s.AssertEqual(200, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200260 data, err := io.ReadAll(resp.Body)
Adrian Villin4677d922024-06-14 09:32:39 +0200261 s.AssertNil(err, fmt.Sprint(err))
262 s.AssertContains(string(data), "interface_stats")
263 s.AssertContains(string(data), "local0")
264 s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).Peer.Name())
Matus Fabian82ad9662024-06-04 19:00:00 +0200265}
266
267func validatePostInterfaceStats(s *NoTopoSuite, data string) {
Adrian Villin4677d922024-06-14 09:32:39 +0200268 s.AssertContains(data, "interface_stats")
269 s.AssertContains(data, s.GetInterfaceByName(TapInterfaceName).Peer.Name())
270 s.AssertNotContains(data, "error")
271 s.AssertNotContains(data, "local0")
Matus Fabian82ad9662024-06-04 19:00:00 +0200272}
273
274func HttpStaticBuildInUrlPostIfStatsTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200275 vpp := s.GetContainerByName("vpp").VppInstance
276 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
277 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
278 body := []byte(s.GetInterfaceByName(TapInterfaceName).Peer.Name())
Matus Fabian82ad9662024-06-04 19:00:00 +0200279
Adrian Villin4677d922024-06-14 09:32:39 +0200280 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200281 req, err := http.NewRequest("POST",
282 "http://"+serverAddress+":80/interface_stats.json", bytes.NewBuffer(body))
Adrian Villin4677d922024-06-14 09:32:39 +0200283 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200284 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200285 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200286 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200287 s.AssertEqual(200, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200288 data, err := io.ReadAll(resp.Body)
Adrian Villin4677d922024-06-14 09:32:39 +0200289 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200290 validatePostInterfaceStats(s, string(data))
291}
292
293func HttpStaticMacTimeTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200294 vpp := s.GetContainerByName("vpp").VppInstance
295 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
296 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
297 s.Log(vpp.Vppctl("mactime enable-disable " + s.GetInterfaceByName(TapInterfaceName).Peer.Name()))
Matus Fabian82ad9662024-06-04 19:00:00 +0200298
Adrian Villin4677d922024-06-14 09:32:39 +0200299 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200300 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/mactime.json", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200301 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200302 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200303 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200304 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200305 s.AssertEqual(200, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200306 data, err := io.ReadAll(resp.Body)
Adrian Villin4677d922024-06-14 09:32:39 +0200307 s.AssertNil(err, fmt.Sprint(err))
308 s.AssertContains(string(data), "mactime")
309 s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).Ip4AddressString())
310 s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).HwAddress.String())
Matus Fabian82ad9662024-06-04 19:00:00 +0200311}
312
313func HttpInvalidRequestLineTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200314 vpp := s.GetContainerByName("vpp").VppInstance
315 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
316 vpp.Vppctl("http cli server")
Matus Fabian82ad9662024-06-04 19:00:00 +0200317
Adrian Villin4677d922024-06-14 09:32:39 +0200318 resp, err := TcpSendReceive(serverAddress+":80", "GET / HTTP/1.1")
319 s.AssertNil(err, fmt.Sprint(err))
320 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid framing not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200321
Adrian Villin4677d922024-06-14 09:32:39 +0200322 resp, err = TcpSendReceive(serverAddress+":80", "GET / HTTP/1.1\r\n")
323 s.AssertNil(err, fmt.Sprint(err))
324 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid framing not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200325
Adrian Villin4677d922024-06-14 09:32:39 +0200326 resp, err = TcpSendReceive(serverAddress+":80", "GET /\r\n\r\n")
327 s.AssertNil(err, fmt.Sprint(err))
328 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "HTTP-version must be present")
Matus Fabian82ad9662024-06-04 19:00:00 +0200329
Adrian Villin4677d922024-06-14 09:32:39 +0200330 resp, err = TcpSendReceive(serverAddress+":80", "GET HTTP/1.1\r\n\r\n")
331 s.AssertNil(err, fmt.Sprint(err))
332 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "request-target must be present")
Matus Fabian82ad9662024-06-04 19:00:00 +0200333
Adrian Villin4677d922024-06-14 09:32:39 +0200334 resp, err = TcpSendReceive(serverAddress+":80", "GET HTTP/1.1\r\n\r\n")
335 s.AssertNil(err, fmt.Sprint(err))
336 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "request-target must be present")
Matus Fabian82ad9662024-06-04 19:00:00 +0200337
Adrian Villin4677d922024-06-14 09:32:39 +0200338 resp, err = TcpSendReceive(serverAddress+":80", "GET / HTTP/x\r\n\r\n")
339 s.AssertNil(err, fmt.Sprint(err))
340 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'HTTP/x' invalid http version not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200341
Adrian Villin4677d922024-06-14 09:32:39 +0200342 resp, err = TcpSendReceive(serverAddress+":80", "GET / HTTP1.1\r\n\r\n")
343 s.AssertNil(err, fmt.Sprint(err))
344 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'HTTP1.1' invalid http version not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200345}
346
347func HttpInvalidTargetSyntaxTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200348 vpp := s.GetContainerByName("vpp").VppInstance
349 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
350 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
Matus Fabian82ad9662024-06-04 19:00:00 +0200351
Adrian Villin4677d922024-06-14 09:32:39 +0200352 resp, err := TcpSendReceive(serverAddress+":80", "GET /interface|stats.json HTTP/1.1\r\n\r\n")
353 s.AssertNil(err, fmt.Sprint(err))
354 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'|' not allowed in target path")
Matus Fabian82ad9662024-06-04 19:00:00 +0200355
Adrian Villin4677d922024-06-14 09:32:39 +0200356 resp, err = TcpSendReceive(serverAddress+":80", "GET /interface#stats.json HTTP/1.1\r\n\r\n")
357 s.AssertNil(err, fmt.Sprint(err))
358 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'#' not allowed in target path")
Matus Fabian82ad9662024-06-04 19:00:00 +0200359
Adrian Villin4677d922024-06-14 09:32:39 +0200360 resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%stats.json HTTP/1.1\r\n\r\n")
361 s.AssertNil(err, fmt.Sprint(err))
362 s.AssertContains(resp, "HTTP/1.1 400 Bad Request",
Matus Fabian82ad9662024-06-04 19:00:00 +0200363 "after '%' there must be two hex-digit characters in target path")
364
Adrian Villin4677d922024-06-14 09:32:39 +0200365 resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%1stats.json HTTP/1.1\r\n\r\n")
366 s.AssertNil(err, fmt.Sprint(err))
367 s.AssertContains(resp, "HTTP/1.1 400 Bad Request",
Matus Fabian82ad9662024-06-04 19:00:00 +0200368 "after '%' there must be two hex-digit characters in target path")
369
Adrian Villin4677d922024-06-14 09:32:39 +0200370 resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%Bstats.json HTTP/1.1\r\n\r\n")
371 s.AssertNil(err, fmt.Sprint(err))
372 s.AssertContains(resp, "HTTP/1.1 400 Bad Request",
Matus Fabian82ad9662024-06-04 19:00:00 +0200373 "after '%' there must be two hex-digit characters in target path")
374
Adrian Villin4677d922024-06-14 09:32:39 +0200375 resp, err = TcpSendReceive(serverAddress+":80", "GET /interface%stats.json%B HTTP/1.1\r\n\r\n")
376 s.AssertNil(err, fmt.Sprint(err))
377 s.AssertContains(resp, "HTTP/1.1 400 Bad Request",
Matus Fabian82ad9662024-06-04 19:00:00 +0200378 "after '%' there must be two hex-digit characters in target path")
379
Adrian Villin4677d922024-06-14 09:32:39 +0200380 resp, err = TcpSendReceive(serverAddress+":80", "GET /version.json?verbose>true HTTP/1.1\r\n\r\n")
381 s.AssertNil(err, fmt.Sprint(err))
382 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'>' not allowed in target query")
Matus Fabian82ad9662024-06-04 19:00:00 +0200383
Adrian Villin4677d922024-06-14 09:32:39 +0200384 resp, err = TcpSendReceive(serverAddress+":80", "GET /version.json?verbose%true HTTP/1.1\r\n\r\n")
385 s.AssertNil(err, fmt.Sprint(err))
386 s.AssertContains(resp, "HTTP/1.1 400 Bad Request",
Matus Fabian82ad9662024-06-04 19:00:00 +0200387 "after '%' there must be two hex-digit characters in target query")
388
Adrian Villin4677d922024-06-14 09:32:39 +0200389 resp, err = TcpSendReceive(serverAddress+":80", "GET /version.json?verbose=%1 HTTP/1.1\r\n\r\n")
390 s.AssertNil(err, fmt.Sprint(err))
391 s.AssertContains(resp, "HTTP/1.1 400 Bad Request",
Matus Fabian82ad9662024-06-04 19:00:00 +0200392 "after '%' there must be two hex-digit characters in target query")
393}
394
395func HttpInvalidContentLengthTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200396 vpp := s.GetContainerByName("vpp").VppInstance
397 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
398 vpp.Vppctl("http cli server")
Matus Fabian82ad9662024-06-04 19:00:00 +0200399
Adrian Villin4677d922024-06-14 09:32:39 +0200400 resp, err := TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nContent-Length:\r\n\r\n")
401 s.AssertNil(err, fmt.Sprint(err))
402 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "Content-Length value must be present")
Matus Fabian82ad9662024-06-04 19:00:00 +0200403
Adrian Villin4677d922024-06-14 09:32:39 +0200404 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nContent-Length: \r\n\r\n")
405 s.AssertNil(err, fmt.Sprint(err))
406 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "Content-Length value must be present")
Matus Fabian82ad9662024-06-04 19:00:00 +0200407
Adrian Villin4677d922024-06-14 09:32:39 +0200408 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nContent-Length: a\r\n\r\n")
409 s.AssertNil(err, fmt.Sprint(err))
410 s.AssertContains(resp, "HTTP/1.1 400 Bad Request",
Matus Fabian82ad9662024-06-04 19:00:00 +0200411 "Content-Length value other than digit not allowed")
412}
413
414func HttpContentLengthTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200415 vpp := s.GetContainerByName("vpp").VppInstance
416 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
417 s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug"))
418 ifName := s.GetInterfaceByName(TapInterfaceName).Peer.Name()
Matus Fabian82ad9662024-06-04 19:00:00 +0200419
Adrian Villin4677d922024-06-14 09:32:39 +0200420 resp, err := TcpSendReceive(serverAddress+":80",
Matus Fabian82ad9662024-06-04 19:00:00 +0200421 "POST /interface_stats.json HTTP/1.1\r\nContent-Length:4\r\n\r\n"+ifName)
Adrian Villin4677d922024-06-14 09:32:39 +0200422 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200423 validatePostInterfaceStats(s, resp)
424
Adrian Villin4677d922024-06-14 09:32:39 +0200425 resp, err = TcpSendReceive(serverAddress+":80",
Matus Fabian82ad9662024-06-04 19:00:00 +0200426 "POST /interface_stats.json HTTP/1.1\r\n Content-Length: 4 \r\n\r\n"+ifName)
Adrian Villin4677d922024-06-14 09:32:39 +0200427 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200428 validatePostInterfaceStats(s, resp)
429
Adrian Villin4677d922024-06-14 09:32:39 +0200430 resp, err = TcpSendReceive(serverAddress+":80",
Matus Fabian82ad9662024-06-04 19:00:00 +0200431 "POST /interface_stats.json HTTP/1.1\r\n\tContent-Length:\t\t4\r\n\r\n"+ifName)
Adrian Villin4677d922024-06-14 09:32:39 +0200432 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200433 validatePostInterfaceStats(s, resp)
434}
435
436func HttpMethodNotImplementedTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200437 vpp := s.GetContainerByName("vpp").VppInstance
438 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
439 vpp.Vppctl("http cli server")
Matus Fabian82ad9662024-06-04 19:00:00 +0200440
Adrian Villin4677d922024-06-14 09:32:39 +0200441 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200442 req, err := http.NewRequest("OPTIONS", "http://"+serverAddress+":80/show/version", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200443 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200444 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200445 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200446 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200447 s.AssertEqual(501, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200448}
449
450func HttpVersionNotSupportedTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200451 vpp := s.GetContainerByName("vpp").VppInstance
452 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
453 vpp.Vppctl("http cli server")
Matus Fabian82ad9662024-06-04 19:00:00 +0200454
Adrian Villin4677d922024-06-14 09:32:39 +0200455 resp, err := TcpSendReceive(serverAddress+":80", "GET / HTTP/2\r\n\r\n")
456 s.AssertNil(err, fmt.Sprint(err))
457 s.AssertContains(resp, "HTTP/1.1 505 HTTP Version Not Supported")
Matus Fabian82ad9662024-06-04 19:00:00 +0200458}
459
460func HttpUriDecodeTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200461 vpp := s.GetContainerByName("vpp").VppInstance
462 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
463 vpp.Vppctl("http cli server")
Matus Fabian82ad9662024-06-04 19:00:00 +0200464
Adrian Villin4677d922024-06-14 09:32:39 +0200465 client := NewHttpClient()
Matus Fabian82ad9662024-06-04 19:00:00 +0200466 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/sh%6fw%20versio%6E%20verbose", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200467 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200468 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200469 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian82ad9662024-06-04 19:00:00 +0200470 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200471 s.AssertEqual(200, resp.StatusCode)
Matus Fabian82ad9662024-06-04 19:00:00 +0200472 data, err := io.ReadAll(resp.Body)
Adrian Villin4677d922024-06-14 09:32:39 +0200473 s.AssertNil(err, fmt.Sprint(err))
474 s.Log(string(data))
475 s.AssertNotContains(string(data), "unknown input")
476 s.AssertContains(string(data), "Compiler")
Matus Fabian82ad9662024-06-04 19:00:00 +0200477}
478
479func HttpHeadersTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200480 vpp := s.GetContainerByName("vpp").VppInstance
481 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
482 vpp.Vppctl("http cli server")
Matus Fabian82ad9662024-06-04 19:00:00 +0200483
Adrian Villin4677d922024-06-14 09:32:39 +0200484 resp, err := TcpSendReceive(
Matus Fabian82ad9662024-06-04 19:00:00 +0200485 serverAddress+":80",
486 "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 Villin4677d922024-06-14 09:32:39 +0200487 s.AssertNil(err, fmt.Sprint(err))
488 s.AssertContains(resp, "HTTP/1.1 200 OK")
489 s.AssertContains(resp, "Content-Type: text / plain")
490 s.AssertNotContains(resp, "<html>", "html content received instead of plain text")
Matus Fabian82ad9662024-06-04 19:00:00 +0200491}
492
493func HttpInvalidHeadersTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200494 vpp := s.GetContainerByName("vpp").VppInstance
495 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
496 vpp.Vppctl("http cli server")
Matus Fabian82ad9662024-06-04 19:00:00 +0200497
Adrian Villin4677d922024-06-14 09:32:39 +0200498 resp, err := TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nUser-Agent: test\r\n")
499 s.AssertNil(err, fmt.Sprint(err))
500 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "Header section must end with CRLF CRLF")
Matus Fabian82ad9662024-06-04 19:00:00 +0200501
Adrian Villin4677d922024-06-14 09:32:39 +0200502 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser@Agent:test\r\n\r\n")
503 s.AssertNil(err, fmt.Sprint(err))
504 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'@' not allowed in field name")
Matus Fabian82ad9662024-06-04 19:00:00 +0200505
Adrian Villin4677d922024-06-14 09:32:39 +0200506 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser-Agent\r\n\r\n")
507 s.AssertNil(err, fmt.Sprint(err))
508 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "incomplete field line not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200509
Adrian Villin4677d922024-06-14 09:32:39 +0200510 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\n: test\r\n\r\n")
511 s.AssertNil(err, fmt.Sprint(err))
512 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "empty field name not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200513
Adrian Villin4677d922024-06-14 09:32:39 +0200514 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\rUser-Agent:test\r\n\r\n")
515 s.AssertNil(err, fmt.Sprint(err))
516 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid field line end not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200517
Adrian Villin4677d922024-06-14 09:32:39 +0200518 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\nUser-Agent:test\r\n\r\n")
519 s.AssertNil(err, fmt.Sprint(err))
520 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "invalid field line end not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200521
Adrian Villin4677d922024-06-14 09:32:39 +0200522 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser-Agent:\r\n\r\n")
523 s.AssertNil(err, fmt.Sprint(err))
524 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "empty field value not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200525
Adrian Villin4677d922024-06-14 09:32:39 +0200526 resp, err = TcpSendReceive(serverAddress+":80", "GET /show/version HTTP/1.1\r\nHost:"+serverAddress+":80\r\nUser-Agent: \r\n\r\n")
527 s.AssertNil(err, fmt.Sprint(err))
528 s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "empty field value not allowed")
Matus Fabian82ad9662024-06-04 19:00:00 +0200529}
530
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200531func HeaderServerTest(s *NoTopoSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200532 vpp := s.GetContainerByName("vpp").VppInstance
533 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
534 vpp.Vppctl("http cli server")
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200535
Adrian Villin4677d922024-06-14 09:32:39 +0200536 client := NewHttpClient()
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200537 req, err := http.NewRequest("GET", "http://"+serverAddress+":80/show/version", nil)
Adrian Villin4677d922024-06-14 09:32:39 +0200538 s.AssertNil(err, fmt.Sprint(err))
Matus Fabian595d8cb2024-05-17 11:28:43 +0200539 resp, err := client.Do(req)
Adrian Villin4677d922024-06-14 09:32:39 +0200540 s.AssertNil(err, fmt.Sprint(err))
Matus Fabianb7a9ed72024-05-10 16:20:40 +0200541 defer resp.Body.Close()
Adrian Villin4677d922024-06-14 09:32:39 +0200542 s.AssertEqual("http_cli_server", resp.Header.Get("Server"))
Matus Fabian616201a2024-05-02 11:17:15 +0200543}