* * 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 = new 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; $fromWire = new TSIG(); $fromWire->fromWire($wireFormat, $offset, $rdLength); $this->assertEquals($tsig, $fromWire); $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:----U2hAWy11q+V0qFsSI+Kh8em7QcfsgN3ik/9s6lzKovUegZ/nRB8nOYa2Ovx4mrg7xL3YUL1tAZXBWDP2YgjR1soYRlr4yWKccO6ghj5Rf2yxO55LTTB7Xpot9DcddKZ2mXorRz68ArklFe6eMRzqxyc7/aiyIDZXQUU5A6nF4iaF4wPHIbjzmf5tov+/C6eP+jJATD10YO8i4J12ZsD+eUYktrTSr5RqaBZwx1wcN4f4lOvWLtrOs1ToH7SFjCQ6DDl5ho4rG0dwDO9tpO3jqLZmjlUVRnuknDh29EnYctdjQy0k5n5l7i7fkXLpwLrn0udligm5hthZooV8XhdoroWx+L4gXiUEThuStcMgTTQ1kqDG9SrtduffbJ/D/942yrXXKnhAE/wlfFVTIaznZrnet51TtanvelGG15nCDaw2mZvuIjWv/uf6M/nkRV97veneewzXcfGuA+WoPj+BY+sWZ5wzWqJEZ6tZmVP5DsbP0Nrl89TcIqf2usH3kRpuytuqLAh08F656bOjQzi4VfGRvAn3+HIIUcnVLEGOdEMT/X13hGxxZf3dhFCwGJVZMJDcwbn3ENBLr5FjvJmugc4LQL5Av4pR3NY5YH2hHasa53G431d1T+b8bK6gjiQo9HiQ0T4pYcVqugdlJLcpKZADDrp2qCgzZ3VgPEJWkP8=----ATTACHMENT:----NDgzMDAyODMyODIxMzIxOCA0ODE1MDgxMjkwMzIxNjk4IDUyMDkxMDIxOTgxOTY0MjM=