summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-05-16 16:32:18 -0700
committerNick Lewis <nick@puppetlabs.com>2011-05-16 16:32:18 -0700
commitd22b1303de9a0dbc2c5b887eab0c9e146fcf13c6 (patch)
treed820b3e468d15038f6f16cee8115422387bbd1e7
parent551cb3e5ee6c1ef4218adcebf04004c50fe4119f (diff)
downloadpuppet-d22b1303de9a0dbc2c5b887eab0c9e146fcf13c6.tar.gz
puppet-d22b1303de9a0dbc2c5b887eab0c9e146fcf13c6.tar.xz
puppet-d22b1303de9a0dbc2c5b887eab0c9e146fcf13c6.zip
(#7114) Fix specs for ssh authorized key parsed provider
These tests were unnecessarily creating a stub resource, as well as failing to re-initvars on the provider before each test. This led to test ordering failures, and incompatibilities with the other commits in this series. Now we use a real resource, and properly reinitialize before each test. Paired-With: Josh Cooper
-rwxr-xr-xspec/unit/provider/ssh_authorized_key/parsed_spec.rb53
1 files changed, 21 insertions, 32 deletions
diff --git a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb
index 69d29c674..bd5e55a9e 100755
--- a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb
+++ b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb
@@ -9,23 +9,19 @@ describe provider_class do
include PuppetSpec::Files
before :each do
- @sshauthkey_class = Puppet::Type.type(:ssh_authorized_key)
- @provider = @sshauthkey_class.provider(:parsed)
@keyfile = tmpfile('authorized_keys')
- @provider.any_instance.stubs(:target).returns @keyfile
+ @provider_class = provider_class
+ @provider_class.initvars
+ @provider_class.any_instance.stubs(:target).returns @keyfile
@user = 'random_bob'
Puppet::Util.stubs(:uid).with(@user).returns 12345
end
- after :each do
- @provider.initvars
- end
-
def mkkey(args)
args[:target] = @keyfile
args[:user] = @user
resource = Puppet::Type.type(:ssh_authorized_key).new(args)
- key = @provider.new(resource)
+ key = @provider_class.new(resource)
args.each do |p,v|
key.send(p.to_s + "=", v)
end
@@ -33,26 +29,26 @@ describe provider_class do
end
def genkey(key)
- @provider.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam)
+ @provider_class.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam)
File.stubs(:chown)
File.stubs(:chmod)
Puppet::Util::SUIDManager.stubs(:asuser).yields
key.flush
- @provider.target_object(@keyfile).read
+ @provider_class.target_object(@keyfile).read
end
it_should_behave_like "all parsedfile providers", provider_class
it "should be able to generate a basic authorized_keys file" do
- key = mkkey(:name => "Just Testing",
+ key = mkkey(:name => "Just_Testing",
:key => "AAAAfsfddsjldjgksdflgkjsfdlgkj",
:type => "ssh-dss",
:ensure => :present,
:options => [:absent]
)
- genkey(key).should == "ssh-dss AAAAfsfddsjldjgksdflgkjsfdlgkj Just Testing\n"
+ genkey(key).should == "ssh-dss AAAAfsfddsjldjgksdflgkjsfdlgkj Just_Testing\n"
end
it "should be able to generate a authorized_keys file with options" do
@@ -71,25 +67,25 @@ describe provider_class do
options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty}
optionstr = options.join(", ")
- @provider.parse_options(optionstr).should == options
+ @provider_class.parse_options(optionstr).should == options
end
it "should use '' as name for entries that lack a comment" do
line = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAut8aOSxenjOqF527dlsdHWV4MNoAsX14l9M297+SQXaQ5Z3BedIxZaoQthkDALlV/25A1COELrg9J2MqJNQc8Xe9XQOIkBQWWinUlD/BXwoOTWEy8C8zSZPHZ3getMMNhGTBO+q/O+qiJx3y5cA4MTbw2zSxukfWC87qWwcZ64UUlegIM056vPsdZWFclS9hsROVEa57YUMrehQ1EGxT4Z5j6zIopufGFiAPjZigq/vqgcAqhAKP6yu4/gwO6S9tatBeEjZ8fafvj1pmvvIplZeMr96gHE7xS3pEEQqnB3nd4RY7AF6j9kFixnsytAUO7STPh/M3pLiVQBN89TvWPQ=="
- @provider.parse(line)[0][:name].should == ""
+ @provider_class.parse(line)[0][:name].should == ""
end
end
describe provider_class do
before :each do
- @resource = stub("resource", :name => "foo")
- @resource.stubs(:[]).returns "foo"
- @resource.class.stubs(:key_attributes).returns( [:name] )
+ @resource = Puppet::Type.type(:ssh_authorized_key).new(:name => "foo", :user => "random_bob")
@provider = provider_class.new(@resource)
provider_class.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam)
Puppet::Util::SUIDManager.stubs(:asuser).yields
+
+ provider_class.initvars
end
describe "when flushing" do
@@ -103,9 +99,9 @@ describe provider_class do
describe "and both a user and a target have been specified" do
before :each do
Puppet::Util.stubs(:uid).with("random_bob").returns 12345
- @resource.stubs(:should).with(:user).returns "random_bob"
+ @resource[:user] = "random_bob"
target = "/tmp/.ssh_dir/place_to_put_authorized_keys"
- @resource.stubs(:should).with(:target).returns target
+ @resource[:target] = target
end
it "should create the directory" do
@@ -134,8 +130,7 @@ describe provider_class do
describe "and a user has been specified with no target" do
before :each do
- @resource.stubs(:should).with(:user).returns "nobody"
- @resource.stubs(:should).with(:target).returns nil
+ @resource[:user] = "nobody"
#
# I'd like to use random_bob here and something like
#
@@ -186,26 +181,20 @@ describe provider_class do
end
describe "and a target has been specified with no user" do
- before :each do
- @resource.stubs(:should).with(:user).returns nil
- @resource.stubs(:should).with(:target).returns("/tmp/.ssh_dir/place_to_put_authorized_keys")
- end
-
it "should raise an error" do
+ @resource = Puppet::Type.type(:ssh_authorized_key).new(:name => "foo", :target => "/tmp/.ssh_dir/place_to_put_authorized_keys")
+ @provider = provider_class.new(@resource)
+
proc { @provider.flush }.should raise_error
end
end
describe "and a invalid user has been specified with no target" do
- before :each do
- @resource.stubs(:should).with(:user).returns "thisusershouldnotexist"
- @resource.stubs(:should).with(:target).returns nil
- end
-
it "should catch an exception and raise a Puppet error" do
+ @resource[:user] = "thisusershouldnotexist"
+
lambda { @provider.flush }.should raise_error(Puppet::Error)
end
end
-
end
end