public void DnsRequestHeader_ChangeRecursion()
        {
            var header = new DnsRequestHeader(23, true, DnsOpCode.Notify);

            Assert.Equal(8448, header.RawFlags);

            header.UseRecursion = false;
            Assert.False(header.UseRecursion);
            Assert.Equal(8192, header.RawFlags);

            header.UseRecursion = true;
            Assert.True(header.UseRecursion);
            Assert.Equal(8448, header.RawFlags);

            header.UseRecursion = false;
            Assert.False(header.UseRecursion);
            Assert.Equal(8192, header.RawFlags);

            header.UseRecursion = true;
            Assert.True(header.UseRecursion);
            Assert.Equal(8448, header.RawFlags);

            Assert.Equal(23, header.Id);
            Assert.Equal(DnsOpCode.Notify, header.OpCode);
        }
Пример #2
0
        public void DnsRequestHeader_ValidateCtor1()
        {
            var header = new DnsRequestHeader(DnsOpCode.Notify);

            Assert.True(header.UseRecursion);
            Assert.Equal(DnsOpCode.Notify, header.OpCode);
        }
        private DnsRequestMessage GetDnsRequestMessage(ushort headerId = 0)
        {
            DnsRequestHeader  header   = new DnsRequestHeader(headerId, true, DnsOpCode.Query);
            DnsQuestion       question = new DnsQuestion(mockDnsString.Object, QueryType.A, QueryClass.IN);
            DnsRequestMessage message  = new DnsRequestMessage(header, question);

            return(message);
        }
        /// <summary> Constructs a DNS query request object for given domain name to resolve. </summary>
        /// <param name="domainNameToResolve">Domain name to resolve. E.g. www.microsoft.com</param>
        /// <returns>Dns query request object.</returns>
        public DnsRequestMessage ProcessRequest(string domainNameToResolve)
        {
            ushort           headerId = GetNextUniqueId();
            DnsRequestHeader header   = new DnsRequestHeader(headerId, true, DnsOpCode.Query);

            DnsQuestion       question = new DnsQuestion(dnsString.Parse(domainNameToResolve), QueryType.A, QueryClass.IN);
            DnsRequestMessage message  = new DnsRequestMessage(header, question);

            return(message);
        }
        public void Resolve_overload_with_IPEndpoint_and_DnsRequetMessage_should_throw_DnsResponseException_when_header_ids_dont_match()
        {
            // Arrange.
            const string domainNameToResolve     = "www.A-Dummy-Domain.com";
            string       domainNameToResolveRoot = domainNameToResolve + ".";
            const ushort headerId = 123; // because we are *only* setting this up in the request header, it should not match with the response header.

            DnsRequestHeader  header            = new DnsRequestHeader(headerId, true, DnsOpCode.Query);
            DnsQuestion       question          = new DnsQuestion(mockDnsString.Object, QueryType.A, QueryClass.IN);
            DnsRequestMessage dnsRequestMessage = new DnsRequestMessage(header, question);
            IPEndPoint        dnsServerIP       = new IPEndPoint(IPAddress.Parse("10.0.0.10"), dnsPort53);

            mockDnsString.Setup(m => m.Value).Returns(domainNameToResolveRoot);
            DnsResponseMessage responseMessage = GetDnsResponseMessage();

            mockMessageProcessor.Setup(m => m.ProcessResponse(It.IsAny <ArraySegment <byte> >())).Returns(responseMessage);
            IDnsResolver resolver = new DnsResolver(mockCommunicator.Object, mockMessageProcessor.Object);

            // Act => Act.

            Assert.Throws <DnsResponseException>(() => resolver.Resolve(dnsServerIP, dnsRequestMessage), "Header id mismatch.");
        }
Пример #6
0
 public DnsRequestMessage(DnsRequestHeader header, DnsQuestion question)
 {
     Header   = header;
     Question = question;
 }