@@ -36,6 +36,36 @@ func WithServer(t *testing.T, f func(string)) {
3636 f ("http://localhost:8475" )
3737}
3838
39+ func TestBrowserGets403 (t * testing.T ) {
40+ WithServer (t , func (addr string ) {
41+ client := http.Client {}
42+
43+ req , _ := http .NewRequest ("GET" , "http://localhost:8475/proxies" , nil )
44+ req .Header .Add ("User-Agent" , "Mozilla/5.0 (Linux; Android 4.4.2); Nexus 5 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Mobile Safari/537.36 OPR/20.0.1396.72047" )
45+
46+ resp , _ := client .Do (req )
47+
48+ if resp .StatusCode != 403 {
49+ t .Fatal ("Browser-like UserAgent was not denied access to Toxiproxy" )
50+ }
51+ })
52+ }
53+
54+ func TestNonBrowserGets200 (t * testing.T ) {
55+ WithServer (t , func (addr string ) {
56+ client := http.Client {}
57+
58+ req , _ := http .NewRequest ("GET" , "http://localhost:8475/proxies" , nil )
59+ req .Header .Add ("User-Agent" , "Wget/2.1" )
60+
61+ resp , _ := client .Do (req )
62+
63+ if resp .StatusCode == 403 {
64+ t .Fatal ("Non-Browser-like UserAgent was denied access to Toxiproxy" )
65+ }
66+ })
67+ }
68+
3969func TestIndexWithNoProxies (t * testing.T ) {
4070 WithServer (t , func (addr string ) {
4171 client := tclient .NewClient (addr )
0 commit comments