• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gameap / gameap / 28878367588

07 Jul 2026 03:30PM UTC coverage: 82.185% (+5.7%) from 76.45%
28878367588

Pull #22

github

et-nik
e2e fixes
Pull Request #22: Develop into master

47018 of 57210 relevant lines covered (82.18%)

34985.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.85
/internal/api/users/postusers/input.go
1
package postusers
2

3
import (
4
        "fmt"
5
        "strings"
6

7
        "github.com/gameap/gameap/internal/domain"
8
        "github.com/gameap/gameap/pkg/api"
9
        "github.com/gameap/gameap/pkg/auth"
10
        "github.com/gameap/gameap/pkg/flexible"
11
        "github.com/gameap/gameap/pkg/validation"
12
        "github.com/pkg/errors"
13
)
14

15
const (
16
        maxLoginLength = 255
17
        maxEmailLength = 255
18
        maxNameLength  = 255
19
)
20

21
var (
22
        ErrLoginRequired = api.NewValidationError("login is required")
23
        ErrEmailRequired = api.NewValidationError("email is required")
24
        ErrLoginTooLong  = api.NewValidationError(
25
                fmt.Sprintf("login must not exceed %d characters", maxLoginLength),
26
        )
27
        ErrEmailTooLong = api.NewValidationError(
28
                fmt.Sprintf("email must not exceed %d characters", maxEmailLength),
29
        )
30
        ErrNameTooLong = api.NewValidationError(
31
                fmt.Sprintf("name must not exceed %d characters", maxNameLength),
32
        )
33
        ErrInvalidEmail = api.NewValidationError("email is not valid")
34
        ErrLoginEmpty   = api.NewValidationError("login cannot be empty")
35
        ErrEmailEmpty   = api.NewValidationError("email cannot be empty")
36
        ErrNameEmpty    = api.NewValidationError("name cannot be empty")
37
)
38

39
type createUserInput struct {
40
        Login    string          `json:"login"`
41
        Email    string          `json:"email"`
42
        Password string          `json:"password"`
43
        Name     *string         `json:"name,omitempty"`
44
        Roles    []string        `json:"roles"`
45
        Servers  []flexible.Uint `json:"servers"`
46
}
47

48
func (input *createUserInput) Validate() error {
17✔
49
        if input.Login == "" {
18✔
50
                return ErrLoginRequired
1✔
51
        }
1✔
52

53
        loginValue := strings.TrimSpace(input.Login)
16✔
54
        if loginValue == "" {
17✔
55
                return ErrLoginEmpty
1✔
56
        }
1✔
57

58
        if len(loginValue) > maxLoginLength {
16✔
59
                return ErrLoginTooLong
1✔
60
        }
1✔
61

62
        input.Login = loginValue
14✔
63

14✔
64
        if input.Email == "" {
15✔
65
                return ErrEmailRequired
1✔
66
        }
1✔
67

68
        emailValue := strings.TrimSpace(input.Email)
13✔
69
        if emailValue == "" {
14✔
70
                return ErrEmailEmpty
1✔
71
        }
1✔
72

73
        if len(emailValue) > maxEmailLength {
13✔
74
                return ErrEmailTooLong
1✔
75
        }
1✔
76

77
        if !validation.IsEmail(emailValue) {
12✔
78
                return ErrInvalidEmail
1✔
79
        }
1✔
80

81
        input.Email = emailValue
10✔
82

10✔
83
        if err := auth.ValidatePassword(input.Password); err != nil {
13✔
84
                return err
3✔
85
        }
3✔
86

87
        if input.Name != nil {
11✔
88
                nameValue := strings.TrimSpace(*input.Name)
4✔
89
                if nameValue == "" {
5✔
90
                        return ErrNameEmpty
1✔
91
                }
1✔
92

93
                if len(nameValue) > maxNameLength {
4✔
94
                        return ErrNameTooLong
1✔
95
                }
1✔
96

97
                input.Name = &nameValue
2✔
98
        }
99

100
        return nil
5✔
101
}
102

103
func (input *createUserInput) ToDomain() (*domain.User, error) {
3✔
104
        // Hash the exact bytes that were validated — do not trim. ASVS §2.1.3
3✔
105
        // forbids modifying the password between validation and storage.
3✔
106
        hashedPassword, err := auth.HashPassword(input.Password)
3✔
107
        if err != nil {
3✔
108
                return nil, errors.WithMessage(err, "failed to hash password")
×
109
        }
×
110

111
        var name *string
3✔
112
        if input.Name != nil {
5✔
113
                nameValue := strings.TrimSpace(*input.Name)
2✔
114
                name = &nameValue
2✔
115
        }
2✔
116

117
        return &domain.User{
3✔
118
                Login:    strings.TrimSpace(input.Login),
3✔
119
                Email:    strings.TrimSpace(input.Email),
3✔
120
                Password: hashedPassword,
3✔
121
                Name:     name,
3✔
122
        }, nil
3✔
123
}
124

125
func (input *createUserInput) ServerIDs() []uint {
3✔
126
        result := make([]uint, 0, len(input.Servers))
3✔
127
        for _, s := range input.Servers {
3✔
128
                result = append(result, s.Uint())
×
129
        }
×
130

131
        return result
3✔
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc