Skip to content

Commit ab86053

Browse files
authored
test: Ensure Authorization is not set with empty token (#3790)
1 parent b755d64 commit ab86053

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

github/github_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,26 @@ func TestWithAuthToken(t *testing.T) {
395395
t.Parallel()
396396
validate(t, NewTokenClient(t.Context(), token).Client(), token)
397397
})
398+
399+
t.Run("do not set Authorization when empty token", func(t *testing.T) {
400+
t.Parallel()
401+
c := new(Client).WithAuthToken("")
402+
403+
gotReq := false
404+
ifAuthorizationSet := false
405+
srv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
406+
gotReq = true
407+
_, ifAuthorizationSet = r.Header["Authorization"]
408+
}))
409+
_, err := c.client.Get(srv.URL)
410+
assertNilError(t, err)
411+
if !gotReq {
412+
t.Error("request not sent")
413+
}
414+
if ifAuthorizationSet {
415+
t.Error("The header 'Authorization' must not be set")
416+
}
417+
})
398418
}
399419

400420
func TestWithEnterpriseURLs(t *testing.T) {

0 commit comments

Comments
 (0)