From 2e4fc0bbd9aba4060f8c519b706b5bec57a9b2a0 Mon Sep 17 00:00:00 2001 From: Elena Kolevska Date: Mon, 2 Dec 2024 18:11:39 +0000 Subject: [PATCH] Fixes state cert tests (#3596) Signed-off-by: Elena Kolevska --- .../infrastructure/docker-compose-sqlserver.yml | 2 +- .../state/azure/cosmosdb/cosmosdb_test.go | 12 ++++-------- .../state/memcached/memcached_test.go | 7 ++++--- .../state/sqlserver/sqlserver_test.go | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/infrastructure/docker-compose-sqlserver.yml b/.github/infrastructure/docker-compose-sqlserver.yml index f878ba221e..7d289d6fef 100644 --- a/.github/infrastructure/docker-compose-sqlserver.yml +++ b/.github/infrastructure/docker-compose-sqlserver.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' services: sqlserver: image: mcr.microsoft.com/mssql/server:2019-latest diff --git a/tests/certification/state/azure/cosmosdb/cosmosdb_test.go b/tests/certification/state/azure/cosmosdb/cosmosdb_test.go index b29396117d..81cb1a097c 100644 --- a/tests/certification/state/azure/cosmosdb/cosmosdb_test.go +++ b/tests/certification/state/azure/cosmosdb/cosmosdb_test.go @@ -133,17 +133,13 @@ func TestAzureCosmosDBStorage(t *testing.T) { "partitionKey": "mypartition", } - test := func(setMeta, getMeta map[string]string, expectedValue string, expectedErr bool) { + test := func(setMeta, getMeta map[string]string, expectedValue string) { // save state, default options: strong, last-write err = client.SaveState(ctx, statestore, stateKey, []byte(stateValue), setMeta) require.NoError(t, err) // get state item, err := client.GetState(ctx, statestore, stateKey, getMeta) - if expectedErr { - require.Error(t, err) - return - } require.NoError(t, err) assert.Equal(t, expectedValue, string(item.Value)) @@ -153,13 +149,13 @@ func TestAzureCosmosDBStorage(t *testing.T) { } // Test with no partition key - test(nil, meta1, stateValue, false) + test(nil, meta1, stateValue) // Test with specific partition key - test(meta2, meta2, stateValue, false) + test(meta2, meta2, stateValue) // Test with incorrect partition key - test(meta2, meta1, "", true) + test(meta2, meta1, "") return nil } diff --git a/tests/certification/state/memcached/memcached_test.go b/tests/certification/state/memcached/memcached_test.go index 955c090eea..c8058a26dc 100644 --- a/tests/certification/state/memcached/memcached_test.go +++ b/tests/certification/state/memcached/memcached_test.go @@ -22,6 +22,9 @@ import ( "github.com/dapr/components-contrib/state" "github.com/dapr/go-sdk/client" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + state_memcached "github.com/dapr/components-contrib/state/memcached" "github.com/dapr/components-contrib/tests/certification/embedded" "github.com/dapr/components-contrib/tests/certification/flow" @@ -31,8 +34,6 @@ import ( state_loader "github.com/dapr/dapr/pkg/components/state" dapr_testing "github.com/dapr/dapr/pkg/testing" "github.com/dapr/kit/logger" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const ( @@ -168,7 +169,7 @@ func TestMemcached(t *testing.T) { key := certificationTestPrefix + "_expiresInOneSecondKey" value := "This key will self-destroy in 1 second" - ttlExpirationTime := 1 * time.Second + ttlExpirationTime := 3 * time.Second ttlInSeconds := int(ttlExpirationTime.Seconds()) mapOptionsExpiringKey := map[string]string{ "ttlInSeconds": strconv.Itoa(ttlInSeconds), diff --git a/tests/certification/state/sqlserver/sqlserver_test.go b/tests/certification/state/sqlserver/sqlserver_test.go index 9dbd79a6e1..b1ac0cc15c 100644 --- a/tests/certification/state/sqlserver/sqlserver_test.go +++ b/tests/certification/state/sqlserver/sqlserver_test.go @@ -60,6 +60,20 @@ const ( ) func TestSqlServer(t *testing.T) { + // The default certificate created by the docker container sometimes contains a negative serial number. + // A TLS certificate with a negative serial number is invalid, although it was tolerated until 1.22 + // Since Go 1.23 the default behavior has changed and the certificate is rejected. + // This environment variable is used to revert to the old behavior. + // Ref: https://github.com/microsoft/mssql-docker/issues/895 + oldDebugValue := os.Getenv("GODEBUG") + err := os.Setenv("GODEBUG", "x509negativeserial=1") + if err != nil { + t.Fatalf("Failed to set GODEBUG environment variable: %v", err) + } + defer func() { + os.Setenv("GODEBUG", oldDebugValue) + }() + ports, err := dapr_testing.GetFreePorts(2) require.NoError(t, err)