spec/debian/commands_spec.rb in serverspec-0.2.18 vs spec/debian/commands_spec.rb in serverspec-0.2.19

- old
+ new

@@ -123,15 +123,32 @@ it { should eq "id root | grep '^uid=0('" } end describe 'have_login_shell', :os => :debian do subject { commands.check_login_shell('root', '/bin/bash') } - it { should eq "grep -w ^root /etc/passwd | cut -f 7 -d ':' | grep -w /bin/bash" } + it { should eq "getent passwd root | cut -f 7 -d ':' | grep -w /bin/bash" } end describe 'have_home_directory', :os => :debian do subject { commands.check_home_directory('root', '/root') } - it { should eq "grep -w ^root /etc/passwd | cut -f 6 -d ':' | grep -w /root" } + it { should eq "getent passwd root | cut -f 6 -d ':' | grep -w /root" } +end + +describe 'have_authorized_key', :os => :debian do + key = "ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH" + + context 'with commented publickey' do + commented_key = key + " foo@bar.local" + subject { commands.check_authorized_key('root', commented_key) } + describe 'when command insert publickey is removed comment' do + it { should eq "grep -w '#{key}' ~root/.ssh/authorized_keys" } + end + end + + context 'with uncomented publickey' do + subject { commands.check_authorized_key('root', key) } + it { should eq "grep -w '#{key}' ~root/.ssh/authorized_keys" } + end end describe 'check_ipatbles', :os => :debian do context 'check a rule without a table and a chain' do subject { commands.check_iptables_rule('-P INPUT ACCEPT') }