mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* s3: compare If-None-Match weakly, as the filer and volume servers do The S3 gateway matched conditional ETags by trimming quotes, so a weak tag such as W/"etag" in If-None-Match never matched and a revalidating GET got 200 instead of 304. Move the filer's RFC 9110 matcher to weed/util and use it in the gateway: weak comparison for If-None-Match, strong for If-Match. The routed write condition now sets AllowWeak on IF_ETAG_NOT_MATCH so the check under the object lock agrees with the gateway's pre-check. * s3: split write-condition ETag lists the way the gateway matches them etagList split on every comma and kept empty elements, so the filer's locked If-None-Match check (now a weak comparison) could match a fragment of one quoted tag, or an empty element, that the gateway's pre-check ignores. A PUT with If-None-Match: W/"<etag>,x" passed the pre-check and then got 412 under the lock. Reuse the gateway's quote-aware splitter and drop empty elements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Mansur Akhmadi <10739460+mansur-akhmadi@users.noreply.github.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
package util
|
|
|
|
import "testing"
|
|
|
|
func TestParseHostPort(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
hostPort string
|
|
wantHost string
|
|
wantPort int64
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "hostname",
|
|
hostPort: "localhost:8888",
|
|
wantHost: "localhost",
|
|
wantPort: 8888,
|
|
},
|
|
{
|
|
name: "ipv4",
|
|
hostPort: "127.0.0.1:8888",
|
|
wantHost: "127.0.0.1",
|
|
wantPort: 8888,
|
|
},
|
|
{
|
|
name: "bracketed ipv6",
|
|
hostPort: "[::1]:8888",
|
|
wantHost: "::1",
|
|
wantPort: 8888,
|
|
},
|
|
{
|
|
name: "missing port",
|
|
hostPort: "localhost",
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid port",
|
|
hostPort: "localhost:bad",
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotHost, gotPort, err := ParseHostPort(tt.hostPort)
|
|
if gotErr := err != nil; gotErr != tt.wantErr {
|
|
t.Fatalf("ParseHostPort(%q) error = %v, wantErr %v", tt.hostPort, err, tt.wantErr)
|
|
}
|
|
if tt.wantErr {
|
|
return
|
|
}
|
|
if gotHost != tt.wantHost || gotPort != tt.wantPort {
|
|
t.Fatalf("ParseHostPort(%q) = (%q, %d), want (%q, %d)", tt.hostPort, gotHost, gotPort, tt.wantHost, tt.wantPort)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestETagListMatches(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
header string
|
|
etag string
|
|
weak bool
|
|
want bool
|
|
}{
|
|
{"star", "*", `"abc"`, false, true},
|
|
{"quoted", `"abc"`, `"abc"`, false, true},
|
|
{"unquoted", "abc", `"abc"`, false, true},
|
|
{"list", `"x", "abc"`, `"abc"`, false, true},
|
|
{"miss", `"x", "y"`, `"abc"`, false, false},
|
|
{"weak tag, weak comparison", `W/"abc"`, `"abc"`, true, true},
|
|
{"weak tag, strong comparison", `W/"abc"`, `"abc"`, false, false},
|
|
{"strong tag after weak tag, strong comparison", `W/"x", "abc"`, `"abc"`, false, true},
|
|
{"comma inside a quoted tag", `"a,b"`, `"a,b"`, false, true},
|
|
{"trailing comma against an empty etag", `"x",`, `""`, true, false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := ETagListMatches(tt.header, tt.etag, tt.weak); got != tt.want {
|
|
t.Errorf("ETagListMatches(%q, %q, %v) = %v, want %v", tt.header, tt.etag, tt.weak, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|