Fix sending of basic auth credentials in http output (#4609)

This commit is contained in:
Daniel Nelson 2018-08-29 12:28:29 -07:00 committed by GitHub
parent 8b2d64585d
commit 7b05993a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -131,6 +131,10 @@ func (h *HTTP) write(reqBody []byte) error {
return err return err
} }
if h.Username != "" || h.Password != "" {
req.SetBasicAuth(h.Username, h.Password)
}
req.Header.Set("Content-Type", defaultContentType) req.Header.Set("Content-Type", defaultContentType)
for k, v := range h.Headers { for k, v := range h.Headers {
req.Header.Set(k, v) req.Header.Set(k, v)

View File

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