| 97 | } |
| 98 | |
| 99 | func Test_Match(t *testing.T) { |
| 100 | t.Parallel() |
| 101 | tests := []struct { |
| 102 | schemeA, hostA, schemeB, hostB string |
| 103 | want bool |
| 104 | }{ |
| 105 | {"https", "example.com", "https", "example.com", true}, |
| 106 | {"https", "example.com", "https", "example.com:443", true}, |
| 107 | {"http", "example.com", "http", "example.com:80", true}, |
| 108 | {"https", "example.com:443", "https", "example.com:443", true}, |
| 109 | {"HTTPS", "Example.com", "https", "example.com", true}, |
| 110 | {"https", "example.com", "http", "example.com", false}, |
| 111 | {"https", "example.com", "https", "evil.com", false}, |
| 112 | {"https", "example.com:8080", "https", "example.com", false}, |
| 113 | {"https", "[::1]", "https", "[::1]:443", true}, |
| 114 | {"https", "[::1]:8080", "https", "[::1]", false}, |
| 115 | } |
| 116 | for _, tc := range tests { |
| 117 | got := Match(tc.schemeA, tc.hostA, tc.schemeB, tc.hostB) |
| 118 | assert.Equal(t, tc.want, got, "Match(%q,%q,%q,%q)", tc.schemeA, tc.hostA, tc.schemeB, tc.hostB) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | func Benchmark_normalizeSchemeHost(b *testing.B) { |
| 123 | cases := []struct{ name, scheme, host string }{ |