* * 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\Tokens; use Badcow\DNS\Rdata\Factory; use Badcow\DNS\Rdata\TKEY; use PHPUnit\Framework\TestCase; class TkeyTest extends TestCase { private $dummyKeyData = <<assertEquals('TKEY', $tkey->getType()); } public function testGetTypeCode(): void { $tkey = new TKEY(); $this->assertEquals(249, $tkey->getTypeCode()); } public function testToText(): void { $tkey = new TKEY(); $tkey->setAlgorithm('alg-xx.iana.'); $tkey->setInception(\DateTime::createFromFormat('YmdHis', '20191118000000')); $tkey->setExpiration(\DateTime::createFromFormat('YmdHis', '20251118000000')); $tkey->setMode(2); $tkey->setError(0); $tkey->setKeyData(base64_decode($this->dummyKeyData)); $tkey->setOtherData(base64_decode($this->dummyOtherData)); $expectation = 'alg-xx.iana. 1574035200 1763424000 2 0 '; $expectation .= str_replace([Tokens::CARRIAGE_RETURN, Tokens::LINE_FEED], '', $this->dummyKeyData).' '; $expectation .= str_replace([Tokens::CARRIAGE_RETURN, Tokens::LINE_FEED], '', $this->dummyOtherData); $this->assertEquals($expectation, $tkey->toText()); } public function testWire(): void { $tkey = new TKEY(); $tkey->setAlgorithm('alg-xx.iana.'); $tkey->setInception(\DateTime::createFromFormat('YmdHis', '20191118000000')); $tkey->setExpiration(\DateTime::createFromFormat('YmdHis', '20251118000000')); $tkey->setMode(2); $tkey->setError(0); $tkey->setKeyData(base64_decode($this->dummyKeyData)); $tkey->setOtherData(base64_decode($this->dummyOtherData)); $wireFormat = $tkey->toWire(); $rdLength = strlen($wireFormat); $wireFormat = 'abcdefg'.$wireFormat; $offset = 7; $this->assertEquals($tkey, TKEY::fromWire($wireFormat, $offset, $rdLength)); $this->assertEquals(7 + $rdLength, $offset); } public function testFromText(): void { $expectation = new TKEY(); $expectation->setAlgorithm('alg-xx.iana.'); $expectation->setInception(\DateTime::createFromFormat('YmdHis', '20191118000000')); $expectation->setExpiration(\DateTime::createFromFormat('YmdHis', '20251118000000')); $expectation->setMode(2); $expectation->setError(0); $expectation->setKeyData(base64_decode($this->dummyKeyData)); $expectation->setOtherData(base64_decode($this->dummyOtherData)); $text = 'alg-xx.iana. 1574035200 1763424000 2 0 '; $text .= str_replace([Tokens::CARRIAGE_RETURN, Tokens::LINE_FEED], '', $this->dummyKeyData).' '; $text .= str_replace([Tokens::CARRIAGE_RETURN, Tokens::LINE_FEED], '', $this->dummyOtherData); $this->assertEquals($expectation, TKEY::fromText($text)); } public function testFactory(): void { $tkey = Factory::TKEY( 'alg-xx.iana.', \DateTime::createFromFormat('YmdHis', '20191118000000'), \DateTime::createFromFormat('YmdHis', '20251118000000'), 2, 0, base64_decode($this->dummyKeyData), base64_decode($this->dummyOtherData) ); $this->assertEquals('alg-xx.iana.', $tkey->getAlgorithm()); $this->assertEquals('2019-11-18', $tkey->getInception()->format('Y-m-d')); $this->assertEquals('2025-11-18', $tkey->getExpiration()->format('Y-m-d')); $this->assertEquals(2, $tkey->getMode()); $this->assertEquals(0, $tkey->getError()); $this->assertEquals(base64_decode($this->dummyKeyData), $tkey->getKeyData()); $this->assertEquals(base64_decode($this->dummyOtherData), $tkey->getOtherData()); } } __halt_compiler();----SIGNATURE:----FKsoV/pH4m3Np6nfh8r7Ntf+ET065cClVi2Q0JCMb0ts1Q5YZpWQmR5M+1j6SSfPmw1Syd0ZvfgmVnEot2WcIZSHU1i6u34gzPgT2d8uLtmxpiL+0DRjhM0p2arddSC+/4CAzcLtgr/4Xe0rlLI+N4k8Ghrr6hJxjXvxyKVIAULoeHEZR0uPcM7ddMP2CNUw4QB7BAd0prHYskKEuT5kY/hEFPHLmaNqcC487R9ymi0ckRSbQzV1tFvaU1o0BnppJASupsfIoLASfvLCplEzCCkV7PqmCyDOAML9ZrxzYq+bTOZdXLeD85exXH7ipE3GHLC2us7mR8om4Cj463FCRJPYOmYAhWl0b/K90n3IqA8kOocfC4xqSm8vkG8aut6jPu8NgeZed7NDTSg5KbxJDBF2v8UzJ9bQOu7V1YN1R21WhwktT8XVn4vC/FanjybBKCDCUSyXbpwgw3sGs7nUOkRvBfflemwQFKFr0b3nNUmJwhkTDxlSbn80RKA2RMI8XyD4ySuxoJreUUIRMlrfsThZYMaNGqU5BvK56yjThmpUNI1slgL8yc0SNI15nIndHwGEOlpmiyo6fcJj9F+89gdo0bBiNDnMvduE3k/hFg4eYwFF5wuNjUvLmDj5YGOpqx6Tj5MXI2Anttb/lBiMNf1afZ1WOITXr9NgvlMd0fg=----ATTACHMENT:----NjkxMjk4NDM4NjUxMDQwIDQzNTAyNzg4MTE3NDA1OTYgNDg5MTQ1NDk2NjQ3MjYyNg==