Fixed http request wf function basic auth header
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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==")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user