2024-06-20 10:45:03: merge [main:e4755abdc84b002eec3c2871d1161ea669541291];

This commit is contained in:
txix committed 2024-06-20 10:45:03 +03:00
1 parent ed8a4eef5d
commit 17747f5b74
55 files changed
+715 -756

No files matched your search

+10 -10
View File
@@ -4,13 +4,13 @@ import (
"context"
"testing"
"github.com/integration-system/isp-kit/dbx"
"github.com/integration-system/isp-kit/grpc/client"
"github.com/integration-system/isp-kit/http/httpcli"
"github.com/integration-system/isp-kit/test"
"github.com/integration-system/isp-kit/test/dbt"
"github.com/integration-system/isp-kit/test/grpct"
"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/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"
"msp-admin-service/assembly"
@@ -35,7 +35,7 @@ type AuditSuite struct {
func (t *AuditSuite) SetupTest() {
testInstance, _ := test.New(t.T())
t.test = testInstance
t.db = dbt.New(testInstance, dbx.WithMigration("../migrations"))
t.db = dbt.New(testInstance, dbx.WithMigrationRunner("../migrations", testInstance.Logger()))
remote := conf.Remote{
Audit: conf.Audit{
@@ -96,7 +96,7 @@ func (t *AuditSuite) Test_Events_DefaultEvents() {
t.Require().Equal(name, event.Name)
delete(expectedEventList, event.Event)
}
t.Require().Equal(0, len(expectedEventList))
t.Require().Empty(expectedEventList)
}
func (t *AuditSuite) Test_Events_SortEvents() {
@@ -110,7 +110,7 @@ func (t *AuditSuite) Test_Events_SortEvents() {
{Event: entity.EventUserChanged, Enable: true},
{Event: "новый#2", Enable: false},
})
t.NoError(err)
t.Require().NoError(err)
response := make([]domain.AuditEvent, 0)
err = t.grpcCli.
@@ -154,7 +154,7 @@ func (t *AuditSuite) Test_SetEvents_HappyPath() {
t.Require().Equal(enable, event.Enable)
delete(expectedEventList, event.Event)
}
t.Require().Equal(0, len(expectedEventList))
t.Require().Empty(expectedEventList)
}
func (t *AuditSuite) Test_SetEvents_InvalidEvent() {
+12 -13
View File
@@ -18,14 +18,14 @@ import (
"msp-admin-service/entity"
"msp-admin-service/repository"
"github.com/integration-system/isp-kit/dbx"
"github.com/integration-system/isp-kit/grpc/client"
"github.com/integration-system/isp-kit/http/httpcli"
"github.com/integration-system/isp-kit/json"
"github.com/integration-system/isp-kit/test"
"github.com/integration-system/isp-kit/test/dbt"
"github.com/integration-system/isp-kit/test/grpct"
"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"
)
@@ -46,7 +46,7 @@ type AuthTestSuite struct {
func (s *AuthTestSuite) SetupTest() {
testInstance, _ := test.New(s.T())
s.test = testInstance
s.db = dbt.New(testInstance, dbx.WithMigration("../migrations"))
s.db = dbt.New(testInstance, dbx.WithMigrationRunner("../migrations", testInstance.Logger()))
s.httpCli = httpcli.New()
mocksrv, host := s.initMockSudir()
@@ -181,7 +181,7 @@ func (s *AuthTestSuite) initMockSudir() (*httptest.Server, string) {
data, err := json.Marshal(res)
s.Require().NoError(err)
_, err = writer.Write(data)
s.Require().NoError(err)
s.NoError(err)
})
mux.HandleFunc("/blitz/oauth/me", func(writer http.ResponseWriter, request *http.Request) {
res := entity.SudirUserResponse{
@@ -195,7 +195,7 @@ func (s *AuthTestSuite) initMockSudir() (*httptest.Server, string) {
data, err := json.Marshal(res)
s.Require().NoError(err)
_, err = writer.Write(data)
s.Require().NoError(err)
s.NoError(err)
})
srv := httptest.NewServer(mux)
return srv, srv.URL
@@ -229,7 +229,7 @@ func (s *AuthTestSuite) Test_Logout_NotFound() {
audit := repository.NewAudit(s.db)
auditList, err := audit.All(context.Background(), 10, 0)
s.Require().NoError(err)
s.Require().Equal(1, len(auditList))
s.Require().Len(auditList, 1) //nolint:mnd
s.Require().Equal(entity.EventSuccessLogout, auditList[0].Event)
}
@@ -262,8 +262,7 @@ func (s *AuthTestSuite) TestBruteForceLogin() {
tooManyRequestsErrorCount := &atomic.Int32{}
unauthorizedErrorCount := &atomic.Int32{}
group, ctx := errgroup.WithContext(context.Background())
for i := 0; i < 100; i++ {
index := i
for index := range 100 {
group.Go(func() error {
start := time.Now()
response := domain.LoginResponse{}
+6 -6
View File
@@ -4,12 +4,12 @@ import (
"context"
"testing"
"github.com/integration-system/isp-kit/dbx"
"github.com/integration-system/isp-kit/grpc/client"
"github.com/integration-system/isp-kit/test"
"github.com/integration-system/isp-kit/test/dbt"
"github.com/integration-system/isp-kit/test/grpct"
"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/test"
"github.com/txix-open/isp-kit/test/dbt"
"github.com/txix-open/isp-kit/test/grpct"
"msp-admin-service/assembly"
"msp-admin-service/conf"
)
@@ -29,7 +29,7 @@ type CustomizationTestSuite struct {
func (s *CustomizationTestSuite) SetupTest() {
testInstance, _ := test.New(s.T())
s.test = testInstance
s.db = dbt.New(testInstance, dbx.WithMigration("../migrations"))
s.db = dbt.New(testInstance, dbx.WithMigrationRunner("../migrations", testInstance.Logger()))
remote := conf.Remote{
UiDesign: conf.UIDesign{
+2 -2
View File
@@ -1,9 +1,9 @@
package tests_test
import (
"github.com/integration-system/isp-kit/db/query"
"github.com/integration-system/isp-kit/test/dbt"
"github.com/pkg/errors"
"github.com/txix-open/isp-kit/db/query"
"github.com/txix-open/isp-kit/test/dbt"
"golang.org/x/crypto/bcrypt"
"msp-admin-service/entity"
)
+5 -5
View File
@@ -5,10 +5,10 @@ import (
"testing"
"time"
"github.com/integration-system/isp-kit/bgjobx"
"github.com/integration-system/isp-kit/dbx"
"github.com/integration-system/isp-kit/test"
"github.com/integration-system/isp-kit/test/dbt"
"github.com/txix-open/isp-kit/bgjobx"
"github.com/txix-open/isp-kit/dbx"
"github.com/txix-open/isp-kit/test"
"github.com/txix-open/isp-kit/test/dbt"
"msp-admin-service/assembly"
"msp-admin-service/conf"
"msp-admin-service/entity"
@@ -20,7 +20,7 @@ func TestInactiveWorker(t *testing.T) {
t.Parallel()
test, require := test.New(t)
db := dbt.New(test, dbx.WithMigration("../migrations"))
db := dbt.New(test, dbx.WithMigrationRunner("../migrations", test.Logger()))
userId := InsertUser(db, entity.User{Email: "a@test"})
InsertUser(db, entity.User{Email: "b@test"})
+7 -7
View File
@@ -5,14 +5,14 @@ import (
"testing"
"time"
"github.com/integration-system/isp-kit/dbx"
"github.com/integration-system/isp-kit/grpc/client"
"github.com/integration-system/isp-kit/http/httpcli"
"github.com/integration-system/isp-kit/test"
"github.com/integration-system/isp-kit/test/dbt"
"github.com/integration-system/isp-kit/test/grpct"
"github.com/stretchr/testify/require"
"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/test"
"github.com/txix-open/isp-kit/test/dbt"
"github.com/txix-open/isp-kit/test/grpct"
"msp-admin-service/assembly"
"msp-admin-service/conf"
"msp-admin-service/domain"
@@ -34,7 +34,7 @@ type SecureSuite struct {
func (s *SecureSuite) SetupTest() {
s.test, s.require = test.New(s.T())
s.db = dbt.New(s.test, dbx.WithMigration("../migrations"))
s.db = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
httpCli := httpcli.New()
remote := conf.Remote{
ExpireSec: 3600,
+51 -8
View File
@@ -2,18 +2,20 @@ package tests_test
import (
"context"
"github.com/txix-open/isp-kit/grpc/apierrors"
"golang.org/x/crypto/bcrypt"
"strconv"
"testing"
"time"
"github.com/google/uuid"
"github.com/integration-system/isp-kit/dbx"
"github.com/integration-system/isp-kit/grpc/client"
"github.com/integration-system/isp-kit/http/httpcli"
"github.com/integration-system/isp-kit/test"
"github.com/integration-system/isp-kit/test/dbt"
"github.com/integration-system/isp-kit/test/grpct"
"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/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"
"msp-admin-service/assembly"
@@ -45,7 +47,7 @@ type UserTestSuite struct {
func (s *UserTestSuite) SetupTest() {
testInstance, _ := test.New(s.T())
s.test = testInstance
s.db = dbt.New(testInstance, dbx.WithMigration("../migrations"))
s.db = dbt.New(testInstance, dbx.WithMigrationRunner("../migrations", testInstance.Logger()))
s.httpCli = httpcli.New()
remote := conf.Remote{
@@ -169,7 +171,7 @@ func (s *UserTestSuite) TestGetUsers() {
Do(context.Background())
s.Require().NoError(err)
s.Require().Equal(1, len(response.Items))
s.Require().Len(response.Items, 1) //nolint:mnd
s.Require().Equal(int64(5), response.Items[0].Id)
}
@@ -338,3 +340,44 @@ func (s *UserTestSuite) TestBlockUser() {
s.Require().NoError(err)
s.EqualValues(entity.TokenStatusRevoked, t.Status)
}
func (s *UserTestSuite) TestChangePasswordUser() {
// insert user with old password
adminId := InsertUser(s.db, entity.User{Email: "a_del@a.ru", Password: "password"})
InsertTokenEntity(s.db, entity.Token{
Token: "token-841297641213",
UserId: adminId,
Status: entity.TokenStatusAllowed,
CreatedAt: time.Time{},
ExpiredAt: time.Time{},
})
// check for err when invalid data
invalidReq := domain.ChangePasswordRequest{OldPassword: "invalid", NewPassword: "new_password"}
err := s.grpcCli.Invoke("admin/user/change_password").
AppendMetadata(domain.AdminAuthIdHeader, strconv.Itoa(int(adminId))).
JsonRequestBody(invalidReq).
Do(context.Background())
s.Require().Error(err)
err = apierrors.FromError(err)
s.Require().Contains(err.Error(), strconv.Itoa(domain.ErrCodeInvalidPassword))
// change password
changePswReq := domain.ChangePasswordRequest{OldPassword: "password", NewPassword: "new_password"}
err = s.grpcCli.Invoke("admin/user/change_password").
AppendMetadata(domain.AdminAuthIdHeader, strconv.Itoa(int(adminId))).
JsonRequestBody(changePswReq).
Do(context.Background())
s.Require().NoError(err)
var newPassword string
s.db.Must().SelectRow(&newPassword, "select password from users where id = $1", adminId)
notEqualErr := bcrypt.CompareHashAndPassword([]byte(newPassword), []byte(changePswReq.NewPassword))
s.Require().NoError(notEqualErr)
tokenInfo := SelectTokenEntityByToken(s.db, "token-841297641213")
s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status)
}