Permalink
Browse files

Merge pull request #131 from cvicente/issue-130

Fix for issue #130
  • Loading branch information...
cvicente committed Nov 8, 2018
2 parents aed2a2d + fcafb90 commit 099ae9836596705d09e7db1737629a0366ad88d5
Showing with 29 additions and 6 deletions.
  1. +1 −2 lib/Netdot/Model/RR.pm
  2. +4 −2 lib/Netdot/Model/RRMX.pm
  3. +24 −2 t/RR.t
@@ -387,11 +387,10 @@ sub update_ptr {
sub delete {
my $self = shift;
$self->isa_object_method('delete');
my $class = ref($self);
my @cnames = RRCNAME->search(cname=>$self->get_label);
my @mxs = RRMX->search(exchange=>$self->get_label);
foreach my $o ( @cnames, @mxs ){
$o->rr->delete() if ($o->rr->get_label ne $self->get_label);
$o->delete();
}
return $self->SUPER::delete();
}
@@ -167,10 +167,12 @@ sub _validate_args {
if ( $name eq $domain ){
$name = '@';
}
my $rr = RR->search(name=>$name, zone=>$z)->first ||
my $mxrr = RR->search(name=>$name, zone=>$z)->first;
unless ( $mxrr ){
$self->throw_user("Exchange ".$argv->{exchange}.
" within active zone '$domain', but name '$name' does not exist");
unless ( $rr->a_records ){
}
unless ( $mxrr->a_records ){
$self->throw_user("Exchange ".$argv->{exchange}.
" has no address (A or AAAA) records");
}
26 t/RR.t
@@ -1,5 +1,6 @@
use strict;
use Test::More qw(no_plan);
use Test::Exception;
use lib "lib";
BEGIN {
@@ -15,14 +16,15 @@ my $domain = 'testdomain';
my $domainrev = '168.192.in-addr.arpa';
my $v4address = '192.168.1.10';
my $v6address = 'fec0:1234:5678:9abc::10';
my $mailaddr = '192.168.1.99';
sub cleanup{
foreach my $val (($domain, $domainrev)){
if ( my $obj = Zone->search(name=>$val)->first ){
$obj->delete();
}
}
foreach my $val (($v4address, $v6address)){
foreach my $val (($v4address, $v6address, $mailaddr)){
if ( my $obj = Ipblock->search(address=>$val)->first ){
$obj->delete();
}
@@ -46,7 +48,7 @@ is(RR->search(name=>$name, zone=>$domain)->first, $rr, 'search_domain_as_name');
is(RR->search(name=>"$name.$domain")->first, $rr, 'search_as_fqdn' );
is($rr->get_label, "$name.$domain", 'get_label');
# Labels longer that 63 characters shoud throw a user exception
# Labels longer that 63 characters should throw a user exception
my $long_name = '1234567890123456789012345678901234567890123456789012345678901234';
eval{
RR->insert({name=>$long_name, zone=>$domain});
@@ -91,6 +93,26 @@ my $rrmx = RR->insert({type=>'MX', name=>$name, zone=>$domain, ttl=>3600, prefer
isa_ok($rrmx, 'Netdot::Model::RRMX', 'insert_mx');
is($rrmx->as_text, "$name.$domain. 3600 IN MX 10 smtp.example.net.", 'as_text');
# When exchage points to an A record in Netdot
throws_ok {
RR->insert({type=>'MX', name=>$name, zone=>$domain,
ttl=>3600, preference=>10, exchange=>"mail.$domain"});
} qr/does not exist/, 'fails if exchange within local zone does not exist';
my $mail_rr = RR->insert({type=>'A', name=>'mail', zone=>$domain,
ttl=>3600, ipblock=>$mailaddr });
my $rrmx2 = RR->insert({type=>'MX', name=>$name, zone=>$domain,
ttl=>3600, preference=>20, exchange=>"mail.$domain"});
isa_ok($rrmx2, 'Netdot::Model::RRMX', 'insert_mx2');
# Issue #130
$mail_rr->delete();
is(RR->search(name=>$name, zone=>$domain)->first, $rraddr->rr,
'Deleting MX host does not delete RR that references it');
is(RRMX->search(exchange=>"mail.$domain"), 0, 'MX pointing to deleted host gets deleted');
# RRNAPTR
my $rrnaptr = RR->insert({type=>'NAPTR', name=>'@', zone=>$domain, ttl=>3600, order_field=>"100", preference=>"10", flags=>"u", services=>"E2U+sip",
regexpr=>'^.*$', replacement=>'sip:information@pbx.example.com'});

0 comments on commit 099ae98

Please sign in to comment.