Ignore:
Timestamp:
02/18/26 18:17:35 (33 hours ago)
Author:
Kris Deugau
Message:

/branches/cname-collision

First block of actual tests - add nonexpiring non-CNAME
See #72, #88

File:
1 edited

Legend:

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

    r1031 r1042  
    585585
    586586
     587## Double-check non-CNAMEs colliding with CNAMEs, and not each other
     588subtest "New records colliding with CNAMEs" => sub {
     589  $rectype = 1;  # Any type will do, since all the checks based on type are "CNAME" and "not-CNAME"
     590
     591  subtest "Non-expiring new record" => sub {
     592    subtest "New record vs non-CNAME" => sub {
     593      $newname = 'blocker01.cname-blocks1.test';
     594      $newval = '192.168.2.1';
     595      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900);
     596      ok( $code eq 'OK', "addRec() claimed succeess" );
     597      if ($code eq 'OK') {
     598        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     599        ok( $rcount == 2, " ... [$rcount] yep, hostname now occurs twice" );
     600      } else {
     601        print "not ok: $msg";
     602      }
     603    };
     604    subtest "New record vs non-timestamped CNAME" => sub {
     605      $newname = 'blocker02.cname-blocks1.test';
     606      $newval = '192.168.2.2';
     607      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900);
     608      cmp_ok( $code, 'eq', 'FAIL', "addRec() claimed failure" );
     609      if ($code eq 'FAIL') {
     610        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     611        cmp_ok( $rcount, '==', 1, " ... [$rcount] record(s) with $newname already exist" );
     612        like( $msg, qr/There is already a CNAME present/, " ... returned matching error" );
     613      }
     614    };
     615    subtest "New record vs expiring CNAME" => sub {
     616      $newname = 'blocker03.cname-blocks1.test';
     617      $newval = '192.168.2.3';
     618      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900);
     619      cmp_ok( $code, 'eq', 'FAIL', "addRec() claimed failure" );
     620      if ($code eq 'FAIL') {
     621        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     622        cmp_ok( $rcount, '==', 1, " ... [$rcount] record(s) with $newname already exist" );
     623        like( $msg, qr/There is already a CNAME with a timestamp present/, " ... returned matching error" );
     624      }
     625    };
     626    subtest "New record vs valid-after CNAME" => sub {
     627      $newname = 'blocker04.cname-blocks1.test';
     628      $newval = '192.168.2.4';
     629      ($code, $msg) = $dnsdb->addRec('n', 'n', 7, \$newname, \$rectype, \$newval, 900);
     630      cmp_ok( $code, 'eq', 'FAIL', "addRec() claimed failure" );
     631      if ($code eq 'FAIL') {
     632        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 7 AND host = '$newname'");
     633        cmp_ok( $rcount, '==', 1, " ... [$rcount] record(s) with $newname already exist" );
     634        like( $msg, qr/There is already a CNAME with a timestamp present/, " ... returned matching error" );
     635      }
     636    };
     637  }; # non-expiring non-CNAMEs
     638
     639}; # non-CNAMEs colliding with CNAMEs
     640
     641
    587642done_testing();
Note: See TracChangeset for help on using the changeset viewer.