Skip to content

Commit

Permalink
Make auth column be set to 1 rather than NULL, set ordername
Browse files Browse the repository at this point in the history
Tests and some subleties needs to be fixed for both; fixes #25, fixes #17
Related: #28, #29, #26
  • Loading branch information
abh committed Apr 28, 2012
1 parent cf4552f commit bcbf8d4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ namespace::clean
Test::More
Try::Tiny
Net::DNS
Net::DNS::SEC
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Try::Tiny = 0
[Prereqs / TestRequires ]
Test::More = 0
Net::DNS = 0
Net::DNS::SEC = 0.16

[@Git]
# push_to = all
Expand Down
6 changes: 5 additions & 1 deletion lib/PowerDNS/API/Handler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,17 @@ sub post_record {
$data->{$f} = $self->param($f);
}
$data->{type} = uc $data->{type};
$data->{name} = lc $domain->clean_hostname( $data->{name} );
$data->{ordername} = $data->{name};
$data->{name} = $domain->clean_hostname( $data->{name} );
unless (defined $data->{ttl}) {
$data->{ttl} = $data->{type} eq 'NS' ? 86400 : 7200;
}

$data->{change_date} = time;

# TODO: 0 for NS and glue records, see issue #29
$data->{auth} = 1;

my $record = $domain->add_to_records($data);
$domain->increment_serial;

Expand Down
1 change: 1 addition & 0 deletions lib/PowerDNS/API/Schema/Role/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sub soa {
{ domain_id => $self->id,
name => $self->name,
type => 'SOA',
auth => 1,
change_date => time,
}
);
Expand Down
1 change: 1 addition & 0 deletions t/domain.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ok(my $cas = $domain->cas, 'got cas');

ok( $domain = $schema->domain->find( { name => $domain_name }));
is( $domain->soa->serial, $serial, "serial is $serial" );
is( $domain->soa->auth, 1, 'soa auth is 1');
is( $domain->cas, $cas, "cas is the same");

is( $domain->soa->default_ttl, 3600, "got the default ttl");
Expand Down
34 changes: 25 additions & 9 deletions t/live.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ diag "Config: ", pp($db_config);

my $pdns_pid = fork();
if (!$pdns_pid) {
my @cmd = ($pdns_path, "--guardian=no", "--launch=gmysql", "--local-port=$port", "--socket-dir=/tmp");
push @cmd, "--gmysql-user=$db_config->{user}" if $db_config->{user};
push @cmd, "--gmysql-dbname=$db_config->{database}" if $db_config->{database};
exec(@cmd);
die "Could not exec " . join(" ", @cmd) . ": $!";

my @cmd = (
$pdns_path, "--guardian=no",
"--local-port=$port", "--socket-dir=/tmp",
"--launch=gmysql", "--gmysql-dnssec",
);

push @cmd, "--gmysql-user=$db_config->{user}" if $db_config->{user};
push @cmd, "--gmysql-dbname=$db_config->{database}" if $db_config->{database};
push @cmd, "--gmysql-password=$db_config->{password}" if $db_config->{password};
exec(@cmd);
die "Could not exec " . join(" ", @cmd) . ": $!";
}

sleep 1;
Expand All @@ -42,6 +49,9 @@ my $res = Net::DNS::Resolver->new(
recurse => 0
);

#$res->dnssec(1);
#$res->cdflag(1);

my $domain = test_domain_name;
my $slave_domain = "slave-$domain";

Expand All @@ -56,11 +66,9 @@ my $r;
ok($r = api_call(PUT => "domain/$domain", { user => $account }), 'setup new domain');
$t->status_is(201, 'ok, created');

diag(pp($r->{domain}));

{
my $a = $res->send($domain, 'SOA');
diag(pp($a));
#diag(pp($a));

my $soa = ($a->answer)[0];
isa_ok($soa, 'Net::DNS::RR', 'DNS answer is a Net::DNS::RR');
Expand All @@ -71,7 +79,15 @@ diag(pp($r->{domain}));
is($dns_serial, $r->{domain}->{soa}->{serial}, "got serial");
}

# diag pp($r);
ok($r = api_call(POST => "record/$domain", { type => 'A', name => 'wwW', content => '10.0.0.1' }), 'setup A record');
$t->status_is(201, 'ok, created');

#diag(pp($r->{record}));
{
my $a = $res->query("WWW." . $domain, 'A');
is($a->answer && ($a->answer)[0]->address, '10.0.0.1', 'got correct A record back');
}


$account->delete;
$account2->delete;
Expand Down

0 comments on commit bcbf8d4

Please # to comment.