Fix segfault in x509_cert (#4874)

This commit is contained in:
Fred Cox 2018-10-17 21:46:44 +03:00 committed by Greg
parent f10de93da4
commit 48745c3171
4 changed files with 28 additions and 2 deletions

View File

@ -10,7 +10,7 @@ file or network connection.
# Reads metrics from a SSL certificate
[[inputs.x509_cert]]
## List certificate sources
sources = ["/etc/ssl/certs/ssl-cert-snakeoil.pem", "https://example.org"]
sources = ["/etc/ssl/certs/ssl-cert-snakeoil.pem", "https://example.org:443"]
## Timeout for SSL connection
# timeout = "5s"

View File

@ -0,0 +1,5 @@
[[inputs.x509_cert]]
sources = ["https://www.influxdata.com:443"]
[[outputs.file]]
files = ["stdout"]

View File

@ -80,7 +80,10 @@ func (c *X509Cert) getCert(location string, timeout time.Duration) ([]*x509.Cert
}
defer ipConn.Close()
tlsCfg.ServerName = u.Host
if tlsCfg == nil {
tlsCfg = &tls.Config{}
}
tlsCfg.ServerName = u.Hostname()
conn := tls.Client(ipConn, tlsCfg)
defer conn.Close()

View File

@ -4,6 +4,8 @@ import (
"crypto/tls"
"encoding/base64"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"testing"
@ -203,3 +205,19 @@ func TestStrings(t *testing.T) {
})
}
}
func TestGatherCert(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
m := &X509Cert{
Sources: []string{"https://www.influxdata.com:443"},
}
var acc testutil.Accumulator
err := m.Gather(&acc)
require.NoError(t, err)
assert.True(t, acc.HasMeasurement("x509_cert"))
}