MSP-3427 added logout after password change
This commit is contained in:
1 parent
3a564dfae8
commit
4251ca3da9
6 files changed
+2853
-4
No files matched your search
@@ -77,6 +77,7 @@ func (l Locator) Config(ctx context.Context, ldapRepoSupplier ldap.RepoSupplier,
|
||||
auditService,
|
||||
txManager,
|
||||
ldapService,
|
||||
tokenService,
|
||||
cfg.IdleTimeoutMs,
|
||||
l.logger,
|
||||
)
|
||||
|
||||
+1718
File diff suppressed because it is too large.
Load diff
+1109
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -246,7 +246,7 @@ func (u User) ChangePassword(ctx context.Context, userId int64, newPassword stri
|
||||
|
||||
_, err = u.db.Exec(ctx, q, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "user.repo.ChangePassword: exec query")
|
||||
return errors.WithMessagef(err, "user.repo.ChangePassword: exec query: %s", q)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+13
-3
@@ -62,6 +62,7 @@ type User struct {
|
||||
auditService auditService
|
||||
txRunner UserTransactionRunner
|
||||
ldapService LdapService
|
||||
tokenService tokenService
|
||||
idleTimeoutMs int
|
||||
logger log.Logger
|
||||
}
|
||||
@@ -74,6 +75,7 @@ func NewUser(
|
||||
service auditService,
|
||||
txRunner UserTransactionRunner,
|
||||
ldapService LdapService,
|
||||
tokenService tokenService,
|
||||
idleTimeoutMs int,
|
||||
logger log.Logger,
|
||||
) User {
|
||||
@@ -85,6 +87,7 @@ func NewUser(
|
||||
auditService: service,
|
||||
txRunner: txRunner,
|
||||
ldapService: ldapService,
|
||||
tokenService: tokenService,
|
||||
idleTimeoutMs: idleTimeoutMs,
|
||||
logger: logger,
|
||||
}
|
||||
@@ -469,9 +472,9 @@ func (u User) ChangePassword(ctx context.Context, adminId int64, oldPassword str
|
||||
return domain.ErrInvalidPassword
|
||||
}
|
||||
|
||||
encryptedPassword, errNew := u.cryptPassword(newPassword)
|
||||
if errNew != nil {
|
||||
return errors.WithMessage(errNew, "user.service.ChangePassword: crypt new password")
|
||||
encryptedPassword, err := u.cryptPassword(newPassword)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "user.service.ChangePassword: crypt new password")
|
||||
}
|
||||
|
||||
err = u.userRepo.ChangePassword(ctx, adminId, encryptedPassword)
|
||||
@@ -479,5 +482,12 @@ func (u User) ChangePassword(ctx context.Context, adminId int64, oldPassword str
|
||||
return errors.WithMessage(err, "user.service.ChangePassword: change password ")
|
||||
}
|
||||
|
||||
err = u.tokenService.RevokeAllByUserId(ctx, adminId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "revoke all tokens by user id")
|
||||
}
|
||||
|
||||
u.auditService.SaveAuditAsync(ctx, adminId, "Выход", entity.EventSuccessLogout)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -345,6 +345,14 @@ 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").
|
||||
@@ -369,4 +377,7 @@ func (s *UserTestSuite) TestChangePasswordUser() {
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user