|
| 1 | +package types |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 8 | + |
| 9 | + "github.com/openshift/installer/pkg/ipnet" |
| 10 | +) |
| 11 | + |
| 12 | +func TestBuildNoProxySet(t *testing.T) { |
| 13 | + cases := []struct { |
| 14 | + name string |
| 15 | + config *InstallConfig |
| 16 | + expected []string |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "empty networking and no user entries", |
| 20 | + config: &InstallConfig{ |
| 21 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 22 | + BaseDomain: "example.com", |
| 23 | + Networking: &Networking{}, |
| 24 | + }, |
| 25 | + expected: []string{".cluster.local", ".svc", "127.0.0.1", "api-int.test.example.com", "localhost"}, |
| 26 | + }, |
| 27 | + { |
| 28 | + name: "service network entries are included", |
| 29 | + config: &InstallConfig{ |
| 30 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 31 | + BaseDomain: "example.com", |
| 32 | + Networking: &Networking{ |
| 33 | + ServiceNetwork: []ipnet.IPNet{ |
| 34 | + *ipnet.MustParseCIDR("172.30.0.0/16"), |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + expected: []string{".cluster.local", ".svc", "127.0.0.1", "172.30.0.0/16", "api-int.test.example.com", "localhost"}, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "machine network entries are included", |
| 42 | + config: &InstallConfig{ |
| 43 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 44 | + BaseDomain: "example.com", |
| 45 | + Networking: &Networking{ |
| 46 | + MachineNetwork: []MachineNetworkEntry{ |
| 47 | + {CIDR: *ipnet.MustParseCIDR("10.0.0.0/16")}, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + expected: []string{".cluster.local", ".svc", "10.0.0.0/16", "127.0.0.1", "api-int.test.example.com", "localhost"}, |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "cluster network entries are included", |
| 55 | + config: &InstallConfig{ |
| 56 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 57 | + BaseDomain: "example.com", |
| 58 | + Networking: &Networking{ |
| 59 | + ClusterNetwork: []ClusterNetworkEntry{ |
| 60 | + {CIDR: *ipnet.MustParseCIDR("10.128.0.0/14")}, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + expected: []string{".cluster.local", ".svc", "10.128.0.0/14", "127.0.0.1", "api-int.test.example.com", "localhost"}, |
| 65 | + }, |
| 66 | + { |
| 67 | + name: "single user no-proxy entry is included", |
| 68 | + config: &InstallConfig{ |
| 69 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 70 | + BaseDomain: "example.com", |
| 71 | + Networking: &Networking{}, |
| 72 | + Proxy: &Proxy{ |
| 73 | + NoProxy: "example.com", |
| 74 | + }, |
| 75 | + }, |
| 76 | + expected: []string{".cluster.local", ".svc", "127.0.0.1", "api-int.test.example.com", "example.com", "localhost"}, |
| 77 | + }, |
| 78 | + { |
| 79 | + name: "multiple comma-separated user entries are included", |
| 80 | + config: &InstallConfig{ |
| 81 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 82 | + BaseDomain: "example.com", |
| 83 | + Networking: &Networking{}, |
| 84 | + Proxy: &Proxy{ |
| 85 | + NoProxy: "example.com,internal.corp,192.168.1.0/24", |
| 86 | + }, |
| 87 | + }, |
| 88 | + expected: []string{".cluster.local", ".svc", "127.0.0.1", "192.168.1.0/24", "api-int.test.example.com", "example.com", "internal.corp", "localhost"}, |
| 89 | + }, |
| 90 | + { |
| 91 | + name: "user entries with surrounding whitespace are trimmed", |
| 92 | + config: &InstallConfig{ |
| 93 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 94 | + BaseDomain: "example.com", |
| 95 | + Networking: &Networking{}, |
| 96 | + Proxy: &Proxy{ |
| 97 | + NoProxy: " example.com , internal.corp ", |
| 98 | + }, |
| 99 | + }, |
| 100 | + expected: []string{".cluster.local", ".svc", "127.0.0.1", "api-int.test.example.com", "example.com", "internal.corp", "localhost"}, |
| 101 | + }, |
| 102 | + { |
| 103 | + name: "empty segments in user no-proxy are ignored", |
| 104 | + config: &InstallConfig{ |
| 105 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 106 | + BaseDomain: "example.com", |
| 107 | + Networking: &Networking{}, |
| 108 | + Proxy: &Proxy{ |
| 109 | + NoProxy: "example.com,,internal.corp,", |
| 110 | + }, |
| 111 | + }, |
| 112 | + expected: []string{".cluster.local", ".svc", "127.0.0.1", "api-int.test.example.com", "example.com", "internal.corp", "localhost"}, |
| 113 | + }, |
| 114 | + { |
| 115 | + name: "all network types and user entries combined", |
| 116 | + config: &InstallConfig{ |
| 117 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 118 | + BaseDomain: "example.com", |
| 119 | + Networking: &Networking{ |
| 120 | + ServiceNetwork: []ipnet.IPNet{ |
| 121 | + *ipnet.MustParseCIDR("172.30.0.0/16"), |
| 122 | + }, |
| 123 | + MachineNetwork: []MachineNetworkEntry{ |
| 124 | + {CIDR: *ipnet.MustParseCIDR("10.0.0.0/16")}, |
| 125 | + }, |
| 126 | + ClusterNetwork: []ClusterNetworkEntry{ |
| 127 | + {CIDR: *ipnet.MustParseCIDR("10.128.0.0/14")}, |
| 128 | + }, |
| 129 | + }, |
| 130 | + Proxy: &Proxy{ |
| 131 | + NoProxy: "example.com", |
| 132 | + }, |
| 133 | + }, |
| 134 | + expected: []string{ |
| 135 | + ".cluster.local", ".svc", "10.0.0.0/16", "10.128.0.0/14", |
| 136 | + "127.0.0.1", "172.30.0.0/16", "api-int.test.example.com", "example.com", "localhost", |
| 137 | + }, |
| 138 | + }, |
| 139 | + { |
| 140 | + name: "duplicate user entry matching a built-in entry is deduplicated", |
| 141 | + config: &InstallConfig{ |
| 142 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 143 | + BaseDomain: "example.com", |
| 144 | + Networking: &Networking{ |
| 145 | + ServiceNetwork: []ipnet.IPNet{ |
| 146 | + *ipnet.MustParseCIDR("172.30.0.0/16"), |
| 147 | + }, |
| 148 | + }, |
| 149 | + Proxy: &Proxy{ |
| 150 | + NoProxy: "172.30.0.0/16,localhost", |
| 151 | + }, |
| 152 | + }, |
| 153 | + expected: []string{".cluster.local", ".svc", "127.0.0.1", "172.30.0.0/16", "api-int.test.example.com", "localhost"}, |
| 154 | + }, |
| 155 | + { |
| 156 | + name: "multiple entries in each network type", |
| 157 | + config: &InstallConfig{ |
| 158 | + ObjectMeta: metav1.ObjectMeta{Name: "test"}, |
| 159 | + BaseDomain: "example.com", |
| 160 | + Networking: &Networking{ |
| 161 | + ServiceNetwork: []ipnet.IPNet{ |
| 162 | + *ipnet.MustParseCIDR("172.30.0.0/16"), |
| 163 | + *ipnet.MustParseCIDR("fd02::/112"), |
| 164 | + }, |
| 165 | + MachineNetwork: []MachineNetworkEntry{ |
| 166 | + {CIDR: *ipnet.MustParseCIDR("10.0.0.0/16")}, |
| 167 | + {CIDR: *ipnet.MustParseCIDR("fd00::/48")}, |
| 168 | + }, |
| 169 | + ClusterNetwork: []ClusterNetworkEntry{ |
| 170 | + {CIDR: *ipnet.MustParseCIDR("10.128.0.0/14")}, |
| 171 | + {CIDR: *ipnet.MustParseCIDR("fd01::/48")}, |
| 172 | + }, |
| 173 | + }, |
| 174 | + }, |
| 175 | + expected: []string{ |
| 176 | + ".cluster.local", ".svc", "10.0.0.0/16", "10.128.0.0/14", |
| 177 | + "127.0.0.1", "172.30.0.0/16", "api-int.test.example.com", |
| 178 | + "fd00::/48", "fd01::/48", "fd02::/112", "localhost", |
| 179 | + }, |
| 180 | + }, |
| 181 | + } |
| 182 | + |
| 183 | + for _, tc := range cases { |
| 184 | + t.Run(tc.name, func(t *testing.T) { |
| 185 | + result := BuildNoProxySet(tc.config) |
| 186 | + assert.ElementsMatch(t, tc.expected, result.List()) |
| 187 | + }) |
| 188 | + } |
| 189 | +} |
0 commit comments