| 9 | ) |
| 10 | |
| 11 | func TestTrimURL(t *testing.T) { |
| 12 | type newTest struct { |
| 13 | input, host string |
| 14 | isURL bool |
| 15 | err error |
| 16 | } |
| 17 | tests := map[string]newTest{ |
| 18 | "true-http": {"https://smallstep.com", "smallstep.com:443", true, nil}, |
| 19 | "true-tcp": {"tcp://smallstep.com:8080", "smallstep.com:8080", true, nil}, |
| 20 | "true-tls": {"tls://smallstep.com/onboarding", "smallstep.com:443", true, nil}, |
| 21 | "false": {"./certs/root_ca.crt", "", false, nil}, |
| 22 | "false-err": {"https://google.com hello", "", false, errors.New("error parsing URL 'https://google.com hello'")}, |
| 23 | "true-http-case": {"hTtPs://sMaLlStEp.cOm", "sMaLlStEp.cOm:443", true, nil}, |
| 24 | } |
| 25 | |
| 26 | for name, tc := range tests { |
| 27 | t.Run(name, func(t *testing.T) { |
| 28 | host, isURL, err := trimURL(tc.input) |
| 29 | assert.Equals(t, tc.host, host) |
| 30 | assert.Equals(t, tc.isURL, isURL) |
| 31 | if err != nil { |
| 32 | if assert.NotNil(t, tc.err) { |
| 33 | assert.HasPrefix(t, err.Error(), tc.err.Error()) |
| 34 | } |
| 35 | } else { |
| 36 | assert.Nil(t, tc.err) |
| 37 | } |
| 38 | }) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestGetPeerCertificateServerName(t *testing.T) { |
| 43 | host := "smallstep.com" |