From b918a193de16f9b1c88687ccfab91664f975f1ab Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Thu, 21 Jun 2018 14:45:50 -0700 Subject: Apply automatic PDK validation cleanup --- .../provider/ssh_authorized_key_spec.rb | 143 ++++++++++----------- spec/integration/provider/sshkey_spec.rb | 94 +++++++------- 2 files changed, 117 insertions(+), 120 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/ssh_authorized_key_spec.rb b/spec/integration/provider/ssh_authorized_key_spec.rb index 14af2de..7dc40e3 100644 --- a/spec/integration/provider/ssh_authorized_key_spec.rb +++ b/spec/integration/provider/ssh_authorized_key_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'puppet/file_bucket/dipper' -describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration)', :unless => Puppet.features.microsoft_windows? do +describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration)', unless: Puppet.features.microsoft_windows? do include PuppetSpec::Files let :fake_userfile do @@ -18,7 +18,7 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration [ 'AAAAB3NzaC1yc2EAAAADAQABAAAAgQCi18JBZOq10X3w4f67nVhO0O3s5Y1vHH4UgMSM3ZnQwbC5hjGyYSi9UULOoQQoQynI/a0I9NL423/Xk/XJVIKCHcS8q6V2Wmjd+fLNelOjxxoW6mbIytEt9rDvwgq3Mof3/m21L3t2byvegR00a+ikKbmInPmKwjeWZpexCIsHzQ==', # 1024 bit 'AAAAB3NzaC1yc2EAAAADAQABAAAAgQDLClyvi3CsJw5Id6khZs2/+s11qOH4Gdp6iDioDsrIp0m8kSiPr71VGyQYAfPzzvHemHS7Xg0NkG1Kc8u9tRqBQfTvz7ubq0AT/g01+4P2hQ/soFkuwlUG/HVnnaYb6N0Qp5SHWvD5vBE2nFFQVpP5GrSctPtHSjzJq/i+6LYhmQ==', # 1024 bit - 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDLygAO6txXkh9FNV8xSsBkATeqLbHzS7sFjGI3gt0Dx6q3LjyKwbhQ1RLf28kd5G6VWiXmClU/RtiPdUz8nrGuun++2mrxzrXrvpR9dq1lygLQ2wn2cI35dN5bjRMtXy3decs6HUhFo9MoNwX250rUWfdCyNPhGIp6OOfmjdy+UeLGNxq9wDx6i4bT5tVVSqVRtsEfw9+ICXchzl85QudjneVVpP+thriPZXfXA5eaGwAo/dmoKOIhUwF96gpdLqzNtrGQuxPbV80PTbGv9ZtAtTictxaDz8muXO7he9pXmchUpxUKtMFjHkL0FAZ9tRPmv3RA30sEr2fZ8+LKvnE50w0' #2048 Bit + 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDLygAO6txXkh9FNV8xSsBkATeqLbHzS7sFjGI3gt0Dx6q3LjyKwbhQ1RLf28kd5G6VWiXmClU/RtiPdUz8nrGuun++2mrxzrXrvpR9dq1lygLQ2wn2cI35dN5bjRMtXy3decs6HUhFo9MoNwX250rUWfdCyNPhGIp6OOfmjdy+UeLGNxq9wDx6i4bT5tVVSqVRtsEfw9+ICXchzl85QudjneVVpP+thriPZXfXA5eaGwAo/dmoKOIhUwF96gpdLqzNtrGQuxPbV80PTbGv9ZtAtTictxaDz8muXO7he9pXmchUpxUKtMFjHkL0FAZ9tRPmv3RA30sEr2fZ8+LKvnE50w0' # 2048 Bit ] end @@ -33,16 +33,16 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration "ssh-rsa #{sample_rsa_keys[1]} root@someotherhost", "ssh-dss #{sample_dsa_keys[0]} root@anywhere", "ssh-rsa #{sample_rsa_keys[2]} paul", - "ssh-rsa #{sample_rsa_keys[2]} dummy" + "ssh-rsa #{sample_rsa_keys[2]} dummy", ] end let :dummy do Puppet::Type.type(:ssh_authorized_key).new( - :name => 'dummy', - :target => fake_userfile, - :user => 'nobody', - :ensure => :absent + name: 'dummy', + target: fake_userfile, + user: 'nobody', + ensure: :absent, ) end @@ -57,7 +57,7 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration end def create_fake_key(username, content) - filename = (username == :root ? fake_rootfile : fake_userfile ) + filename = ((username == :root) ? fake_rootfile : fake_userfile) File.open(filename, 'w') do |f| content.each do |line| f.puts line @@ -66,8 +66,8 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration end def check_fake_key(username, expected_content) - filename = (username == :root ? fake_rootfile : fake_userfile ) - content = File.readlines(filename).map(&:chomp).sort.reject{ |x| x =~ /^# HEADER:/ } + filename = ((username == :root) ? fake_rootfile : fake_userfile) + content = File.readlines(filename).map(&:chomp).sort.reject { |x| x =~ %r{^# HEADER:} } expect(content.join("\n")).to eq(expected_content.sort.join("\n")) end @@ -82,35 +82,34 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration catalog.apply end - it "should not complain about empty lines and comments" do + it 'does not complain about empty lines and comments' do described_class.expects(:flush).never - sample = ['',sample_lines[0],' ',sample_lines[1],'# just a comment','#and another'] - create_fake_key(:user,sample) + sample = ['', sample_lines[0], ' ', sample_lines[1], '# just a comment', '#and another'] + create_fake_key(:user, sample) run_in_catalog(dummy) check_fake_key(:user, sample) end - it "should keep empty lines and comments when modifying a file" do - create_fake_key(:user, ['',sample_lines[0],' ',sample_lines[3],'# just a comment','#and another']) + it 'keeps empty lines and comments when modifying a file' do + create_fake_key(:user, ['', sample_lines[0], ' ', sample_lines[3], '# just a comment', '#and another']) run_in_catalog(dummy) - check_fake_key(:user, ['',sample_lines[0],' ','# just a comment','#and another']) + check_fake_key(:user, ['', sample_lines[0], ' ', '# just a comment', '#and another']) end - describe "when managing one resource" do - - describe "with ensure set to absent" do + describe 'when managing one resource' do + describe 'with ensure set to absent' do let :resource do Puppet::Type.type(:ssh_authorized_key).new( - :name => 'root@hostname', - :type => :rsa, - :key => sample_rsa_keys[0], - :target => fake_rootfile, - :user => 'root', - :ensure => :absent + name: 'root@hostname', + type: :rsa, + key: sample_rsa_keys[0], + target: fake_rootfile, + user: 'root', + ensure: :absent, ) end - it "should not modify root's keyfile if resource is currently not present" do + it "does not modify root's keyfile if resource is currently not present" do create_fake_key(:root, sample_lines) run_in_catalog(resource) check_fake_key(:root, sample_lines) @@ -123,96 +122,96 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration end end - describe "when ensure is present" do + describe 'when ensure is present' do let :resource do Puppet::Type.type(:ssh_authorized_key).new( - :name => 'root@hostname', - :type => :rsa, - :key => sample_rsa_keys[0], - :target => fake_rootfile, - :user => 'root', - :ensure => :present + name: 'root@hostname', + type: :rsa, + key: sample_rsa_keys[0], + target: fake_rootfile, + user: 'root', + ensure: :present, ) end # just a dummy so the parsedfile provider is aware # of the user's authorized_keys file - it "should add the key if it is not present" do + it 'adds the key if it is not present' do create_fake_key(:root, sample_lines) run_in_catalog(resource) - check_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) + check_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) end - it "should modify the type if type is out of sync" do - create_fake_key(:root,sample_lines + [ "ssh-dss #{sample_rsa_keys[0]} root@hostname" ]) + it 'modifies the type if type is out of sync' do + create_fake_key(:root, sample_lines + ["ssh-dss #{sample_rsa_keys[0]} root@hostname"]) run_in_catalog(resource) - check_fake_key(:root, sample_lines + [ "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) + check_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) end - it "should modify the key if key is out of sync" do - create_fake_key(:root,sample_lines + [ "ssh-rsa #{sample_rsa_keys[1]} root@hostname" ]) + it 'modifies the key if key is out of sync' do + create_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[1]} root@hostname"]) run_in_catalog(resource) - check_fake_key(:root, sample_lines + [ "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) + check_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) end - it "should remove the key from old file if target is out of sync" do - create_fake_key(:user, [ sample_lines[0], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) - create_fake_key(:root, [ sample_lines[1], sample_lines[2] ]) + it 'removes the key from old file if target is out of sync' do + create_fake_key(:user, [sample_lines[0], "ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) + create_fake_key(:root, [sample_lines[1], sample_lines[2]]) run_in_catalog(resource, dummy) - check_fake_key(:user, [ sample_lines[0] ]) - #check_fake_key(:root, [ sample_lines[1], sample_lines[2], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) + check_fake_key(:user, [sample_lines[0]]) + # check_fake_key(:root, [ sample_lines[1], sample_lines[2], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) end - it "should add the key to new file if target is out of sync" do - create_fake_key(:user, [ sample_lines[0], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) - create_fake_key(:root, [ sample_lines[1], sample_lines[2] ]) + it 'adds the key to new file if target is out of sync' do + create_fake_key(:user, [sample_lines[0], "ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) + create_fake_key(:root, [sample_lines[1], sample_lines[2]]) run_in_catalog(resource, dummy) - #check_fake_key(:user, [ sample_lines[0] ]) - check_fake_key(:root, [ sample_lines[1], sample_lines[2], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) + # check_fake_key(:user, [ sample_lines[0] ]) + check_fake_key(:root, [sample_lines[1], sample_lines[2], "ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) end - it "should modify options if options are out of sync" do - resource[:options]=[ 'from="*.domain1,host1.domain2"', 'no-port-forwarding', 'no-pty' ] - create_fake_key(:root, sample_lines + [ "from=\"*.false,*.false2\",no-port-forwarding,no-pty ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) + it 'modifies options if options are out of sync' do + resource[:options] = ['from="*.domain1,host1.domain2"', 'no-port-forwarding', 'no-pty'] + create_fake_key(:root, sample_lines + ["from=\"*.false,*.false2\",no-port-forwarding,no-pty ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) run_in_catalog(resource) - check_fake_key(:root, sample_lines + [ "from=\"*.domain1,host1.domain2\",no-port-forwarding,no-pty ssh-rsa #{sample_rsa_keys[0]} root@hostname"] ) + check_fake_key(:root, sample_lines + ["from=\"*.domain1,host1.domain2\",no-port-forwarding,no-pty ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) end end end - describe "when managing two resource" do + describe 'when managing two resource' do let :examples do resources = [] resources << Puppet::Type.type(:ssh_authorized_key).new( - :name => 'root@hostname', - :type => :rsa, - :key => sample_rsa_keys[0], - :target => fake_rootfile, - :user => 'root', - :ensure => :present + name: 'root@hostname', + type: :rsa, + key: sample_rsa_keys[0], + target: fake_rootfile, + user: 'root', + ensure: :present, ) resources << Puppet::Type.type(:ssh_authorized_key).new( - :name => 'user@hostname', - :key => sample_rsa_keys[1], - :type => :rsa, - :target => fake_userfile, - :user => 'nobody', - :ensure => :present + name: 'user@hostname', + key: sample_rsa_keys[1], + type: :rsa, + target: fake_userfile, + user: 'nobody', + ensure: :present, ) resources end - describe "and both keys are absent" do + describe 'and both keys are absent' do before :each do create_fake_key(:root, sample_lines) create_fake_key(:user, sample_lines) end - it "should add both keys" do + it 'adds both keys' do run_in_catalog(*examples) - check_fake_key(:root, sample_lines + [ "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ]) - check_fake_key(:user, sample_lines + [ "ssh-rsa #{sample_rsa_keys[1]} user@hostname" ]) + check_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[0]} root@hostname"]) + check_fake_key(:user, sample_lines + ["ssh-rsa #{sample_rsa_keys[1]} user@hostname"]) end end end diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index f461460..5328f85 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -6,7 +6,7 @@ require 'puppet_spec/files' require 'puppet_spec/compiler' describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', - :unless => Puppet.features.microsoft_windows? do + unless: Puppet.features.microsoft_windows? do include PuppetSpec::Files include PuppetSpec::Compiler @@ -14,8 +14,8 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', # Don't backup to filebucket Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # We don't want to execute anything - described_class.stubs(:filetype). - returns Puppet::Util::FileType::FileTypeFlat + described_class.stubs(:filetype) + .returns Puppet::Util::FileType::FileTypeFlat @sshkey_file = tmpfile('sshkey_integration_specs') FileUtils.cp(my_fixture('sample'), @sshkey_file) @@ -28,10 +28,9 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', let(:type_under_test) { 'sshkey' } - describe "when managing a ssh known hosts file it..." do - - let(:super_unique) { "my.super.unique.host" } - it "should create a new known_hosts file with mode 0644" do + describe 'when managing a ssh known hosts file it...' do + let(:super_unique) { 'my.super.unique.host' } + it 'creates a new known_hosts file with mode 0644' do target = tmpfile('ssh_known_hosts') manifest = "#{type_under_test} { '#{super_unique}': ensure => 'present', @@ -39,51 +38,51 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', key => 'TESTKEY', target => '#{target}' }" apply_with_error_check(manifest) - expect_file_mode(target, "644") + expect_file_mode(target, '644') end - it "should create an SSH host key entry (ensure present)" do + it 'creates an SSH host key entry (ensure present)' do manifest = "#{type_under_test} { '#{super_unique}': ensure => 'present', type => 'rsa', key => 'mykey', target => '#{@sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(/#{super_unique}.*mykey/) + expect(File.read(@sshkey_file)).to match(%r{#{super_unique}.*mykey}) end let(:sshkey_name) { 'kirby.madstop.com' } - it "should delete an entry for an SSH host key" do + it 'deletes an entry for an SSH host key' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'absent', target => '#{@sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).not_to match(/#{sshkey_name}.*Yqk0=/) + expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end - it "should update an entry for an SSH host key" do + it 'updates an entry for an SSH host key' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', type => 'rsa', key => 'mynewshinykey', target => '#{@sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(/#{sshkey_name}.*mynewshinykey/) - expect(File.read(@sshkey_file)).not_to match(/#{sshkey_name}.*Yqk0=/) + expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name}.*mynewshinykey}) + expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end # test all key types - types = ["ssh-dss", "dsa", - "ssh-ed25519", "ed25519", - "ssh-rsa", "rsa", - "ecdsa-sha2-nistp256", - "ecdsa-sha2-nistp384", - "ecdsa-sha2-nistp521"] + types = ['ssh-dss', 'dsa', + 'ssh-ed25519', 'ed25519', + 'ssh-rsa', 'rsa', + 'ecdsa-sha2-nistp256', + 'ecdsa-sha2-nistp384', + 'ecdsa-sha2-nistp521'] # these types are treated as aliases for sshkey type # so they are populated as the *values* below - aliases = {"dsa" => "ssh-dss", - "ed25519" => "ssh-ed25519", - "rsa" => "ssh-rsa"} + aliases = { 'dsa' => 'ssh-dss', + 'ed25519' => 'ssh-ed25519', + 'rsa' => 'ssh-rsa' } types.each do |type| it "should update an entry with #{type} type" do manifest = "#{type_under_test} { '#{sshkey_name}': @@ -93,67 +92,66 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', target => '#{@sshkey_file}' }" apply_with_error_check(manifest) - if aliases.has_key?(type) + if aliases.key?(type) full_type = aliases[type] - expect(File.read(@sshkey_file)). - to match(/#{sshkey_name}.*#{full_type}.*mynew/) + expect(File.read(@sshkey_file)) + .to match(%r{#{sshkey_name}.*#{full_type}.*mynew}) else - expect(File.read(@sshkey_file)). - to match(/#{sshkey_name}.*#{type}.*mynew/) + expect(File.read(@sshkey_file)) + .to match(%r{#{sshkey_name}.*#{type}.*mynew}) end end end # test unknown key type fails let(:invalid_type) { 'ssh-er0ck' } - it "should raise an error with an unknown type" do + it 'raises an error with an unknown type' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', type => '#{invalid_type}', key => 'mynewshinykey', target => '#{@sshkey_file}' }" expect { - apply_compiled_manifest(manifest) - }.to raise_error(Puppet::ResourceError, /Invalid value "#{invalid_type}"/) + apply_compiled_manifest(manifest) + }.to raise_error(Puppet::ResourceError, %r{Invalid value "#{invalid_type}"}) end - #single host_alias + # single host_alias let(:host_alias) { 'r0ckdata.com' } - it "should update an entry with new host_alias" do + it 'updates an entry with new host_alias' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', host_aliases => '#{host_alias}', target => '#{@sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(/#{sshkey_name},#{host_alias}\s/) - expect(File.read(@sshkey_file)).not_to match(/#{sshkey_name}\s/) + expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) + expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}\s}) end - #array host_alias - let(:host_aliases) { "r0ckdata.com,erict.net" } - it "should update an entry with new host_alias" do + # array host_alias + let(:host_aliases) { 'r0ckdata.com,erict.net' } + + it 'updates an entry with new host_alias' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', host_aliases => '#{host_alias}', target => '#{@sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(/#{sshkey_name},#{host_alias}\s/) - expect(File.read(@sshkey_file)).not_to match(/#{sshkey_name}\s/) + expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) + expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}\s}) end - #puppet resource sshkey - it "should fetch an entry from resources" do + # puppet resource sshkey + it 'fetches an entry from resources' do @resource_app = Puppet::Application[:resource] @resource_app.preinit - @resource_app.command_line.stubs(:args). - returns([type_under_test, sshkey_name, "target=#{@sshkey_file}"]) + @resource_app.command_line.stubs(:args) + .returns([type_under_test, sshkey_name, "target=#{@sshkey_file}"]) @resource_app.expects(:puts).with do |args| - expect(args).to match(/#{sshkey_name}/) + expect(args).to match(%r{#{sshkey_name}}) end @resource_app.main end - end - end -- cgit v1.2.3 From 2ea8606920156a3188def27f1ff906610f61f3a7 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Fri, 22 Jun 2018 09:44:42 -0700 Subject: Clean up Rubocop Lint/ScriptPermission violations --- spec/integration/provider/ssh_authorized_key_spec.rb | 2 -- spec/integration/provider/sshkey_spec.rb | 2 -- spec/unit/provider/sshkey/parsed_spec.rb | 1 - spec/unit/type/ssh_authorized_key_spec.rb | 1 - spec/unit/type/sshkey_spec.rb | 1 - 5 files changed, 7 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/ssh_authorized_key_spec.rb b/spec/integration/provider/ssh_authorized_key_spec.rb index 7dc40e3..397b609 100644 --- a/spec/integration/provider/ssh_authorized_key_spec.rb +++ b/spec/integration/provider/ssh_authorized_key_spec.rb @@ -1,5 +1,3 @@ -#! /usr/bin/env ruby - require 'spec_helper' require 'puppet/file_bucket/dipper' diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index 5328f85..ee74193 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -1,5 +1,3 @@ -#!/usr/bin/env ruby - require 'spec_helper' require 'puppet/file_bucket/dipper' require 'puppet_spec/files' diff --git a/spec/unit/provider/sshkey/parsed_spec.rb b/spec/unit/provider/sshkey/parsed_spec.rb index 3e7eade..6a86f0c 100644 --- a/spec/unit/provider/sshkey/parsed_spec.rb +++ b/spec/unit/provider/sshkey/parsed_spec.rb @@ -1,4 +1,3 @@ -#! /usr/bin/env ruby require 'spec_helper' describe 'sshkey parsed provider' do diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb index bc27b64..845cf46 100644 --- a/spec/unit/type/ssh_authorized_key_spec.rb +++ b/spec/unit/type/ssh_authorized_key_spec.rb @@ -1,4 +1,3 @@ -#! /usr/bin/env ruby require 'spec_helper' describe Puppet::Type.type(:ssh_authorized_key), unless: Puppet.features.microsoft_windows? do diff --git a/spec/unit/type/sshkey_spec.rb b/spec/unit/type/sshkey_spec.rb index af3b677..452610e 100644 --- a/spec/unit/type/sshkey_spec.rb +++ b/spec/unit/type/sshkey_spec.rb @@ -1,4 +1,3 @@ -#! /usr/bin/env ruby require 'spec_helper' describe Puppet::Type.type(:sshkey) do -- cgit v1.2.3 From 4345a09778021c45f92758d8b13b128c7c4732b1 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 08:27:03 -0700 Subject: Remove Rubocop RSpec/InstanceVariable violations --- spec/integration/provider/sshkey_spec.rb | 51 ++++++++++++++++--------------- spec/unit/type/ssh_authorized_key_spec.rb | 7 +++-- 2 files changed, 31 insertions(+), 27 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index ee74193..47af892 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -8,6 +8,8 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', include PuppetSpec::Files include PuppetSpec::Compiler + let(:sshkey_file) { tmpfile('sshkey_integration_specs') } + before :each do # Don't backup to filebucket Puppet::FileBucket::Dipper.any_instance.stubs(:backup) @@ -15,8 +17,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', described_class.stubs(:filetype) .returns Puppet::Util::FileType::FileTypeFlat - @sshkey_file = tmpfile('sshkey_integration_specs') - FileUtils.cp(my_fixture('sample'), @sshkey_file) + FileUtils.cp(my_fixture('sample'), sshkey_file) end after :each do @@ -44,18 +45,18 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => 'rsa', key => 'mykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{super_unique}.*mykey}) + expect(File.read(sshkey_file)).to match(%r{#{super_unique}.*mykey}) end let(:sshkey_name) { 'kirby.madstop.com' } it 'deletes an entry for an SSH host key' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'absent', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end it 'updates an entry for an SSH host key' do @@ -63,10 +64,10 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => 'rsa', key => 'mynewshinykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name}.*mynewshinykey}) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name}.*mynewshinykey}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end # test all key types @@ -87,15 +88,15 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => '#{type}', key => 'mynewshinykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) if aliases.key?(type) full_type = aliases[type] - expect(File.read(@sshkey_file)) + expect(File.read(sshkey_file)) .to match(%r{#{sshkey_name}.*#{full_type}.*mynew}) else - expect(File.read(@sshkey_file)) + expect(File.read(sshkey_file)) .to match(%r{#{sshkey_name}.*#{type}.*mynew}) end end @@ -108,7 +109,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => '#{invalid_type}', key => 'mynewshinykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" expect { apply_compiled_manifest(manifest) }.to raise_error(Puppet::ResourceError, %r{Invalid value "#{invalid_type}"}) @@ -120,10 +121,10 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', host_aliases => '#{host_alias}', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}\s}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}\s}) end # array host_alias @@ -133,23 +134,23 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', host_aliases => '#{host_alias}', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}\s}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}\s}) end # puppet resource sshkey it 'fetches an entry from resources' do - @resource_app = Puppet::Application[:resource] - @resource_app.preinit - @resource_app.command_line.stubs(:args) - .returns([type_under_test, sshkey_name, "target=#{@sshkey_file}"]) + resource_app = Puppet::Application[:resource] + resource_app.preinit + resource_app.command_line.stubs(:args) + .returns([type_under_test, sshkey_name, "target=#{sshkey_file}"]) - @resource_app.expects(:puts).with do |args| + resource_app.expects(:puts).with do |args| expect(args).to match(%r{#{sshkey_name}}) end - @resource_app.main + resource_app.main end end end diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb index 845cf46..ea32af9 100644 --- a/spec/unit/type/ssh_authorized_key_spec.rb +++ b/spec/unit/type/ssh_authorized_key_spec.rb @@ -169,8 +169,11 @@ describe Puppet::Type.type(:ssh_authorized_key), unless: Puppet.features.microso it 'informs about an absent user' do Puppet::Log.level = :debug - described_class.new(name: 'whev', user: 'idontexist').should(:target) - expect(@logs.map(&:message)).to include('The required user is not yet present on the system') + logs = [] + Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do + described_class.new(name: 'whev', user: 'idontexist').should(:target) + end + expect(logs.map(&:message)).to include('The required user is not yet present on the system') end end end -- cgit v1.2.3 From 7bda4caa4f26d379bc119e9c06f9b3685f20668c Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 08:47:52 -0700 Subject: Remove Rubocop RSpec/ScatteredLet violations --- spec/integration/provider/sshkey_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index 47af892..ffcf932 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -9,6 +9,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', include PuppetSpec::Compiler let(:sshkey_file) { tmpfile('sshkey_integration_specs') } + let(:type_under_test) { 'sshkey' } before :each do # Don't backup to filebucket @@ -25,10 +26,13 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', described_class.clear end - let(:type_under_test) { 'sshkey' } - describe 'when managing a ssh known hosts file it...' do + let(:host_alias) { 'r0ckdata.com' } + let(:host_aliases) { 'r0ckdata.com,erict.net' } + let(:invalid_type) { 'ssh-er0ck' } + let(:sshkey_name) { 'kirby.madstop.com' } let(:super_unique) { 'my.super.unique.host' } + it 'creates a new known_hosts file with mode 0644' do target = tmpfile('ssh_known_hosts') manifest = "#{type_under_test} { '#{super_unique}': @@ -50,7 +54,6 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', expect(File.read(sshkey_file)).to match(%r{#{super_unique}.*mykey}) end - let(:sshkey_name) { 'kirby.madstop.com' } it 'deletes an entry for an SSH host key' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'absent', @@ -103,7 +106,6 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', end # test unknown key type fails - let(:invalid_type) { 'ssh-er0ck' } it 'raises an error with an unknown type' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', @@ -116,7 +118,6 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', end # single host_alias - let(:host_alias) { 'r0ckdata.com' } it 'updates an entry with new host_alias' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', @@ -128,7 +129,6 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', end # array host_alias - let(:host_aliases) { 'r0ckdata.com,erict.net' } it 'updates an entry with new host_alias' do manifest = "#{type_under_test} { '#{sshkey_name}': -- cgit v1.2.3 From b848ea0ecd6e343f276499698100a9f84255308e Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 09:08:53 -0700 Subject: Fix duplicate test removing RSpec/RepeatedExample violation The "array host_alias" test was never actually testing against a list of host aliases, as it was using the exact same code as the "single host_alias" test. We now test against an actual array of host aliases in the manifest, and check that it is properly written out to the file. --- spec/integration/provider/sshkey_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index ffcf932..3f70dd2 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -28,7 +28,6 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', describe 'when managing a ssh known hosts file it...' do let(:host_alias) { 'r0ckdata.com' } - let(:host_aliases) { 'r0ckdata.com,erict.net' } let(:invalid_type) { 'ssh-er0ck' } let(:sshkey_name) { 'kirby.madstop.com' } let(:super_unique) { 'my.super.unique.host' } @@ -118,7 +117,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', end # single host_alias - it 'updates an entry with new host_alias' do + it 'updates an entry with a single new host_alias' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', host_aliases => '#{host_alias}', @@ -129,14 +128,13 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', end # array host_alias - - it 'updates an entry with new host_alias' do + it 'updates an entry with multiple new host_aliases' do manifest = "#{type_under_test} { '#{sshkey_name}': - ensure => 'present', - host_aliases => '#{host_alias}', - target => '#{sshkey_file}' }" + ensure => 'present', + host_aliases => [ 'r0ckdata.com', 'erict.net' ], + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name},r0ckdata\.com,erict\.net\s}) expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}\s}) end -- cgit v1.2.3 From 1e652d7083f6d372e5df547b4ac7d5dd28c7281d Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 09:10:44 -0700 Subject: Clean up hard tabs and whitespace --- spec/integration/provider/sshkey_spec.rb | 78 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 37 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index 3f70dd2..2d057b5 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -35,71 +35,75 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', it 'creates a new known_hosts file with mode 0644' do target = tmpfile('ssh_known_hosts') manifest = "#{type_under_test} { '#{super_unique}': - ensure => 'present', - type => 'rsa', - key => 'TESTKEY', - target => '#{target}' }" + ensure => 'present', + type => 'rsa', + key => 'TESTKEY', + target => '#{target}' }" apply_with_error_check(manifest) expect_file_mode(target, '644') end it 'creates an SSH host key entry (ensure present)' do manifest = "#{type_under_test} { '#{super_unique}': - ensure => 'present', - type => 'rsa', - key => 'mykey', - target => '#{sshkey_file}' }" + ensure => 'present', + type => 'rsa', + key => 'mykey', + target => '#{sshkey_file}' }" apply_with_error_check(manifest) expect(File.read(sshkey_file)).to match(%r{#{super_unique}.*mykey}) end it 'deletes an entry for an SSH host key' do manifest = "#{type_under_test} { '#{sshkey_name}': - ensure => 'absent', - target => '#{sshkey_file}' }" + ensure => 'absent', + target => '#{sshkey_file}' }" apply_with_error_check(manifest) expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end it 'updates an entry for an SSH host key' do manifest = "#{type_under_test} { '#{sshkey_name}': - ensure => 'present', - type => 'rsa', - key => 'mynewshinykey', - target => '#{sshkey_file}' }" + ensure => 'present', + type => 'rsa', + key => 'mynewshinykey', + target => '#{sshkey_file}' }" apply_with_error_check(manifest) expect(File.read(sshkey_file)).to match(%r{#{sshkey_name}.*mynewshinykey}) expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end # test all key types - types = ['ssh-dss', 'dsa', - 'ssh-ed25519', 'ed25519', - 'ssh-rsa', 'rsa', - 'ecdsa-sha2-nistp256', - 'ecdsa-sha2-nistp384', - 'ecdsa-sha2-nistp521'] + types = [ + 'ssh-dss', 'dsa', + 'ssh-ed25519', 'ed25519', + 'ssh-rsa', 'rsa', + 'ecdsa-sha2-nistp256', + 'ecdsa-sha2-nistp384', + 'ecdsa-sha2-nistp521' + ] # these types are treated as aliases for sshkey type # so they are populated as the *values* below - aliases = { 'dsa' => 'ssh-dss', - 'ed25519' => 'ssh-ed25519', - 'rsa' => 'ssh-rsa' } + aliases = { + 'dsa' => 'ssh-dss', + 'ed25519' => 'ssh-ed25519', + 'rsa' => 'ssh-rsa' + } types.each do |type| it "should update an entry with #{type} type" do manifest = "#{type_under_test} { '#{sshkey_name}': - ensure => 'present', - type => '#{type}', - key => 'mynewshinykey', - target => '#{sshkey_file}' }" + ensure => 'present', + type => '#{type}', + key => 'mynewshinykey', + target => '#{sshkey_file}' }" apply_with_error_check(manifest) if aliases.key?(type) full_type = aliases[type] expect(File.read(sshkey_file)) - .to match(%r{#{sshkey_name}.*#{full_type}.*mynew}) + .to match(%r{#{sshkey_name}.*#{full_type}.*mynew}) else expect(File.read(sshkey_file)) - .to match(%r{#{sshkey_name}.*#{type}.*mynew}) + .to match(%r{#{sshkey_name}.*#{type}.*mynew}) end end end @@ -107,10 +111,10 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', # test unknown key type fails it 'raises an error with an unknown type' do manifest = "#{type_under_test} { '#{sshkey_name}': - ensure => 'present', - type => '#{invalid_type}', - key => 'mynewshinykey', - target => '#{sshkey_file}' }" + ensure => 'present', + type => '#{invalid_type}', + key => 'mynewshinykey', + target => '#{sshkey_file}' }" expect { apply_compiled_manifest(manifest) }.to raise_error(Puppet::ResourceError, %r{Invalid value "#{invalid_type}"}) @@ -119,9 +123,9 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', # single host_alias it 'updates an entry with a single new host_alias' do manifest = "#{type_under_test} { '#{sshkey_name}': - ensure => 'present', - host_aliases => '#{host_alias}', - target => '#{sshkey_file}' }" + ensure => 'present', + host_aliases => '#{host_alias}', + target => '#{sshkey_file}' }" apply_with_error_check(manifest) expect(File.read(sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}\s}) @@ -143,7 +147,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', resource_app = Puppet::Application[:resource] resource_app.preinit resource_app.command_line.stubs(:args) - .returns([type_under_test, sshkey_name, "target=#{sshkey_file}"]) + .returns([type_under_test, sshkey_name, "target=#{sshkey_file}"]) resource_app.expects(:puts).with do |args| expect(args).to match(%r{#{sshkey_name}}) -- cgit v1.2.3 From b2e901c13d1b151ab38b54a544d70ea3c2fe0d1d Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 09:14:58 -0700 Subject: Remove Rubocop RSpec/DescribeMethod violations --- spec/integration/provider/ssh_authorized_key_spec.rb | 2 +- spec/integration/provider/sshkey_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/ssh_authorized_key_spec.rb b/spec/integration/provider/ssh_authorized_key_spec.rb index 397b609..a493918 100644 --- a/spec/integration/provider/ssh_authorized_key_spec.rb +++ b/spec/integration/provider/ssh_authorized_key_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'puppet/file_bucket/dipper' -describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration)', unless: Puppet.features.microsoft_windows? do +describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), unless: Puppet.features.microsoft_windows? do include PuppetSpec::Files let :fake_userfile do diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index 2d057b5..ebe80fb 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -3,8 +3,7 @@ require 'puppet/file_bucket/dipper' require 'puppet_spec/files' require 'puppet_spec/compiler' -describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', - unless: Puppet.features.microsoft_windows? do +describe Puppet::Type.type(:sshkey).provider(:parsed), unless: Puppet.features.microsoft_windows? do include PuppetSpec::Files include PuppetSpec::Compiler -- cgit v1.2.3 From e31c621d5da4203d4ad1bf254de3132b964a47f0 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 09:21:27 -0700 Subject: Disable Rubocop RSpec/AnyInstance check for specific instances There isn't really a clean way to disable FileBucket backups without stubbing any_instance in these cases. --- spec/integration/provider/ssh_authorized_key_spec.rb | 2 +- spec/integration/provider/sshkey_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/ssh_authorized_key_spec.rb b/spec/integration/provider/ssh_authorized_key_spec.rb index a493918..fd3ce10 100644 --- a/spec/integration/provider/ssh_authorized_key_spec.rb +++ b/spec/integration/provider/ssh_authorized_key_spec.rb @@ -70,7 +70,7 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), unless: Puppe end def run_in_catalog(*resources) - Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # Don't backup to the filebucket + Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # rubocop:disable RSpec/AnyInstance catalog = Puppet::Resource::Catalog.new catalog.host_config = false resources.each do |resource| diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index ebe80fb..cd1f9bb 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -12,7 +12,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), unless: Puppet.features.m before :each do # Don't backup to filebucket - Puppet::FileBucket::Dipper.any_instance.stubs(:backup) + Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # rubocop:disable RSpec/AnyInstance # We don't want to execute anything described_class.stubs(:filetype) .returns Puppet::Util::FileType::FileTypeFlat -- cgit v1.2.3 From 9ba23f8b8694d8c0b80f7ee66c0bc2152ad0da76 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 09:39:09 -0700 Subject: Disable Rubocop Metrics/LineLength check for SSH key lines SSH keys are long, and splitting them into multiple lines can be error-prone, so we'll just disable the Metrics/LineLength check for lines that are SSH keys. --- spec/integration/provider/ssh_authorized_key_spec.rb | 4 ++++ spec/unit/provider/sshkey/parsed_spec.rb | 2 +- spec/unit/type/ssh_authorized_key_spec.rb | 10 ++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/ssh_authorized_key_spec.rb b/spec/integration/provider/ssh_authorized_key_spec.rb index fd3ce10..784415c 100644 --- a/spec/integration/provider/ssh_authorized_key_spec.rb +++ b/spec/integration/provider/ssh_authorized_key_spec.rb @@ -12,6 +12,7 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), unless: Puppe tmpfile('authorized_keys.root') end + # rubocop:disable Metrics/LineLength let :sample_rsa_keys do [ 'AAAAB3NzaC1yc2EAAAADAQABAAAAgQCi18JBZOq10X3w4f67nVhO0O3s5Y1vHH4UgMSM3ZnQwbC5hjGyYSi9UULOoQQoQynI/a0I9NL423/Xk/XJVIKCHcS8q6V2Wmjd+fLNelOjxxoW6mbIytEt9rDvwgq3Mof3/m21L3t2byvegR00a+ikKbmInPmKwjeWZpexCIsHzQ==', # 1024 bit @@ -19,12 +20,15 @@ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), unless: Puppe 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDLygAO6txXkh9FNV8xSsBkATeqLbHzS7sFjGI3gt0Dx6q3LjyKwbhQ1RLf28kd5G6VWiXmClU/RtiPdUz8nrGuun++2mrxzrXrvpR9dq1lygLQ2wn2cI35dN5bjRMtXy3decs6HUhFo9MoNwX250rUWfdCyNPhGIp6OOfmjdy+UeLGNxq9wDx6i4bT5tVVSqVRtsEfw9+ICXchzl85QudjneVVpP+thriPZXfXA5eaGwAo/dmoKOIhUwF96gpdLqzNtrGQuxPbV80PTbGv9ZtAtTictxaDz8muXO7he9pXmchUpxUKtMFjHkL0FAZ9tRPmv3RA30sEr2fZ8+LKvnE50w0' # 2048 Bit ] end + # rubocop:enable Metrics/LineLength + # rubocop:disable Metrics/LineLength let :sample_dsa_keys do [ 'AAAAB3NzaC1kc3MAAACBAOPck2O8MIDSqxPSnvENt6tzRrKJ5oOhB6Nc6oEcWm+VEH1gvuxdiRqwoMgRwyEf1yUd+UAcLw3a6Jn+EtFyEBN/5WF+4Tt4xTxZ0Pfik2Wc5uqHbQ2dkmOoXiAOYPiD3JUQ1Xwm/J0CgetjitoLfzAGdCNhMqguqAuHcVJ78ZZbAAAAFQCIBKFYZ+I18I+dtgteirXh+VVEEwAAAIEAs1yvQ/wnLLrRCM660pF4kBiw3D6dJfMdCXWQpn0hZmkBQSIzZv4Wuk3giei5luxscDxNc+y3CTXtnyG4Kt1Yi2sOdvhRI3rX8tD+ejn8GHazM05l5VIo9uu4AQPIE32iV63IqgApSBbJ6vDJW91oDH0J492WdLCar4BS/KE3cRwAAACBAN0uSDyJqYLRsfYcFn4HyVf6TJxQm1IcwEt6GcJVzgjri9VtW7FqY5iBqa9B9Zdh5XXAYJ0XLsWQCcrmMHM2XGHGpA4gL9VlCJ/0QvOcXxD2uK7IXwAVUA7g4V4bw8EVnFv2Flufozhsp+4soo1xiYc5jiFVHwVlk21sMhAtKAeF' # 1024 Bit ] end + # rubocop:enable Metrics/LineLength let :sample_lines do [ diff --git a/spec/unit/provider/sshkey/parsed_spec.rb b/spec/unit/provider/sshkey/parsed_spec.rb index 436b632..6442183 100644 --- a/spec/unit/provider/sshkey/parsed_spec.rb +++ b/spec/unit/provider/sshkey/parsed_spec.rb @@ -11,7 +11,7 @@ describe 'sshkey parsed provider' do end def key - 'AAAAB3NzaC1yc2EAAAABIwAAAQEAzwHhxXvIrtfIwrudFqc8yQcIfMudrgpnuh1F3AV6d2BrLgu/yQE7W5UyJMUjfj427sQudRwKW45O0Jsnr33F4mUw+GIMlAAmp9g24/OcrTiB8ZUKIjoPy/cO4coxGi8/NECtRzpD/ZUPFh6OEpyOwJPMb7/EC2Az6Otw4StHdXUYw22zHazBcPFnv6zCgPx1hA7QlQDWTu4YcL0WmTYQCtMUb3FUqrcFtzGDD0ytosgwSd+JyN5vj5UwIABjnNOHPZ62EY1OFixnfqX/+dUwrFSs5tPgBF/KkC6R7tmbUfnBON6RrGEmu+ajOTOLy23qUZB4CQ53V7nyAWhzqSK+hw==' + 'AAAAB3NzaC1yc2EAAAABIwAAAQEAzwHhxXvIrtfIwrudFqc8yQcIfMudrgpnuh1F3AV6d2BrLgu/yQE7W5UyJMUjfj427sQudRwKW45O0Jsnr33F4mUw+GIMlAAmp9g24/OcrTiB8ZUKIjoPy/cO4coxGi8/NECtRzpD/ZUPFh6OEpyOwJPMb7/EC2Az6Otw4StHdXUYw22zHazBcPFnv6zCgPx1hA7QlQDWTu4YcL0WmTYQCtMUb3FUqrcFtzGDD0ytosgwSd+JyN5vj5UwIABjnNOHPZ62EY1OFixnfqX/+dUwrFSs5tPgBF/KkC6R7tmbUfnBON6RrGEmu+ajOTOLy23qUZB4CQ53V7nyAWhzqSK+hw==' # rubocop:disable Metrics/LineLength end it 'parses the name from the first field' do diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb index ea32af9..e375f58 100644 --- a/spec/unit/type/ssh_authorized_key_spec.rb +++ b/spec/unit/type/ssh_authorized_key_spec.rb @@ -86,17 +86,23 @@ describe Puppet::Type.type(:ssh_authorized_key), unless: Puppet.features.microso end describe 'for key' do + # rubocop:disable Metrics/LineLength it 'supports a valid key like a 1024 bit rsa key' do expect { described_class.new(name: 'whev', type: :rsa, user: 'nobody', key: 'AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCPfzW2ry7XvMc6E5Kj2e5fF/YofhKEvsNMUogR3PGL/HCIcBlsEjKisrY0aYgD8Ikp7ZidpXLbz5dBsmPy8hJiBWs5px9ZQrB/EOQAwXljvj69EyhEoGawmxQMtYw+OAIKHLJYRuk1QiHAMHLp5piqem8ZCV2mLb9AsJ6f7zUVw==') }.not_to raise_error end + # rubocop:enable Metrics/LineLength + # rubocop:disable Metrics/LineLength it 'supports a valid key like a 4096 bit rsa key' do - expect { described_class.new(name: 'whev', type: :rsa, user: 'nobody', key: 'AAAAB3NzaC1yc2EAAAADAQABAAACAQDEY4pZFyzSfRc9wVWI3DfkgT/EL033UZm/7x1M+d+lBD00qcpkZ6CPT7lD3Z+vylQlJ5S8Wcw6C5Smt6okZWY2WXA9RCjNJMIHQbJAzwuQwgnwU/1VMy9YPp0tNVslg0sUUgpXb13WW4mYhwxyGmIVLJnUrjrQmIFhtfHsJAH8ZVqCWaxKgzUoC/YIu1u1ScH93lEdoBPLlwm6J0aiM7KWXRb7Oq1nEDZtug1zpX5lhgkQWrs0BwceqpUbY+n9sqeHU5e7DCyX/yEIzoPRW2fe2Gx1Iq6JKM/5NNlFfaW8rGxh3Z3S1NpzPHTRjw8js3IeGiV+OPFoaTtM1LsWgPDSBlzIdyTbSQR7gKh0qWYCNV/7qILEfa0yIFB5wIo4667iSPZw2pNgESVtenm8uXyoJdk8iWQ4mecdoposV/znknNb2GPgH+n/2vme4btZ0Sl1A6rev22GQjVgbWOn8zaDglJ2vgCN1UAwmq41RXprPxENGeLnWQppTnibhsngu0VFllZR5kvSIMlekLRSOFLFt92vfd+tk9hZIiKm9exxcbVCGGQPsf6dZ27rTOmg0xM2Sm4J6RRKuz79HQgA4Eg18+bqRP7j/itb89DmtXEtoZFAsEJw8IgIfeGGDtHTkfAlAC92mtK8byeaxGq57XCTKbO/r5gcOMElZHy1AcB8kw==') }.not_to raise_error + expect { described_class.new(name: 'whev', type: :rsa, user: 'nobody', key: 'AAAAB3NzaC1yc2EAAAADAQABAAACAQDEY4pZFyzSfRc9wVWI3DfkgT/EL033UZm/7x1M+d+lBD00qcpkZ6CPT7lD3Z+vylQlJ5S8Wcw6C5Smt6okZWY2WXA9RCjNJMIHQbJAzwuQwgnwU/1VMy9YPp0tNVslg0sUUgpXb13WW4mYhwxyGmIVLJnUrjrQmIFhtfHsJAH8ZVqCWaxKgzUoC/YIu1u1ScH93lEdoBPLlwm6J0aiM7KWXRb7Oq1nEDZtug1zpX5lhgkQWrs0BwceqpUbY+n9sqeHU5e7DCyX/yEIzoPRW2fe2Gx1Iq6JKM/5NNlFfaW8rGxh3Z3S1NpzPHTRjw8js3IeGiV+OPFoaTtM1LsWgPDSBlzIdyTbSQR7gKh0qWYCNV/7qILEfa0yIFB5wIo4667iSPZw2pNgESVtenm8uXyoJdk8iWQ4mecdoposV/znknNb2GPgH+n/2vme4btZ0Sl1A6rev22GQjVgbWOn8zaDglJ2vgCN1UAwmq41RXprPxENGeLnWQppTnibhsngu0VFllZR5kvSIMlekLRSOFLFt92vfd+tk9hZIiKm9exxcbVCGGQPsf6dZ27rTOmg0xM2Sm4J6RRKuz79HQgA4Eg18+bqRP7j/itb89DmtXEtoZFAsEJw8IgIfeGGDtHTkfAlAC92mtK8byeaxGq57XCTKbO/r5gcOMElZHy1AcB8kw==') }.not_to raise_error # rubocop:disable Metrics/LineLength end + # rubocop:enable Metrics/LineLength + # rubocop:disable Metrics/LineLength it 'supports a valid key like a 1024 bit dsa key' do - expect { described_class.new(name: 'whev', type: :dsa, user: 'nobody', key: 'AAAAB3NzaC1kc3MAAACBAI80iR78QCgpO4WabVqHHdEDigOjUEHwIjYHIubR/7u7DYrXY+e+TUmZ0CVGkiwB/0yLHK5dix3Y/bpj8ZiWCIhFeunnXccOdE4rq5sT2V3l1p6WP33RpyVYbLmeuHHl5VQ1CecMlca24nHhKpfh6TO/FIwkMjghHBfJIhXK+0w/AAAAFQDYzLupuMY5uz+GVrcP+Kgd8YqMmwAAAIB3SVN71whLWjFPNTqGyyIlMy50624UfNOaH4REwO+Of3wm/cE6eP8n75vzTwQGBpJX3BPaBGW1S1Zp/DpTOxhCSAwZzAwyf4WgW7YyAOdxN3EwTDJZeyiyjWMAOjW9/AOWt9gtKg0kqaylbMHD4kfiIhBzo31ZY81twUzAfN7angAAAIBfva8sTSDUGKsWWIXkdbVdvM4X14K4gFdy0ZJVzaVOtZ6alysW6UQypnsl6jfnbKvsZ0tFgvcX/CPyqNY/gMR9lyh/TCZ4XQcbqeqYPuceGehz+jL5vArfqsW2fJYFzgCcklmr/VxtP5h6J/T0c9YcDgc/xIfWdZAlznOnphI/FA==') }.not_to raise_error + expect { described_class.new(name: 'whev', type: :dsa, user: 'nobody', key: 'AAAAB3NzaC1kc3MAAACBAI80iR78QCgpO4WabVqHHdEDigOjUEHwIjYHIubR/7u7DYrXY+e+TUmZ0CVGkiwB/0yLHK5dix3Y/bpj8ZiWCIhFeunnXccOdE4rq5sT2V3l1p6WP33RpyVYbLmeuHHl5VQ1CecMlca24nHhKpfh6TO/FIwkMjghHBfJIhXK+0w/AAAAFQDYzLupuMY5uz+GVrcP+Kgd8YqMmwAAAIB3SVN71whLWjFPNTqGyyIlMy50624UfNOaH4REwO+Of3wm/cE6eP8n75vzTwQGBpJX3BPaBGW1S1Zp/DpTOxhCSAwZzAwyf4WgW7YyAOdxN3EwTDJZeyiyjWMAOjW9/AOWt9gtKg0kqaylbMHD4kfiIhBzo31ZY81twUzAfN7angAAAIBfva8sTSDUGKsWWIXkdbVdvM4X14K4gFdy0ZJVzaVOtZ6alysW6UQypnsl6jfnbKvsZ0tFgvcX/CPyqNY/gMR9lyh/TCZ4XQcbqeqYPuceGehz+jL5vArfqsW2fJYFzgCcklmr/VxtP5h6J/T0c9YcDgc/xIfWdZAlznOnphI/FA==') }.not_to raise_error # rubocop:disable Metrics/LineLength end + # rubocop:enable Metrics/LineLength it "doesn't support whitespaces" do expect { described_class.new(name: 'whev', type: :rsa, user: 'nobody', key: 'AAA FA==') }.to raise_error(Puppet::Error, %r{Key must not contain whitespace}) -- cgit v1.2.3 From 76a4dfb9a976799317206e40bb85b9c398996863 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 09:45:54 -0700 Subject: Remove Rubocop Style/TrailingCommaInLiteral violation --- spec/integration/provider/sshkey_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index cd1f9bb..770825b 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -85,7 +85,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), unless: Puppet.features.m aliases = { 'dsa' => 'ssh-dss', 'ed25519' => 'ssh-ed25519', - 'rsa' => 'ssh-rsa' + 'rsa' => 'ssh-rsa', } types.each do |type| it "should update an entry with #{type} type" do -- cgit v1.2.3 From 9da73bb9720df51c796dab64267f72fe999c9280 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 25 Jun 2018 09:50:56 -0700 Subject: Remove Rubocop Layout/MultilineMethodCallIndentation violations --- spec/integration/provider/sshkey_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'spec/integration/provider') diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index 770825b..4a3bf87 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -98,11 +98,9 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), unless: Puppet.features.m apply_with_error_check(manifest) if aliases.key?(type) full_type = aliases[type] - expect(File.read(sshkey_file)) - .to match(%r{#{sshkey_name}.*#{full_type}.*mynew}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name}.*#{full_type}.*mynew}) else - expect(File.read(sshkey_file)) - .to match(%r{#{sshkey_name}.*#{type}.*mynew}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name}.*#{type}.*mynew}) end end end @@ -145,8 +143,9 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), unless: Puppet.features.m it 'fetches an entry from resources' do resource_app = Puppet::Application[:resource] resource_app.preinit - resource_app.command_line.stubs(:args) - .returns([type_under_test, sshkey_name, "target=#{sshkey_file}"]) + resource_app.command_line + .stubs(:args) + .returns([type_under_test, sshkey_name, "target=#{sshkey_file}"]) resource_app.expects(:puts).with do |args| expect(args).to match(%r{#{sshkey_name}}) -- cgit v1.2.3