Skip to content

Commit

Permalink
Correctly unmarshal Protocol (elastic#17843)
Browse files Browse the repository at this point in the history
The Protocol (https/http) was not correctly unmarshaly and assigned to
the value of the struct. Because of this the checking was trying to use
a plain text connection or a TLS enabled endpoint.

Fixes: elastic#17841
(cherry picked from commit 0765f94)
  • Loading branch information
ph committed Apr 21, 2020
1 parent b54f503 commit a1a015d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Fix issues when running `mage package` for all the platforms. {pull}17767[17767]
- Rename the User-Agent string from Beats Agent to Elastic Agent. {pull}17765[17765]
- Remove the kbn-version on each request to the Kibana API. {pull}17764[17764]
- Make sure that the Elastic Agent connect over TLS in cloud. {pull}17843[17843]

==== New features

Expand Down
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/pkg/kibana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func (p *Protocol) Unpack(from string) error {
if from != "https" && from != "http" {
return fmt.Errorf("invalid protocol %s, accepted values are 'http' and 'https'", from)
}

*p = Protocol(from)
return nil
}

Expand Down
37 changes: 37 additions & 0 deletions x-pack/elastic-agent/pkg/kibana/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package kibana

import (
"reflect"
"testing"
"time"

"gopkg.in/yaml.v2"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPackUnpack(t *testing.T) {
c := Config{
Protocol: Protocol("https"),
SpaceID: "123",
Username: "foo",
Password: "bar",
Path: "/ok",
Timeout: 10 * time.Second,
}

b, err := yaml.Marshal(&c)
require.NoError(t, err)

c2 := Config{}

err = yaml.Unmarshal(b, &c2)
require.NoError(t, err)

assert.True(t, reflect.DeepEqual(c, c2))
}

0 comments on commit a1a015d

Please sign in to comment.