Ignore:
Timestamp:
02/20/26 13:42:37 (28 hours ago)
Author:
Kris Deugau
Message:

/branches/cname-collision

Add a second non-CNAME validating non-collision with non-CNAMEs
Add the block of tests checking collisions between a new expiring record
and various existing CNAMEs
See #72, #88

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cname-collision/t/cname.t

    r1044 r1045  
    390390  ## - to misquote Rincewind, "Don't worry about from ... The important word is to.")
    391391  ## Update to CNAME with no timestamp
    392  subtest 'Update to CNAME - no timestamp' => sub {
     392  subtest 'Update to CNAME - no timestamp' => sub {
    393393    $newval = 'target.example.com';
    394394    subtest 'collision with expired record' => sub {
     
    600600        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
    601601        ok( $rcount == 2, " ... [$rcount] yep, hostname now occurs twice" );
     602        # and test another record of another type Just In Case
     603        my $secondtype = 28;
     604        $newval = '2001:db8::eeee';
     605        ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$secondtype, \$newval, 900);
     606        ok( $code eq 'OK', "addRec() claimed succeess" );
     607        if ($code eq 'OK') {
     608          ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     609          ok( $rcount == 3, " ... [$rcount] yep, hostname now occurs three times" );
     610        } else {
     611          print "not ok: $msg";
     612        }
    602613      } else {
    603614        print "not ok: $msg";
     
    639650  }; # non-expiring non-CNAMEs
    640651
     652  subtest "Expiring new record" => sub {
     653    my @ltime = localtime(time + 86400 * 3);
     654    $expirystamp = sprintf "%i-%i-%i %i:%i", $ltime[5] + 1900, ($ltime[4] + 1) % 12, $ltime[3], 15, $ltime[1];
     655    subtest "New record vs non-timestamped CNAME" => sub {
     656      $newname = 'blocker05.cname-blocks1.test';
     657      $newval = '192.168.2.5';
     658      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900, undef, 't', $expirystamp);
     659      ok($code eq 'FAIL', "addRec() claimed failure");
     660      if ($code eq 'FAIL') {
     661        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     662        ok( $rcount == 1, " ... [$rcount] yep, hostname only occurs once" );
     663        like( $msg, qr/There is already a CNAME present/, " ... returned matching error" );
     664      }
     665    };
     666    subtest "New record vs expiring CNAME" => sub {
     667      $newname = 'blocker06.cname-blocks1.test';
     668      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900, undef, 't', $expirystamp);
     669      ok( $code eq 'FAIL', "addRec() claimed failure");
     670      if ($code eq 'FAIL') {
     671        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     672        ok( $rcount == 1, " ... [$rcount] record(s) with $newname already exist" );
     673        like( $msg, qr/There is already a CNAME with a timestamp present/, " ... returned matching error" );
     674      }
     675    };
     676    subtest "New record expiring after valid-after CNAME" => sub {
     677      $newname = 'blocker07.cname-blocks1.test';
     678      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900, undef, 't', $expirystamp);
     679      cmp_ok( $code, 'eq', 'WARN', "addRec() claimed success with warning" );
     680      if ($code eq 'WARN') {
     681        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     682        ok( $rcount == 2, " ... [$rcount] correct number of records for $newname" );
     683        like( $msg, qr/added with modified expiry time;  conflicting valid-after record found/, " ... returned appropriate warning message" );
     684        my ($newstamp) = $dbh->selectrow_array("SELECT stamp FROM records WHERE domain_id = 7 AND host = '$newname' ".
     685                "AND stampactive = 't' AND expires = 't' AND type = 1");
     686        my ($oldstamp) = $dbh->selectrow_array("SELECT stamp FROM records WHERE domain_id = 7 AND host = '$newname' ".
     687                "AND stampactive = 't' AND expires = 'f'");
     688        ok( $newstamp eq $oldstamp, " ... coerced timestamp matches existing active-after timestamp" );
     689        # second record
     690        my $secondtype = 28;
     691        $newval = '2001:db8::eeee';
     692        ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$secondtype, \$newval, 900, undef, 't', $expirystamp);
     693        cmp_ok( $code, 'eq', 'WARN', "second addRec() claimed success with warning" );
     694        if ($code eq 'WARN') {
     695          ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     696          ok( $rcount == 3, " ... [$rcount] correct number of records for $newname" );
     697          like( $msg, qr/added with modified expiry time;  conflicting valid-after record found/, " ... returned appropriate warning message" );
     698          my ($newstamp) = $dbh->selectrow_array("SELECT stamp FROM records WHERE domain_id = 7 AND host = '$newname' ".
     699                "AND stampactive = 't' AND expires = 't' AND type = 28");
     700          my ($oldstamp) = $dbh->selectrow_array("SELECT stamp FROM records WHERE domain_id = 7 AND host = '$newname' ".
     701                "AND stampactive = 't' AND expires = 'f'");
     702          ok( $newstamp eq $oldstamp, " ... coerced timestamp matches existing active-after timestamp" );
     703        } else {
     704          print "not ok: $msg";
     705        }
     706      } else {
     707        print "not ok: $msg";
     708      }
     709    };
     710    subtest "New record expires before valid-after CNAME" => sub {
     711      $newname = 'blocker08.cname-blocks1.test';
     712      $newval = '192.168.2.8';
     713      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900, undef, 't', $expirystamp);
     714      ok( $code eq 'OK', "addRec() claimed succeess" );
     715      if ($code eq 'OK') {
     716        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     717        ok( $rcount == 2, " ... [$rcount] yep, hostname now occurs twice" );
     718        my ($newstamp) = $dbh->selectrow_array("SELECT extract(epoch from stamp) FROM records WHERE domain_id = 7 AND host = '$newname' ".
     719                "AND stampactive = 't' AND expires = 't' AND type = 1");
     720        my ($oldstamp) = $dbh->selectrow_array("SELECT extract(epoch from stamp) FROM records WHERE domain_id = 7 AND host = '$newname' ".
     721                "AND stampactive = 't' AND expires = 'f'");
     722        ok( $newstamp <= $oldstamp, " ... added record expires before existing active-after record goes active" );
     723        # second record
     724        my $secondtype = 28;
     725        $newval = '2001:db8::eeee';
     726        ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$secondtype, \$newval, 900, undef, 't', $expirystamp);
     727        ok( $code eq 'OK', "second addRec() claimed succeess" );
     728        if ($code eq 'OK') {
     729          ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     730          ok( $rcount == 3, " ... [$rcount] yep, hostname now occurs three times" );
     731          my ($newstamp) = $dbh->selectrow_array("SELECT extract(epoch from stamp) FROM records WHERE domain_id = 7 AND host = '$newname' ".
     732                "AND stampactive = 't' AND expires = 't' AND type = 28");
     733          my ($oldstamp) = $dbh->selectrow_array("SELECT extract(epoch from stamp) FROM records WHERE domain_id = 7 AND host = '$newname' ".
     734                "AND stampactive = 't' AND expires = 'f'");
     735          ok( $newstamp <= $oldstamp, " ... added record expires before existing active-after record goes active" );
     736        } else {
     737          print "not ok: $msg";
     738        }
     739      } else {
     740        print "not ok: $msg";
     741      }
     742    };
     743  }; # expiring non-CNAMEs
     744
    641745}; # non-CNAMEs colliding with CNAMEs
    642746
Note: See TracChangeset for help on using the changeset viewer.