MCPcopy Create free account
hub / github.com/SamNet-dev/snix / TestClientHelloGolden

Function TestClientHelloGolden

core/injector/clienthello_test.go:28–61  ·  view source on GitHub ↗

TestClientHelloGolden verifies byte-for-byte parity with the upstream Python ClientHelloMaker. Vectors are generated by test/golden/gen_golden.py.

(t *testing.T)

Source from the content-addressed store, hash-verified

26// TestClientHelloGolden verifies byte-for-byte parity with the upstream
27// Python ClientHelloMaker. Vectors are generated by test/golden/gen_golden.py.
28func TestClientHelloGolden(t *testing.T) {
29 path := filepath.Join("..", "..", "test", "golden", "clienthello_golden.json")
30 raw, err := os.ReadFile(path)
31 if err != nil {
32 t.Fatalf("read golden: %v", err)
33 }
34 var gf goldenFile
35 if err := json.Unmarshal(raw, &gf); err != nil {
36 t.Fatalf("parse golden: %v", err)
37 }
38 if len(gf.Vectors) == 0 {
39 t.Fatal("no golden vectors")
40 }
41
42 for _, v := range gf.Vectors {
43 v := v
44 t.Run(v.Name, func(t *testing.T) {
45 rnd, _ := hex.DecodeString(v.Rnd)
46 sess, _ := hex.DecodeString(v.SessID)
47 ks, _ := hex.DecodeString(v.KeyShare)
48 got, err := BuildClientHello(rnd, sess, []byte(v.SNI), ks)
49 if err != nil {
50 t.Fatalf("BuildClientHello: %v", err)
51 }
52 if len(got) != v.ExpectedLen {
53 t.Fatalf("len: got %d want %d", len(got), v.ExpectedLen)
54 }
55 want, _ := hex.DecodeString(v.ExpectedHex)
56 if hex.EncodeToString(got) != v.ExpectedHex {
57 t.Fatalf("byte mismatch\n got: %x\n want: %x", got, want)
58 }
59 })
60 }
61}
62
63func TestClientHelloRejectsBadInput(t *testing.T) {
64 bad31 := make([]byte, 31)

Callers

nothing calls this directly

Calls 2

BuildClientHelloFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected