mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
test: refuse unknown published segment fields
This commit is contained in:
1 parent
325c7555f7
commit
6a2bd2a4e3
1 file changed
+38
@@ -0,0 +1,38 @@
|
||||
package chunkstore
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
func TestManifestFormatUpgradeRefusesUnknownSegmentField(t *testing.T) {
|
||||
f, b, _, _, _ := gcFixture(t)
|
||||
r, h := publishSegmented(t, f, b)
|
||||
ctx := context.Background()
|
||||
if _, err := r.GetHead(ctx); err != nil {
|
||||
t.Fatalf("valid legacy segment refused: %v", err)
|
||||
}
|
||||
ref := h.Segments[0]
|
||||
body, err := r.Get(ctx, ref.Key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Keep the object hash valid: the refusal must come from the segment schema.
|
||||
body = append(bytes.TrimSuffix(body, []byte("}")), []byte(",\"future_encoding\":\"unsupported\"}")...)
|
||||
if err := r.Put(ctx, "format-upgrade-unknown-field", body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ref.Key = qualifyManifestKey(ref.Owner, "format-upgrade-unknown-field")
|
||||
ref.SHA256 = sha256.Sum256(body)
|
||||
h.Segments[0] = ref
|
||||
if _, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: h.Epoch}, h); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.GetHead(ctx); err == nil {
|
||||
t.Fatal("published segment with unknown field accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user