@@ -61,15 +61,15 @@ func waitPersist(t *testing.T, inj *Injector, n int) {
6161
6262func TestInterceptOAuthResponseJSON (t * testing.T ) {
6363 // Token endpoint returns a JSON token response.
64- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
64+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
6565 w .Header ().Set ("Content-Type" , "application/json" )
6666 resp := map [string ]interface {}{
6767 "access_token" : "new-real-access-token-12345" ,
6868 "refresh_token" : "new-real-refresh-token-67890" ,
6969 "expires_in" : 3600 ,
7070 "token_type" : "Bearer" ,
7171 }
72- json .NewEncoder (w ).Encode (resp )
72+ _ = json .NewEncoder (w ).Encode (resp )
7373 }))
7474 defer tokenEndpoint .Close ()
7575
@@ -96,7 +96,7 @@ func TestInterceptOAuthResponseJSON(t *testing.T) {
9696 if err != nil {
9797 t .Fatal (err )
9898 }
99- defer resp .Body .Close ()
99+ defer func () { _ = resp .Body .Close () } ()
100100
101101 body , _ := io .ReadAll (resp .Body )
102102 bodyStr := string (body )
@@ -130,9 +130,9 @@ func TestInterceptOAuthResponseJSON(t *testing.T) {
130130
131131func TestInterceptOAuthResponseFormEncoded (t * testing.T ) {
132132 // Token endpoint returns a form-encoded response (per RFC 6749).
133- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
133+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
134134 w .Header ().Set ("Content-Type" , "application/x-www-form-urlencoded" )
135- fmt .Fprint (w , "access_token=form-real-access&refresh_token=form-real-refresh&expires_in=7200&token_type=bearer" )
135+ _ , _ = fmt .Fprint (w , "access_token=form-real-access&refresh_token=form-real-refresh&expires_in=7200&token_type=bearer" )
136136 }))
137137 defer tokenEndpoint .Close ()
138138
@@ -158,7 +158,7 @@ func TestInterceptOAuthResponseFormEncoded(t *testing.T) {
158158 if err != nil {
159159 t .Fatal (err )
160160 }
161- defer resp .Body .Close ()
161+ defer func () { _ = resp .Body .Close () } ()
162162
163163 body , _ := io .ReadAll (resp .Body )
164164 bodyStr := string (body )
@@ -186,14 +186,14 @@ func TestInterceptOAuthResponseFormEncoded(t *testing.T) {
186186
187187func TestInterceptOAuthResponseOnlyAccessToken (t * testing.T ) {
188188 // Token endpoint returns only access_token, no refresh_token.
189- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
189+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
190190 w .Header ().Set ("Content-Type" , "application/json" )
191191 resp := map [string ]interface {}{
192192 "access_token" : "access-only-real-token" ,
193193 "expires_in" : 1800 ,
194194 "token_type" : "Bearer" ,
195195 }
196- json .NewEncoder (w ).Encode (resp )
196+ _ = json .NewEncoder (w ).Encode (resp )
197197 }))
198198 defer tokenEndpoint .Close ()
199199
@@ -220,7 +220,7 @@ func TestInterceptOAuthResponseOnlyAccessToken(t *testing.T) {
220220 if err != nil {
221221 t .Fatal (err )
222222 }
223- defer resp .Body .Close ()
223+ defer func () { _ = resp .Body .Close () } ()
224224
225225 body , _ := io .ReadAll (resp .Body )
226226 bodyStr := string (body )
@@ -255,10 +255,10 @@ func TestInterceptOAuthResponseOnlyAccessToken(t *testing.T) {
255255
256256func TestInterceptOAuthResponseNon2xx (t * testing.T ) {
257257 // Non-2xx responses should pass through unchanged.
258- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
258+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
259259 w .Header ().Set ("Content-Type" , "application/json" )
260260 w .WriteHeader (http .StatusBadRequest )
261- fmt .Fprint (w , `{"error":"invalid_grant","error_description":"token expired"}` )
261+ _ , _ = fmt .Fprint (w , `{"error":"invalid_grant","error_description":"token expired"}` )
262262 }))
263263 defer tokenEndpoint .Close ()
264264
@@ -284,7 +284,7 @@ func TestInterceptOAuthResponseNon2xx(t *testing.T) {
284284 if err != nil {
285285 t .Fatal (err )
286286 }
287- defer resp .Body .Close ()
287+ defer func () { _ = resp .Body .Close () } ()
288288
289289 if resp .StatusCode != http .StatusBadRequest {
290290 t .Errorf ("expected 400, got %d" , resp .StatusCode )
@@ -298,13 +298,13 @@ func TestInterceptOAuthResponseNon2xx(t *testing.T) {
298298
299299func TestInterceptOAuthResponseNonMatchingURL (t * testing.T ) {
300300 // A response from a non-token-URL should pass through unchanged.
301- apiEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
301+ apiEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
302302 w .Header ().Set ("Content-Type" , "application/json" )
303303 resp := map [string ]interface {}{
304304 "access_token" : "this-looks-like-a-token-but-is-not" ,
305305 "data" : "some api response" ,
306306 }
307- json .NewEncoder (w ).Encode (resp )
307+ _ = json .NewEncoder (w ).Encode (resp )
308308 }))
309309 defer apiEndpoint .Close ()
310310
@@ -330,7 +330,7 @@ func TestInterceptOAuthResponseNonMatchingURL(t *testing.T) {
330330 if err != nil {
331331 t .Fatal (err )
332332 }
333- defer resp .Body .Close ()
333+ defer func () { _ = resp .Body .Close () } ()
334334
335335 body , _ := io .ReadAll (resp .Body )
336336 // The response should contain the original token since this URL does not
@@ -342,15 +342,15 @@ func TestInterceptOAuthResponseNonMatchingURL(t *testing.T) {
342342
343343func TestInterceptOAuthResponseVaultPersistence (t * testing.T ) {
344344 // Verify that the vault is updated with new tokens after interception.
345- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
345+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
346346 w .Header ().Set ("Content-Type" , "application/json" )
347347 resp := map [string ]interface {}{
348348 "access_token" : "updated-access-token" ,
349349 "refresh_token" : "updated-refresh-token" ,
350350 "expires_in" : 7200 ,
351351 "token_type" : "Bearer" ,
352352 }
353- json .NewEncoder (w ).Encode (resp )
353+ _ = json .NewEncoder (w ).Encode (resp )
354354 }))
355355 defer tokenEndpoint .Close ()
356356
@@ -411,7 +411,7 @@ func TestInterceptOAuthResponseConcurrentRefreshDedup(t *testing.T) {
411411 var mu sync.Mutex
412412 requestCount := 0
413413
414- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
414+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
415415 mu .Lock ()
416416 requestCount ++
417417 count := requestCount
@@ -423,7 +423,7 @@ func TestInterceptOAuthResponseConcurrentRefreshDedup(t *testing.T) {
423423 "refresh_token" : fmt .Sprintf ("concurrent-refresh-%d" , count ),
424424 "expires_in" : 3600 ,
425425 }
426- json .NewEncoder (w ).Encode (resp )
426+ _ = json .NewEncoder (w ).Encode (resp )
427427 }))
428428 defer tokenEndpoint .Close ()
429429
@@ -494,9 +494,9 @@ func TestInterceptOAuthResponseConcurrentRefreshDedup(t *testing.T) {
494494func TestInterceptOAuthResponseNonJSONContentType (t * testing.T ) {
495495 // Non-JSON/non-form content type that happens to contain token-like fields
496496 // should fail parsing and pass through unchanged.
497- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
497+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
498498 w .Header ().Set ("Content-Type" , "text/plain" )
499- fmt .Fprint (w , "this is not a token response" )
499+ _ , _ = fmt .Fprint (w , "this is not a token response" )
500500 }))
501501 defer tokenEndpoint .Close ()
502502
@@ -522,7 +522,7 @@ func TestInterceptOAuthResponseNonJSONContentType(t *testing.T) {
522522 if err != nil {
523523 t .Fatal (err )
524524 }
525- defer resp .Body .Close ()
525+ defer func () { _ = resp .Body .Close () } ()
526526
527527 body , _ := io .ReadAll (resp .Body )
528528 if string (body ) != "this is not a token response" {
@@ -532,14 +532,14 @@ func TestInterceptOAuthResponseNonJSONContentType(t *testing.T) {
532532
533533func TestInterceptOAuthResponseTransferEncodingCleared (t * testing.T ) {
534534 // Verify that Transfer-Encoding is cleared and Content-Length is set.
535- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
535+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
536536 w .Header ().Set ("Content-Type" , "application/json" )
537537 w .Header ().Set ("Transfer-Encoding" , "chunked" )
538538 resp := map [string ]interface {}{
539539 "access_token" : "real-token-for-te-test" ,
540540 "expires_in" : 3600 ,
541541 }
542- json .NewEncoder (w ).Encode (resp )
542+ _ = json .NewEncoder (w ).Encode (resp )
543543 }))
544544 defer tokenEndpoint .Close ()
545545
@@ -565,7 +565,7 @@ func TestInterceptOAuthResponseTransferEncodingCleared(t *testing.T) {
565565 if err != nil {
566566 t .Fatal (err )
567567 }
568- defer resp .Body .Close ()
568+ defer func () { _ = resp .Body .Close () } ()
569569
570570 body , _ := io .ReadAll (resp .Body )
571571
@@ -660,13 +660,13 @@ func TestOAuthPhantomTokenFormat(t *testing.T) {
660660
661661func TestInterceptOAuthResponseEmptyIndex (t * testing.T ) {
662662 // With an empty OAuth index, all responses should pass through unchanged.
663- backend := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
663+ backend := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
664664 w .Header ().Set ("Content-Type" , "application/json" )
665665 resp := map [string ]interface {}{
666666 "access_token" : "some-token-value" ,
667667 "token_type" : "Bearer" ,
668668 }
669- json .NewEncoder (w ).Encode (resp )
669+ _ = json .NewEncoder (w ).Encode (resp )
670670 }))
671671 defer backend .Close ()
672672
@@ -688,7 +688,7 @@ func TestInterceptOAuthResponseEmptyIndex(t *testing.T) {
688688 if err != nil {
689689 t .Fatal (err )
690690 }
691- defer resp .Body .Close ()
691+ defer func () { _ = resp .Body .Close () } ()
692692
693693 body , _ := io .ReadAll (resp .Body )
694694 if ! strings .Contains (string (body ), "some-token-value" ) {
@@ -698,19 +698,19 @@ func TestInterceptOAuthResponseEmptyIndex(t *testing.T) {
698698
699699func TestInterceptOAuthResponseMultipleCredentials (t * testing.T ) {
700700 // Test with multiple OAuth credentials and verify correct one is matched.
701- tokenEndpoint1 := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
701+ tokenEndpoint1 := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
702702 w .Header ().Set ("Content-Type" , "application/json" )
703- json .NewEncoder (w ).Encode (map [string ]interface {}{
703+ _ = json .NewEncoder (w ).Encode (map [string ]interface {}{
704704 "access_token" : "real-token-for-cred1" ,
705705 "refresh_token" : "real-refresh-for-cred1" ,
706706 "expires_in" : 3600 ,
707707 })
708708 }))
709709 defer tokenEndpoint1 .Close ()
710710
711- tokenEndpoint2 := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
711+ tokenEndpoint2 := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
712712 w .Header ().Set ("Content-Type" , "application/json" )
713- json .NewEncoder (w ).Encode (map [string ]interface {}{
713+ _ = json .NewEncoder (w ).Encode (map [string ]interface {}{
714714 "access_token" : "real-token-for-cred2" ,
715715 "refresh_token" : "real-refresh-for-cred2" ,
716716 "expires_in" : 1800 ,
@@ -727,14 +727,14 @@ func TestInterceptOAuthResponseMultipleCredentials(t *testing.T) {
727727 TokenURL : tokenEndpoint1 .URL ,
728728 }
729729 data1 , _ := cred1 .Marshal ()
730- vaultStore .Add ("cred1" , string (data1 ))
730+ _ , _ = vaultStore .Add ("cred1" , string (data1 ))
731731
732732 cred2 := & vault.OAuthCredential {
733733 AccessToken : "old-access-2" ,
734734 TokenURL : tokenEndpoint2 .URL ,
735735 }
736736 data2 , _ := cred2 .Marshal ()
737- vaultStore .Add ("cred2" , string (data2 ))
737+ _ , _ = vaultStore .Add ("cred2" , string (data2 ))
738738
739739 metas := []store.CredentialMeta {
740740 {Name : "cred1" , CredType : "oauth" , TokenURL : tokenEndpoint1 .URL },
@@ -788,9 +788,9 @@ func TestInterceptOAuthResponseVaultWriteFailure(t *testing.T) {
788788 // Even if the vault write would fail (e.g., provider doesn't support Add),
789789 // the response should still contain phantom tokens. We test this by using
790790 // a provider wrapper that does not implement Add.
791- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
791+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
792792 w .Header ().Set ("Content-Type" , "application/json" )
793- json .NewEncoder (w ).Encode (map [string ]interface {}{
793+ _ = json .NewEncoder (w ).Encode (map [string ]interface {}{
794794 "access_token" : "real-token-vault-fail" ,
795795 "refresh_token" : "real-refresh-vault-fail" ,
796796 "expires_in" : 3600 ,
@@ -855,7 +855,7 @@ func TestInterceptOAuthResponseVaultWriteFailure(t *testing.T) {
855855 if err != nil {
856856 t .Fatal (err )
857857 }
858- defer resp .Body .Close ()
858+ defer func () { _ = resp .Body .Close () } ()
859859
860860 body , _ := io .ReadAll (resp .Body )
861861 bodyStr := string (body )
@@ -874,9 +874,9 @@ func TestInterceptOAuthResponseVaultWriteFailure(t *testing.T) {
874874func TestInterceptOAuthResponsePhantomFileWrite (t * testing.T ) {
875875 // Verify that phantom files are written after vault persistence when
876876 // phantomDir is configured.
877- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
877+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
878878 w .Header ().Set ("Content-Type" , "application/json" )
879- json .NewEncoder (w ).Encode (map [string ]interface {}{
879+ _ = json .NewEncoder (w ).Encode (map [string ]interface {}{
880880 "access_token" : "new-real-access-for-phantom" ,
881881 "refresh_token" : "new-real-refresh-for-phantom" ,
882882 "expires_in" : 3600 ,
@@ -919,19 +919,19 @@ func TestInterceptOAuthResponsePhantomFileWrite(t *testing.T) {
919919 accessPath := phantomDir + "/PHANTOM_WRITE_OAUTH_ACCESS"
920920 refreshPath := phantomDir + "/PHANTOM_WRITE_OAUTH_REFRESH"
921921
922- if _ , err := readFileContent (accessPath ); err != nil {
922+ if err := checkFileExists (accessPath ); err != nil {
923923 t .Errorf ("access phantom file not found: %v" , err )
924924 }
925- if _ , err := readFileContent (refreshPath ); err != nil {
925+ if err := checkFileExists (refreshPath ); err != nil {
926926 t .Errorf ("refresh phantom file not found: %v" , err )
927927 }
928928}
929929
930930func TestInterceptOAuthResponseNoPhantomFileWithoutDir (t * testing.T ) {
931931 // When phantomDir is not set, no phantom files should be written.
932- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
932+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
933933 w .Header ().Set ("Content-Type" , "application/json" )
934- json .NewEncoder (w ).Encode (map [string ]interface {}{
934+ _ = json .NewEncoder (w ).Encode (map [string ]interface {}{
935935 "access_token" : "access-no-dir" ,
936936 "refresh_token" : "refresh-no-dir" ,
937937 "expires_in" : 3600 ,
@@ -991,9 +991,9 @@ func TestInterceptOAuthResponseOversizedBody(t *testing.T) {
991991 // Response body exceeding maxProxyBody (16 MiB) should pass through
992992 // unchanged without phantom replacement.
993993 bigBody := strings .Repeat ("x" , maxProxyBody + 1 )
994- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
994+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
995995 w .Header ().Set ("Content-Type" , "application/json" )
996- w .Write ([]byte (bigBody ))
996+ _ , _ = w .Write ([]byte (bigBody ))
997997 }))
998998 defer tokenEndpoint .Close ()
999999
@@ -1028,12 +1028,9 @@ func TestInterceptOAuthResponseOversizedBody(t *testing.T) {
10281028 }
10291029}
10301030
1031- func readFileContent (path string ) (string , error ) {
1032- data , err := os .ReadFile (path )
1033- if err != nil {
1034- return "" , err
1035- }
1036- return string (data ), nil
1031+ func checkFileExists (path string ) error {
1032+ _ , err := os .Stat (path )
1033+ return err
10371034}
10381035
10391036// readOnlyProvider wraps a vault.Provider but does not implement the Add interface,
@@ -1057,9 +1054,9 @@ func (p *readOnlyProvider) Name() string {
10571054func TestInterceptOAuthResponseChainProviderPersistence (t * testing.T ) {
10581055 // Verify that OAuth token persistence works when the injector uses a
10591056 // ChainProvider wrapping a vault.Store (which implements Add).
1060- tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1057+ tokenEndpoint := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
10611058 w .Header ().Set ("Content-Type" , "application/json" )
1062- json .NewEncoder (w ).Encode (map [string ]interface {}{
1059+ _ = json .NewEncoder (w ).Encode (map [string ]interface {}{
10631060 "access_token" : "chain-updated-access" ,
10641061 "refresh_token" : "chain-updated-refresh" ,
10651062 "expires_in" : 3600 ,
0 commit comments