dns_mock 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 959009b04aab3780b0f571bc7b31ad5c651cf454828c7f65535fdcebe5f6a6ca
4
- data.tar.gz: 6dccffd38d203b4216c940099b1c65ba770c27d811350af2fd5c0841405ff5a0
3
+ metadata.gz: fc32cd03521879fd373e554a2dbb29ae26ca002586418675fdc066b7ad5eab57
4
+ data.tar.gz: f309b21a3e48780dedef123a95bab5267dc3679ec3809def258a189485f5a6c4
5
5
  SHA512:
6
- metadata.gz: 150da67d3baefc081928aa4551fe7b6830162a65c174052483ed4529fc259c87213ff45114f6507847513646c96127dca19fd8732c8c06ea3b4416a07e28a631
7
- data.tar.gz: 881c264d38be38328285725a8b13b48c7e82628e5ef786853c4ca9067c67ebfd15e7d83befd8a84b6f4dd89307995ea59cc77dbbf07c2f93cff8565b53a52fbe
6
+ metadata.gz: fa16a2db1e2c9b8e903b29241f08d2b7695dfa3b98c9364c7d8ea87b361a67b21e72f898378d64b75500f9bc0ab90d14a33b94443561760ec99a820e02c0d8b4
7
+ data.tar.gz: 3f236e1c88970784a9d137994562595b06f3d78c0555aa3279810ae1821792d5b46c50f56e8bb63b3c66c060f9f495e4e09f6ada7ee6ae0588772a2ebb7d1a72
@@ -7,7 +7,7 @@ checks:
7
7
  plugins:
8
8
  rubocop:
9
9
  enabled: true
10
- channel: rubocop-1-8
10
+ channel: rubocop-1-9
11
11
 
12
12
  reek:
13
13
  enabled: true
data/.reek.yml CHANGED
@@ -45,3 +45,9 @@ detectors:
45
45
  LongParameterList:
46
46
  exclude:
47
47
  - DnsMock::Server#initialize
48
+ - DnsMock#start_server
49
+
50
+ BooleanParameter:
51
+ exclude:
52
+ - DnsMock::Server#initialize
53
+ - DnsMock#start_server
@@ -118,6 +118,9 @@ Style/EndlessMethod:
118
118
  Style/HashExcept:
119
119
  Enabled: true
120
120
 
121
+ Style/IfWithBooleanLiteralBranches:
122
+ Enabled: true
123
+
121
124
  Layout/LineLength:
122
125
  Max: 150
123
126
 
@@ -203,6 +206,18 @@ Lint/RedundantDirGlobSort:
203
206
  Lint/UnmodifiedReduceAccumulator:
204
207
  Enabled: true
205
208
 
209
+ Lint/NumberedParameterAssignment:
210
+ Enabled: true
211
+
212
+ Lint/OrAssignmentToConstant:
213
+ Enabled: true
214
+
215
+ Lint/SymbolConversion:
216
+ Enabled: true
217
+
218
+ Lint/TripleQuotes:
219
+ Enabled: true
220
+
206
221
  Performance/AncestorsInclude:
207
222
  Enabled: true
208
223
 
@@ -2,6 +2,52 @@
2
2
 
3
3
  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).
4
4
 
5
+ ## [1.0.0] - 2021-01-29
6
+
7
+ ### Configurable record not found behaviour
8
+
9
+ Added configurable strategy for record not found case. By default it won't raise an exception when DNS record not found in mocked records dictionary:
10
+
11
+ ```ruby
12
+ DnsMock.start_server(port: 5300)
13
+ ```
14
+
15
+ ```bash
16
+ dig @localhost -p 5300 A example.com
17
+ ```
18
+
19
+ ```
20
+ ; <<>> DiG 9.10.6 <<>> @localhost -p 5300 A example.com
21
+ ;; Got answer:
22
+ ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38632
23
+ ;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
24
+ ;; WARNING: recursion requested but not available
25
+
26
+ ;; OPT PSEUDOSECTION:
27
+ ; EDNS: version: 0, flags:; udp: 4096
28
+ ;; QUESTION SECTION:
29
+ ;example.com. IN A
30
+
31
+ ;; Query time: 0 msec
32
+ ;; SERVER: 127.0.0.1#5300(127.0.0.1)
33
+ ;; WHEN: Fri Jan 29 08:21:30 EET 2021
34
+ ;; MSG SIZE rcvd: 40
35
+ ```
36
+
37
+ If you want raise an exception when record not found, just start `DnsMock` with `exception_if_not_found: true` option:
38
+
39
+ ```ruby
40
+ DnsMock.start_server(exception_if_not_found: true)
41
+ ```
42
+
43
+ ### Changed
44
+
45
+ - Updated `DnsMock.start_server`
46
+ - Updated `DnsMock::Server`
47
+ - Updated `DnsMock::Response::Message`
48
+ - Updated `DnsMock::Response::Answer`
49
+ - Updated gem version, readme
50
+
5
51
  ## [0.2.1] - 2021-01-27
6
52
 
7
53
  ### Fixed RDNS lookup representation
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dns_mock (0.2.1)
4
+ dns_mock (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.1)
9
+ ast (2.4.2)
10
10
  bundler-audit (0.7.0.1)
11
11
  bundler (>= 1.2.0, < 3)
12
12
  thor (>= 0.18, < 2)
@@ -14,7 +14,7 @@ GEM
14
14
  childprocess (4.0.0)
15
15
  coderay (1.1.3)
16
16
  colorize (0.8.1)
17
- concurrent-ruby (1.1.7)
17
+ concurrent-ruby (1.1.8)
18
18
  diff-lcs (1.4.4)
19
19
  dnsruby (1.61.5)
20
20
  simpleidn (~> 0.1)
@@ -65,11 +65,11 @@ GEM
65
65
  rspec-expectations (3.10.1)
66
66
  diff-lcs (>= 1.2.0, < 2.0)
67
67
  rspec-support (~> 3.10.0)
68
- rspec-mocks (3.10.1)
68
+ rspec-mocks (3.10.2)
69
69
  diff-lcs (>= 1.2.0, < 2.0)
70
70
  rspec-support (~> 3.10.0)
71
- rspec-support (3.10.1)
72
- rubocop (1.8.1)
71
+ rspec-support (3.10.2)
72
+ rubocop (1.9.0)
73
73
  parallel (~> 1.10)
74
74
  parser (>= 3.0.0.0)
75
75
  rainbow (>= 2.2.2, < 4.0)
@@ -78,7 +78,7 @@ GEM
78
78
  rubocop-ast (>= 1.2.0, < 2.0)
79
79
  ruby-progressbar (~> 1.7)
80
80
  unicode-display_width (>= 1.4.0, < 3.0)
81
- rubocop-ast (1.4.0)
81
+ rubocop-ast (1.4.1)
82
82
  parser (>= 2.7.1.5)
83
83
  rubocop-performance (1.9.2)
84
84
  rubocop (>= 0.90.0, < 2.0)
@@ -97,7 +97,7 @@ GEM
97
97
  simplecov-html (0.10.2)
98
98
  simpleidn (0.2.1)
99
99
  unf (~> 0.1.4)
100
- thor (1.0.1)
100
+ thor (1.1.0)
101
101
  unf (0.1.4)
102
102
  unf_ext
103
103
  unf_ext (0.0.7.7)
@@ -118,7 +118,7 @@ DEPENDENCIES
118
118
  reek (~> 6.0, >= 6.0.3)
119
119
  rspec (~> 3.10)
120
120
  rspec-dns (~> 0.1.8)
121
- rubocop (~> 1.8, >= 1.8.1)
121
+ rubocop (~> 1.9)
122
122
  rubocop-performance (~> 1.9, >= 1.9.2)
123
123
  rubocop-rspec (~> 2.1)
124
124
  simplecov (~> 0.17.1)
data/README.md CHANGED
@@ -82,10 +82,12 @@ records = {
82
82
  }
83
83
  }
84
84
 
85
- # Main DnsMock interface. records:Hash, port:Integer are an
86
- # optional params. By default creates dns mock server with empty
87
- # records. A free port for server will be randomly assigned in
88
- # the range from 49152 to 65535. Returns current dns mock server
85
+ # Main DnsMock interface
86
+ # records:Hash, port:Integer, exception_if_not_found:Boolean
87
+ # are optional params. By default creates dns mock server with
88
+ # empty records. A free port for server will be randomly assigned
89
+ # in the range from 49152 to 65535, if record not found exception
90
+ # won't raises. Returns current dns mock server
89
91
  dns_mock_server = DnsMock.start_server(records: records) # => DnsMock::Server instance
90
92
 
91
93
  # returns current dns mock server port
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.3'
42
42
  spec.add_development_dependency 'rspec', '~> 3.10'
43
43
  spec.add_development_dependency 'rspec-dns', '~> 0.1.8'
44
- spec.add_development_dependency 'rubocop', '~> 1.8', '>= 1.8.1'
44
+ spec.add_development_dependency 'rubocop', '~> 1.9'
45
45
  spec.add_development_dependency 'rubocop-performance', '~> 1.9', '>= 1.9.2'
46
46
  spec.add_development_dependency 'rubocop-rspec', '~> 2.1'
47
47
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
@@ -4,8 +4,8 @@ require_relative 'dns_mock/core'
4
4
 
5
5
  module DnsMock
6
6
  class << self
7
- def start_server(server = DnsMock::Server, records: {}, port: nil)
8
- server.new(records: records, port: port)
7
+ def start_server(server = DnsMock::Server, records: {}, port: nil, exception_if_not_found: false)
8
+ server.new(records: records, port: port, exception_if_not_found: exception_if_not_found)
9
9
  end
10
10
 
11
11
  def running_servers
@@ -8,8 +8,9 @@ module DnsMock
8
8
  hash[::Resolv::DNS::Resource::IN.const_get(record_type.upcase)] = record_type
9
9
  end.freeze
10
10
 
11
- def initialize(records)
11
+ def initialize(records, exception_if_not_found)
12
12
  @records = records
13
+ @exception_if_not_found = exception_if_not_found
13
14
  end
14
15
 
15
16
  def build(hostname, record_class)
@@ -19,13 +20,13 @@ module DnsMock
19
20
 
20
21
  private
21
22
 
22
- attr_reader :records, :hostname
23
+ attr_reader :records, :exception_if_not_found, :hostname
23
24
 
24
25
  def record_by_type(record_class)
25
26
  record_type = DnsMock::Response::Answer::REVERSE_TYPE_MAPPER[record_class]
26
27
  found_records = records.dig(hostname.to_s, record_type)
27
- raise DnsMock::Error::RecordNotFound.new(record_type, hostname) unless found_records
28
- found_records
28
+ raise DnsMock::Error::RecordNotFound.new(record_type, hostname) unless found_records || !exception_if_not_found
29
+ Array(found_records)
29
30
  end
30
31
  end
31
32
  end
@@ -3,8 +3,14 @@
3
3
  module DnsMock
4
4
  module Response
5
5
  class Message
6
- def initialize(packet, records, dns_answer = DnsMock::Response::Answer, dns_message = ::Resolv::DNS::Message)
7
- @dns_answer = dns_answer.new(records)
6
+ def initialize(
7
+ packet,
8
+ records,
9
+ exception_if_not_found,
10
+ dns_answer = DnsMock::Response::Answer,
11
+ dns_message = ::Resolv::DNS::Message
12
+ )
13
+ @dns_answer = dns_answer.new(records, exception_if_not_found)
8
14
  @dns_message = dns_message.decode(packet)
9
15
  end
10
16
 
@@ -15,13 +15,15 @@ module DnsMock
15
15
  random_available_port = DnsMock::Server::RandomAvailablePort,
16
16
  thread_class = ::Thread,
17
17
  records: nil,
18
- port: nil
18
+ port: nil,
19
+ exception_if_not_found: false
19
20
  )
20
21
  @socket = socket
21
22
  @records_dictionary_builder = records_dictionary_builder
22
23
  @thread_class = thread_class
23
24
  @records = records_dictionary_builder.call(records || {})
24
25
  @port = port || random_available_port.call
26
+ @exception_if_not_found = exception_if_not_found
25
27
  prepare_server_thread
26
28
  end
27
29
 
@@ -34,7 +36,7 @@ module DnsMock
34
36
  break if packet.size.zero?
35
37
 
36
38
  address, port = addr.values_at(3, 1)
37
- socket.send(DnsMock::Response::Message.new(packet, records).as_binary_string, 0, address, port)
39
+ socket.send(DnsMock::Response::Message.new(packet, records, exception_if_not_found).as_binary_string, 0, address, port)
38
40
  end
39
41
  ensure
40
42
  socket.close
@@ -63,7 +65,7 @@ module DnsMock
63
65
 
64
66
  private
65
67
 
66
- attr_reader :socket, :records_dictionary_builder, :thread_class
68
+ attr_reader :socket, :records_dictionary_builder, :thread_class, :exception_if_not_found
67
69
  attr_accessor :records, :thread
68
70
 
69
71
  def prepare_socket_for_session
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DnsMock
4
- VERSION = '0.2.1'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -174,20 +174,14 @@ dependencies:
174
174
  requirements:
175
175
  - - "~>"
176
176
  - !ruby/object:Gem::Version
177
- version: '1.8'
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: 1.8.1
177
+ version: '1.9'
181
178
  type: :development
182
179
  prerelease: false
183
180
  version_requirements: !ruby/object:Gem::Requirement
184
181
  requirements:
185
182
  - - "~>"
186
183
  - !ruby/object:Gem::Version
187
- version: '1.8'
188
- - - ">="
189
- - !ruby/object:Gem::Version
190
- version: 1.8.1
184
+ version: '1.9'
191
185
  - !ruby/object:Gem::Dependency
192
186
  name: rubocop-performance
193
187
  requirement: !ruby/object:Gem::Requirement