Files
seaweedfs/weed/command/s3_iceberg_endpoint_test.go
T
9fc8a6aec2 mount: read SSE-S3 objects through the S3 gateway (#12909)
* mount: read SSE-S3 objects through an authenticated S3 gateway

* mount: check each comma-joined mount option against -sseS3ReadEndpoint

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: read a mounted version file by its object key and version id

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: read a current null-version object without s3:GetObjectVersion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: declare -sseS3ReadEndpoint with the other mount options so weed fuse accepts it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: require the canonical bucket path as the root of an SSE-S3 read mount

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: fall back to the null version when the current object is another version

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* master: list the S3 endpoint each S3 gateway advertises

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* s3: advertise the gateway's S3 endpoint to the master

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: find the S3 gateway through the masters instead of -sseS3ReadEndpoint

-sseS3Read turns gateway reads on. The reader lists the S3 endpoints the
filer's masters have registered, prefers HTTPS, and picks another gateway
when the current one cannot be reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: retry an unreachable S3 gateway read on a different gateway

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: warn when -sseS3Read falls back to a plain-HTTP gateway

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: do not retry an unreachable HTTPS gateway over plain HTTP

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: tell HTTPS gateways apart by the parsed URL scheme

An S3 gateway advertised as HTTPS://host lost the HTTPS preference and
the plain-HTTP fallback guard, since the check matched the raw string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:32:18 -08:00

129 lines
3.2 KiB
Go

package command
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/util"
)
func strp(s string) *string { return &s }
func intp(i int) *int { return &i }
func TestDeriveS3AdvertisedEndpoint(t *testing.T) {
tests := []struct {
name string
opt S3Options
want string
}{
{
name: "wildcard bind IP with no externalUrl does not advertise an endpoint",
opt: S3Options{
bindIp: strp("0.0.0.0"),
port: intp(8333),
portHttps: intp(0),
tlsPrivateKey: strp(""),
externalUrl: strp(""),
},
want: "",
},
{
name: "empty bind IP with no externalUrl does not advertise an endpoint",
opt: S3Options{
bindIp: strp(""),
port: intp(8333),
portHttps: intp(0),
tlsPrivateKey: strp(""),
externalUrl: strp(""),
},
want: "",
},
{
name: "explicit bind IP is kept",
opt: S3Options{
bindIp: strp("10.0.0.5"),
port: intp(8333),
portHttps: intp(0),
tlsPrivateKey: strp(""),
externalUrl: strp(""),
},
want: "http://10.0.0.5:8333",
},
{
name: "IPv6 literals are bracketed",
opt: S3Options{
bindIp: strp("fe80::1"),
port: intp(8333),
portHttps: intp(0),
tlsPrivateKey: strp(""),
externalUrl: strp(""),
},
want: "http://[fe80::1]:8333",
},
{
name: "TLS key + https port switches scheme and port",
opt: S3Options{
bindIp: strp("10.0.0.5"),
port: intp(8333),
portHttps: intp(8443),
tlsPrivateKey: strp("/etc/seaweed/tls.key"),
externalUrl: strp(""),
},
want: "https://10.0.0.5:8443",
},
{
name: "TLS-only (no separate https port) still uses https on the HTTP port",
opt: S3Options{
bindIp: strp("10.0.0.5"),
port: intp(8333),
portHttps: intp(0),
tlsPrivateKey: strp("/etc/seaweed/tls.key"),
externalUrl: strp(""),
},
want: "https://10.0.0.5:8333",
},
{
name: "externalUrl wins and trailing slash is stripped",
opt: S3Options{
bindIp: strp("10.0.0.5"),
port: intp(8333),
portHttps: intp(0),
tlsPrivateKey: strp(""),
externalUrl: strp("https://s3.example.com/"),
},
want: "https://s3.example.com",
},
}
for i := range tests {
tc := &tests[i]
t.Run(tc.name, func(t *testing.T) {
got := tc.opt.deriveS3AdvertisedEndpoint()
if got != tc.want {
t.Fatalf("deriveS3AdvertisedEndpoint() = %q, want %q", got, tc.want)
}
})
}
}
func TestS3Endpoint(t *testing.T) {
tls := S3Options{
ip: strp(""),
bindIp: strp("0.0.0.0"),
port: intp(8333),
portHttps: intp(8443),
tlsPrivateKey: strp("/etc/seaweed/tls.key"),
externalUrl: strp(""),
}
if got, want := tls.s3Endpoint(), "https://"+util.JoinHostPort(util.DetectedHostAddress(), 8443); got != want {
t.Fatalf("wildcard bind: got %q, want %q", got, want)
}
tls.ip = strp("10.0.0.7")
if got := tls.s3Endpoint(); got != "https://10.0.0.7:8443" {
t.Fatalf("explicit -ip: got %q", got)
}
tls.externalUrl = strp("https://s3.example.com/")
if got := tls.s3Endpoint(); got != "https://s3.example.com" {
t.Fatalf("externalUrl: got %q", got)
}
}