MSP-8974 fix tests
This commit is contained in:
1 parent
9aeb791c53
commit
82a5de3782
50 files changed
+365
-2965
No files matched your search
+30
-31
@@ -18,16 +18,15 @@ import (
|
||||
|
||||
"github.com/txix-open/isp-kit/errors"
|
||||
"github.com/txix-open/isp-kit/test/fake"
|
||||
"github.com/txix-open/isp-kit/test/httpt"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/http/httpcli"
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
"github.com/txix-open/isp-kit/test/grpct"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -42,7 +41,7 @@ type AuthTestSuite struct {
|
||||
|
||||
test *test.Test
|
||||
db *dbt.TestDb
|
||||
grpcCli *client.Client
|
||||
httpCli *httpcli.Client
|
||||
oauthCli *httpcli.Client
|
||||
oauthClientName string
|
||||
}
|
||||
@@ -77,15 +76,15 @@ func (s *AuthTestSuite) SetupTest() {
|
||||
},
|
||||
}
|
||||
|
||||
cfg, err := assembly.NewLocator(testInstance.Logger(), s.oauthCli, s.db).
|
||||
cfg, err := assembly.NewLocator(testInstance.Logger(), s.oauthCli, httpcli.New(), s.db).
|
||||
Config(s.T().Context(), remote, time.Minute)
|
||||
s.Require().NoError(err)
|
||||
|
||||
server, apiCli := grpct.TestServer(testInstance, cfg.Handler)
|
||||
s.grpcCli = apiCli
|
||||
server, cli := httpt.TestServer(s.test, cfg.Handler)
|
||||
s.httpCli = cli
|
||||
|
||||
testInstance.T().Cleanup(func() {
|
||||
server.Shutdown()
|
||||
server.Close()
|
||||
mocksrv.Close()
|
||||
})
|
||||
}
|
||||
@@ -99,13 +98,13 @@ func (s *AuthTestSuite) TestLoginHappyPath() {
|
||||
})
|
||||
|
||||
response := domain.LoginResponse{}
|
||||
err := s.grpcCli.Invoke("admin/auth/login").
|
||||
err := s.httpCli.Post("admin/auth/login").
|
||||
JsonRequestBody(domain.LoginRequest{
|
||||
Email: "a@a.ru",
|
||||
Password: "password",
|
||||
}).
|
||||
JsonResponseBody(&response).
|
||||
Do(s.T().Context())
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
tokenInfo := SelectTokenEntityByToken(s.db, response.Token)
|
||||
@@ -115,12 +114,12 @@ func (s *AuthTestSuite) TestLoginHappyPath() {
|
||||
}
|
||||
|
||||
func (s *AuthTestSuite) TestLoginNotFound() {
|
||||
err := s.grpcCli.Invoke("admin/auth/login").
|
||||
err := s.httpCli.Post("admin/auth/login").
|
||||
JsonRequestBody(domain.LoginRequest{
|
||||
Email: "a1@a.ru",
|
||||
Password: "password",
|
||||
}).
|
||||
Do(s.T().Context())
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().Error(err)
|
||||
st, ok := status.FromError(err)
|
||||
s.Require().True(ok)
|
||||
@@ -138,12 +137,12 @@ func (s *AuthTestSuite) TestBlockedUser() {
|
||||
Blocked: true,
|
||||
})
|
||||
|
||||
err := s.grpcCli.Invoke("admin/auth/login").
|
||||
err := s.httpCli.Post("admin/auth/login").
|
||||
JsonRequestBody(domain.LoginRequest{
|
||||
Email: "a@a.ru",
|
||||
Password: "password",
|
||||
}).
|
||||
Do(s.T().Context())
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().Error(err)
|
||||
st, ok := status.FromError(err)
|
||||
s.Require().True(ok)
|
||||
@@ -160,12 +159,12 @@ func (s *AuthTestSuite) TestLoginWrongPassword() {
|
||||
Password: "password",
|
||||
})
|
||||
|
||||
err := s.grpcCli.Invoke("admin/auth/login").
|
||||
err := s.httpCli.Post("admin/auth/login").
|
||||
JsonRequestBody(domain.LoginRequest{
|
||||
Email: "a@a.ru",
|
||||
Password: "WrongPassword",
|
||||
}).
|
||||
Do(s.T().Context())
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().Error(err)
|
||||
st, ok := status.FromError(err)
|
||||
s.Require().True(ok)
|
||||
@@ -177,13 +176,13 @@ func (s *AuthTestSuite) TestLoginWrongPassword() {
|
||||
func (s *AuthTestSuite) TestOauthLoginHappyPath() {
|
||||
response := domain.LoginResponse{}
|
||||
|
||||
err := s.grpcCli.Invoke("admin/auth/login_with_oauth").
|
||||
err := s.httpCli.Post("admin/auth/login_with_oauth").
|
||||
JsonRequestBody(domain.LoginOauthRequest{
|
||||
AuthCode: "code",
|
||||
ClientName: s.oauthClientName,
|
||||
}).
|
||||
JsonResponseBody(&response).
|
||||
Do(s.T().Context())
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
user := entity.User{}
|
||||
s.db.Must().SelectRow(&user, "select id, email, full_name from users where oauth_user_id = $1", "oauthUser1")
|
||||
@@ -199,13 +198,13 @@ func (s *AuthTestSuite) TestOauthLoginHappyPath() {
|
||||
func (s *AuthTestSuite) TestOauthLogin_UnknownClient() {
|
||||
response := domain.LoginResponse{}
|
||||
|
||||
err := s.grpcCli.Invoke("admin/auth/login_with_oauth").
|
||||
err := s.httpCli.Post("admin/auth/login_with_oauth").
|
||||
JsonRequestBody(domain.LoginOauthRequest{
|
||||
AuthCode: "code",
|
||||
ClientName: s.oauthClientName + fake.It[string](),
|
||||
}).
|
||||
JsonResponseBody(&response).
|
||||
Do(s.T().Context())
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().Error(err)
|
||||
st, ok := status.FromError(err)
|
||||
s.Require().True(ok)
|
||||
@@ -221,9 +220,9 @@ func (s *AuthTestSuite) Test_Logout_HappyPath() {
|
||||
CreatedAt: time.Time{},
|
||||
ExpiredAt: time.Time{},
|
||||
})
|
||||
err := s.grpcCli.Invoke("admin/auth/logout").
|
||||
AppendMetadata(domain.AdminAuthIdHeader, strconv.Itoa(int(userId))).
|
||||
Do(s.T().Context())
|
||||
err := s.httpCli.Post("admin/auth/logout").
|
||||
Header(domain.AdminAuthIdHeader, strconv.Itoa(int(userId))).
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
tokenInfo := SelectTokenEntityByToken(s.db, "token-841297641213")
|
||||
@@ -233,15 +232,15 @@ func (s *AuthTestSuite) Test_Logout_HappyPath() {
|
||||
}
|
||||
|
||||
func (s *AuthTestSuite) Test_Logout_NotFound() {
|
||||
err := s.grpcCli.Invoke("admin/auth/logout").
|
||||
AppendMetadata(domain.AdminAuthIdHeader, "0143218411981").
|
||||
Do(s.T().Context())
|
||||
err := s.httpCli.Post("admin/auth/logout").
|
||||
Header(domain.AdminAuthIdHeader, "0143218411981").
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
time.Sleep(time.Second)
|
||||
audit := repository.NewAudit(s.db)
|
||||
auditList, err := audit.AllByRequest(s.T().Context(), domain.AuditPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffsetParams: domain.LimitOffsetParams{
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
},
|
||||
@@ -266,9 +265,9 @@ func (s *AuthTestSuite) Test_Logout_AlreadyRevoke() {
|
||||
CreatedAt: time.Time{},
|
||||
ExpiredAt: time.Time{},
|
||||
})
|
||||
err := s.grpcCli.Invoke("admin/auth/logout").
|
||||
AppendMetadata(domain.AdminAuthIdHeader, strconv.Itoa(int(userId))).
|
||||
Do(s.T().Context())
|
||||
err := s.httpCli.Post("admin/auth/logout").
|
||||
Header(domain.AdminAuthIdHeader, strconv.Itoa(int(userId))).
|
||||
DoWithoutResponse(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
tokenInfo := SelectTokenEntityByToken(s.db, "token-148623719462")
|
||||
@@ -292,13 +291,13 @@ func (s *AuthTestSuite) TestBruteForceLogin() {
|
||||
group.Go(func() error {
|
||||
start := time.Now()
|
||||
response := domain.LoginResponse{}
|
||||
err := s.grpcCli.Invoke("admin/auth/login").
|
||||
err := s.httpCli.Post("admin/auth/login").
|
||||
JsonRequestBody(domain.LoginRequest{
|
||||
Email: "a@a.ru",
|
||||
Password: fmt.Sprintf("password %s", strconv.Itoa(index)),
|
||||
}).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
DoWithoutResponse(ctx)
|
||||
s.Require().Error(err)
|
||||
|
||||
switch status.Code(err) { // nolint:exhaustive
|
||||
|
||||
Reference in new issue
Block a user