MCPcopy Index your code
hub / github.com/ContentSquare/chproxy / TestReverseProxy_ServeHTTP2

Function TestReverseProxy_ServeHTTP2

proxy_test.go:964–1056  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

962}
963
964func TestReverseProxy_ServeHTTP2(t *testing.T) {
965 testCases := []struct {
966 name string
967 allowedNetworks config.Networks
968 expResponse string
969 }{
970 {
971 name: "empty allowed networks",
972 allowedNetworks: config.Networks{},
973 },
974 {
975 name: "allow addr",
976 allowedNetworks: config.Networks{getNetwork("192.0.2.1")},
977 },
978 {
979 name: "allow addr by mask",
980 allowedNetworks: config.Networks{getNetwork("192.0.2.1/32")},
981 },
982 }
983
984 f := func(cfg *config.Config) {
985 proxy, err := getProxy(cfg)
986 if err != nil {
987 t.Fatalf("unexpected error: %s", err)
988 }
989 resp := makeRequest(proxy)
990 b := bbToString(t, resp.Body)
991 resp.Body.Close()
992 if !strings.Contains(b, okResponse) {
993 t.Fatalf("expected response: %q; got: %q", okResponse, b)
994 }
995 }
996
997 for _, tc := range testCases {
998 t.Run("user "+tc.name, func(t *testing.T) {
999 goodCfg.Users[0].AllowedNetworks = tc.allowedNetworks
1000 f(goodCfg)
1001 })
1002 t.Run("cluster user "+tc.name, func(t *testing.T) {
1003 goodCfg.Clusters[0].ClusterUsers[0].AllowedNetworks = tc.allowedNetworks
1004 f(goodCfg)
1005 })
1006 }
1007
1008 t.Run("cluster user disallow addr", func(t *testing.T) {
1009 goodCfg.Clusters[0].ClusterUsers[0].AllowedNetworks = config.Networks{getNetwork("192.0.2.2/32"), getNetwork("192.0.2.2")}
1010 proxy, err := getProxy(goodCfg)
1011 if err != nil {
1012 t.Fatalf("unexpected error: %s", err)
1013 }
1014 resp := makeRequest(proxy)
1015 expected := "cluster user \"web\" is not allowed to access"
1016 b := bbToString(t, resp.Body)
1017 resp.Body.Close()
1018 if !strings.Contains(b, expected) {
1019 t.Fatalf("expected response: %q; got: %q", expected, b)
1020 }
1021 })

Callers

nothing calls this directly

Calls 7

getNetworkFunction · 0.85
getProxyFunction · 0.85
makeRequestFunction · 0.85
bbToStringFunction · 0.85
makeCustomRequestFunction · 0.85
ContainsMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected