diff --git a/automation/automation/http_request_handler.go b/automation/automation/http_request_handler.go index 7523f157d..a59164595 100644 --- a/automation/automation/http_request_handler.go +++ b/automation/automation/http_request_handler.go @@ -145,21 +145,18 @@ func (h httpRequestHandler) makeRequest(ctx context.Context, args *httpRequestSe args.Headers.Set("User-Agent", args.HeaderUserAgent) - switch { - case len(args.HeaderAuthBearer) > 0: - args.Headers.Add("Authorization", "Bearer "+args.HeaderAuthBearer) - case len(args.HeaderAuthPassword+args.HeaderAuthPassword) > 0: - req.SetBasicAuth( - args.HeaderAuthPassword, - args.HeaderAuthPassword, - ) - } - if len(args.HeaderContentType) > 0 { args.Headers.Add("Content-Type", args.HeaderContentType) } req.Header = args.Headers + switch { + case len(args.HeaderAuthBearer) > 0: + req.Header.Add("Authorization", "Bearer "+args.HeaderAuthBearer) + case len(args.HeaderAuthUsername+args.HeaderAuthPassword) > 0: + req.SetBasicAuth(args.HeaderAuthUsername, args.HeaderAuthPassword) + } + return } diff --git a/automation/automation/http_request_handler_test.go b/automation/automation/http_request_handler_test.go index 540e629e1..569fed40a 100644 --- a/automation/automation/http_request_handler_test.go +++ b/automation/automation/http_request_handler_test.go @@ -71,4 +71,19 @@ func TestHttpRequestMaker(t *testing.T) { r.Equal("POST", req.Method) validateBody(r, req, "a=a&b=b&b=b&i=42") }) + + t.Run("basic auth", func(t *testing.T) { + var ( + r = require.New(t) + in = &httpRequestSendArgs{ + HeaderAuthUsername: "foo", + HeaderAuthPassword: "bar", + } + req, err = httpRequestHandler{}.makeRequest(context.Background(), in) + ) + + r.NoError(err) + r.Len(req.Header["Authorization"], 1) + r.Equal(req.Header["Authorization"][0], "Basic Zm9vOmJhcg==") + }) }