Реализовать lab3 в общем Helm-релизе с Traefik, TLS и HPA

This commit is contained in:
Vladislav Agapov
2026-10-16 11:51:20 +03:00
parent a57cbcf329
commit 9494547300
88 changed files with 1922 additions and 255 deletions
+11
View File
@@ -106,3 +106,14 @@ func decodeCursorPosition(payload []byte, resource string) (Position, error) {
}
return Position{CreatedAt: cursor.Time, ID: cursor.ID}, nil
}
// NewShared creates a codec from the common 256-bit key provisioned to every replica.
func NewShared(encoded string) (*Codec, error) {
key, err := base64.StdEncoding.DecodeString(encoded)
if err != nil || len(key) != cursorSigningKeyBytes {
return nil, fmt.Errorf("CURSOR_SIGNING_KEY must encode exactly 32 bytes as base64")
}
codec := &Codec{}
copy(codec.key[:], key)
return codec, nil
}
+33
View File
@@ -177,3 +177,36 @@ func encodeFixture(t *testing.T, codec *Codec, resource string) string {
}
return token
}
// TestSharedCodec verifies a second process can verify the first process's cursor.
func TestSharedCodec(t *testing.T) {
key := base64.StdEncoding.EncodeToString(make([]byte, 32))
first, err := NewShared(key)
if err != nil {
t.Fatal(err)
}
second, err := NewShared(key)
if err != nil {
t.Fatal(err)
}
position := Position{CreatedAt: time.Now().UTC(), ID: uuid.New()}
encoded, err := first.Encode("chat", position)
if err != nil {
t.Fatal(err)
}
result, err := second.Decode(encoded, "chat")
if err != nil || result != position {
t.Fatalf("cross-replica cursor: %v", err)
}
}
// TestSharedCodecRejectsInvalidKey requires a full 256-bit decoded secret.
func TestSharedCodecRejectsInvalidKey(t *testing.T) {
for _, key := range []string{"", "broken!", base64.StdEncoding.EncodeToString([]byte("short"))} {
t.Run(key, func(t *testing.T) {
if _, err := NewShared(key); err == nil {
t.Fatal("invalid key accepted")
}
})
}
}