Skip to content

Commit

Permalink
Fix DNS name server blocker
Browse files Browse the repository at this point in the history
Case RE-318:  Updated to check name server type the system is
configured to use in order to determine whether to block on it.

Changelog: Fix DNS blocker to check the systems name server type.
  • Loading branch information
timmullin committed Apr 23, 2024
1 parent d4f83fa commit be45c60
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
10 changes: 9 additions & 1 deletion elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -957,14 +957,22 @@ EOS
our @ISA;
BEGIN { push @ISA, qw(Elevate::Blockers::Base); }

use Cpanel::Config::LoadCpConf ();

use Cwd ();

# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }

sub check ($self) {

return $self->_blocker_non_bind_powerdns;
return $self->_blocker_non_bind_powerdns( _get_nameserver_type() );
}

sub _get_nameserver_type () {

my $cpconf = Cpanel::Config::LoadCpConf::loadcpconf();
return $cpconf->{'local_nameserver_type'} // '';
}

sub _blocker_non_bind_powerdns ( $self, $nameserver = '' ) {
Expand Down
10 changes: 9 additions & 1 deletion lib/Elevate/Blockers/DNS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ use Elevate::Constants ();

use parent qw{Elevate::Blockers::Base};

use Cpanel::Config::LoadCpConf ();

use Cwd ();
use Log::Log4perl qw(:easy);

sub check ($self) {

return $self->_blocker_non_bind_powerdns;
return $self->_blocker_non_bind_powerdns( _get_nameserver_type() );
}

sub _get_nameserver_type () {

my $cpconf = Cpanel::Config::LoadCpConf::loadcpconf();
return $cpconf->{'local_nameserver_type'} // '';
}

sub _blocker_non_bind_powerdns ( $self, $nameserver = '' ) {
Expand Down
23 changes: 18 additions & 5 deletions t/blocker-dns.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ use cPstrict;
my $cpev_mock = Test::MockModule->new('cpev');
my $dns_mock = Test::MockModule->new('Elevate::Blockers::DNS');

my $cpconf;
my $conf_mock = Test::MockModule->new('Cpanel::Config::LoadCpConf');
$conf_mock->redefine(
loadcpconf => sub { return $cpconf; },
);

my $cpev = cpev->new;
my $dns = $cpev->get_blocker('DNS');

{
for my $os ( 'cent', 'cloud' ) {
set_os_to($os);
my $expected_target_os = $os eq 'cent' ? 'AlmaLinux 8' : 'CloudLinux 8';
$cpconf = { 'local_nameserver_type' => 'nsd' };
is(
$dns->_blocker_non_bind_powerdns('nsd'),
$dns->check(),
{
id => q[Elevate::Blockers::DNS::_blocker_non_bind_powerdns],
msg => <<~"EOS",
Expand All @@ -39,8 +46,9 @@ my $dns = $cpev->get_blocker('DNS');
'nsd nameserver is a blocker.'
);

$cpconf = { 'local_nameserver_type' => 'mydns' };
is(
$dns->_blocker_non_bind_powerdns('mydns'),
$dns->check(),
{
id => q[Elevate::Blockers::DNS::_blocker_non_bind_powerdns],
msg => <<~"EOS",
Expand All @@ -51,9 +59,14 @@ my $dns = $cpev->get_blocker('DNS');
'mydns nameserver is a blocker.'
);

is( $dns->_blocker_non_bind_powerdns('bind'), 0, "if they use bind, we're ok" );
is( $dns->_blocker_non_bind_powerdns('powerdns'), 0, "if they use powerdns, we're ok" );
is( $dns->_blocker_non_bind_powerdns('disabled'), 0, "if they use no dns, we're ok" );
$cpconf = {};
is( $dns->check(), 0, "Nothing set, we're ok" );
$cpconf = { 'local_nameserver_type' => 'bind' };
is( $dns->check(), 0, "if they use bind, we're ok" );
$cpconf = { 'local_nameserver_type' => 'powerdns' };
is( $dns->check(), 0, "if they use powerdns, we're ok" );
$cpconf = { 'local_nameserver_type' => 'disabled' };
is( $dns->check(), 0, "if they use no dns, we're ok" );
}
}

Expand Down

0 comments on commit be45c60

Please sign in to comment.