forked from googleapis/google-cloud-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(storage): retry SignBlob call for URL signing (googleapis#11154)
* fix(storage): retry SignBlob call for URL signing Adds a retry to the SignBlob call made by the default SignBytes function from BucketHandle.SignedURL(). This is an idempotent call so fully safe to retry. Signed URL integration tests pass locally. * fmt * add test with mock transport
- Loading branch information
Showing
2 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package storage | |
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -1640,3 +1641,30 @@ func TestBucketSignedURL_Endpoint_Emulator_Host(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
// Test retry logic for default SignBlob function used by BucketHandle.SignedURL. | ||
// This cannot be tested via the emulator so we use a mock. | ||
func TestDefaultSignBlobRetry(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
// Use mock transport. Return 2 503 responses before succeeding. | ||
mt := mockTransport{} | ||
mt.addResult(&http.Response{StatusCode: 503, Body: bodyReader("")}, nil) | ||
mt.addResult(&http.Response{StatusCode: 503, Body: bodyReader("")}, nil) | ||
mt.addResult(&http.Response{StatusCode: 200, Body: bodyReader("{}")}, nil) | ||
|
||
client, err := NewClient(ctx, option.WithHTTPClient(&http.Client{Transport: &mt})) | ||
if err != nil { | ||
t.Fatalf("NewClient: %v", err) | ||
} | ||
|
||
b := client.Bucket("fakebucket") | ||
|
||
if _, err := b.SignedURL("fakeobj", &SignedURLOptions{ | ||
Method: "GET", | ||
Expires: time.Now().Add(time.Hour), | ||
SignBytes: b.defaultSignBytesFunc("[email protected]"), | ||
}); err != nil { | ||
t.Fatalf("BucketHandle.SignedURL: %v", err) | ||
} | ||
} |