mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
s3vectors: read the bucket once per authorization Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package s3tables
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
// GetTableBucket decides on the bucket entry's metadata, policy and tags, all
|
|
// returned by one lookup of the entry, yet fetched each attribute with a
|
|
// lookup of its own: two lookups, three under a policy.
|
|
func TestGetTableBucketLooksUpTheBucketOnce(t *testing.T) {
|
|
for _, withPolicy := range []bool{false, true} {
|
|
name := "no policy"
|
|
if withPolicy {
|
|
name = "policy"
|
|
}
|
|
t.Run(name, func(t *testing.T) {
|
|
fs, m := startEmptyBucket(t)
|
|
if withPolicy {
|
|
requireOK(t, m, fs, "PutTableBucketPolicy", &PutTableBucketPolicyRequest{TableBucketARN: mustBucketARN(t),
|
|
ResourcePolicy: `{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*","Action":"s3tables:*","Resource":"*"}]}`})
|
|
}
|
|
lookups := 0
|
|
fs.OnLookup = func(dir, name string) {
|
|
if dir == TablesPath && name == renameTestBucket {
|
|
lookups++
|
|
}
|
|
}
|
|
defer func() { fs.OnLookup = nil }()
|
|
if code, resp := runHandler(t, m, fs.Client, "GetTableBucket", &GetTableBucketRequest{TableBucketARN: mustBucketARN(t)}); code != http.StatusOK {
|
|
t.Fatalf("GetTableBucket = %d %+v", code, resp)
|
|
}
|
|
if lookups != 1 {
|
|
t.Errorf("GetTableBucket looked up the bucket %d times, want 1", lookups)
|
|
}
|
|
})
|
|
}
|
|
}
|