* * 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:----fARwYuu6hLFJ0jxgYHtZ5T4xmf95dFS+ZB1ZDo5TnUbTWAMZmH+ccS82dCDil2u81nE3omVbirSXV3vTfuA/0IFwY131mOt+jsJ6W8FUJvQcDGOMu3qQwP6lORdvtmPLEe73HmLy6c/q0KifVMIXy8eDwlu49zmB5O8icKKNqvWOurVlhBUC4EwPqdR/C8a3RPibzxev1uFQzvUeTGjvHaUc8I90FlZXk3iGdBq0/52/39xmZ73YZWdffZSlcKxe6xKlM0p2dtIIlwBaoZoK5iT+eP5GDuJ8dkC7o3NfVI4v/xRagwaKGfYUlj771RqXJVXBwkzKFi4yrZ0rQcxwxjnIlpU6KQaT8I8obysMPbKrx/8iKXgNE7+8+0vicEkht6e52nr1geoxiXrjqVBGUKIBrc/5bzlRuj24cHQqz/L94IovS+qRpLuy3Nngych7PPqKNKV0H/RwkMtIuvRJigPGnCJShe9VQT4l1PiB3azjVEj7OKf0cLdLxz51Li2jVg0W+R+jAmrtaZdwQnz0OS778HZAUG3TlIIOGJzapOh9aarjDNt9xye7NdtF7YT9tEF4ZFyYb4l26MDIKgTybWrbASWOrC1JanZN1WK5+YpcpfeOlQwgLvyDOofv+zbbp8ETczldkPZLjGkrzRSCC9Y1de3VlYGTUPN+g/Y88as=----ATTACHMENT:----MTgyOTk5MTc1MDM1MTMyOSA3OTg2MTYzODI5MTUzNTM2IDczNzI0MjkwMzM0NDcwODU=