This repository was archived by the owner on Aug 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
SAAS-175 Add tests for auth API #116
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
542d75e
SAAS-175 Add permission tests for auth API
artemgavrilov 07105e0
SAAS-175 Add auth API tests
artemgavrilov 52336e2
SAAS-175 Fix test
artemgavrilov 2996279
SAAS-175 Mute linter
artemgavrilov 073a2fd
SAAS-175 Set dev auth host
artemgavrilov 1987f45
SAAS-175 Update pmm dependency, fix tests
artemgavrilov 1d0d6a6
SAAS-175 Generate passwords in tests
artemgavrilov 48ce80e
SAAS-175 Add coment
artemgavrilov 53f7a2f
SAAS-175 Fix typo
artemgavrilov 05c40c2
SAAS-175 Add context to request
artemgavrilov 3545851
SAAS-175 Move seeding into a single place
AlekSi 71c890f
SAAS-174 SAAS-175 Update pmm dependecny
artemgavrilov 637505e
SAAS-174 SAAS-175 More detailed platform API tests
artemgavrilov e7ec9b9
SAAS-174 Update pmm dependency
artemgavrilov e4efc6c
SAAS-174 Remove password reset tests
artemgavrilov d4a78e0
SAAS-175 Update pmm dependency
artemgavrilov 6a22021
SAAS-175 Remove password reset permission test
artemgavrilov e939217
Merge branch 'master' into SAAS-175-auth-api
artemgavrilov 2a1c9e5
SAAS-175 Update API branch
AlekSi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/brianvoe/gofakeit" | ||
| serverClient "github.com/percona/pmm/api/serverpb/json/client" | ||
| "github.com/percona/pmm/api/serverpb/json/client/server" | ||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/grpc/codes" | ||
|
|
||
| pmmapitests "github.com/Percona-Lab/pmm-api-tests" | ||
| ) | ||
|
|
||
| // Tests in this file cover Percona Platform authentication. | ||
|
|
||
| func TestPlatform(t *testing.T) { | ||
artemgavrilov marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci-lint] reported by reviewdog 🐶 |
||
| client := serverClient.Default.Server | ||
|
|
||
| t.Run("signUp", func(t *testing.T) { | ||
| t.Run("normal", func(t *testing.T) { | ||
| _, err := client.PlatformSignUp(&server.PlatformSignUpParams{ | ||
| Body: server.PlatformSignUpBody{ | ||
| Email: gofakeit.Email(), | ||
| Password: gofakeit.Password(true, true, true, false, false, 14), | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| t.Run("invalid email", func(t *testing.T) { | ||
| _, err := client.PlatformSignUp(&server.PlatformSignUpParams{ | ||
| Body: server.PlatformSignUpBody{ | ||
| Email: "not-email", | ||
| Password: gofakeit.Password(true, true, true, false, false, 14), | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "Error Creating Your Account.") | ||
| }) | ||
|
|
||
| t.Run("invalid password", func(t *testing.T) { | ||
| _, err := client.PlatformSignUp(&server.PlatformSignUpParams{ | ||
| Body: server.PlatformSignUpBody{ | ||
| Email: gofakeit.Email(), | ||
| Password: "weak-pass", | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "Error Creating Your Account.") | ||
| }) | ||
|
|
||
| t.Run("empty email", func(t *testing.T) { | ||
| _, err := client.PlatformSignUp(&server.PlatformSignUpParams{ | ||
| Body: server.PlatformSignUpBody{ | ||
| Email: "", | ||
| Password: gofakeit.Password(true, true, true, false, false, 14), | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid field Email: value '' must not be an empty string") | ||
| }) | ||
|
|
||
| t.Run("empty password", func(t *testing.T) { | ||
| _, err := client.PlatformSignUp(&server.PlatformSignUpParams{ | ||
| Body: server.PlatformSignUpBody{ | ||
| Email: gofakeit.Email(), | ||
| Password: "", | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid field Password: value '' must not be an empty string") | ||
| }) | ||
| }) | ||
|
|
||
| t.Run("signIn", func(t *testing.T) { | ||
| email := gofakeit.Email() | ||
| password := gofakeit.Password(true, true, true, false, false, 14) | ||
|
|
||
| _, err := client.PlatformSignUp(&server.PlatformSignUpParams{ | ||
| Body: server.PlatformSignUpBody{ | ||
| Email: email, | ||
| Password: password, | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| t.Run("normal", func(t *testing.T) { | ||
| _, err = client.PlatformSignIn(&server.PlatformSignInParams{ | ||
| Body: server.PlatformSignInBody{ | ||
| Email: email, | ||
| Password: password, | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| t.Run("wrong email", func(t *testing.T) { | ||
| _, err = client.PlatformSignIn(&server.PlatformSignInParams{ | ||
| Body: server.PlatformSignInBody{ | ||
| Email: "wrong@example.com", | ||
| Password: password, | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "Incorrect username or password.") | ||
| }) | ||
|
|
||
| t.Run("wrong password", func(t *testing.T) { | ||
| _, err = client.PlatformSignIn(&server.PlatformSignInParams{ | ||
| Body: server.PlatformSignInBody{ | ||
| Email: email, | ||
| Password: "WrongPassword12345", | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "Incorrect username or password.") | ||
| }) | ||
|
|
||
| t.Run("empty email", func(t *testing.T) { | ||
| _, err = client.PlatformSignIn(&server.PlatformSignInParams{ | ||
| Body: server.PlatformSignInBody{ | ||
| Email: "", | ||
| Password: password, | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid field Email: value '' must not be an empty string") | ||
| }) | ||
|
|
||
| t.Run("empty password", func(t *testing.T) { | ||
| _, err = client.PlatformSignIn(&server.PlatformSignInParams{ | ||
| Body: server.PlatformSignInBody{ | ||
| Email: email, | ||
| Password: "", | ||
| }, | ||
| Context: pmmapitests.Context, | ||
| }) | ||
| pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid field Password: value '' must not be an empty string") | ||
| }) | ||
| }) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golangci-lint] reported by reviewdog 🐶
Function 'TestPermissions' is too long (80 > 60) (funlen)