Ignore:
Timestamp:
01/15/26 11:29:54 (12 days ago)
Author:
Kris Deugau
Message:

/branches/cname-collision

Added specific test for CNAME colliding with a record that has a valid-after
timestamp in the past.

  • additional test record
  • adjusted timestamp-retrieval SQL
  • extend logic tree for this case

See #72, #88

Location:
branches/cname-collision
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/cname-collision/DNSDB.pm

    r983 r984  
    665665    # Check timestamps of pending active-after records.  Coerce expires-at fields to soonest match if found.
    666666    if ($args{defrec} eq 'n') {
    667       $sql = "SELECT extract(epoch from stamp) FROM "._rectable($args{defrec}, $args{revrec}).
    668        " WHERE "._recparent($args{defrec}, $args{revrec})." = ? AND type $tcompare 5 AND $hfield = ?".
    669        " AND stampactive = 't' AND expires = 'f' AND stamp >= now() ";
     667      $sql = "SELECT extract(epoch from stamp),stamp < now() FROM "._rectable($args{defrec}, $args{revrec}).
     668        " WHERE "._recparent($args{defrec}, $args{revrec})." = ? AND type $tcompare 5 AND $hfield = ?".
     669        " AND stampactive = 't' AND expires = 'f'";
    670670      my @lookupargs = ($args{id}, $hcheck);
    671671      if ($args{update}) {
    672         $sql .= "AND record_id <> ? ";
     672        $sql .= " AND record_id <> ?";
    673673        push @lookupargs, $args{update};
    674674      }
    675       $sql .= "ORDER BY stamp LIMIT 1";
     675      $sql .= " ORDER BY stamp LIMIT 1";
    676676      my @t = $dbh->selectrow_array($sql, undef, @lookupargs);
    677677      if (@t) {
     
    693693          }
    694694        } else {
    695           # no expiry requested, but we found a valid-after, so coerce the new record down to expiring at that time
    696           ${$args{stamp}} = strftime('%Y-%m-%d %H:%M:%S', localtime($t[0]));
    697           ${$args{expires}} = 't';
    698           return ('WARN', "CNAME added with expiry time;  conflicting valid-after record found");
     695          if ($t[1]) {
     696            return('FAIL', "Cannot add CNAME, a record with a valid-after time in the past is already present");
     697          } else {
     698            # no expiry requested, but we found a valid-after, so coerce the new record down to expiring at that time
     699            ${$args{stamp}} = strftime('%Y-%m-%d %H:%M:%S', localtime($t[0]));
     700            ${$args{expires}} = 't';
     701            return ('WARN', "CNAME added with expiry time;  conflicting valid-after record found");
     702          }
    699703        }
    700704      }
  • branches/cname-collision/t/cname.t

    r982 r984  
    226226      }
    227227    };
    228     subtest '  - collision with active-after record' => sub {
     228    subtest '  - collision with pending active-after record' => sub {
    229229      $newname = 'active-after1.expiry1.test';
    230230      ($code, $msg) = $dnsdb->addRec('n', 'n', 4, \$newname, \$rectype, \$newval, 900);
     
    243243      }
    244244    };
     245    subtest '  - collision with active active-after record' => sub {
     246      $newname = 'active-after2.expiry1.test';
     247      ($code, $msg) = $dnsdb->addRec('n', 'n', 4, \$newname, \$rectype, \$newval, 900);
     248      ok( $code eq 'FAIL', "addRec() claimed failure" );
     249      if ($code eq 'FAIL') {
     250        ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = 4 AND host = '$newname' AND type <> 5");
     251        ok( $rcount == 1, " ... [$rcount] record(s) with $newname already exist" );
     252        like( $msg, qr/record with a valid-after time in the past/, " ... returned matching error" );
     253      }
     254    };
    245255  }; # add non-timestamp CNAME
    246256
  • branches/cname-collision/t/dns-unitbase.sql

    r976 r984  
    6576572       example.org     1               1       2025121800      D       f       ac
    6586583       example.net     1               1       2025121800      D       f       ab
    659 4       expiry1.test    1               1       2026010702      D       t       
     6594       expiry1.test    1               1       2026011400      D       t       
    660660\.
    661661
     
    76476457      4       1       1       admin   Initial User    Added record 'expired2.expiry1.test TXT imma expire soon', TTL 5400, expires at 2026-01-10 07:00        2026-01-07 17:57:07.015962-05   0       0
    76576558      4       1       1       admin   Initial User    Added record 'active-after1.expiry1.test TXT not active yet', TTL 5400, valid after 2026-01-11 11:30    2026-01-07 18:12:57.491476-05   0       0
     76659      4       1       1       admin   Initial User    Added record 'active-after2.expiry1.test TXT I'm done waiting', TTL 5400, expires at 2025-12-31 14:00   2026-01-14 18:02:13.876839-05   0       0
    766767\.
    767768
     
    771772--
    772773
    773 SELECT pg_catalog.setval('public.log_log_id_seq', 58, true);
     774SELECT pg_catalog.setval('public.log_log_id_seq', 59, true);
    774775
    775776
     
    8618624       48      expired2.expiry1.test   16      imma expire soon        0       0       0       5400    \N      0               2026-01-10 07:00:00-05  t       t       \N
    8628634       49      active-after1.expiry1.test      16      not active yet  0       0       0       5400    \N      0               2026-01-11 11:30:00-05  f       t       \N
     8644       50      active-after2.expiry1.test      16      I'm done waiting        0       0       0       5400    \N      0               2025-12-31 14:00:00-05  f       t       \N
    863865\.
    864866
     
    868870--
    869871
    870 SELECT pg_catalog.setval('public.records_record_id_seq', 49, true);
     872SELECT pg_catalog.setval('public.records_record_id_seq', 50, true);
    871873
    872874
  • branches/cname-collision/t/test-cname-timestamps.sql

    r979 r984  
    66UPDATE records SET stamp = date_trunc('day', now() + interval '3 day') + '07:00' WHERE record_id = 48;
    77UPDATE records SET stamp = date_trunc('day', now() + interval '5 day') + '11:30' WHERE record_id = 49;
     8UPDATE records SET stamp = date_trunc('day', now() - interval '3 day') + '14:00' WHERE record_id = 50;
Note: See TracChangeset for help on using the changeset viewer.