* * 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:----W9VGncBiH23VuVQEWL/hkd5vhSeyRvnQtO6+2XZ0AGcZTzQGD41hZ2oQQiO/SfQUkKpRZds9JBgJteUlgnWiYUUcDF1/81Y91BW8rwgVk/Lj0+Fi8H+LEWPDJV1LXIuWDoVd9wfv5NL7VhMUZGSPccVaUONplqoKbHnCpAjKJXaVo3tEl1oBm5F699lLeNn/64nXrsXps6tlie0cQYaUkoM3HFYPDrc/o1in23sh3tgQRKm8QNofrCEzzDIJvZCRZ3ZV1yx3TjoW1dlnEjvQ0edRSoOhYMNM2ykNJc3vksxu2QfX17Qx8MNj9hhM2Wq8LbW7ShzQGkoRxaFA1Y+2nSzyI2E3dyMCYrVV7WFZsVAaspzlAn6fQ6/1Hsu8HFp6mdaK+BdmSyjPrdFp7dr5gQQrMJ0Dn11pchZ2Dgow1k0CwTfYQ8bfTajxNMNagZmq5nradKrTEkF4Hu3MN3Wtsn0d53EOCRfGCTOG88es4jjPATsmzFJUGSGvvR9NtIt+I0NlE0XCiKhLW7rYUt81Xl07jqiggTe6kdagyew4hxUrhd9DfVeqBUvTNefTkfoTNXmisi0DDw15lt1hsiAyABcCQ0nh6x3JygcQjVpltWzBRhOwa6yssz9InC+6JnXAYj8BuEM6unenHQ6zsgD4o/IB/mYBAys1jz4rJ3VChg4=----ATTACHMENT:----NzA2MDkzMDU1NTUwNTMwMiA3MTQzNzQ5OTkyMjg5NjMxIDkxMDA2Mzg4NDQxOTIzNzA=