Skip to content

Commit

Permalink
Bugfix/RDNS lookup representation (#22)
Browse files Browse the repository at this point in the history
* Updated DnsMock::Server::RecordsDictionaryBuilder
* Updated integration test cases
* Updated gem version, readme, changelog
  • Loading branch information
bestwebua authored Jan 27, 2021
1 parent e0d77ec commit 7a098e9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.1] - 2021-01-27

### Fixed RDNS lookup representation

Fixed RDNS lookup representatin for IP address in PTR record feature.

## [0.2.0] - 2021-01-26

### PTR record support
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
dns_mock (0.2.0)
dns_mock (0.2.1)

GEM
remote: https://rubygems.org/
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Maintainability](https://api.codeclimate.com/v1/badges/5ea9da61ef468b8ad4c4/maintainability)](https://codeclimate.com/github/mocktools/ruby-dns-mock/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/5ea9da61ef468b8ad4c4/test_coverage)](https://codeclimate.com/github/mocktools/ruby-dns-mock/test_coverage)
[![CircleCI](https://circleci.com/gh/mocktools/ruby-dns-mock/tree/develop.svg?style=svg)](https://circleci.com/gh/mocktools/ruby-dns-mock/tree/develop)
[![CircleCI](https://circleci.com/gh/mocktools/ruby-dns-mock/tree/master.svg?style=svg)](https://circleci.com/gh/mocktools/ruby-dns-mock/tree/master)
[![Gem Version](https://badge.fury.io/rb/dns_mock.svg)](https://badge.fury.io/rb/dns_mock)
[![Downloads](https://img.shields.io/gem/dt/dns_mock.svg?colorA=004d99&colorB=0073e6)](https://rubygems.org/gems/dns_mock)
[![GitHub](https://img.shields.io/github/license/mocktools/ruby-dns-mock)](LICENSE.txt)
Expand All @@ -23,10 +23,6 @@
- [Versioning](#versioning)
- [Changelog](CHANGELOG.md)

## Requirements

Ruby MRI 2.5.0+

## Features

- Ability to mimic any DNS records (`A`, `AAAA`, `CNAME`, `MX`, `NS`, `PTR`, `SOA` and `TXT`)
Expand All @@ -35,6 +31,10 @@ Ruby MRI 2.5.0+
- Test framework agnostic (it's PORO, so you can use it outside of `RSpec`, `Test::Unit` or `MiniTest`)
- Simple and intuitive DSL

## Requirements

Ruby MRI 2.5.0+

## Installation

Add this line to your application's `Gemfile`:
Expand Down Expand Up @@ -77,7 +77,7 @@ records = {
}
]
},
'1.1.1.1' => {
'1.2.3.4' => {
ptr: %w[domain_1.com domain_2.com]
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/dns_mock/server/records_dictionary_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class RecordsDictionaryBuilder
include DnsMock::Error::Helper

IP_ADDRESS_PATTERN = /\A((1\d|[1-9]|2[0-4])?\d|25[0-5])(\.\g<1>){3}\z/.freeze
RDNS_LOOKUP_PREFIX = '.in-addr.arpa'
IP_OCTET_GROUPS = /(\d+).(\d+).(\d+).(\d+)/.freeze
RDNS_LOOKUP_REPRESENTATION = '\4.\3.\2.\1.in-addr.arpa'
TYPE_MAPPER = DnsMock::AVAILABLE_DNS_RECORD_TYPES.zip(
[
[DnsMock::Record::Builder::A, DnsMock::Record::Factory::A, ::Array],
Expand Down Expand Up @@ -47,7 +48,10 @@ def build(records_to_build)
def rdns_lookup_prefix(hostname)
return hostname unless hostname[DnsMock::Server::RecordsDictionaryBuilder::IP_ADDRESS_PATTERN]

"#{hostname}#{DnsMock::Server::RecordsDictionaryBuilder::RDNS_LOOKUP_PREFIX}"
hostname.gsub(
DnsMock::Server::RecordsDictionaryBuilder::IP_OCTET_GROUPS,
DnsMock::Server::RecordsDictionaryBuilder::RDNS_LOOKUP_REPRESENTATION
)
end

def build_records_instances_by_type(record_type, records_to_build)
Expand Down
2 changes: 1 addition & 1 deletion lib/dns_mock/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DnsMock
VERSION = '0.2.0'
VERSION = '0.2.1'
end
5 changes: 3 additions & 2 deletions spec/dns_mock/server/records_dictionary_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
RSpec.describe DnsMock::Server::RecordsDictionaryBuilder do
describe 'defined constants' do
it { expect(described_class).to be_const_defined(:IP_ADDRESS_PATTERN) }
it { expect(described_class).to be_const_defined(:RDNS_LOOKUP_PREFIX) }
it { expect(described_class).to be_const_defined(:IP_OCTET_GROUPS) }
it { expect(described_class).to be_const_defined(:RDNS_LOOKUP_REPRESENTATION) }
it { expect(described_class).to be_const_defined(:TYPE_MAPPER) }
end

Expand Down Expand Up @@ -64,7 +65,7 @@
record_type_1 => builder_result_1,
record_type_2 => builder_result_2
},
"#{target_domain_2}.in-addr.arpa" => {
"#{target_domain_2.split('.').reverse.join('.')}.in-addr.arpa" => {
record_type_3 => builder_result_3
}
}
Expand Down
13 changes: 11 additions & 2 deletions spec/dns_mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
describe 'DNS mock server integration tests' do
let(:port) { 5300 }
let(:domain) { random_hostname }
let(:records) { create_records(domain) }
let(:ip_address) { random_ip_v4_address }
let(:records) { create_records(domain).merge(create_records(ip_address, :ptr)) }
let(:records_by_domain) { records[domain] }
let(:records_by_ip_address) { records[ip_address] }
let(:rspec_dns_config) { { nameserver: 'localhost', port: port } }

before { described_class.start_server(records: records, port: port) }
Expand Down Expand Up @@ -101,13 +103,20 @@
.config(**rspec_dns_config)
end

it 'returns predefined PTR record' do
it 'returns predefined host name PTR record' do
expect(domain).to have_dns
.with_type('PTR')
.and_domainname(records_by_domain[:ptr].first)
.config(**rspec_dns_config)
end

it 'returns predefined host address PTR record' do
expect(ip_address).to have_dns
.with_type('PTR')
.and_domainname(records_by_ip_address[:ptr].first)
.config(**rspec_dns_config)
end

it 'returns predefined MX record' do
expect(domain).to have_dns
.with_type('MX')
Expand Down

0 comments on commit 7a098e9

Please sign in to comment.