| 156 | } |
| 157 | |
| 158 | func TestRemoteIPMatcher(t *testing.T) { |
| 159 | ctx, cancel := caddy.NewContext(caddy.Context{Context: context.Background()}) |
| 160 | defer cancel() |
| 161 | |
| 162 | for i, tc := range []struct { |
| 163 | ranges []string |
| 164 | notRanges []string |
| 165 | input string |
| 166 | expect bool |
| 167 | }{ |
| 168 | { |
| 169 | ranges: []string{"127.0.0.1"}, |
| 170 | input: "127.0.0.1:12345", |
| 171 | expect: true, |
| 172 | }, |
| 173 | { |
| 174 | ranges: []string{"127.0.0.1"}, |
| 175 | input: "127.0.0.2:12345", |
| 176 | expect: false, |
| 177 | }, |
| 178 | { |
| 179 | ranges: []string{"127.0.0.1/16"}, |
| 180 | input: "127.0.1.23:12345", |
| 181 | expect: true, |
| 182 | }, |
| 183 | { |
| 184 | ranges: []string{"127.0.0.1", "192.168.1.105"}, |
| 185 | input: "192.168.1.105:12345", |
| 186 | expect: true, |
| 187 | }, |
| 188 | { |
| 189 | notRanges: []string{"127.0.0.1"}, |
| 190 | input: "127.0.0.1:12345", |
| 191 | expect: false, |
| 192 | }, |
| 193 | { |
| 194 | notRanges: []string{"127.0.0.2"}, |
| 195 | input: "127.0.0.1:12345", |
| 196 | expect: true, |
| 197 | }, |
| 198 | { |
| 199 | ranges: []string{"127.0.0.1"}, |
| 200 | notRanges: []string{"127.0.0.2"}, |
| 201 | input: "127.0.0.1:12345", |
| 202 | expect: true, |
| 203 | }, |
| 204 | { |
| 205 | ranges: []string{"127.0.0.2"}, |
| 206 | notRanges: []string{"127.0.0.2"}, |
| 207 | input: "127.0.0.2:12345", |
| 208 | expect: false, |
| 209 | }, |
| 210 | { |
| 211 | ranges: []string{"127.0.0.2"}, |
| 212 | notRanges: []string{"127.0.0.2"}, |
| 213 | input: "127.0.0.3:12345", |
| 214 | expect: false, |
| 215 | }, |