Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akrantz01 committed Apr 11, 2022
1 parent d442602 commit af1e14c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plugins/inputs/x509_cert/x509_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func (c *X509Cert) SampleConfig() string {
func (c *X509Cert) sourcesToURLs() error {
for _, source := range c.Sources {
if strings.HasPrefix(source, "file://") ||
strings.HasPrefix(source, "/") ||
strings.Index(source, ":\\") != 1 {
strings.HasPrefix(source, "/") {
source = filepath.ToSlash(strings.TrimPrefix(source, "file://"))
g, err := globpath.Compile(source)
if err != nil {
Expand Down Expand Up @@ -115,6 +114,7 @@ func (c *X509Cert) serverName(u *url.URL) (string, error) {
}

func (c *X509Cert) getCert(u *url.URL, timeout time.Duration) ([]*x509.Certificate, error) {
protocol := u.Scheme
switch u.Scheme {
case "udp", "udp4", "udp6":
ipConn, err := net.DialTimeout(u.Scheme, u.Host, timeout)
Expand Down Expand Up @@ -155,14 +155,15 @@ func (c *X509Cert) getCert(u *url.URL, timeout time.Duration) ([]*x509.Certifica

return certs, nil
case "https":
protocol = "tcp"
fallthrough
case "tcp", "tcp4", "tcp6":
dialer, err := c.Proxy()
if err != nil {
return nil, err
}

ipConn, err := dialer.DialTimeout(u.Scheme, u.Host, timeout)
ipConn, err := dialer.DialTimeout(protocol, u.Host, timeout)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/inputs/x509_cert/x509_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func TestGatherTCPCert(t *testing.T) {

m := &X509Cert{
Sources: []string{ts.URL},
Log: testutil.Logger{},
}
require.NoError(t, m.Init())

Expand Down Expand Up @@ -370,6 +371,7 @@ func TestGatherCertIntegration(t *testing.T) {

m := &X509Cert{
Sources: []string{"https://www.influxdata.com:443"},
Log: testutil.Logger{},
}
require.NoError(t, m.Init())

Expand All @@ -386,6 +388,7 @@ func TestGatherCertMustNotTimeout(t *testing.T) {
duration := time.Duration(15) * time.Second
m := &X509Cert{
Sources: []string{"https://www.influxdata.com:443"},
Log: testutil.Logger{},
Timeout: config.Duration(duration),
}
require.NoError(t, m.Init())
Expand Down

0 comments on commit af1e14c

Please sign in to comment.