Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for checking sender address #75

Merged
merged 1 commit into from
Jul 29, 2018

Conversation

smortex
Copy link
Member

@smortex smortex commented Jul 24, 2018

Pull Request (PR) description

The Debian Stretch template use a hardcoded sender address: fail2ban@localhost.

This PR use the sender address configured with $fail2ban::sender instead.

The Debian Stetch template used to have a static sender address, ignoring $fail2ban::sender. This problem was addressed as a side effect of #77 but a unit-test for the correct behavior still makes sense.

This Pull Request (PR) fixes the following issues

n/a

@smortex
Copy link
Member Author

smortex commented Jul 24, 2018

Transient Travis-CI failure 🙄 Trying to be much more lucky by closing/reopening PR…

@smortex smortex closed this Jul 24, 2018
@smortex smortex reopened this Jul 24, 2018
@@ -72,7 +72,7 @@ destemail = <%= scope['::fail2ban::email'] %>
sendername = Fail2Ban

# Email address of the sender
sender = fail2ban@localhost
sender = <%= scope['::fail2ban::sender'] %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please use @fail2ban::sender to access the variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant $fail2ban::sender, but this is an erb template, not an epp one 😃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The desired way to access a variable in an erb template is @class::variable:
https://puppet.com/docs/puppet/5.5/lang_template_erb.html#variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested to be absolutely certain that it is not working as expected in erb.

@fail2ban is nil, and nil::sender is basically nil.sender, so:

fail2ban
  on debian-9-x86_64
    fail2ban::config
      when content template
        should contain File[fail2ban.conf] with ensure => "present", content =~ /THIS FILE IS MANAGED BY PUPPET/, notify => "Service[fail2ban]", require => "Package[fail2ban]" and content =~ /^chain = INPUT$/ (FAILED - 1)
      when content template (custom)
        should contain File[fail2ban.conf] with ensure => "present", content =~ /THIS FILE IS MANAGED BY PUPPET/, notify => "Service[fail2ban]", require => "Package[fail2ban]" and content =~ /^chain = INPUT$/ (FAILED - 2)
      when iptables chain provided
        should contain File[fail2ban.conf] with content =~ /^chain = TEST$/ (FAILED - 3)
      when custom banaction is provided
        should contain File[fail2ban.conf] with content =~ /^banaction = iptables$/ (FAILED - 4)
[...]
Failures:

  1) fail2ban on debian-9-x86_64 fail2ban::config when content template should contain File[fail2ban.conf] with ensure => "present", content =~ /THIS FILE IS MANAGED BY PUPPET/, notify => "Service[fail2ban]", require => "Package[fail2ban]" and content =~ /^chain = INPUT$/
     Failure/Error: return call_function('template', template_name) unless template_name.end_with?('.epp')
     
     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Function Call, Failed to parse template fail2ban/stretch/etc/fail2ban/jail.conf.erb:
         Filepath: /usr/home/romain/Projects/puppet/modules/fail2ban/spec/fixtures/modules/fail2ban/templates/stretch/etc/fail2ban/jail.conf.erb
         Line: 75
         Detail: undefined method `sender' for nil:NilClass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That maybe doesn't work because sender isn't a variable within the fail2ban::jail class. let's stick with the scope way.

@bastelfreak bastelfreak added the bug Something isn't working label Jul 24, 2018
@bastelfreak
Copy link
Member

Hi @smortex, thanks for the fix. Can you please add a test that sets the variable and verifies the file content?

@bastelfreak
Copy link
Member

#76 this just got merged and should fix your travis issues. Can you please rebase against our latest master?

@smortex smortex force-pushed the stretch-sender branch 2 times, most recently from 3058979 to ff28921 Compare July 25, 2018 06:19
@smortex smortex changed the title Fix sender address in Debian Stretch template [WIP] Fix sender address in Debian Stretch template Jul 25, 2018
@smortex smortex force-pushed the stretch-sender branch 2 times, most recently from c9ad604 to 5234c39 Compare July 25, 2018 09:14
@smortex smortex changed the title [WIP] Fix sender address in Debian Stretch template Fix sender address in Debian Stretch template Jul 25, 2018
@smortex
Copy link
Member Author

smortex commented Jul 25, 2018

@bastelfreak I added a commit that adds an acceptance test to show the problem on top of master, then moved the commit you previously saw on top if this to fix the issue.

@bastelfreak
Copy link
Member

@smortex can you please rebase? Afterwards I can merge this.

@smortex
Copy link
Member Author

smortex commented Jul 29, 2018

@bastelfreak I am working on it ;-) #77 has superseded these changes, but the unit test for checking the sender may still make sense.

@smortex smortex changed the title Fix sender address in Debian Stretch template Add unit test for checking sender address Jul 29, 2018
@smortex
Copy link
Member Author

smortex commented Jul 29, 2018

@bastelfreak I just rebased the branch on top of master with all that was added today \o/.

Thank you for the hard work :-)

@bastelfreak bastelfreak removed the bug Something isn't working label Jul 29, 2018
@bastelfreak
Copy link
Member

Thanks!

@bastelfreak bastelfreak merged commit cc06b72 into voxpupuli:master Jul 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants