Skip to content

Commit

Permalink
Merge branch 'fix-rr'
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelwilliams committed May 2, 2019
2 parents 91e6aa7 + 4b2abbd commit 56e4456
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/Validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Validation
==========

Very little validation is done automatically when setting RData or Resource Record objects, so the onus is on the
implementor to validate the resource data and the zone record. Contained within the library, however, are some useful
validation tools. These are static functions contained within `Badcow\DNS\Validator` (here, simply referred to as
`Validator`).

## Validate the Zone
`Validator::zone()` will inspect a number of properties of a Zone, namely:
* There is exactly one SOA record,
* There are NS records, and
* There is exactly one record class (while it is permissible to use obsolete classes such as CHAOS, in all modern
contexts, this is always IN).

The return value is a binary sum of error codes which can be determined using boolean operands. A valid zone will
return `0`, AKA `Validator::ZONE_OKAY`. _Exempli gratia:_
```php
$zone //Some Badcow\DNS\Zone
if (Validator::zone($zone) & Validator::ZONE_NO_SOA) echo "There are no SOA Records";
if (Validator::zone($zone) & Validator::ZONE_TOO_MANY_CLASSES) echo "There are too many classes.";
```

The return codes are:
* `ZONE_NO_SOA`
* `ZONE_TOO_MANY_SOA`
* `ZONE_NO_NS`
* `ZONE_NO_CLASS`
* `ZONE_TOO_MANY_CLASSES`
* `ZONE_OKAY`

12 changes: 12 additions & 0 deletions tests/ResourceRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ public function testSettersAndGetters()
$this->assertEquals($comment, $rr->getComment());
$this->assertEquals($a->getType(), $rr->getType());
}

public function testUnsetTtl()
{
$rr = new ResourceRecord('example.com.');
$ttl = 10800;

$this->assertNull($rr->getTtl());
$rr->setTtl($ttl);
$this->assertEquals($ttl, $rr->getTtl());
$rr->setTtl(null);
$this->assertNull($rr->getTtl());
}
}

0 comments on commit 56e4456

Please sign in to comment.