/**
  * Create a resource record from a Line
  *
  * @param Line $line
  * @return ResourceRecord
  */
 private function lineToRr(Line $line)
 {
     $rr = new ResourceRecord();
     if (null !== ($class = Interpreter::getClassFromLine($line->getData()))) {
         $rr->setClass($class);
     }
     $rr->setRdata($this->getRData($line->getData()));
     $rr->setComment($line->getComment());
     $rr->setName(Interpreter::getResourceNameFromLine($line->getData()));
     return $rr;
 }
Exemple #2
0
 public function testSettersAndGetters()
 {
     $rr = new ResourceRecord();
     $name = 'test';
     $ttl = 3500;
     $comment = 'Hello';
     $a = Factory::A('192.168.7.7');
     $rr->setName($name);
     $rr->setClass(Classes::INTERNET);
     $rr->setRdata($a);
     $rr->setTtl($ttl);
     $rr->setComment($comment);
     $this->assertEquals($a, $rr->getRdata());
     $this->assertEquals($name, $rr->getName());
     $this->assertEquals($ttl, $rr->getTtl());
     $this->assertEquals($comment, $rr->getComment());
     $this->assertEquals($a->getType(), $rr->getType());
 }
Exemple #3
0
 /**
  * @expectedException \Badcow\DNS\ZoneException
  * @expectedExceptionMessage There must be exactly one type of class, 2 given.
  */
 public function testValidateNumberOfClasses()
 {
     $zone = $this->buildTestZone();
     $a = new ResourceRecord();
     $a->setName('test');
     $a->setClass(Classes::CHAOS);
     $a->setRdata(Factory::A('192.168.0.1'));
     $a->setComment('This class does not belong here');
     $zone->addResourceRecord($a);
     Validator::validate($zone);
 }
Exemple #4
0
 /**
  * @return Zone
  */
 protected function buildTestZone()
 {
     $soa = new ResourceRecord();
     $soa->setClass('IN');
     $soa->setName('@');
     $soa->setRdata(Factory::Soa('example.com.', 'postmaster.example.com.', 2015050801, 3600, 14400, 604800, 3600, false));
     $ns1 = new ResourceRecord();
     $ns1->setClass('IN');
     $ns1->setName('@');
     $ns1->setTtl(14400);
     $ns1->setRdata(Factory::Ns('ns1.example.net.au.'));
     $ns2 = new ResourceRecord();
     $ns2->setClass('IN');
     $ns2->setName('@');
     $ns2->setTtl(14400);
     $ns2->setRdata(Factory::Ns('ns2.example.net.au.'));
     $a_record = new ResourceRecord();
     $a_record->setName('subdomain.au');
     $a_record->setRdata(Factory::A('192.168.1.2'));
     $a_record->setComment('This is a local ip.');
     $cname = new ResourceRecord();
     $cname->setName('alias');
     $cname->setRdata(Factory::Cname('subdomain.au.example.com.'));
     $aaaa = new ResourceRecord('ipv6domain', Factory::Aaaa('::1'), 3600, Classes::INTERNET, 'This is an IPv6 domain.');
     $mx1 = new ResourceRecord();
     $mx1->setName('@');
     $mx1->setRdata(Factory::Mx(10, 'mail-gw1.example.net.'));
     $mx2 = new ResourceRecord();
     $mx2->setName('@');
     $mx2->setRdata(Factory::Mx(20, 'mail-gw2.example.net.'));
     $mx3 = new ResourceRecord();
     $mx3->setName('@');
     $mx3->setRdata(Factory::Mx(30, 'mail-gw3.example.net.'));
     $txt = new ResourceRecord();
     $txt->setName('example.net.');
     $txt->setRdata(Factory::txt('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all'));
     $txt->setClass(Classes::INTERNET);
     $loc = new ResourceRecord();
     $loc->setName('canberra');
     $loc->setRdata(Factory::Loc(-35.3075, 149.1244, 500, 20.12, 200.3, 300.1));
     $loc->setComment('This is Canberra');
     $loc->setClass(Classes::INTERNET);
     $dname = new ResourceRecord();
     $dname->setName('bar.example.com.');
     $dname->setClass(Classes::INTERNET);
     $dname->setRdata(Factory::Dname('foo.example.com.'));
     $hinfo = new ResourceRecord();
     $hinfo->setName('@');
     $hinfo->setClass(Classes::INTERNET);
     $hinfo->setRdata(Factory::Hinfo('2.7GHz', 'Ubuntu 12.04'));
     return new Zone('example.com.', 3600, [$soa, $ns1, $ns2, $a_record, $aaaa, $loc, $dname, $mx3, $mx1, $mx2, $cname, $txt, $hinfo]);
 }
Exemple #5
0
 public function testCompareResourceRecords()
 {
     $soa = new ResourceRecord();
     $soa->setClass('IN');
     $soa->setName('@');
     $soa->setRdata(Factory::Soa('example.com.', 'postmaster.example.com.', 2015050801, 3600, 14400, 604800, 3600));
     $ns1 = new ResourceRecord();
     $ns1->setClass(Classes::INTERNET);
     $ns1->setName('@');
     $ns1->setTtl(14400);
     $ns1->setRdata(Factory::Ns('ns1.example.net.au.'));
     $ns2 = new ResourceRecord();
     $ns2->setClass('IN');
     $ns2->setName('@');
     $ns2->setTtl(14400);
     $ns2->setRdata(Factory::Ns('ns2.example.net.au.'));
     $a = new ResourceRecord();
     $a->setName('subdomain.au');
     $a->setRdata(Factory::A('192.168.1.2'));
     $a->setComment('This is a local ip.');
     $cname = new ResourceRecord();
     $cname->setName('alias');
     $cname->setRdata(Factory::Cname('subdomain.au.example.com.'));
     $cname->setClass(Classes::INTERNET);
     $aaaa = new ResourceRecord('ipv6domain', Factory::Aaaa('::1'), 3600);
     $mx1 = new ResourceRecord();
     $mx1->setName('@');
     $mx1->setRdata(Factory::Mx(10, 'mailgw01.example.net.'));
     $mx2 = new ResourceRecord();
     $mx2->setName('@');
     $mx2->setRdata(Factory::Mx(20, 'mailgw02.example.net.'));
     $txt = new ResourceRecord();
     $txt->setName('example.net.');
     $txt->setRdata(Factory::txt('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all'));
     $dummy = new ResourceRecord();
     $dummy->setName('example.com.');
     $dummy->setRdata(new DummyRdata());
     $this->assertTrue(AlignedBuilder::compareResourceRecords($soa, $ns1) < 0);
     $this->assertTrue(AlignedBuilder::compareResourceRecords($aaaa, $cname) < 0);
     $this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $mx2) < 0);
     $this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $mx2) < 0);
     $this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $dummy) < 0);
     $this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $a) > 0);
     $this->assertTrue(AlignedBuilder::compareResourceRecords($ns2, $ns1) > 0);
     $this->assertTrue(AlignedBuilder::compareResourceRecords($dummy, $txt) > 0);
 }