diff --git a/NOTICE.txt b/NOTICE.txt index a398d0f68ba..c40076d38b6 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -13406,11 +13406,11 @@ SOFTWARE -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-libs -Version: v0.17.5 +Version: v0.18.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.17.5/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.18.0/LICENSE: Apache License Version 2.0, January 2004 diff --git a/go.mod b/go.mod index 262087f98e5..291363a0577 100644 --- a/go.mod +++ b/go.mod @@ -184,7 +184,7 @@ require ( github.com/elastic/bayeux v1.0.5 github.com/elastic/ebpfevents v0.6.0 github.com/elastic/elastic-agent-autodiscover v0.9.0 - github.com/elastic/elastic-agent-libs v0.17.5 + github.com/elastic/elastic-agent-libs v0.18.0 github.com/elastic/elastic-agent-system-metrics v0.11.7 github.com/elastic/go-elasticsearch/v8 v8.14.0 github.com/elastic/go-quark v0.2.0 diff --git a/go.sum b/go.sum index 18864a5bdea..be0dafd5e6f 100644 --- a/go.sum +++ b/go.sum @@ -340,8 +340,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0 github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE= github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI= -github.com/elastic/elastic-agent-libs v0.17.5 h1:oyv5BohMia+49tZnsOmTyRWp5LoZbH8iOmGa7c4TqTs= -github.com/elastic/elastic-agent-libs v0.17.5/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= +github.com/elastic/elastic-agent-libs v0.18.0 h1:PKG1StgHu2MfOwOryGuAVgNZlZXyvVSDw3SvLUfel+w= +github.com/elastic/elastic-agent-libs v0.18.0/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= github.com/elastic/elastic-agent-system-metrics v0.11.7 h1:1xm2okCM0eQZ4jivZgUFSlt6HAn/nPgKB/Fj8eLG6mY= github.com/elastic/elastic-agent-system-metrics v0.11.7/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI= github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA= diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index 0f26e3bb6f0..ebfecf191c7 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -21,10 +21,8 @@ package instance import ( "bytes" - "crypto/tls" "io/ioutil" "os" - "path/filepath" "testing" "github.com/elastic/beats/v7/libbeat/cfgfile" @@ -35,7 +33,6 @@ import ( "github.com/elastic/elastic-agent-client/v7/pkg/client" "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/transport/tlscommon" "github.com/elastic/go-ucfg/yaml" "github.com/gofrs/uuid/v5" @@ -479,50 +476,6 @@ func TestLogSystemInfo(t *testing.T) { } } -func TestTLSDefaultVersions(t *testing.T) { - b, err := NewBeat("mockbeat", "testidx", "0.9", false, nil) - require.NoError(t, err) - - cfg, err := cfgfile.Load(filepath.Join("testdata", "tls.yml"), nil) - require.NoError(t, err) - err = cfg.Unpack(&b.Config) - require.NoError(t, err) - assert.True(t, b.Config.Output.IsSet()) - sslCfg, err := b.Config.Output.Config().Child("ssl", -1) - require.NoError(t, err) - var common tlscommon.Config - err = sslCfg.Unpack(&common) - require.NoError(t, err) - tlsCfg, err := tlscommon.LoadTLSConfig(&common) - require.NoError(t, err) - - c := tlsCfg.ToConfig() - assert.Equal(t, uint16(tls.VersionTLS11), c.MinVersion) - assert.Equal(t, uint16(tls.VersionTLS13), c.MaxVersion) -} - -func TestTLSVersion10(t *testing.T) { - b, err := NewBeat("mockbeat", "testidx", "0.9", false, nil) - require.NoError(t, err) - - cfg, err := cfgfile.Load(filepath.Join("testdata", "tls10.yml"), nil) - require.NoError(t, err) - err = cfg.Unpack(&b.Config) - require.NoError(t, err) - assert.True(t, b.Config.Output.IsSet()) - sslCfg, err := b.Config.Output.Config().Child("ssl", -1) - require.NoError(t, err) - var common tlscommon.Config - err = sslCfg.Unpack(&common) - require.NoError(t, err) - tlsCfg, err := tlscommon.LoadTLSConfig(&common) - require.NoError(t, err) - - c := tlsCfg.ToConfig() - assert.Equal(t, uint16(tls.VersionTLS10), c.MinVersion) - assert.Equal(t, uint16(tls.VersionTLS10), c.MaxVersion) -} - type mockManager struct { enabled bool } diff --git a/libbeat/cmd/root_test.go b/libbeat/cmd/root_test.go new file mode 100644 index 00000000000..72612c98ef5 --- /dev/null +++ b/libbeat/cmd/root_test.go @@ -0,0 +1,104 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !integration + +package cmd + +import ( + "crypto/tls" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "github.com/elastic/beats/v7/libbeat/beat" + "github.com/elastic/beats/v7/libbeat/cfgfile" + "github.com/elastic/beats/v7/libbeat/cmd/instance" + "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/transport/tlscommon" +) + +type MockBeater struct { + mock.Mock +} + +func (m *MockBeater) Run(b *beat.Beat) error { + args := m.Called(b) + return args.Error(0) +} + +func (m *MockBeater) Stop() { + m.Called() +} + +func genMockCreator(m *MockBeater) beat.Creator { + return func(b *beat.Beat, c *config.C) (beat.Beater, error) { + return m, nil + } +} + +func TestGenRootCmdWithSettings_TLSDefaults(t *testing.T) { + mb := &MockBeater{} + settings := instance.Settings{} + _ = GenRootCmdWithSettings(genMockCreator(mb), settings) + + t.Run("Test defaults", func(t *testing.T) { + b, err := instance.NewBeat("mockbeat", "testidx", "0.9", false, nil) + require.NoError(t, err) + cfg, err := cfgfile.Load(filepath.Join("instance", "testdata", "tls.yml"), nil) + require.NoError(t, err) + err = cfg.Unpack(&b.Config) + require.NoError(t, err) + assert.True(t, b.Config.Output.IsSet()) + sslCfg, err := b.Config.Output.Config().Child("ssl", -1) + require.NoError(t, err) + var common tlscommon.Config + err = sslCfg.Unpack(&common) + require.NoError(t, err) + tlsCfg, err := tlscommon.LoadTLSConfig(&common) + require.NoError(t, err) + + c := tlsCfg.ToConfig() + assert.Equal(t, uint16(tls.VersionTLS11), c.MinVersion) + assert.Equal(t, uint16(tls.VersionTLS13), c.MaxVersion) + }) + + t.Run("Set min TLSv1.0", func(t *testing.T) { + b, err := instance.NewBeat("mockbeat", "testidx", "0.9", false, nil) + require.NoError(t, err) + + cfg, err := cfgfile.Load(filepath.Join("instance", "testdata", "tls10.yml"), nil) + require.NoError(t, err) + err = cfg.Unpack(&b.Config) + require.NoError(t, err) + assert.True(t, b.Config.Output.IsSet()) + sslCfg, err := b.Config.Output.Config().Child("ssl", -1) + require.NoError(t, err) + var common tlscommon.Config + err = sslCfg.Unpack(&common) + require.NoError(t, err) + tlsCfg, err := tlscommon.LoadTLSConfig(&common) + require.NoError(t, err) + + c := tlsCfg.ToConfig() + assert.Equal(t, uint16(tls.VersionTLS10), c.MinVersion) + assert.Equal(t, uint16(tls.VersionTLS10), c.MaxVersion) + }) +}