Files
seaweedfs/weed/security/assign_token_collection_test.go
T
0f3a9b315c filer: assignment tokens and chunk proofs for scoped writes (#12923)
* filer: assignment tokens and chunk proofs for scoped writes

* filer: tighten scoped chunk identities and write boundaries

* filer: apply gRPC key removal on config reload

* filer: prevent scoped chunk alias and remote append data loss

* filer: guard scoped writes across stored data representations

* filer: preserve lazy scoped admission lookups

* filer: avoid summing chunk counts for map capacity

* filer: keep a scoped assign in its path's collection

A scoped token could name another bucket's collection in AssignVolume and
upload chunks there, charging that bucket's quota and losing them when that
collection is deleted. A scoped caller now gets the collection its path
resolves to; naming a different one is refused before the master call.

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

* filer: rotate gRPC keys and bind chunk proofs to collections

---------

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

41 lines
1.3 KiB
Go

package security
import (
"testing"
"time"
jwt "github.com/golang-jwt/jwt/v5"
)
func TestAssignmentTokenBindsCollectionIncludingDefault(t *testing.T) {
key := SigningKey("assignment-collection-test-key")
const fid = "3,0100000011"
for _, collection := range []string{"", "bucket-a"} {
t.Run(collection, func(t *testing.T) {
proof := GenJwtForAssign(key, time.Hour, fid, "session", 2, collection)
if !VerifyAssignJwt(key, nil, proof, fid+"_1", "session", 0, collection) {
t.Fatal("proof refused in its assigned collection")
}
if VerifyAssignJwt(key, nil, proof, fid, "session", 0, "other") {
t.Fatal("proof accepted in another collection")
}
})
}
// A pre-collection proof must not silently become a proof for the default
// collection, even though decoding a missing string would yield empty.
for _, missing := range []bool{true, false} {
claims := jwt.MapClaims{"fid": fid, "cnt": 1, "jti": "session", "exp": time.Now().Add(time.Hour).Unix()}
if !missing {
claims["collection"] = nil
}
raw, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(AssignSigningKey(key)))
if err != nil {
t.Fatal(err)
}
if VerifyAssignJwt(key, nil, EncodedJwt(raw), fid, "session", 0, "") {
t.Fatalf("proof without a collection accepted for the default collection (missing=%v)", missing)
}
}
}