Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(6208): set default to https, updated unit tests #4610

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/pkg/bulk/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ import (

var rand = rnd.New()

var defaultCfg config.Config
var defaultCfgData = []byte(`
var (
defaultCfg config.Config
defaultCfgData = []byte(`
output:
elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:localhost:9200}'
service_token: '${ELASTICSEARCH_SERVICE_TOKEN:test-token}'
protocol: http
fleet:
agent:
id: 1e4954ce-af37-4731-9f4a-407b08e69e42
`)
)

const testPolicy = `{
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func defaultFleet() Fleet {

func defaultElastic() Elasticsearch {
return Elasticsearch{
Protocol: "http",
Protocol: "https",
ServiceToken: "test-token",
Hosts: []string{"localhost:9200"},
MaxRetries: 3,
Expand Down
6 changes: 4 additions & 2 deletions internal/pkg/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (

// The timeout would be driven by the server for long poll.
// Giving it some sane long value.
const httpTransportLongPollTimeout = 10 * time.Minute
const schemeHTTP = "http"
const (
httpTransportLongPollTimeout = 10 * time.Minute
schemeHTTP = "https"
)

var hasScheme = regexp.MustCompile(`^([a-z][a-z0-9+\-.]*)://`)

Expand Down
12 changes: 6 additions & 6 deletions internal/pkg/config/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestToESConfig(t *testing.T) {
require.NoError(t, err)

// cmp.Diff can't handle function pointers.
res.Transport.(*http.Transport).Proxy = nil
res.Transport.(*http.Transport).Proxy = nil //nolint:errcheck // skipping error check in test

test.result.Header.Set("X-elastic-product-origin", "fleet")
assert.True(t, cmp.Equal(test.result, res, copts...), "mismatch (-want +got)\n%s", cmp.Diff(test.result, res, copts...))
Expand All @@ -225,7 +225,7 @@ func TestToESConfig(t *testing.T) {
require.NoError(t, err)

expect := elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
Addresses: []string{"https://localhost:9200"},
ServiceToken: "test-token",
Header: http.Header{"X-Elastic-Product-Origin": []string{"fleet"}},
MaxRetries: 3,
Expand All @@ -240,7 +240,7 @@ func TestToESConfig(t *testing.T) {
},
}

es.Transport.(*http.Transport).Proxy = nil
es.Transport.(*http.Transport).Proxy = nil //nolint:errcheck // skipping error check in test
assert.True(t, cmp.Equal(expect, es, copts...), "mismatch (-want +got)\n%s", cmp.Diff(expect, es, copts...))
})

Expand All @@ -258,7 +258,7 @@ func TestToESConfig(t *testing.T) {
require.NoError(t, err)

expect := elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
Addresses: []string{"https://localhost:9200"},
Header: http.Header{"X-Elastic-Product-Origin": []string{"fleet"}},
MaxRetries: 3,
Transport: &http.Transport{
Expand All @@ -272,7 +272,7 @@ func TestToESConfig(t *testing.T) {
},
}

es.Transport.(*http.Transport).Proxy = nil
es.Transport.(*http.Transport).Proxy = nil //nolint:errcheck // skipping error check in test
assert.True(t, cmp.Equal(expect, es, copts...), "mismatch (-want +got)\n%s", cmp.Diff(expect, es, copts...))
})

Expand Down Expand Up @@ -390,7 +390,7 @@ func Test_Elasticsearch_DiagRequests(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background()) //nolint:usetesting // using context.Background not t.Context
defer cancel()
es := &Elasticsearch{}
es.InitDefaults()
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/testing/fleet-server-testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
output:
elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:localhost:9200}'
service_token: '${ELASTICSEARCH_SERVICE_TOKEN}'
hosts: "${ELASTICSEARCH_HOSTS:localhost:9200}"
service_token: "${ELASTICSEARCH_SERVICE_TOKEN}"
protocol: http

fleet:
agent:
Expand Down
7 changes: 5 additions & 2 deletions internal/pkg/testing/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ import (
"github.com/elastic/fleet-server/v7/internal/pkg/testing/esutil"
)

var defaultCfg config.Config
var defaultCfgData = []byte(`
var (
defaultCfg config.Config
defaultCfgData = []byte(`
output:
elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:localhost:9200}'
service_token: '${ELASTICSEARCH_SERVICE_TOKEN:test-token}'
protocol: http
fleet:
agent:
id: 1e4954ce-af37-4731-9f4a-407b08e69e42
`)
)

func init() {
c, err := yaml.NewConfig(defaultCfgData, config.DefaultOptions...)
Expand Down