feat: secure service connections and login
This commit is contained in:
@@ -15,10 +15,10 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/reconcile"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/reconcile"
|
||||
)
|
||||
|
||||
type PostgresSuite struct {
|
||||
@@ -77,6 +77,27 @@ func (s *PostgresSuite) TestConcurrentUsernameCreation() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PostgresSuite) TestPasswordHashUpdateUsesCompareAndSwap() {
|
||||
username := uniqueUsername()
|
||||
user, err := s.store.CreateUser(context.Background(), username, "Password user", "old-hash")
|
||||
s.Require().NoError(err)
|
||||
|
||||
updated, err := s.store.UpdatePasswordHash(context.Background(), user.ID, "other-hash", "new-hash")
|
||||
s.Require().NoError(err)
|
||||
s.False(updated)
|
||||
|
||||
updated, err = s.store.UpdatePasswordHash(context.Background(), user.ID, "old-hash", "new-hash")
|
||||
s.Require().NoError(err)
|
||||
s.True(updated)
|
||||
updated, err = s.store.UpdatePasswordHash(context.Background(), user.ID, "old-hash", "stale-hash")
|
||||
s.Require().NoError(err)
|
||||
s.False(updated)
|
||||
|
||||
credentials, err := s.store.UserByUsername(context.Background(), username)
|
||||
s.Require().NoError(err)
|
||||
s.Equal("new-hash", credentials.PasswordHash)
|
||||
}
|
||||
|
||||
func (s *PostgresSuite) TestCreateChatRollsBackForUnknownMember() {
|
||||
t := s.T()
|
||||
pool := s.pool
|
||||
|
||||
Reference in New Issue
Block a user