Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
name: "lint and test"

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened ]

permissions:
contents: read
pull-requests: write

jobs:
lint-and-test:
uses: esclient/tools/.github/workflows/lint-and-test-go.yml@v1.0.0
uses: esclient/tools/.github/workflows/lint-and-test-go.yml@v1.0.6
with:
go-version: '1.24.4'
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
go-version: "1.24.4"
16 changes: 1 addition & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,19 @@ go 1.24.4

require (
github.com/jackc/pgx/v5 v5.7.5
github.com/joho/godotenv v1.5.1
github.com/spf13/viper v1.20.1
golang.org/x/crypto v0.37.0
google.golang.org/grpc v1.73.0
google.golang.org/protobuf v1.36.6
)

require (
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
36 changes: 0 additions & 36 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
Expand All @@ -25,37 +19,13 @@ github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
Expand All @@ -68,10 +38,6 @@ go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5J
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
Expand All @@ -89,8 +55,6 @@ google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7E
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
28 changes: 14 additions & 14 deletions internal/userservice/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
)

var (
ErrorEmptyLogin = errors.New("login, field is empty")
ErrorEmptyEmail = errors.New("email, field is empty")
ErrorEmptyPassword = errors.New("password, field is empty")
ErrorEmptyConfirmPassword = errors.New("confirm password, field is empty")
ErrorEmptyLogin = errors.New("login, field is empty")
ErrorEmptyEmail = errors.New("email, field is empty")
ErrorEmptyPassword = errors.New("password, field is empty")
ErrorEmptyConfirmPassword = errors.New("confirm password, field is empty")
ErrorConfirmPasswordMismatch = errors.New("the password field and confirm password do not match")

ErrorCyrillicSymbolsLogin = errors.New("cyrillic symbols are not allowed in the login")
ErrorCyrillicSymbolsEmail = errors.New("cyrillic symbols are not allowed in the email")
ErrorCyrillicSymbolsLogin = errors.New("cyrillic symbols are not allowed in the login")
ErrorCyrillicSymbolsEmail = errors.New("cyrillic symbols are not allowed in the email")
ErrorCyrillicSymbolsPassword = errors.New("cyrillic symbols are not allowed in the password")
)

type UserHandler struct {
pb.UnimplementedUserServiceServer

service *service.UserService
}

Expand All @@ -48,7 +48,7 @@ func (u *UserHandler) RegisterUser(ctx context.Context, req *pb.RegisterUserRequ

userID, err := u.service.Register(ctx, login, email, password)
if err != nil {
return nil, err
return nil, err
}

return &pb.RegisterUserResponse{UserId: userID}, nil
Expand Down Expand Up @@ -97,9 +97,9 @@ func isPasswordConfirmMatch(password string, confirmPassword string) bool {

func hasCyrillic(str string) bool {
for _, r := range str {
if unicode.Is(unicode.Cyrillic, r) {
return true
}
}
return false
}
if unicode.Is(unicode.Cyrillic, r) {
return true
}
}
return false
}
12 changes: 6 additions & 6 deletions internal/userservice/handler/verify_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
const CodeLength = 6

var (
ErrorCodeEmpty = errors.New("confirmation code is empty")
ErrorCodeEmpty = errors.New("confirmation code is empty")
ErrorCodeLengthMismatch = errors.New("the code does not match the required length")
ErrorCodeNotDigitable = errors.New("the code is not digitable")
ErrorCodeNotDigitable = errors.New("the code is not digitable")

ErrorCodeUserIDNegative = errors.New("user ID is negative")
)
Expand Down Expand Up @@ -48,18 +48,18 @@ func validateConfirmationCode(code string) error {
return err
}

return nil
return nil
}

func isCodeEmpty(code string) error {
if (code == "") {
if code == "" {
return ErrorCodeEmpty
}
return nil
}

func isCodeLengthMismatch(code string) error {
if (len(code) != CodeLength) {
if len(code) != CodeLength {
return ErrorCodeLengthMismatch
}
return nil
Expand All @@ -80,4 +80,4 @@ func isUserIDNegative(userID int64) error {
return ErrorCodeUserIDNegative
}
return nil
}
}
116 changes: 57 additions & 59 deletions internal/userservice/handler/verify_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,74 @@ package handler
import "testing"

func TestIsCodeEmpty(t *testing.T) {
if err := isCodeEmpty(""); err == nil {
t.Fatalf("expected error for empty code, got nil")
}
if err := isCodeEmpty("123456"); err != nil {
t.Fatalf("unexpected error for non-empty code: %v", err)
}
if err := isCodeEmpty(""); err == nil {
t.Fatalf("expected error for empty code, got nil")
}
if err := isCodeEmpty("123456"); err != nil {
t.Fatalf("unexpected error for non-empty code: %v", err)
}
}

func TestIsCodeLengthMismatch(t *testing.T) {
if err := isCodeLengthMismatch("12345"); err == nil {
t.Fatalf("expected length mismatch error for 5 digits, got nil")
}
if err := isCodeLengthMismatch("1234567"); err == nil {
t.Fatalf("expected length mismatch error for 7 digits, got nil")
}
if err := isCodeLengthMismatch("123456"); err != nil {
t.Fatalf("unexpected error for correct length: %v", err)
}
if err := isCodeLengthMismatch("12345"); err == nil {
t.Fatalf("expected length mismatch error for 5 digits, got nil")
}
if err := isCodeLengthMismatch("1234567"); err == nil {
t.Fatalf("expected length mismatch error for 7 digits, got nil")
}
if err := isCodeLengthMismatch("123456"); err != nil {
t.Fatalf("unexpected error for correct length: %v", err)
}
}

func TestIsCodeNotDigitable(t *testing.T) {
if err := isCodeNotDigitable("12a456"); err == nil {
t.Fatalf("expected not-digitable error, got nil")
}
if err := isCodeNotDigitable("12345!"); err == nil {
t.Fatalf("expected not-digitable error with symbol, got nil")
}
// Arabic-Indic digits are valid according to unicode.IsDigit
if err := isCodeNotDigitable("١٢٣٤٥٦"); err != nil {
t.Fatalf("unexpected error for unicode digits: %v", err)
}
if err := isCodeNotDigitable("123456"); err != nil {
t.Fatalf("unexpected error for numeric code: %v", err)
}
if err := isCodeNotDigitable("12a456"); err == nil {
t.Fatalf("expected not-digitable error, got nil")
}
if err := isCodeNotDigitable("12345!"); err == nil {
t.Fatalf("expected not-digitable error with symbol, got nil")
}
// Arabic-Indic digits are valid according to unicode.IsDigit
if err := isCodeNotDigitable("١٢٣٤٥٦"); err != nil {
t.Fatalf("unexpected error for unicode digits: %v", err)
}
if err := isCodeNotDigitable("123456"); err != nil {
t.Fatalf("unexpected error for numeric code: %v", err)
}
}

func TestIsUserIDNegative(t *testing.T) {
if err := isUserIDNegative(-1); err == nil {
t.Fatalf("expected error for negative userID, got nil")
}
if err := isUserIDNegative(0); err != nil {
t.Fatalf("unexpected error for non-negative userID: %v", err)
}
if err := isUserIDNegative(-1); err == nil {
t.Fatalf("expected error for negative userID, got nil")
}
if err := isUserIDNegative(0); err != nil {
t.Fatalf("unexpected error for non-negative userID: %v", err)
}
}

func TestValidateConfirmationCode(t *testing.T) {
tests := []struct{
name string
code string
wantErr bool
}{
{name: "empty", code: "", wantErr: true},
{name: "short", code: "12345", wantErr: true},
{name: "long", code: "1234567", wantErr: true},
{name: "non-digit", code: "12a456", wantErr: true},
{name: "ok", code: "123456", wantErr: false},
}
tests := []struct {
name string
code string
wantErr bool
}{
{name: "empty", code: "", wantErr: true},
{name: "short", code: "12345", wantErr: true},
{name: "long", code: "1234567", wantErr: true},
{name: "non-digit", code: "12a456", wantErr: true},
{name: "ok", code: "123456", wantErr: false},
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := validateConfirmationCode(tc.code)
if tc.wantErr && err == nil {
t.Fatalf("expected error, got nil")
}
if !tc.wantErr && err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := validateConfirmationCode(tc.code)
if tc.wantErr && err == nil {
t.Fatalf("expected error, got nil")
}
if !tc.wantErr && err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
}
}


16 changes: 8 additions & 8 deletions internal/userservice/repository/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import (

const (
UserPendingStatus = "PENDIG"
UserActiveStatus = "ACTIVE"
UserActiveStatus = "ACTIVE"
)

const (
DBTimeout = 5 * time.Second

MaxPoolConns = 10
MinPoolConns = 2
MaxPoolConns = 10
MinPoolConns = 2
MaxConnLifetime = time.Hour
MaxConnIdleTime = 30 * time.Minute
)

var (
ErrorQueryFailed = errors.New("DB error code <0>") // db query failed
ErrorQueryFailed = errors.New("DB error code <0>") // db query failed

ErrorLoginTaken = errors.New("DB error code <3>") // login already taken
ErrorEmailTaken = errors.New("DB error code <4>") // email already taken
ErrorLoginTaken = errors.New("DB error code <3>") // login already taken
ErrorEmailTaken = errors.New("DB error code <4>") // email already taken

ErrorUserNotFound = errors.New("DB error code <3>") // user not found
ErrorUserNotFound = errors.New("DB error code <3>") // user not found

ErrorRowDoesNotExist = errors.New("DB error code <27>") // db row does not exist
ErrorCodeExpired = errors.New("DB error code <28>") // code from db expired
ErrorCodeMismatch = errors.New("DB error code <29>") // code mismatch
)
)
Loading
Loading