From 2ee840091dea6faf347b4b25ec0cdc6a0e86bab4 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Thu, 4 Jul 2024 09:51:19 +0300 Subject: [PATCH] PMM-12857 fix auth_test --- api-tests/helpers.go | 3 ++- api-tests/server/auth_test.go | 6 +++--- api-tests/server/serialization_test.go | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api-tests/helpers.go b/api-tests/helpers.go index 29b783c5fb4..45e8b52c14d 100644 --- a/api-tests/helpers.go +++ b/api-tests/helpers.go @@ -22,6 +22,7 @@ import ( "math" "math/big" "reflect" + "strings" "testing" "github.com/AlekSi/pointer" @@ -58,7 +59,7 @@ func TestString(t TestingT, name string) string { n, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt32)) require.NoError(t, err) - return fmt.Sprintf("pmm-api-tests/%s/%s/%s/%d", Hostname, t.Name(), name, n) + return strings.ReplaceAll(fmt.Sprintf("pmm-api-tests-%s-%s-%s-%d", Hostname, t.Name(), name, n), "/", "-") } // AssertAPIErrorf check that actual API error equals expected. diff --git a/api-tests/server/auth_test.go b/api-tests/server/auth_test.go index b43746a93df..507467fb08b 100644 --- a/api-tests/server/auth_test.go +++ b/api-tests/server/auth_test.go @@ -485,17 +485,17 @@ func TestServiceAccountPermissions(t *testing.T) { method string userCase []userCase }{ - {name: "settings", url: "/v1/Settings/Get", method: "POST", userCase: []userCase{ + {name: "settings", url: "/v1/server/settings", method: "GET", userCase: []userCase{ {userType: "default", statusCode: 401}, {userType: "viewer", serviceToken: viewerToken, statusCode: 401}, {userType: "editor", serviceToken: editorToken, statusCode: 401}, {userType: "admin", serviceToken: adminToken, statusCode: 200}, }}, - {name: "platform-connect", url: "/v1/Platform/Connect", method: "POST", userCase: []userCase{ + {name: "platform-connect", url: "/v1/platform:connect", method: "POST", userCase: []userCase{ {userType: "default", statusCode: 401}, {userType: "viewer", serviceToken: viewerToken, statusCode: 401}, {userType: "editor", serviceToken: editorToken, statusCode: 401}, - {userType: "admin", serviceToken: adminToken, statusCode: 400}, // We send bad request, but have access to endpoint + {userType: "admin", serviceToken: adminToken, statusCode: 400}, // We are sending a bad request, but we still have access to the endpoint }}, } diff --git a/api-tests/server/serialization_test.go b/api-tests/server/serialization_test.go index 6d5999c68a9..9239165e680 100644 --- a/api-tests/server/serialization_test.go +++ b/api-tests/server/serialization_test.go @@ -28,13 +28,13 @@ import ( "github.com/stretchr/testify/require" pmmapitests "github.com/percona/pmm/api-tests" - "github.com/percona/pmm/api/server/v1/json/client/server_service" + server "github.com/percona/pmm/api/server/v1/json/client/server_service" ) // This test checks if all (even empty) fields are present in json responses. func TestSerialization(t *testing.T) { // Get json filed names from settings model - var settings server_service.GetSettingsOKBodySettings + var settings server.GetSettingsOKBodySettings jsonFields := extractJSONTagNames(settings) require.NotEmpty(t, jsonFields) @@ -57,7 +57,7 @@ func TestSerialization(t *testing.T) { err = json.Unmarshal(b, &data) require.NoError(t, err) - // Check if all expected fields present in the json response. + // Check if all expected fields are present in the json response. for _, field := range jsonFields { assert.Contains(t, data["settings"], field) }