MCPcopy
hub / github.com/smallstep/cli / TestGetPeerCertificateServerName

Function TestGetPeerCertificateServerName

command/certificate/remote_test.go:42–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestGetPeerCertificateServerName(t *testing.T) {
43 host := "smallstep.com"
44 serverName := host
45 ips, err := net.LookupIP(host)
46 if err != nil {
47 t.Fatalf("unknown host %s: %s", host, err)
48 }
49 var addr string
50 for i, ip := range ips {
51 if ip.To4() != nil {
52 addr = ips[i].String()
53 break
54 }
55 }
56 if addr == "" {
57 assert.FatalError(t, errors.New("could not find ipv4 address for smallstep.com"))
58 return
59 }
60
61 type newTest struct {
62 addr, serverName string
63 err error
64 }
65 tests := map[string]newTest{
66 "sni-disabled-host": {host, "", nil},
67 "sni-enabled-host": {host, serverName, nil},
68 "sni-disabled-ip": {addr, "", errors.New("failed to connect")},
69 "sni-enabled-ip": {addr, serverName, nil},
70 }
71
72 for name, tc := range tests {
73 t.Run(name, func(t *testing.T) {
74 _, err := getPeerCertificates(tc.addr, tc.serverName, "", false)
75 if err != nil {
76 if assert.NotNil(t, tc.err) {
77 assert.HasPrefix(t, err.Error(), tc.err.Error())
78 }
79 } else {
80 assert.Nil(t, tc.err)
81 }
82 })
83 }
84}

Callers

nothing calls this directly

Calls 4

getPeerCertificatesFunction · 0.85
StringMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…