mirror of
https://github.com/juanfont/headscale.git
synced 2025-08-10 13:46:46 +02:00
allow users to be defined with @ in v1
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
603f3ad490
commit
639c5ef150
@ -969,6 +969,10 @@ var (
|
|||||||
func findUserFromToken(users []types.User, token string) (types.User, error) {
|
func findUserFromToken(users []types.User, token string) (types.User, error) {
|
||||||
var potentialUsers []types.User
|
var potentialUsers []types.User
|
||||||
|
|
||||||
|
// This adds the v2 support to looking up users with the new required
|
||||||
|
// policyv2 format where usernames have @ at the end if they are not emails.
|
||||||
|
token = strings.TrimSuffix(token, "@")
|
||||||
|
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
if user.ProviderIdentifier.Valid && user.ProviderIdentifier.String == token {
|
if user.ProviderIdentifier.Valid && user.ProviderIdentifier.String == token {
|
||||||
// Prioritize ProviderIdentifier match and exit early
|
// Prioritize ProviderIdentifier match and exit early
|
||||||
|
@ -2964,6 +2964,16 @@ func TestFindUserByToken(t *testing.T) {
|
|||||||
want: types.User{},
|
want: types.User{},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "test-v2-format-working",
|
||||||
|
users: []types.User{
|
||||||
|
{ProviderIdentifier: sql.NullString{Valid: false, String: ""}, Name: "user1", Email: "another1@example.com"},
|
||||||
|
{ProviderIdentifier: sql.NullString{Valid: false, String: ""}, Name: "user2", Email: "another2@example.com"},
|
||||||
|
},
|
||||||
|
token: "user2",
|
||||||
|
want: types.User{ProviderIdentifier: sql.NullString{Valid: false, String: ""}, Name: "user2", Email: "another2@example.com"},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user