mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
feat: validate usernames upon creation
The validation doesn't apply to already created usernames. This should close #925
This commit is contained in:
parent
518bc4d6ff
commit
e22520fc55
2 changed files with 49 additions and 1 deletions
|
@ -3,7 +3,11 @@
|
|||
|
||||
package validator // import "miniflux.app/v2/internal/validator"
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"miniflux.app/v2/internal/locale"
|
||||
)
|
||||
|
||||
func TestIsValidURL(t *testing.T) {
|
||||
scenarios := map[string]bool{
|
||||
|
@ -77,3 +81,25 @@ func TestIsValidDomain(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateUsername(t *testing.T) {
|
||||
scenarios := map[string]*locale.LocalizedError{
|
||||
"jvoisin": nil,
|
||||
"j.voisin": nil,
|
||||
"j@vois.in": nil,
|
||||
"invalid username": locale.NewLocalizedError("error.invalid_username"),
|
||||
}
|
||||
|
||||
for username, expected := range scenarios {
|
||||
result := validateUsername(username)
|
||||
if expected == nil {
|
||||
if result != nil {
|
||||
t.Errorf(`got an unexpected error for %q instead of nil: %v`, username, result)
|
||||
}
|
||||
} else {
|
||||
if result == nil {
|
||||
t.Errorf(`expected an error, got nil.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue