diff --git a/src/Model/HeaderBag.php b/src/Model/HeaderBag.php deleted file mode 100644 index 559bf068..00000000 --- a/src/Model/HeaderBag.php +++ /dev/null @@ -1,54 +0,0 @@ - 0, - 'anCount' => 0, - 'nsCount' => 0, - 'arCount' => 0, - 'qr' => 0, - 'opcode' => Message::OPCODE_QUERY, - 'aa' => 0, - 'tc' => 0, - 'rd' => 0, - 'ra' => 0, - 'z' => 0, - 'rcode' => Message::RCODE_OK, - ); - - public function get($name) - { - return isset($this->attributes[$name]) ? $this->attributes[$name] : null; - } - - public function set($name, $value) - { - $this->attributes[$name] = $value; - } - - public function isQuery() - { - return 0 === $this->attributes['qr']; - } - - public function isResponse() - { - return 1 === $this->attributes['qr']; - } - - public function isTruncated() - { - return 1 === $this->attributes['tc']; - } - - public function populateCounts(Message $message) - { - $this->attributes['qdCount'] = count($message->questions); - $this->attributes['anCount'] = count($message->answers); - $this->attributes['nsCount'] = count($message->authority); - $this->attributes['arCount'] = count($message->additional); - } -} diff --git a/src/Model/Message.php b/src/Model/Message.php index 9d07a10a..2987c3de 100644 --- a/src/Model/Message.php +++ b/src/Model/Message.php @@ -4,6 +4,11 @@ use React\Dns\Query\Query; +/** + * This class represents an outgoing query message or an incoming response message + * + * @link https://tools.ietf.org/html/rfc1035#section-4.1.1 + */ class Message { const TYPE_A = 1; @@ -39,10 +44,9 @@ class Message public static function createRequestForQuery(Query $query) { $request = new Message(); - $request->header->set('id', self::generateId()); - $request->header->set('rd', 1); + $request->id = self::generateId(); + $request->rd = true; $request->questions[] = $query; - $request->prepare(); return $request; } @@ -57,11 +61,9 @@ public static function createRequestForQuery(Query $query) public static function createResponseWithAnswersForQuery(Query $query, array $answers) { $response = new Message(); - $response->header->set('id', self::generateId()); - $response->header->set('qr', 1); - $response->header->set('opcode', Message::OPCODE_QUERY); - $response->header->set('rd', 1); - $response->header->set('rcode', Message::RCODE_OK); + $response->id = self::generateId(); + $response->qr = true; + $response->rd = true; $response->questions[] = $query; @@ -69,8 +71,6 @@ public static function createResponseWithAnswersForQuery(Query $query, array $an $response->answers[] = $record; } - $response->prepare(); - return $response; } @@ -101,9 +101,55 @@ private static function generateId() } /** - * @var HeaderBag + * The 16 bit message ID + * + * The response message ID has to match the request message ID. This allows + * the receiver to verify this is the correct response message. An outside + * attacker may try to inject fake responses by "guessing" the message ID, + * so this should use a proper CSPRNG to avoid possible cache poisoning. + * + * @var int 16 bit message ID + * @see self::generateId() + */ + public $id = 0; + + /** + * @var bool Query/Response flag, query=false or response=true + */ + public $qr = false; + + /** + * @var int specifies the kind of query (4 bit), see self::OPCODE_* constants + * @see self::OPCODE_QUERY */ - public $header; + public $opcode = self::OPCODE_QUERY; + + /** + * + * @var bool Authoritative Answer + */ + public $aa = false; + + /** + * @var bool TrunCation + */ + public $tc = false; + + /** + * @var bool Recursion Desired + */ + public $rd = false; + + /** + * @var bool Recursion Available + */ + public $ra = false; + + /** + * @var int response code (4 bit), see self::RCODE_* constants + * @see self::RCODE_OK + */ + public $rcode = Message::RCODE_OK; /** * An array of Query objects @@ -136,40 +182,4 @@ private static function generateId() * @var Record[] */ public $additional = array(); - - public function __construct() - { - $this->header = new HeaderBag(); - } - - /** - * Returns the 16 bit message ID - * - * The response message ID has to match the request message ID. This allows - * the receiver to verify this is the correct response message. An outside - * attacker may try to inject fake responses by "guessing" the message ID, - * so this should use a proper CSPRNG to avoid possible cache poisoning. - * - * @return int - * @see self::generateId() - */ - public function getId() - { - return $this->header->get('id'); - } - - /** - * Returns the response code (RCODE) - * - * @return int see self::RCODE_* constants - */ - public function getResponseCode() - { - return $this->header->get('rcode'); - } - - public function prepare() - { - $this->header->populateCounts($this); - } } diff --git a/src/Protocol/BinaryDumper.php b/src/Protocol/BinaryDumper.php index 01b0fc59..098d216b 100644 --- a/src/Protocol/BinaryDumper.php +++ b/src/Protocol/BinaryDumper.php @@ -2,7 +2,6 @@ namespace React\Dns\Protocol; -use React\Dns\Model\HeaderBag; use React\Dns\Model\Message; use React\Dns\Model\Record; use React\Dns\Query\Query; @@ -17,7 +16,7 @@ public function toBinary(Message $message) { $data = ''; - $data .= $this->headerToBinary($message->header); + $data .= $this->headerToBinary($message); $data .= $this->questionToBinary($message->questions); $data .= $this->recordsToBinary($message->answers); $data .= $this->recordsToBinary($message->authority); @@ -30,28 +29,28 @@ public function toBinary(Message $message) * @param Message $message * @return string */ - private function headerToBinary(HeaderBag $header) + private function headerToBinary(Message $message) { $data = ''; - $data .= pack('n', $header->get('id')); + $data .= pack('n', $message->id); $flags = 0x00; - $flags = ($flags << 1) | $header->get('qr'); - $flags = ($flags << 4) | $header->get('opcode'); - $flags = ($flags << 1) | $header->get('aa'); - $flags = ($flags << 1) | $header->get('tc'); - $flags = ($flags << 1) | $header->get('rd'); - $flags = ($flags << 1) | $header->get('ra'); - $flags = ($flags << 3) | $header->get('z'); - $flags = ($flags << 4) | $header->get('rcode'); + $flags = ($flags << 1) | ($message->qr ? 1 : 0); + $flags = ($flags << 4) | $message->opcode; + $flags = ($flags << 1) | ($message->aa ? 1 : 0); + $flags = ($flags << 1) | ($message->tc ? 1 : 0); + $flags = ($flags << 1) | ($message->rd ? 1 : 0); + $flags = ($flags << 1) | ($message->ra ? 1 : 0); + $flags = ($flags << 3) | 0; // skip unused zero bit + $flags = ($flags << 4) | $message->rcode; $data .= pack('n', $flags); - $data .= pack('n', $header->get('qdCount')); - $data .= pack('n', $header->get('anCount')); - $data .= pack('n', $header->get('nsCount')); - $data .= pack('n', $header->get('arCount')); + $data .= pack('n', count($message->questions)); + $data .= pack('n', count($message->answers)); + $data .= pack('n', count($message->authority)); + $data .= pack('n', count($message->additional)); return $data; } diff --git a/src/Protocol/Parser.php b/src/Protocol/Parser.php index 441a4327..0ff19195 100644 --- a/src/Protocol/Parser.php +++ b/src/Protocol/Parser.php @@ -39,20 +39,34 @@ public function parseMessage($data) private function parse($data, Message $message) { - if (!$message->header->get('id')) { - if (!$this->parseHeader($message)) { - return; - } + if (!isset($message->data[12 - 1])) { + return; } - if ($message->header->get('qdCount') != count($message->questions)) { - if (!$this->parseQuestion($message)) { + list($id, $fields, $qdCount, $anCount, $nsCount, $arCount) = array_values(unpack('n*', substr($message->data, 0, 12))); + $message->consumed += 12; + + $message->id = $id; + $message->rcode = $fields & 0xf; + $message->ra = (($fields >> 7) & 1) === 1; + $message->rd = (($fields >> 8) & 1) === 1; + $message->tc = (($fields >> 9) & 1) === 1; + $message->aa = (($fields >> 10) & 1) === 1; + $message->opcode = ($fields >> 11) & 0xf; + $message->qr = (($fields >> 15) & 1) === 1; + + // parse all questions + for ($i = $qdCount; $i > 0; --$i) { + $question = $this->parseQuestion($message); + if ($question === null) { return; + } else { + $message->questions[] = $question; } } // parse all answer records - for ($i = $message->header->get('anCount'); $i > 0; --$i) { + for ($i = $anCount; $i > 0; --$i) { $record = $this->parseRecord($message); if ($record === null) { return; @@ -62,7 +76,7 @@ private function parse($data, Message $message) } // parse all authority records - for ($i = $message->header->get('nsCount'); $i > 0; --$i) { + for ($i = $nsCount; $i > 0; --$i) { $record = $this->parseRecord($message); if ($record === null) { return; @@ -72,7 +86,7 @@ private function parse($data, Message $message) } // parse all additional records - for ($i = $message->header->get('arCount'); $i > 0; --$i) { + for ($i = $arCount; $i > 0; --$i) { $record = $this->parseRecord($message); if ($record === null) { return; @@ -84,36 +98,10 @@ private function parse($data, Message $message) return $message; } - private function parseHeader(Message $message) - { - if (!isset($message->data[12 - 1])) { - return; - } - - $header = substr($message->data, 0, 12); - $message->consumed += 12; - - list($id, $fields, $qdCount, $anCount, $nsCount, $arCount) = array_values(unpack('n*', $header)); - - $rcode = $fields & bindec('1111'); - $z = ($fields >> 4) & bindec('111'); - $ra = ($fields >> 7) & 1; - $rd = ($fields >> 8) & 1; - $tc = ($fields >> 9) & 1; - $aa = ($fields >> 10) & 1; - $opcode = ($fields >> 11) & bindec('1111'); - $qr = ($fields >> 15) & 1; - - $vars = compact('id', 'qdCount', 'anCount', 'nsCount', 'arCount', - 'qr', 'opcode', 'aa', 'tc', 'rd', 'ra', 'z', 'rcode'); - - foreach ($vars as $name => $value) { - $message->header->set($name, $value); - } - - return $message; - } - + /** + * @param Message $message + * @return ?Query + */ private function parseQuestion(Message $message) { $consumed = $message->consumed; @@ -129,17 +117,11 @@ private function parseQuestion(Message $message) $message->consumed = $consumed; - $message->questions[] = new Query( + return new Query( implode('.', $labels), $type, $class ); - - if ($message->header->get('qdCount') != count($message->questions)) { - return $this->parseQuestion($message); - } - - return $message; } /** diff --git a/src/Query/CachingExecutor.php b/src/Query/CachingExecutor.php index 15e486a2..ed96856f 100644 --- a/src/Query/CachingExecutor.php +++ b/src/Query/CachingExecutor.php @@ -44,7 +44,7 @@ function ($message) use ($nameserver, $query, $id, $cache, $executor, &$pending, return $pending = $executor->query($nameserver, $query)->then( function (Message $message) use ($cache, $id, $that) { // DNS response message received => store in cache when not truncated and return - if (!$message->header->isTruncated()) { + if (!$message->tc) { $cache->set($id, $message, $that->ttl($message)); } diff --git a/src/Query/UdpTransportExecutor.php b/src/Query/UdpTransportExecutor.php index 99a3e8a4..a24971f3 100644 --- a/src/Query/UdpTransportExecutor.php +++ b/src/Query/UdpTransportExecutor.php @@ -160,7 +160,7 @@ public function query($nameserver, Query $query) // ignore and await next if we received an unexpected response ID // this may as well be a fake response from an attacker (possible cache poisoning) - if ($response->getId() !== $request->getId()) { + if ($response->id !== $request->id) { return; } @@ -168,7 +168,7 @@ public function query($nameserver, Query $query) $loop->removeReadStream($socket); \fclose($socket); - if ($response->header->isTruncated()) { + if ($response->tc) { $deferred->reject(new \RuntimeException('DNS query for ' . $query->name . ' failed: The server returned a truncated result for a UDP query, but retrying via TCP is currently not supported')); return; } diff --git a/src/Resolver/Resolver.php b/src/Resolver/Resolver.php index c9b13719..0b1ba3a8 100644 --- a/src/Resolver/Resolver.php +++ b/src/Resolver/Resolver.php @@ -135,7 +135,7 @@ public function resolveAll($domain, $type) public function extractValues(Query $query, Message $response) { // reject if response code indicates this is an error response message - $code = $response->getResponseCode(); + $code = $response->rcode; if ($code !== Message::RCODE_OK) { switch ($code) { case Message::RCODE_FORMAT_ERROR: diff --git a/tests/Model/MessageTest.php b/tests/Model/MessageTest.php index fcbf8077..a52f6596 100644 --- a/tests/Model/MessageTest.php +++ b/tests/Model/MessageTest.php @@ -13,8 +13,8 @@ public function testCreateRequestDesiresRecusion() $query = new Query('igor.io', Message::TYPE_A, Message::CLASS_IN); $request = Message::createRequestForQuery($query); - $this->assertTrue($request->header->isQuery()); - $this->assertSame(1, $request->header->get('rd')); + $this->assertFalse($request->qr); + $this->assertTrue($request->rd); } public function testCreateResponseWithNoAnswers() @@ -23,9 +23,7 @@ public function testCreateResponseWithNoAnswers() $answers = array(); $request = Message::createResponseWithAnswersForQuery($query, $answers); - $this->assertFalse($request->header->isQuery()); - $this->assertTrue($request->header->isResponse()); - $this->assertEquals(0, $request->header->get('anCount')); - $this->assertEquals(Message::RCODE_OK, $request->getResponseCode()); + $this->assertTrue($request->qr); + $this->assertEquals(Message::RCODE_OK, $request->rcode); } } diff --git a/tests/Protocol/BinaryDumperTest.php b/tests/Protocol/BinaryDumperTest.php index 43739598..fe739872 100644 --- a/tests/Protocol/BinaryDumperTest.php +++ b/tests/Protocol/BinaryDumperTest.php @@ -20,8 +20,8 @@ public function testToBinaryRequestMessage() $expected = $this->formatHexDump($data); $request = new Message(); - $request->header->set('id', 0x7262); - $request->header->set('rd', 1); + $request->id = 0x7262; + $request->rd = true; $request->questions[] = new Query( 'igor.io', @@ -29,8 +29,6 @@ public function testToBinaryRequestMessage() Message::CLASS_IN ); - $request->prepare(); - $dumper = new BinaryDumper(); $data = $dumper->toBinary($request); $data = $this->convertBinaryToHexDump($data); @@ -50,8 +48,8 @@ public function testToBinaryRequestMessageWithCustomOptForEdns0() $expected = $this->formatHexDump($data); $request = new Message(); - $request->header->set('id', 0x7262); - $request->header->set('rd', 1); + $request->id = 0x7262; + $request->rd = true; $request->questions[] = new Query( 'igor.io', @@ -61,8 +59,6 @@ public function testToBinaryRequestMessageWithCustomOptForEdns0() $request->additional[] = new Record('', 41, 1000, 0, ''); - $request->prepare(); - $dumper = new BinaryDumper(); $data = $dumper->toBinary($request); $data = $this->convertBinaryToHexDump($data); @@ -80,9 +76,9 @@ public function testToBinaryResponseMessageWithoutRecords() $expected = $this->formatHexDump($data); $response = new Message(); - $response->header->set('id', 0x7262); - $response->header->set('rd', 1); - $response->header->set('rcode', Message::RCODE_OK); + $response->id = 0x7262; + $response->rd = true; + $response->rcode = Message::RCODE_OK; $response->questions[] = new Query( 'igor.io', @@ -90,8 +86,6 @@ public function testToBinaryResponseMessageWithoutRecords() Message::CLASS_IN ); - $response->prepare(); - $dumper = new BinaryDumper(); $data = $dumper->toBinary($response); $data = $this->convertBinaryToHexDump($data); @@ -114,9 +108,9 @@ public function testToBinaryForResponseWithSRVRecord() $expected = $this->formatHexDump($data); $response = new Message(); - $response->header->set('id', 0x7262); - $response->header->set('rd', 1); - $response->header->set('rcode', Message::RCODE_OK); + $response->id = 0x7262; + $response->rd = true; + $response->rcode = Message::RCODE_OK; $response->questions[] = new Query( 'igor.io', @@ -130,7 +124,6 @@ public function testToBinaryForResponseWithSRVRecord() 'port' => 8080, 'target' => 'test' )); - $response->prepare(); $dumper = new BinaryDumper(); $data = $dumper->toBinary($response); @@ -157,9 +150,9 @@ public function testToBinaryForResponseWithSOARecord() $expected = $this->formatHexDump($data); $response = new Message(); - $response->header->set('id', 0x7262); - $response->header->set('rd', 1); - $response->header->set('rcode', Message::RCODE_OK); + $response->id = 0x7262; + $response->rd = true; + $response->rcode = Message::RCODE_OK; $response->questions[] = new Query( 'igor.io', @@ -176,7 +169,6 @@ public function testToBinaryForResponseWithSOARecord() 'expire' => 605800, 'minimum' => 3600 )); - $response->prepare(); $dumper = new BinaryDumper(); $data = $dumper->toBinary($response); @@ -207,9 +199,9 @@ public function testToBinaryForResponseWithMultipleAnswerRecords() $expected = $this->formatHexDump($data); $response = new Message(); - $response->header->set('id', 0x7262); - $response->header->set('rd', 1); - $response->header->set('rcode', Message::RCODE_OK); + $response->id = 0x7262; + $response->rd = true; + $response->rcode = Message::RCODE_OK; $response->questions[] = new Query( 'igor.io', @@ -221,7 +213,6 @@ public function testToBinaryForResponseWithMultipleAnswerRecords() $response->answers[] = new Record('igor.io', Message::TYPE_AAAA, Message::CLASS_IN, 0, '::1'); $response->answers[] = new Record('igor.io', Message::TYPE_TXT, Message::CLASS_IN, 0, array('hello', 'world')); $response->answers[] = new Record('igor.io', Message::TYPE_MX, Message::CLASS_IN, 0, array('priority' => 0, 'target' => '')); - $response->prepare(); $dumper = new BinaryDumper(); $data = $dumper->toBinary($response); @@ -246,9 +237,9 @@ public function testToBinaryForResponseWithAnswerAndAdditionalRecord() $expected = $this->formatHexDump($data); $response = new Message(); - $response->header->set('id', 0x7262); - $response->header->set('rd', 1); - $response->header->set('rcode', Message::RCODE_OK); + $response->id = 0x7262; + $response->rd = true; + $response->rcode = Message::RCODE_OK; $response->questions[] = new Query( 'igor.io', @@ -258,7 +249,6 @@ public function testToBinaryForResponseWithAnswerAndAdditionalRecord() $response->answers[] = new Record('igor.io', Message::TYPE_NS, Message::CLASS_IN, 0, 'example.com'); $response->additional[] = new Record('example.com', Message::TYPE_A, Message::CLASS_IN, 0, '127.0.0.1'); - $response->prepare(); $dumper = new BinaryDumper(); $data = $dumper->toBinary($response); diff --git a/tests/Protocol/ParserTest.php b/tests/Protocol/ParserTest.php index ef889c5a..82f67eae 100644 --- a/tests/Protocol/ParserTest.php +++ b/tests/Protocol/ParserTest.php @@ -45,20 +45,14 @@ public function testParseRequest() $this->assertFalse(isset($request->data)); $this->assertFalse(isset($request->consumed)); - $header = $request->header; - $this->assertSame(0x7262, $header->get('id')); - $this->assertSame(1, $header->get('qdCount')); - $this->assertSame(0, $header->get('anCount')); - $this->assertSame(0, $header->get('nsCount')); - $this->assertSame(0, $header->get('arCount')); - $this->assertSame(0, $header->get('qr')); - $this->assertSame(Message::OPCODE_QUERY, $header->get('opcode')); - $this->assertSame(0, $header->get('aa')); - $this->assertSame(0, $header->get('tc')); - $this->assertSame(1, $header->get('rd')); - $this->assertSame(0, $header->get('ra')); - $this->assertSame(0, $header->get('z')); - $this->assertSame(Message::RCODE_OK, $header->get('rcode')); + $this->assertSame(0x7262, $request->id); + $this->assertSame(false, $request->qr); + $this->assertSame(Message::OPCODE_QUERY, $request->opcode); + $this->assertSame(false, $request->aa); + $this->assertSame(false, $request->tc); + $this->assertSame(true, $request->rd); + $this->assertSame(false, $request->ra); + $this->assertSame(Message::RCODE_OK, $request->rcode); $this->assertCount(1, $request->questions); $this->assertSame('igor.io', $request->questions[0]->name); @@ -82,20 +76,14 @@ public function testParseResponse() $response = $this->parser->parseMessage($data); - $header = $response->header; - $this->assertSame(0x7262, $header->get('id')); - $this->assertSame(1, $header->get('qdCount')); - $this->assertSame(1, $header->get('anCount')); - $this->assertSame(0, $header->get('nsCount')); - $this->assertSame(0, $header->get('arCount')); - $this->assertSame(1, $header->get('qr')); - $this->assertSame(Message::OPCODE_QUERY, $header->get('opcode')); - $this->assertSame(0, $header->get('aa')); - $this->assertSame(0, $header->get('tc')); - $this->assertSame(1, $header->get('rd')); - $this->assertSame(1, $header->get('ra')); - $this->assertSame(0, $header->get('z')); - $this->assertSame(Message::RCODE_OK, $header->get('rcode')); + $this->assertSame(0x7262, $response->id); + $this->assertSame(true, $response->qr); + $this->assertSame(Message::OPCODE_QUERY, $response->opcode); + $this->assertSame(false, $response->aa); + $this->assertSame(false, $response->tc); + $this->assertSame(true, $response->rd); + $this->assertSame(true, $response->ra); + $this->assertSame(Message::RCODE_OK, $response->rcode); $this->assertCount(1, $response->questions); $this->assertSame('igor.io', $response->questions[0]->name); @@ -273,20 +261,14 @@ public function testParseAAAAResponse() $response = $this->parser->parseMessage($data); - $header = $response->header; - $this->assertSame(0xcd72, $header->get('id')); - $this->assertSame(1, $header->get('qdCount')); - $this->assertSame(1, $header->get('anCount')); - $this->assertSame(0, $header->get('nsCount')); - $this->assertSame(0, $header->get('arCount')); - $this->assertSame(1, $header->get('qr')); - $this->assertSame(Message::OPCODE_QUERY, $header->get('opcode')); - $this->assertSame(0, $header->get('aa')); - $this->assertSame(0, $header->get('tc')); - $this->assertSame(1, $header->get('rd')); - $this->assertSame(1, $header->get('ra')); - $this->assertSame(0, $header->get('z')); - $this->assertSame(Message::RCODE_OK, $header->get('rcode')); + $this->assertSame(0xcd72, $response->id); + $this->assertSame(true, $response->qr); + $this->assertSame(Message::OPCODE_QUERY, $response->opcode); + $this->assertSame(false, $response->aa); + $this->assertSame(false, $response->tc); + $this->assertSame(true, $response->rd); + $this->assertSame(true, $response->ra); + $this->assertSame(Message::RCODE_OK, $response->rcode); $this->assertCount(1, $response->questions); $this->assertSame('google.com', $response->questions[0]->name); @@ -586,20 +568,14 @@ public function testParsePTRResponse() $response = $this->parser->parseMessage($data); - $header = $response->header; - $this->assertSame(0x5dd8, $header->get('id')); - $this->assertSame(1, $header->get('qdCount')); - $this->assertSame(1, $header->get('anCount')); - $this->assertSame(0, $header->get('nsCount')); - $this->assertSame(0, $header->get('arCount')); - $this->assertSame(1, $header->get('qr')); - $this->assertSame(Message::OPCODE_QUERY, $header->get('opcode')); - $this->assertSame(0, $header->get('aa')); - $this->assertSame(0, $header->get('tc')); - $this->assertSame(1, $header->get('rd')); - $this->assertSame(1, $header->get('ra')); - $this->assertSame(0, $header->get('z')); - $this->assertSame(Message::RCODE_OK, $header->get('rcode')); + $this->assertSame(0x5dd8, $response->id); + $this->assertSame(true, $response->qr); + $this->assertSame(Message::OPCODE_QUERY, $response->opcode); + $this->assertSame(false, $response->aa); + $this->assertSame(false, $response->tc); + $this->assertSame(true, $response->rd); + $this->assertSame(true, $response->ra); + $this->assertSame(Message::RCODE_OK, $response->rcode); $this->assertCount(1, $response->questions); $this->assertSame('4.4.8.8.in-addr.arpa', $response->questions[0]->name); diff --git a/tests/Query/CachingExecutorTest.php b/tests/Query/CachingExecutorTest.php index abd9342a..7be12ef2 100644 --- a/tests/Query/CachingExecutorTest.php +++ b/tests/Query/CachingExecutorTest.php @@ -107,7 +107,7 @@ public function testQueryWillReturnResolvedPromiseWhenCacheReturnsMissAndFallbac public function testQueryWillReturnResolvedPromiseWhenCacheReturnsMissAndFallbackExecutorResolvesWithTruncatedResponseButShouldNotSaveTruncatedMessageToCache() { $message = new Message(); - $message->header->set('tc', 1); + $message->tc = true; $fallback = $this->getMockBuilder('React\Dns\Query\ExecutorInterface')->getMock(); $fallback->expects($this->once())->method('query')->willReturn(\React\Promise\resolve($message)); diff --git a/tests/Query/RetryExecutorTest.php b/tests/Query/RetryExecutorTest.php index f43fed97..a6d9efc1 100644 --- a/tests/Query/RetryExecutorTest.php +++ b/tests/Query/RetryExecutorTest.php @@ -339,10 +339,9 @@ protected function createPromiseMock() protected function createStandardResponse() { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN); $response->answers[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'); - $response->prepare(); return $response; } diff --git a/tests/Query/UdpTransportExecutorTest.php b/tests/Query/UdpTransportExecutorTest.php index f7222dcf..3b0ff9d3 100644 --- a/tests/Query/UdpTransportExecutorTest.php +++ b/tests/Query/UdpTransportExecutorTest.php @@ -123,7 +123,7 @@ public function testQueryKeepsPendingIfServerSendInvalidId() $data = stream_socket_recvfrom($server, 512, 0, $peer); $message = $parser->parseMessage($data); - $message->header->set('id', 0); + $message->id = 0; stream_socket_sendto($server, $dumper->toBinary($message), 0, $peer); }); @@ -158,7 +158,7 @@ public function testQueryRejectsIfServerSendsTruncatedResponse() $data = stream_socket_recvfrom($server, 512, 0, $peer); $message = $parser->parseMessage($data); - $message->header->set('tc', 1); + $message->tc = true; stream_socket_sendto($server, $dumper->toBinary($message), 0, $peer); }); diff --git a/tests/Resolver/ResolverTest.php b/tests/Resolver/ResolverTest.php index 3c601d42..6159b66d 100644 --- a/tests/Resolver/ResolverTest.php +++ b/tests/Resolver/ResolverTest.php @@ -22,7 +22,7 @@ public function resolveShouldQueryARecords() ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record($query->name, $query->type, $query->class); $response->answers[] = new Record($query->name, $query->type, $query->class, 3600, '178.79.169.131'); @@ -43,7 +43,7 @@ public function resolveAllShouldQueryGivenRecords() ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record($query->name, $query->type, $query->class); $response->answers[] = new Record($query->name, $query->type, $query->class, 3600, '::1'); @@ -64,7 +64,7 @@ public function resolveAllShouldIgnoreRecordsWithOtherTypes() ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record($query->name, $query->type, $query->class); $response->answers[] = new Record($query->name, Message::TYPE_TXT, $query->class, 3600, array('ignored')); $response->answers[] = new Record($query->name, $query->type, $query->class, 3600, '::1'); @@ -86,12 +86,11 @@ public function resolveAllShouldReturnMultipleValuesForAlias() ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record($query->name, $query->type, $query->class); $response->answers[] = new Record($query->name, Message::TYPE_CNAME, $query->class, 3600, 'example.com'); $response->answers[] = new Record('example.com', $query->type, $query->class, 3600, '::1'); $response->answers[] = new Record('example.com', $query->type, $query->class, 3600, '::2'); - $response->prepare(); return Promise\resolve($response); })); @@ -112,7 +111,7 @@ public function resolveShouldQueryARecordsAndIgnoreCase() ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record('Blog.wyrihaximus.net', $query->type, $query->class); $response->answers[] = new Record('Blog.wyrihaximus.net', $query->type, $query->class, 3600, '178.79.169.131'); @@ -133,7 +132,7 @@ public function resolveShouldFilterByName() ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record($query->name, $query->type, $query->class); $response->answers[] = new Record('foo.bar', $query->type, $query->class, 3600, '178.79.169.131'); @@ -158,7 +157,7 @@ public function resolveWithNoAnswersShouldCallErrbackIfGiven() ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) { $response = new Message(); - $response->header->set('qr', 1); + $response->qr = true; $response->questions[] = new Record($query->name, $query->type, $query->class); return Promise\resolve($response); @@ -215,8 +214,8 @@ public function resolveWithRcodeErrorShouldCallErrbackIfGiven($code, $expectedMe ->with($this->anything(), $this->isInstanceOf('React\Dns\Query\Query')) ->will($this->returnCallback(function ($nameserver, $query) use ($code) { $response = new Message(); - $response->header->set('qr', 1); - $response->header->set('rcode', $code); + $response->qr = true; + $response->rcode = $code; $response->questions[] = new Record($query->name, $query->type, $query->class); return Promise\resolve($response);