MSP-3427 password change realized
This commit is contained in:
1 parent
03bbdd1761
commit
d799b5be60
14 files changed
+136
-10
No files matched your search
+1
-1
@@ -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{
|
||||
|
||||
+1
-1
@@ -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()
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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"})
|
||||
|
||||
@@ -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,
|
||||
|
||||
+34
-1
@@ -2,6 +2,8 @@ package tests_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -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{
|
||||
@@ -338,3 +340,34 @@ 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"})
|
||||
|
||||
// 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(), "1001")
|
||||
|
||||
// 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)
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user