Files
CLIProxyAPI/internal/runtime/executor/helps/gemini_interactions_test.go
sususu a8582fbaca fix(signature): pin Vertex bare-Tink recognition to observed key ids
Without a protobuf wrapper, the ciphertext after the Tink prefix byte is
indistinguishable from uniform random bytes. Matching only the 0x01
prefix byte claimed about 1/256 of unenveloped payloads as Gemini: xAI
encrypted_content starting with 0x01 was then rejected by the Grok
validator and dropped from replay, and Kimi signatures were misclassified.

- require the observed Vertex key id (8f3d6b5f) in addition to the
  prefix byte; a rotated key falls back to the bypass sentinel, which is
  the behavior before bare-Tink recognition
- expose IsGeminiVertexBareTinkSignature and scope the Gemini
  Interactions sanitizer: the public endpoint drops bare-Tink thought
  steps, the Vertex Interactions endpoint keeps them
- restore the xAI seed and Kimi ordering tests that had been adjusted
  around the false positive, and add regressions for a 0x01-leading Grok
  payload and an unknown key id
2026-10-27 09:39:35 +08:00

32 lines
1.1 KiB
Go

package helps
import (
"encoding/base64"
"testing"
"github.com/tidwall/gjson"
)
func testVertexBareTinkInteractionsSignature() string {
payload := []byte{0x01, 0x8f, 0x3d, 0x6b, 0x5f}
for len(payload) < 405 {
payload = append(payload, byte(0xA0+len(payload)%0x20))
}
return base64.StdEncoding.EncodeToString(payload)
}
func TestSanitizeGeminiInteractionsUnsupportedInputIDs_ScopesVertexBareTink(t *testing.T) {
sig := testVertexBareTinkInteractionsSignature()
body := []byte(`{"input":[{"type":"user_input","content":[{"type":"text","text":"hi"}]},{"type":"thought","signature":"` + sig + `"}]}`)
public := SanitizeGeminiInteractionsUnsupportedInputIDs(body, false)
if gjson.GetBytes(public, `input.#(type=="thought")`).Exists() {
t.Fatalf("public Interactions endpoint must drop the Vertex bare-Tink thought: %s", public)
}
vertex := SanitizeGeminiInteractionsUnsupportedInputIDs(body, true)
if got := gjson.GetBytes(vertex, `input.#(type=="thought").signature`).String(); got != sig {
t.Fatalf("Vertex Interactions endpoint must keep the bare-Tink signature, got %q", got)
}
}