Skip to content

Commit

Permalink
Correctly unmarshal Protocol (#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: #17841
  • Loading branch information
ph authored Apr 21, 2020
1 parent 3b99438 commit 0765f94
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 @@ -23,6 +23,7 @@
- Remove the kbn-version on each request to the Kibana API. {pull}17764[17764]
- Fixed process spawning on Windows {pull}17751[17751]
- Fixed injected log path to monitoring beat {pull}17833[17833]
- Make sure that the Elastic Agent connect over TLS in cloud. {pull}xx[xxx]

==== 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 0765f94

Please sign in to comment.