1// Copyright 2020 Istio Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package outboundtrafficpolicy 16 17import ( 18 "testing" 19) 20 21func TestOutboundTrafficPolicy_AllowAny(t *testing.T) { 22 cases := []*TestCase{ 23 { 24 Name: "HTTP Traffic", 25 PortName: "http", 26 Expected: Expected{ 27 Metric: "istio_requests_total", 28 PromQueryFormat: `sum(istio_requests_total{reporter="source",destination_service_name="PassthroughCluster",response_code="200"})`, 29 ResponseCode: []string{"200"}, 30 }, 31 }, 32 { 33 Name: "HTTPS Traffic", 34 PortName: "https", 35 Expected: Expected{ 36 Metric: "istio_tcp_connections_opened_total", 37 PromQueryFormat: `sum(istio_tcp_connections_opened_total{reporter="source",destination_service_name="PassthroughCluster"})`, 38 ResponseCode: []string{"200"}, 39 }, 40 }, 41 { 42 Name: "HTTPS Traffic Conflict", 43 PortName: "https-conflict", 44 Expected: Expected{ 45 Metric: "istio_tcp_connections_opened_total", 46 PromQueryFormat: `sum(istio_tcp_connections_opened_total{reporter="source",destination_service_name="PassthroughCluster"})`, 47 ResponseCode: []string{"200"}, 48 }, 49 }, 50 { 51 Name: "HTTP Traffic Egress", 52 PortName: "http", 53 Host: "some-external-site.com", 54 Gateway: true, 55 Expected: Expected{ 56 Metric: "istio_requests_total", 57 PromQueryFormat: `sum(istio_requests_total{reporter="source",destination_service_name="istio-egressgateway",response_code="200"})`, 58 ResponseCode: []string{"200"}, 59 }, 60 }, 61 // TODO add HTTPS through gateway 62 { 63 Name: "TCP", 64 PortName: "tcp", 65 Expected: Expected{ 66 // TODO(https://github.com/istio/istio/issues/22717) re-enable TCP 67 //Metric: "istio_tcp_connections_closed_total", 68 //PromQueryFormat: `sum(istio_tcp_connections_closed_total{reporter="destination",source_workload="client-v1",destination_workload="destination-v1"})`, 69 ResponseCode: []string{"200"}, 70 }, 71 }, 72 { 73 Name: "TCP Conflict", 74 PortName: "tcp-conflict", 75 Expected: Expected{ 76 // TODO(https://github.com/istio/istio/issues/22717) re-enable TCP 77 //Metric: "istio_tcp_connections_closed_total", 78 //PromQueryFormat: `sum(istio_tcp_connections_closed_total{reporter="destination",source_workload="client-v1",destination_workload="destination-v1"})`, 79 ResponseCode: []string{"200"}, 80 }, 81 }, 82 } 83 RunExternalRequest(cases, prom, AllowAny, t) 84} 85