Skip to content

Commit

Permalink
Adapt to rubocop 1.22
Browse files Browse the repository at this point in the history
Comply with new rubocop configuration
  • Loading branch information
traylenator committed Mar 22, 2022
1 parent 99aa23d commit 9c887b4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 51 deletions.
9 changes: 8 additions & 1 deletion spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

case fact('osfamily')
Expand Down Expand Up @@ -75,13 +77,16 @@ class { 'fail2ban':
describe package(package_name) do
it { is_expected.not_to be_installed }
end

describe file(config_file_path) do
it { is_expected.to be_file }
end

describe service(service_name) do
it { is_expected.not_to be_running }
# The docker images of Debian do not use systemd, the following test
# cannot be performed on these images.

it { is_expected.not_to be_enabled } if fact('osfamily') != 'Debian'
end
end
Expand All @@ -102,9 +107,11 @@ class { 'fail2ban':
describe package(package_name) do
it { is_expected.not_to be_installed }
end

describe file(config_file_path) do
it { is_expected.not_to be_file }
end

describe service(service_name) do
it { is_expected.not_to be_running }
it { is_expected.not_to be_enabled }
Expand Down Expand Up @@ -243,6 +250,7 @@ class { 'fail2ban': }
expect(fail2ban_status.output).to contain ssh_jail
end
end

context 'when service start/stop notification are disabled' do
it 'is expected.to have empty sshd actions' do
pp = <<-EOS
Expand All @@ -265,6 +273,5 @@ class { 'fail2ban':
end
end
end
# rubocop:enable RSpec/MultipleExpectations
end
end
66 changes: 36 additions & 30 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'fail2ban', type: :class do
Expand Down Expand Up @@ -53,13 +55,15 @@
'ensure' => 'absent'
)
end

it do
is_expected.to contain_file('fail2ban.conf').with(
'ensure' => 'present',
'notify' => 'Service[fail2ban]',
'ensure' => 'present',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end

it do
is_expected.to contain_service('fail2ban').with(
'ensure' => 'stopped',
Expand All @@ -82,13 +86,15 @@
'ensure' => 'purged'
)
end

it do
is_expected.to contain_file('fail2ban.conf').with(
'ensure' => 'absent',
'notify' => 'Service[fail2ban]',
'ensure' => 'absent',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end

it do
is_expected.to contain_service('fail2ban').with(
'ensure' => 'stopped',
Expand All @@ -102,8 +108,8 @@
context 'defaults' do
it do
is_expected.to contain_file('fail2ban.conf').with(
'ensure' => 'present',
'notify' => 'Service[fail2ban]',
'ensure' => 'present',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -118,12 +124,12 @@

it do
is_expected.to contain_file('fail2ban.dir').with(
'ensure' => 'directory',
'force' => false,
'purge' => false,
'ensure' => 'directory',
'force' => false,
'purge' => false,
'recurse' => true,
'source' => 'puppet:///modules/profile/fail2ban/etc/fail2ban',
'notify' => 'Service[fail2ban]',
'source' => 'puppet:///modules/profile/fail2ban/etc/fail2ban',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -139,12 +145,12 @@

it do
is_expected.to contain_file('fail2ban.dir').with(
'ensure' => 'directory',
'force' => true,
'purge' => true,
'ensure' => 'directory',
'force' => true,
'purge' => true,
'recurse' => true,
'source' => 'puppet:///modules/profile/fail2ban/etc/fail2ban',
'notify' => 'Service[fail2ban]',
'source' => 'puppet:///modules/profile/fail2ban/etc/fail2ban',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -159,9 +165,9 @@

it do
is_expected.to contain_file('fail2ban.conf').with(
'ensure' => 'present',
'source' => 'puppet:///modules/profile/fail2ban/etc/fail2ban/jail.conf',
'notify' => 'Service[fail2ban]',
'ensure' => 'present',
'source' => 'puppet:///modules/profile/fail2ban/etc/fail2ban/jail.conf',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -176,9 +182,9 @@

it do
is_expected.to contain_file('fail2ban.conf').with(
'ensure' => 'present',
'ensure' => 'present',
'content' => %r{THIS FILE IS MANAGED BY PUPPET},
'notify' => 'Service[fail2ban]',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -193,9 +199,9 @@

it do
is_expected.to contain_file('fail2ban.conf').with(
'ensure' => 'present',
'ensure' => 'present',
'content' => %r{THIS FILE IS MANAGED BY PUPPET},
'notify' => 'Service[fail2ban]',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
).with_content(%r{^chain = INPUT$})
end
Expand All @@ -213,9 +219,9 @@

it do
is_expected.to contain_file('fail2ban.conf').with(
'ensure' => 'present',
'ensure' => 'present',
'content' => %r{THIS FILE IS MANAGED BY PUPPET},
'notify' => 'Service[fail2ban]',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
).with_content(%r{^chain = INPUT$})
end
Expand All @@ -232,9 +238,9 @@

it do
is_expected.to contain_file('00-firewalld.conf').with(
'ensure' => 'present',
'path' => '/etc/fail2ban/jail.d/00-firewalld.conf',
'notify' => 'Service[fail2ban]',
'ensure' => 'present',
'path' => '/etc/fail2ban/jail.d/00-firewalld.conf',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -249,8 +255,8 @@

it do
is_expected.to contain_file('defaults-debian.conf').with(
'ensure' => 'present',
'path' => '/etc/fail2ban/jail.d/defaults-debian.conf',
'ensure' => 'present',
'path' => '/etc/fail2ban/jail.d/defaults-debian.conf',
'require' => 'Package[fail2ban]'
)
end
Expand Down
20 changes: 11 additions & 9 deletions spec/defines/define_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'fail2ban::define', type: :define do
Expand All @@ -19,9 +21,9 @@

it do
is_expected.to contain_file('define_fail2ban.conf').with(
'ensure' => 'present',
'source' => 'puppet:///modules/fail2ban/Debian/10/etc/fail2ban/jail.conf',
'notify' => 'Service[fail2ban]',
'ensure' => 'present',
'source' => 'puppet:///modules/fail2ban/Debian/10/etc/fail2ban/jail.conf',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -36,9 +38,9 @@

it do
is_expected.to contain_file('define_fail2ban.conf').with(
'ensure' => 'present',
'ensure' => 'present',
'content' => %r{THIS FILE IS MANAGED BY PUPPET},
'notify' => 'Service[fail2ban]',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
)
end
Expand All @@ -53,9 +55,9 @@

it do
is_expected.to contain_file('define_fail2ban.conf').with(
'ensure' => 'present',
'ensure' => 'present',
'content' => %r{THIS FILE IS MANAGED BY PUPPET},
'notify' => 'Service[fail2ban]',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
).with_content(%r{^chain = INPUT$})
end
Expand All @@ -73,9 +75,9 @@

it do
is_expected.to contain_file('define_fail2ban.conf').with(
'ensure' => 'present',
'ensure' => 'present',
'content' => %r{THIS FILE IS MANAGED BY PUPPET},
'notify' => 'Service[fail2ban]',
'notify' => 'Service[fail2ban]',
'require' => 'Package[fail2ban]'
).with_content(%r{^chain = INPUT$})
end
Expand Down
24 changes: 13 additions & 11 deletions spec/defines/fail2ban_jail_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'fail2ban::jail' do
Expand All @@ -12,9 +14,9 @@

let(:params) do
{
'logpath' => '/var/log/syslog',
'filter_failregex' => 'Login failed for user .* from <HOST>',
'filter_maxlines' => 10,
'logpath' => '/var/log/syslog',
'filter_failregex' => 'Login failed for user .* from <HOST>',
'filter_maxlines' => 10,
'filter_datepattern' => '%%Y-%%m-%%d %%H:%%M(?::%%S)?'
}
end
Expand All @@ -25,32 +27,32 @@

it do
is_expected.to contain_file('custom_jail_spec_test_jail').with(
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'content' => %r{\[spec_test_jail\]}
)
end

it do
is_expected.to contain_file('custom_filter_spec_test_jail').with(
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'content' => %r{failregex = Login failed for user .* from <HOST>}
)
end

it do
is_expected.to contain_file('custom_filter_spec_test_jail').with(
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'content' => %r{maxlines = 10}
)
end

it do
is_expected.to contain_file('custom_filter_spec_test_jail').with(
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'content' => %r{datepattern = %%Y-%%m-%%d %%H:%%M(?::%%S)?}
)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'voxpupuli/acceptance/spec_helper_acceptance'

configure_beaker do |host|
Expand Down

0 comments on commit 9c887b4

Please sign in to comment.