fix(protocol): harden gateway contract validation
This commit is contained in:
@@ -141,3 +141,37 @@ func TestGatewayClipboardAuditIsMetadataOnlyAndStrict(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewayClipboardTextMeasuresDecodedUTF8Bytes(t *testing.T) {
|
||||
for name, text := range map[string]string{
|
||||
"ascii-boundary": strings.Repeat("a", 65536),
|
||||
"utf8-boundary": strings.Repeat("é", 32768),
|
||||
"escape-heavy": strings.Repeat(`"`, 32768),
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
value := protocol.GatewayClipboardText{
|
||||
Direction: "client_to_provider",
|
||||
Text: text,
|
||||
Encoding: "utf-8",
|
||||
LoopToken: "abcdefghijklmnop",
|
||||
}
|
||||
encoded, err := protocol.EncodeGatewayClipboardText(value)
|
||||
if err != nil {
|
||||
t.Fatalf("EncodeGatewayClipboardText() error = %v", err)
|
||||
}
|
||||
decoded, err := protocol.DecodeGatewayClipboardText(encoded)
|
||||
if err != nil || decoded.Text != text {
|
||||
t.Fatalf("DecodeGatewayClipboardText() = %d bytes, %v", len(decoded.Text), err)
|
||||
}
|
||||
})
|
||||
}
|
||||
tooLarge := protocol.GatewayClipboardText{
|
||||
Direction: "client_to_provider",
|
||||
Text: strings.Repeat("a", 65537),
|
||||
Encoding: "utf-8",
|
||||
LoopToken: "abcdefghijklmnop",
|
||||
}
|
||||
if _, err := protocol.EncodeGatewayClipboardText(tooLarge); err == nil {
|
||||
t.Fatal("EncodeGatewayClipboardText() accepted 65,537 decoded UTF-8 bytes")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user