From 684ef8da7ab4ddc7b0d236fe5e6ce9aa5344c760 Mon Sep 17 00:00:00 2001 From: Anders Eknert Date: Thu, 20 Feb 2025 18:34:51 +0100 Subject: [PATCH] Fix test failures with Go 1.24 (#7376) CI build will have to determine whether they also work in Go 1.23 :) Signed-off-by: Anders Eknert --- internal/prometheus/prometheus_test.go | 13 +++++++++---- v1/plugins/rest/aws_test.go | 16 ++++++++-------- v1/topdown/crypto_test.go | 2 +- v1/topdown/tokens_test.go | 10 +++++++++- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/internal/prometheus/prometheus_test.go b/internal/prometheus/prometheus_test.go index ba301af4a4..d3233b61f9 100644 --- a/internal/prometheus/prometheus_test.go +++ b/internal/prometheus/prometheus_test.go @@ -2,9 +2,9 @@ // Use of this source code is governed by an Apache2 // license that can be found in the LICENSE file. // -// NOTE(sr): Different go runtime metrics on 1.20 vs 1.22. -// Let's only test these on 1.22. -//go:build go1.22 +// NOTE: Different go runtime metrics in pretty much +// every Go version. Let's only test these on latest. +//go:build go1.24 package prometheus @@ -131,7 +131,7 @@ func TestJSONSerialization(t *testing.T) { "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total", - "go_godebug_non_default_behavior_x509sha1_events_total", + // "go_godebug_non_default_behavior_x509sha1_events_total", // removed in 1.24 "go_godebug_non_default_behavior_x509usefallbackroots_events_total", "go_godebug_non_default_behavior_zipinsecurepath_events_total", "go_godebug_non_default_behavior_tlsmaxrsasize_events_total", @@ -150,6 +150,11 @@ func TestJSONSerialization(t *testing.T) { "go_godebug_non_default_behavior_asynctimerchan_events_total", "go_godebug_non_default_behavior_httpservecontentkeepheaders_events_total", "go_godebug_non_default_behavior_tls3des_events_total", + + "go_godebug_non_default_behavior_randseednop_events_total", + "go_godebug_non_default_behavior_x509rsacrt_events_total", + "go_godebug_non_default_behavior_gotestjsonbuildtext_events_total", + "go_godebug_non_default_behavior_rsa1024min_events_total", }, "SUMMARY": { "go_gc_duration_seconds", diff --git a/v1/plugins/rest/aws_test.go b/v1/plugins/rest/aws_test.go index 57178dce27..0c78e48ec5 100644 --- a/v1/plugins/rest/aws_test.go +++ b/v1/plugins/rest/aws_test.go @@ -629,14 +629,14 @@ func TestV4Signing(t *testing.T) { { sigVersion: "4a", expectedAuthorization: []string{ + // this signature is for go 1.24+ + "AWS4-ECDSA-P256-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20190424/s3/aws4_request, " + + "SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-security-token, " + + "Signature=3045022100ed23c88c8f952c049237b023994df067b51e05c9f9cf22b26a5d662e150e2d6c02205910f19c142e9b26fe9abb63a54f35ade8cdcad993297aef3931bce6a3d93003", // this signature is for go 1.20+, which changed crypto/ecdsa so signatures differ from go 1.18 "AWS4-ECDSA-P256-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20190424/s3/aws4_request, " + "SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-security-token, " + "Signature=3045022031b9dd601cd02650193586a32721d0614bf2e34bbc76cff0d9812366d1dc8878022100d0cfbd91bd2dd98f1e2d7feb9091c48f8b66a20174922770ec9e3b74db8e1826", - // this signature is for go 1.18+. Remove this and only test for a single value when OPA drops go 1.19 - "AWS4-ECDSA-P256-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20190424/s3/aws4_request, " + - "SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-security-token, " + - "Signature=304402207d1bcb6fb68d85be3e9f6948a8dc8596a531b3f5a82ca2350acabe98941312bc02207d81ed07c7356226d93611820548a806c8e1f0cc72ff41ba672d23901e5a06bf", }, }, } @@ -832,10 +832,10 @@ func TestV4SigningOmitsIgnoredHeaders(t *testing.T) { "AWS4-ECDSA-P256-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20190424/execute-api/aws4_request, " + "SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-security-token, " + "Signature=3045022100e62b33949d5d5666c1cc737db6673600d7893b977df48e4eb64a6e8747582a2f022011f56ad285472956a3e00c6971d03ebd8ecb579804d8fd91a6fb483a1f502118", - // this signature is for go 1.18+. Remove this and only test for a single value when OPA drops go 1.19 + // this signature is for go 1.24+ "AWS4-ECDSA-P256-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20190424/execute-api/aws4_request, " + "SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-security-token, " + - "Signature=30450221009f3b0cda178456dfd1bec61b78bdbd115c0cf497eaa52c58bbb2850ad9c49c3002207009cb88a1219a4a6626056c31823a6b5bc2728bc88bc98a06e12e1148482c94", + "Signature=304402203ed4a726081286801d80dae4967a2fb1f5b9487b9ce16e8334e405be549e310a022043a425ab44fd79762e9ca75a8c390fc88685073f268fd244448bc3f464aa082f", }, }, } @@ -997,10 +997,10 @@ func TestV4SigningWithMultiValueHeaders(t *testing.T) { "AWS4-ECDSA-P256-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20190424/execute-api/aws4_request, " + "SignedHeaders=accept;content-length;host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-security-token, " + "Signature=3046022100f7fd07e2a00b1be3074be0c2e3871bd42ddc4c01549b1ffc4809ef3fafde80780221008c6bf906cdb9040ebeb94d1134598e7920fa8cb7bda91b00ce0ab9838b79631b", - // this signature is for go 1.18+. Remove this and only test for a single value when OPA drops go 1.19 + // this signature is for go 1.24+ "AWS4-ECDSA-P256-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20190424/execute-api/aws4_request, " + "SignedHeaders=accept;content-length;host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-security-token, " + - "Signature=304402202d5f2d4d42fe59b2e61fa455cb35a335139d109c2d37aaa8946d45fd0fb4989c022068238cbfbc80326f5cc391f2b6837910191ceabb58ec0bf986c0141f76046594", + "Signature=3045022100d53765da79a23a5d20129640f9c4c2b51d100430039941f5d28a038287b2c772022039889ff47cc54e4285c8761933edbaaf6314454d49b3f7dd4dd2a2265905d499", }, }, } diff --git a/v1/topdown/crypto_test.go b/v1/topdown/crypto_test.go index ecbb259534..748d1f0899 100644 --- a/v1/topdown/crypto_test.go +++ b/v1/topdown/crypto_test.go @@ -853,7 +853,7 @@ func TestExtractX509VerifyOptions(t *testing.T) { if !cmp.Equal(vo, testCase.expectVerifyOpt, cmpopts.SortSlices( func(ku1, ku2 x509.ExtKeyUsage) bool { return ku1 < ku2 - })) { + }), cmpopts.IgnoreUnexported(x509.VerifyOptions{})) { t.Fatalf("expected x509.VerifyOptions: %+v \n"+ "got: %+v", testCase.expectVerifyOpt, vo) diff --git a/v1/topdown/tokens_test.go b/v1/topdown/tokens_test.go index bbbca0599f..2c37ee21d2 100644 --- a/v1/topdown/tokens_test.go +++ b/v1/topdown/tokens_test.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "os" + "runtime" "strings" "testing" "time" @@ -491,7 +492,14 @@ func TestTopdownJWTEncodeSignECWithSeedReturnsSameSignature(t *testing.T) { "d":"jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI" }, x)` - encodedSigned := "eyJhbGciOiJFUzI1NiJ9.eyJwYXkiOiJsb2FkIn0.wDU6G2XTYFP3QdVYhy-PBzkacEFNJwVT4HPQHOLtUmJu-OcVUaX9n-Ukv50AJwoF59L2wS5aOzoUwuru48Q4tw" + // NOTE(ae): the signature differs between Go 1.23 and 1.24, as the latter uses the rand/v2 package (or that's my take) + var encodedSigned string + if runtime.Version() < "go1.24" { + encodedSigned = "eyJhbGciOiJFUzI1NiJ9.eyJwYXkiOiJsb2FkIn0.wDU6G2XTYFP3QdVYhy-PBzkacEFNJwVT4HPQHOLtUmJu-OcVUaX9n-Ukv50AJwoF59L2wS5aOzoUwuru48Q4tw" + } else { + encodedSigned = "eyJhbGciOiJFUzI1NiJ9.eyJwYXkiOiJsb2FkIn0.WAh1ydGVRdVwXNQ9i71LqUJSrs3WVDZENdN58jCkecC2oCXEnqcviaADIwcZbYmns5IfHNV1Euo6vBm75o5l9A" + } + for range 10 { q := NewQuery(ast.MustParseBody(query)). WithSeed(&cng{}).