allow period for the alias #1

Merged
lash merged 3 commits from alias-period into master 2025-01-21 14:47:36 +01:00
2 changed files with 42 additions and 1 deletions

View File

@ -5,7 +5,7 @@ import (
) )
const ( const (
aliasRegex = `^[a-zA-Z0-9]+$` aliasRegex = `^[a-zA-Z0-9]+(\.[a-zA-Z0.9]+)*$`
Outdated
Review

Actually this should be previous regex then followed by 1+ dot-prefixed alphanumerics something like ^[a-zA-Z0-9]+(\.[a-zA-Z0.9]+)*$

Actually this should be previous regex then followed by 1+ dot-prefixed alphanumerics something like `^[a-zA-Z0-9]+(\.[a-zA-Z0.9]+)*$`
) )
// IsValidAlias checks if the alias is a valid alias format // IsValidAlias checks if the alias is a valid alias format

41
identity/alias_test.go Normal file
View File

@ -0,0 +1,41 @@
package identity
import (
"testing"
)
func TestAliasesRegext(t *testing.T) {
tests := []struct {
alias string
isValid bool
}{
{
alias: "foobar",
isValid: true,
},
{
alias: "foo.sarafu.local",
isValid: true,
},
{
alias: "foo.sarafu",
isValid: true,
},
{
alias: "foo.",
isValid: false,
},
{
alias: ".foo..bar",
isValid: false,
},
}
for _, tt := range tests {
t.Run(tt.alias, func(t *testing.T) {
isValid := IsValidAlias(tt.alias)
if isValid != tt.isValid {
t.Fatalf("expected %v, got %v", tt.isValid, isValid)
}
})
}
}