mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-24 03:12:20 +00:00
Fix basic regexp for username validation
This commit is contained in:
parent
1816362e9a
commit
da35c59aaa
@ -151,7 +151,7 @@ func (backend *Backend) ValidateUsernameFunc() func(string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func defaultValidationUsernameFunc(userName string) error {
|
func defaultValidationUsernameFunc(userName string) error {
|
||||||
const re = `\w{5,}`
|
const re = `^\w{5,}$`
|
||||||
|
|
||||||
if !regexp.MustCompile(re).MatchString(userName) {
|
if !regexp.MustCompile(re).MatchString(userName) {
|
||||||
return fmt.Errorf("username does not match %s", re)
|
return fmt.Errorf("username does not match %s", re)
|
||||||
|
@ -12,7 +12,7 @@ func TestRegisterUser(t *testing.T) {
|
|||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
username = "user1"
|
username = "username1"
|
||||||
password = "password1"
|
password = "password1"
|
||||||
device = "device1"
|
device = "device1"
|
||||||
)
|
)
|
||||||
@ -28,7 +28,7 @@ func TestRegisterUserWithAlreadyTakenName(t *testing.T) {
|
|||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userName = "user1"
|
userName = "username1"
|
||||||
)
|
)
|
||||||
|
|
||||||
_, _, err := backend.Register(userName, "", "")
|
_, _, err := backend.Register(userName, "", "")
|
||||||
@ -42,7 +42,7 @@ func TestLogin(t *testing.T) {
|
|||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userName = "user1"
|
userName = "username1"
|
||||||
password = "password1"
|
password = "password1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ func TestLoginWithWrongCredentials(t *testing.T) {
|
|||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userName = "user1"
|
userName = "username1"
|
||||||
password = "password1"
|
password = "password1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ func TestLogout(t *testing.T) {
|
|||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userName = "user1"
|
userName = "username1"
|
||||||
password = "password1"
|
password = "password1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ func TestLogout(t *testing.T) {
|
|||||||
func TestGetRoomByID(t *testing.T) {
|
func TestGetRoomByID(t *testing.T) {
|
||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
user, token, err := backend.Register("user", "", "")
|
user, token, err := backend.Register("username", "", "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, user)
|
assert.NotNil(t, user)
|
||||||
assert.NotEmpty(t, token)
|
assert.NotEmpty(t, token)
|
||||||
@ -118,7 +118,7 @@ func TestGetUserByName(t *testing.T) {
|
|||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userName = "user"
|
userName = "username"
|
||||||
)
|
)
|
||||||
|
|
||||||
user, token, err := backend.Register(userName, "", "")
|
user, token, err := backend.Register(userName, "", "")
|
||||||
@ -140,9 +140,9 @@ func TestGetUserByName(t *testing.T) {
|
|||||||
func TestPublicRooms(t *testing.T) {
|
func TestPublicRooms(t *testing.T) {
|
||||||
backend := NewBackend("localhost")
|
backend := NewBackend("localhost")
|
||||||
|
|
||||||
user1, _, err := backend.Register("user1", "", "")
|
username1, _, err := backend.Register("username1", "", "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, user1)
|
assert.NotNil(t, username1)
|
||||||
|
|
||||||
// Create first room
|
// Create first room
|
||||||
request := createroom.Request{
|
request := createroom.Request{
|
||||||
@ -150,7 +150,7 @@ func TestPublicRooms(t *testing.T) {
|
|||||||
Name: "room1",
|
Name: "room1",
|
||||||
Preset: createroom.PublicChat}
|
Preset: createroom.PublicChat}
|
||||||
|
|
||||||
room1, err := user1.CreateRoom(request)
|
room1, err := username1.CreateRoom(request)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, room1)
|
assert.NotNil(t, room1)
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ func TestPublicRooms(t *testing.T) {
|
|||||||
Name: "room2",
|
Name: "room2",
|
||||||
Preset: createroom.PublicChat}
|
Preset: createroom.PublicChat}
|
||||||
|
|
||||||
room2, err := user1.CreateRoom(request)
|
room2, err := username1.CreateRoom(request)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, room2)
|
assert.NotNil(t, room2)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user