-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[s3 gateway] Handle all path characters in SigV2 and add Nessie S3-is…
…h test (#2464) * Change AWS S3 sigV2 verification to use path as documented by AWS * Add Nessie S3-ish test Use the minIO client to test S3 uploads and downloads with both V2 and V4 signatures. (Unlike the AWS S3 client, the minIO client supports signing using SigV2.) * Parallelise S3 gateway test (Timed out on GCP) * Add S3 SigV2, SigV4 component tests Sign using minio, verify using gateway code. * SigV4: Test bothV4 path and host styles * Make S3 gateway test pathnames (just) shorter than 1023 chars * Close channel in Nessie S3 gateway test Also increase parallelism somewhat. * [CR] Use t.Errorf. Kill test if minio client create fails.
- Loading branch information
1 parent
78078b7
commit 4713534
Showing
6 changed files
with
326 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package nessie | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"math/rand" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/minio/minio-go/v7" | ||
"github.com/minio/minio-go/v7/pkg/credentials" | ||
"github.com/spf13/viper" | ||
"github.com/treeverse/lakefs/pkg/testutil" | ||
) | ||
|
||
var sigs = []struct { | ||
Name string | ||
GetCredentials func(id, secret, token string) *credentials.Credentials | ||
}{ | ||
{"V2", credentials.NewStaticV2}, | ||
{"V4", credentials.NewStaticV4}, | ||
} | ||
|
||
const ( | ||
numUploads = 100 | ||
randomDataPathLength = 1020 | ||
prefix = "main/data/" | ||
) | ||
|
||
func TestS3UploadAndDownload(t *testing.T) { | ||
const parallelism = 10 | ||
|
||
ctx, _, repo := setupTest(t) | ||
|
||
accessKeyID := viper.GetString("access_key_id") | ||
secretAccessKey := viper.GetString("secret_access_key") | ||
endpoint := viper.GetString("s3_endpoint") | ||
opts := minio.PutObjectOptions{} | ||
|
||
for _, sig := range sigs { | ||
t.Run("Sig"+sig.Name, func(t *testing.T) { | ||
// Use same sequence of pathnames to test each sig. | ||
rand := rand.New(rand.NewSource(17)) | ||
|
||
creds := sig.GetCredentials(accessKeyID, secretAccessKey, "") | ||
|
||
type Object struct { | ||
Path, Content string | ||
} | ||
|
||
var ( | ||
wg sync.WaitGroup | ||
objects = make(chan Object, parallelism*2) | ||
) | ||
|
||
for i := 0; i < parallelism; i++ { | ||
client, err := minio.New(endpoint, &minio.Options{ | ||
Creds: creds, | ||
Secure: false, | ||
}) | ||
if err != nil { | ||
t.Fatalf("minio.New: %s", err) | ||
} | ||
|
||
wg.Add(1) | ||
go func() { | ||
for o := range objects { | ||
_, err := client.PutObject( | ||
ctx, repo, o.Path, strings.NewReader(o.Content), int64(len(o.Content)), opts) | ||
if err != nil { | ||
t.Errorf("minio.Client.PutObject(%s): %s", o.Path, err) | ||
} | ||
|
||
download, err := client.GetObject( | ||
ctx, repo, o.Path, minio.GetObjectOptions{}) | ||
if err != nil { | ||
t.Errorf("minio.Client.GetObject(%s): %s", o.Path, err) | ||
} | ||
contents := bytes.NewBuffer(nil) | ||
_, err = io.Copy(contents, download) | ||
if err != nil { | ||
t.Errorf("download %s: %s", o.Path, err) | ||
} | ||
if strings.Compare(contents.String(), o.Content) != 0 { | ||
t.Errorf( | ||
"Downloaded bytes %v from uploaded bytes %v", contents.Bytes(), o.Content) | ||
} | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
|
||
for i := 0; i < numUploads; i++ { | ||
objects <- Object{ | ||
Content: testutil.RandomString(rand, randomDataContentLength), | ||
// lakeFS supports _any_ path, even if its | ||
// byte sequence is not legal UTF-8 string. | ||
Path: prefix + testutil.RandomString(rand, randomDataPathLength-len(prefix)), | ||
} | ||
} | ||
close(objects) | ||
wg.Wait() | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.