diff options
-rw-r--r-- | lib/chef/user.rb | 2 | ||||
-rw-r--r-- | spec/unit/user_spec.rb | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/chef/user.rb b/lib/chef/user.rb index 994cbb5773..33fc7d0456 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -38,7 +38,7 @@ class Chef def name(arg=nil) set_or_return(:name, arg, - :regex => /^[\-[:alnum:]_\.]+$/) + :regex => /^[a-z0-9\-_]+$/) end def admin(arg=nil) diff --git a/spec/unit/user_spec.rb b/spec/unit/user_spec.rb index 9d011fc0e0..d5bb4e7213 100644 --- a/spec/unit/user_spec.rb +++ b/spec/unit/user_spec.rb @@ -42,6 +42,20 @@ describe Chef::User do @client.name.should == "ops_master" end + # It is not feasible to check all invalid characters. Here are a few + # that we probably care about. + it "should not accept invalid characters" do + # capital letters + lambda { @user.name "Bar" }.should raise_error(ArgumentError) + # slashes + lambda { @user.name "foo/bar" }.should raise_error(ArgumentError) + # ? + lambda { @user.name "foo?" }.should raise_error(ArgumentError) + # & + lambda { @user.name "foo&" }.should raise_error(ArgumentError) + end + + it "should not accept spaces" do lambda { @client.name "ops master" }.should raise_error(ArgumentError) end |