File tree 2 files changed +6
-6
lines changed
2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ var regexUsername = regexp.MustCompile("^[a-z_][a-z0-9_-]*$")
40
40
// regexPath detects valid Linux path.
41
41
var regexPath = regexp .MustCompile ("^[/a-zA-Z0-9_-]+$" )
42
42
43
+ func ValidateUsername (name string ) bool {
44
+ return regexUsername .MatchString (name )
45
+ }
46
+
43
47
func LookupUser (name string ) (User , error ) {
44
48
if users == nil {
45
49
users = make (map [string ]User )
@@ -111,7 +115,7 @@ func LimaUser(warn bool) (*user.User, error) {
111
115
cache .Do (func () {
112
116
cache .u , cache .err = user .Current ()
113
117
if cache .err == nil {
114
- if ! regexUsername . MatchString (cache .u .Username ) {
118
+ if ! ValidateUsername (cache .u .Username ) {
115
119
warning := fmt .Sprintf ("local user %q is not a valid Linux username (must match %q); using %q username instead" ,
116
120
cache .u .Username , regexUsername .String (), fallbackUser )
117
121
cache .warnings = append (cache .warnings , warning )
Original file line number Diff line number Diff line change @@ -13,15 +13,11 @@ func TestLimaUserWarn(t *testing.T) {
13
13
assert .NilError (t , err )
14
14
}
15
15
16
- func validUsername (username string ) bool {
17
- return regexUsername .MatchString (username )
18
- }
19
-
20
16
func TestLimaUsername (t * testing.T ) {
21
17
user , err := LimaUser (false )
22
18
assert .NilError (t , err )
23
19
// check for reasonable unix user name
24
- assert .Assert (t , validUsername (user .Username ), user .Username )
20
+ assert .Assert (t , ValidateUsername (user .Username ), user .Username )
25
21
}
26
22
27
23
func TestLimaUserUid (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments