This file is indexed.

/usr/share/gocode/src/github.com/influxdata/influxdb/services/subscriber/config_test.go is in golang-github-influxdb-influxdb-dev 1.1.1+dfsg1-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
package subscriber_test

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"

	"github.com/BurntSushi/toml"
	"github.com/influxdata/influxdb/services/subscriber"
)

func TestConfig_Parse(t *testing.T) {
	// Parse configuration.
	var c subscriber.Config
	if _, err := toml.Decode(`
enabled = false
`, &c); err != nil {
		t.Fatal(err)
	}

	// Validate configuration.
	if c.Enabled != false {
		t.Errorf("unexpected enabled state: %v", c.Enabled)
	}
	if c.InsecureSkipVerify == true {
		t.Errorf("InsecureSkipVerify: expected %v. got %v", false, c.InsecureSkipVerify)
	}
}

func TestConfig_ParseTLSConfig(t *testing.T) {
	abspath, err := filepath.Abs("/path/to/ca-certs.pem")
	if err != nil {
		t.Fatalf("Could not construct absolute path. %v", err)
	}

	// Parse configuration.
	var c subscriber.Config
	if _, err := toml.Decode(fmt.Sprintf(`
http-timeout = "60s"
enabled = true
ca-certs = '%s'
insecure-skip-verify = true
write-buffer-size = 1000
write-concurrency = 10
`, abspath), &c); err != nil {
		t.Fatal(err)
	}

	// Validate configuration.
	if c.Enabled != true {
		t.Errorf("unexpected enabled state: %v", c.Enabled)
	}
	if c.CaCerts != abspath {
		t.Errorf("CaCerts: expected %s. got %s", abspath, c.CaCerts)
	}
	if c.InsecureSkipVerify != true {
		t.Errorf("InsecureSkipVerify: expected %v. got %v", true, c.InsecureSkipVerify)
	}
	err = c.Validate()
	if err == nil {
		t.Errorf("Expected Validation to fail (%s doesn't exist)", abspath)
	}

	if err.Error() != fmt.Sprintf("ca-certs file %s does not exist", abspath) {
		t.Errorf("Expected descriptive validation error. Instead got %v", err)
	}
}

func TestConfig_ParseTLSConfigValidCerts(t *testing.T) {
	tmpfile, err := ioutil.TempFile("", "ca-certs.crt")
	if err != nil {
		t.Fatalf("could not create temp file. error was: %v", err)
	}
	defer os.Remove(tmpfile.Name())

	if _, err := tmpfile.Write([]byte("=== BEGIN CERTIFICATE ===\n=== END CERTIFICATE ===")); err != nil {
		t.Fatalf("could not write temp file. error was: %v", err)
	}
	if err := tmpfile.Close(); err != nil {
		t.Fatalf("could not close temp file. error was %v", err)
	}

	// Parse configuration.
	var c subscriber.Config
	if _, err := toml.Decode(fmt.Sprintf(`
http-timeout = "60s"
enabled = true
ca-certs = '%s'
insecure-skip-verify = false
write-buffer-size = 1000
write-concurrency = 10
`, tmpfile.Name()), &c); err != nil {
		t.Fatal(err)
	}

	// Validate configuration.
	if c.Enabled != true {
		t.Errorf("unexpected enabled state: %v", c.Enabled)
	}
	if c.CaCerts != tmpfile.Name() {
		t.Errorf("CaCerts: expected %v. got %v", tmpfile.Name(), c.CaCerts)
	}
	if c.InsecureSkipVerify != false {
		t.Errorf("InsecureSkipVerify: expected %v. got %v", false, c.InsecureSkipVerify)
	}
	if err := c.Validate(); err != nil {
		t.Errorf("Expected Validation to succeed. Instead was: %v", err)
	}
}