Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 01:00 UTC
| 1 | // Copyright 2015 Matthew Holt and The Caddy 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 | |
| 15 | package caddyhttp |
| 16 | |
| 17 | import ( |
| 18 | "slices" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func TestServerLogConfigLoggerNamesCaseInsensitive(t *testing.T) { |
| 23 | slc := ServerLogConfig{ |
| 24 | DefaultLoggerName: "default", |
| 25 | LoggerNames: map[string]StringArray{ |
| 26 | "example.com": {"exact"}, |
| 27 | "Mixed.Example.org": {"mixed"}, |
| 28 | "*.EXAMPLE.net": {"wildcard"}, |
| 29 | "foo.example.dev": {"lower"}, |
| 30 | "FOO.example.dev": {"upper", "lower"}, |
| 31 | "muted.example.com": {}, |
| 32 | }, |
| 33 | } |
| 34 | slc.normalizeLoggerNames() |
| 35 | |
| 36 | for i, tc := range []struct { |
| 37 | host string |
| 38 | expected []string |
| 39 | }{ |
| 40 | {host: "EXAMPLE.COM", expected: []string{"exact"}}, |
| 41 | {host: "mixed.example.org", expected: []string{"mixed"}}, |
| 42 | {host: "Sub.example.NET", expected: []string{"wildcard"}}, |
| 43 | // merged in sorted key order; "FOO..." sorts before "foo..." |
| 44 | {host: "foo.example.dev", expected: []string{"upper", "lower"}}, |
| 45 | // mapped to no loggers, so no fallback to the default logger, |
| 46 | // an empty mapping can only come from a JSON config |
| 47 | {host: "MUTED.example.com", expected: []string{}}, |
| 48 | } { |
| 49 | actual := slc.getLoggerHosts(tc.host) |
| 50 | if !slices.Equal(actual, tc.expected) { |
| 51 | t.Errorf("Test %d (%s): expected %v, got %v", i, tc.host, tc.expected, actual) |
| 52 | } |
| 53 | } |
| 54 | } |