fix: user resource names can be uuidv4 from idp sub claim (#5856)
This commit is contained in:
parent
f8a304bae3
commit
bbded584ce
3 changed files with 4 additions and 2 deletions
|
|
@ -3,5 +3,5 @@ package base
|
|||
import "regexp"
|
||||
|
||||
var (
|
||||
UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,30}[a-zA-Z0-9])?$")
|
||||
UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,34}[a-zA-Z0-9])?$")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ func TestUIDMatcher(t *testing.T) {
|
|||
{"a1234567890123456789012345678901", true},
|
||||
{"abc123", true},
|
||||
{"abc123-", false},
|
||||
{"123e4567-e89b-12d3-a456-426614174000", true}, // UUID v4 from IDP
|
||||
{"a123456789012345678901234567890123456", false}, // 37 characters (too long)
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func ValidateAndGenerateUID(provided string) (string, error) {
|
|||
return shortuuid.New(), nil
|
||||
}
|
||||
if !base.UIDMatcher.MatchString(uid) {
|
||||
return "", status.Errorf(codes.InvalidArgument, "invalid ID format: must be 1-32 characters, alphanumeric and hyphens only, cannot start or end with hyphen")
|
||||
return "", status.Errorf(codes.InvalidArgument, "invalid ID format: must be 1-36 characters, alphanumeric and hyphens only, cannot start or end with hyphen")
|
||||
}
|
||||
return uid, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue