From a3a3d53c999d6d05250e800dbc07f1eed22d2db3 Mon Sep 17 00:00:00 2001 From: Nemu-x Date: Wed, 11 Nov 2026 01:45:56 +0300 Subject: [PATCH] test: build the Chrome 155 tests with Go 1.20 slices is not in the Go 1.20 standard library; use reflect.DeepEqual and a loop instead. --- u_chrome155_test.go | 18 ++++++++++++++---- u_mldsa_json_test.go | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/u_chrome155_test.go b/u_chrome155_test.go index cf1f491c18..557a9ea797 100644 --- a/u_chrome155_test.go +++ b/u_chrome155_test.go @@ -11,7 +11,6 @@ import ( "net" "os" "reflect" - "slices" "sort" "strings" "testing" @@ -113,7 +112,7 @@ func chrome155NormalizeExtension(t *testing.T, id uint16, body []byte) string { outer, kdf, aead := r.number(1), r.number(2), r.number(2) r.take(1) // randomized config_id enc, payload := r.vector(2), r.vector(2) - if outer != 0 || !slices.Contains([]int{144, 176, 208, 240}, len(payload)) { + if outer != 0 || !chrome155ECHPayloadLen(len(payload)) { t.Fatalf("unexpected GREASE ECH shape: outer=%d, payload length=%d", outer, len(payload)) } value = fmt.Sprintf("%d/%d/%d/enc=%d/payload=144,176,208,240", outer, kdf, aead, len(enc)) @@ -251,7 +250,7 @@ func TestChrome155DefaultFingerprintRoundTrip(t *testing.T) { client := chrome155Build(t, HelloCustom, chrome155FixtureServerName(t, raw), spec) got, gotOrder, _ := chrome155ParseWire(t, client.HandshakeState.Hello.Raw) chrome155CompareWire(t, want, got) - if !slices.Equal(gotOrder, wantOrder) { + if !reflect.DeepEqual(gotOrder, wantOrder) { t.Errorf("fingerprint roundtrip reordered extensions: got %x, want %x", gotOrder, wantOrder) } if chrome155TrustAnchors(t, spec.Extensions) == nil { @@ -311,10 +310,21 @@ func TestChrome133CapabilitiesPreserved(t *testing.T) { uint16(ECDSAWithP384AndSHA384), uint16(PSSWithSHA384), uint16(PKCS1WithSHA384), uint16(PSSWithSHA512), uint16(PKCS1WithSHA512), } - if !slices.Equal(got, want) { + if !reflect.DeepEqual(got, want) { t.Fatalf("Chrome 133 signature schemes changed: got %x, want original classical schemes %x", got, want) } if _, ok := raw[0xca34]; ok { t.Fatal("Chrome 155 trust anchor IDs leaked into the Chrome 133 profile") } } + +// chrome155ECHPayloadLen reports a GREASE ECH payload length Chrome uses. A +// loop instead of slices.Contains keeps the tests building with Go 1.20. +func chrome155ECHPayloadLen(n int) bool { + for _, want := range []int{144, 176, 208, 240} { + if n == want { + return true + } + } + return false +} diff --git a/u_mldsa_json_test.go b/u_mldsa_json_test.go index a660e89eca..658454d561 100644 --- a/u_mldsa_json_test.go +++ b/u_mldsa_json_test.go @@ -3,7 +3,7 @@ package tls import ( "encoding/json" "fmt" - "slices" + "reflect" "testing" "github.com/metacubex/utls/dicttls" @@ -46,7 +46,7 @@ func TestMLDSASignatureSchemeJSON(t *testing.T) { t.Fatalf("unexpected extension type %T", ext) } want := []SignatureScheme{GREASE_PLACEHOLDER, MLDSA44, MLDSA65, MLDSA87} - if !slices.Equal(got, want) { + if !reflect.DeepEqual(got, want) { t.Fatalf("signature algorithms = %x, want %x", got, want) } })