Skip to content

Commit

Permalink
PMM-12857 fix auth_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Jul 4, 2024
1 parent 3b18aa8 commit ed517a5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion api-tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math"
"math/big"
"reflect"
"strings"
"testing"

"github.com/AlekSi/pointer"
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions api-tests/server/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}},
}

Expand Down
2 changes: 1 addition & 1 deletion api-tests/server/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestPlatform(t *testing.T) {
},
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, http.StatusBadRequest, codes.InvalidArgument, "invalid field ConnectRequest.ServerName: value '' must not be an empty string")
pmmapitests.AssertAPIErrorf(t, err, http.StatusBadRequest, codes.InvalidArgument, "invalid ConnectRequest.ServerName: value length must be at least 1 runes")
})

t.Run("successful connect and disconnect", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions api-tests/server/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
Expand Down

0 comments on commit ed517a5

Please sign in to comment.