Esempio n. 1
0
        public void CharacterStringFromLongString()
        {
            var result = CharacterString.FromString(new string('a', 512));

            Assert.Equal(3, result.Count);
            Assert.Equal(new [] { 256, 256, 3 }, result.Select(x => x.Size));
            Assert.Equal(new [] { 255, 255, 2 }, result.Select(x => (int)x.ToArray()[0]));
        }
Esempio n. 2
0
        public void CharacterStringFromSimpleString()
        {
            var result = CharacterString.FromString("www");

            Assert.Equal(1, result.Count);

            var characterString = result.First();

            Assert.Equal("www", characterString.ToString());
            Assert.Equal(4, characterString.Size);
        }
Esempio n. 3
0
        public Task <IResponse> Resolve(IRequest request, CancellationToken cancellationToken = new CancellationToken())
        {
            IResponse response = Response.FromRequest(request);

            foreach (var question in response.Questions)
            {
                if (!question.Name.ToString().EndsWith(_dnsSuffix))
                {
                    continue;
                }
                var query = question.Name.ToString().Replace(_dnsSuffix, string.Empty);

                var responseItem = Search(query, question.Type);

                if (responseItem == null)
                {
                    continue;
                }

                switch (question.Type)
                {
                case RecordType.A:
                case RecordType.AAAA:
                    _logger.LogInformation($"A/AAAA response: {responseItem.Result}");

                    response.AnswerRecords.Add(new IPAddressResourceRecord(question.Name, responseItem.Result));
                    break;

                case RecordType.TXT:
                    var txtResponse = responseItem.RblMessage ?? $"Blocked by {responseItem.Rbl}";

                    _logger.LogInformation($"TXT response: {txtResponse}");

                    response.AnswerRecords.Add(new TextResourceRecord(question.Name,
                                                                      CharacterString.FromString(txtResponse)));
                    break;

                default:
                    response.ResponseCode = ResponseCode.Refused;
                    break;
                }
            }

            if (!response.AnswerRecords.Any())
            {
                _logger.LogInformation("No matches found");
                response.ResponseCode = ResponseCode.NameError;
            }

            return(Task.FromResult(response));
        }
Esempio n. 4
0
 private static IList <CharacterString> FormatAttributeNameValue(string attributeName, string attributeValue)
 {
     return(CharacterString.FromString($"{Escape(attributeName)}={attributeValue}"));
 }
Esempio n. 5
0
        public void CharacterStringFromEmptyString()
        {
            var result = CharacterString.FromString("");

            Assert.Empty(result);
        }