Skip to content

Commit

Permalink
Fix sending of basic auth credentials in http output (#4609)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7b05993)
  • Loading branch information
danielnelson committed Aug 29, 2018
1 parent c4a4c7d commit 9bd329c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 4 additions & 0 deletions plugins/outputs/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (h *HTTP) write(reqBody []byte) error {
return err
}

if h.Username != "" || h.Password != "" {
req.SetBasicAuth(h.Username, h.Password)
}

req.Header.Set("Content-Type", defaultContentType)
for k, v := range h.Headers {
req.Header.Set(k, v)
Expand Down
10 changes: 4 additions & 6 deletions plugins/outputs/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,8 @@ func TestBasicAuth(t *testing.T) {
require.NoError(t, err)

tests := []struct {
name string
plugin *HTTP
username string
password string
name string
plugin *HTTP
}{
{
name: "default",
Expand Down Expand Up @@ -274,8 +272,8 @@ func TestBasicAuth(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
username, password, _ := r.BasicAuth()
require.Equal(t, tt.username, username)
require.Equal(t, tt.password, password)
require.Equal(t, tt.plugin.Username, username)
require.Equal(t, tt.plugin.Password, password)
w.WriteHeader(http.StatusOK)
})

Expand Down

0 comments on commit 9bd329c

Please sign in to comment.