* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Badcow\DNS\Tests\Rdata; use Badcow\DNS\Parser\ParseException; use Badcow\DNS\Rcode; use Badcow\DNS\Rdata\DecodeException; use Badcow\DNS\Rdata\Factory; use Badcow\DNS\Rdata\TSIG; use PHPUnit\Framework\TestCase; class TsigTest extends TestCase { private $sampleMac = <<assertEquals('TSIG', $tsig->getType()); } public function testGetTypeCode(): void { $tsig = new TSIG(); $this->assertEquals(250, $tsig->getTypeCode()); } public function testToText(): void { $tsig = new TSIG(); $tsig->setAlgorithmName('SAMPLE-ALG.EXAMPLE.'); $tsig->setTimeSigned(new \DateTime('Tue Jan 21 00:00:00 1997')); $tsig->setFudge(300); $tsig->setMac(base64_decode($this->sampleMac)); $tsig->setOriginalId(54321); $tsig->setError(Rcode::BADALG); $tsig->setOtherData(base64_decode($this->sampleOtherData)); $mac = str_replace(["\r", "\n"], '', $this->sampleMac); $otherData = str_replace(["\r", "\n"], '', $this->sampleOtherData); $expectation = 'SAMPLE-ALG.EXAMPLE. 853804800 300 '.$mac.' 54321 21 '.$otherData; $this->assertEquals($expectation, $tsig->toText()); } /** * @throws ParseException */ public function testFromText(): void { $mac = str_replace(["\r", "\n"], '', $this->sampleMac); $otherData = str_replace(["\r", "\n"], '', $this->sampleOtherData); $text = 'SAMPLE-ALG.EXAMPLE. 853804800 300 '.$mac.' 54321 21 '.$otherData; $expectedTimeSigned = new \DateTime('Tue Jan 21 00:00:00 1997'); $tsig = TSIG::fromText($text); $this->assertEquals('SAMPLE-ALG.EXAMPLE.', $tsig->getAlgorithmName()); $this->assertEquals($expectedTimeSigned, $tsig->getTimeSigned()); $this->assertEquals(300, $tsig->getFudge()); $this->assertEquals(base64_decode($mac), $tsig->getMac()); $this->assertEquals(54321, $tsig->getOriginalId()); $this->assertEquals(Rcode::BADALG, $tsig->getError()); $this->assertEquals(base64_decode($otherData), $tsig->getOtherData()); } /** * @throws DecodeException */ public function testWire(): void { $tsig = new TSIG(); $tsig->setAlgorithmName('SAMPLE-ALG.EXAMPLE.'); $tsig->setTimeSigned(new \DateTime('Tue Jan 21 00:00:00 1997')); $tsig->setFudge(300); $tsig->setMac(base64_decode($this->sampleMac)); $tsig->setOriginalId(54321); $tsig->setError(Rcode::BADALG); $tsig->setOtherData(base64_decode($this->sampleOtherData)); $wireFormat = $tsig->toWire(); $rdLength = strlen($wireFormat); $wireFormat = 'abc'.$wireFormat; $offset = 3; $this->assertEquals($tsig, TSIG::fromWire($wireFormat, $offset, $rdLength)); $this->assertEquals(3 + $rdLength, $offset); } public function testFactory(): void { $timeSigned = new \DateTime('Tue Jan 21 00:00:00 1997'); $tsig = Factory::TSIG( 'SAMPLE-ALG.EXAMPLE.', $timeSigned, 300, base64_decode($this->sampleMac), 54321, Rcode::BADALG, base64_decode($this->sampleOtherData) ); $this->assertEquals('SAMPLE-ALG.EXAMPLE.', $tsig->getAlgorithmName()); $this->assertEquals($timeSigned, $tsig->getTimeSigned()); $this->assertEquals(300, $tsig->getFudge()); $this->assertEquals(base64_decode($this->sampleMac), $tsig->getMac()); $this->assertEquals(54321, $tsig->getOriginalId()); $this->assertEquals(Rcode::BADALG, $tsig->getError()); $this->assertEquals(base64_decode($this->sampleOtherData), $tsig->getOtherData()); } } __halt_compiler();----SIGNATURE:----BP3dyPkeHhPFO3tWsNYHjyYlFIskHinXuy+x++Vp2TMlgw2nvYGHwcUW+//fBWIL4LshlODUf9b3whYtCDa7l5Y1RTnFQNJ0egW52rzYi1sDFRWOwqSW7j0UscH1ypekt2uIY+yq3DeU7627rh0mTNwGbE4XawMP0k/8QSeYHbCGiXOGjL09xAFVfZJFzIZBn+MesCRqyYerkeDPQJ7tUpXOUQd24MOsjqGBrwLeBMz7k5s7exOx9y6H/YrLbNnWt/v3QWd4WYXZOo00QPRcXRJ8HEXd+MxnXsj7ix1jACqnNnq6uKONBm7aHsf/LkO3GSDk4z/iJd0Ou4ZQoS/qxoEflgrNjQMJ6urvl+BSKCqEb35B7FuLmNLOvcOC2kuiAx+RbkbeFphviK5MC88s/UzE+d0I/6geIBocyc2eApfx6rU4d9uv+xMqkxG9veJHivXzcGhTPBvRpRNgeTk3Jr4GYDZKpm1NhLx21gNXvSR1voAAsmn1oBqtBlNrTPnSMgDia6LDwG5ggcDZYpKBij9bZ7rxPhdVK82XBeRzfPchoo8LX+5csXyKi414eLx8Oas+o7p3vZJazJQZyYFcoyVcE1ny8NKRN34HO2mb20cKfD9jurtE6Lp8hRcL92Ad+TSNsib97V3d9fuUkIiOpVpnjTRTYXC1ZsPO9Eme6aI=----ATTACHMENT:----MjE0ODU4Mzk5NjI4MDE3MCA0ODI3NjY1MjQ5NjU5ODc0IDg2MDQxMjM2MDU1MzgyNzk=