diff options
author | Steven Danna <steve@opscode.com> | 2013-01-23 11:18:23 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-02-06 09:51:02 -0800 |
commit | 84e37f62bdf06994242ead934faecf9d219e084a (patch) | |
tree | 6fbec91ae4b235bf560efd56479ae7d7d5f033aa | |
parent | 42d5ab44d53c02a731a7cc5ca987d728f6dc2f59 (diff) | |
download | chef-84e37f62bdf06994242ead934faecf9d219e084a.tar.gz |
Use same name validations as used by the server in user model.
-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 |