dns_mock 1.2.4 → 1.3.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: 48eac73ca0f2e0aef0f0e84a87eb79dc240e44529eb0ac3e3d34417dd2886f1a
4
- data.tar.gz: 604d66dbc157a3c0159ba0355eb5b12d97c9a8da78de580902985b1c452e2e42
3
+ metadata.gz: 7bc358120372b309038c4f457483268e58c22ff6e96667bbdf6a398896248749
4
+ data.tar.gz: d468e04f015a7bd7f5f535454356d2f2affcf3517eb6e0fcc261bc38ddea388d
5
5
  SHA512:
6
- metadata.gz: 2b679e4f84f3f465e05e0d4c4c2a7507899fdd2c4acef4ea2f82ff69f837f9086f2a2d238dbf67548d1c5309e4ca715859ab1877de28fdf471c80c33ae79b616
7
- data.tar.gz: fe8fd0cf5723bc58c3dc72e1f528e8379546f1c9def076413de47a28e025956a4e972f3ac885f77f6dd51675c6d39a7308b6490f637bf4f53f9b7fc406a6b15c
6
+ metadata.gz: 318e2a60578aa2a01a0c548fbccd7477b2556f8d0403af15e26d0425e86a10bb2d596616bae764c7ceec8eaa6d89b09437c34bc6ff2ac5cc20890431289177e0
7
+ data.tar.gz: f74189c81ad853915633bac2ff05f3f48d80a8a52e19198545416b850987fefa8b30475e2db202a8c032ecb7ecf60ab8c4da18645d0c5455620ddee05a0ff73b
data/.codeclimate.yml CHANGED
@@ -7,7 +7,7 @@ checks:
7
7
  plugins:
8
8
  rubocop:
9
9
  enabled: true
10
- channel: rubocop-1-15
10
+ channel: rubocop-1-16
11
11
 
12
12
  reek:
13
13
  enabled: true
data/.rubocop.yml CHANGED
@@ -127,6 +127,15 @@ Style/HashConversion:
127
127
  Style/StringChars:
128
128
  Enabled: true
129
129
 
130
+ Style/InPatternThen:
131
+ Enabled: true
132
+
133
+ Style/MultilineInPatternThen:
134
+ Enabled: true
135
+
136
+ Style/QuotedSymbols:
137
+ Enabled: true
138
+
130
139
  Layout/LineLength:
131
140
  Max: 150
132
141
 
@@ -224,6 +233,9 @@ Lint/SymbolConversion:
224
233
  Lint/TripleQuotes:
225
234
  Enabled: true
226
235
 
236
+ Lint/EmptyInPattern:
237
+ Enabled: true
238
+
227
239
  Gemspec/DateAssignment:
228
240
  Enabled: true
229
241
 
@@ -304,3 +316,9 @@ RSpec/MultipleMemoizedHelpers:
304
316
 
305
317
  RSpec/StubbedMock:
306
318
  Enabled: false
319
+
320
+ RSpec/IdenticalEqualityAssertion:
321
+ Enabled: true
322
+
323
+ RSpec/Rails/AvoidSetupHook:
324
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
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.3.0] - 2021-06-14
6
+
7
+ Detecting random available port via OS features. Thanks [@ioquatix](https://github.com/ioquatix) for [suggestion](https://github.com/mocktools/ruby-dns-mock/issues/42) 🚀
8
+
9
+ ### Removed
10
+
11
+ - Removed `DnsMock::Server::RandomAvailablePort`
12
+
13
+ ### Changed
14
+
15
+ - Updated `DnsMock::Server` class
16
+ - Updated tests helpers/tests
17
+ - Updated gem development dependencies
18
+
19
+ ### Fixed
20
+
21
+ - Test coverage issues
22
+
5
23
  ## [1.2.4] - 2021-05-25
6
24
 
7
25
  ### Changed
@@ -150,7 +168,7 @@ DnsMock.start_server(exception_if_not_found: true)
150
168
 
151
169
  ## [0.2.1] - 2021-01-27
152
170
 
153
- ### Fixed RDNS lookup representation
171
+ ### Fixed
154
172
 
155
173
  Fixed RDNS lookup representatin for IP address in PTR record feature.
156
174
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dns_mock (1.2.4)
4
+ dns_mock (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -11,10 +11,10 @@ GEM
11
11
  bundler (>= 1.2.0, < 3)
12
12
  thor (~> 1.0)
13
13
  byebug (11.1.3)
14
- childprocess (4.0.0)
14
+ childprocess (4.1.0)
15
15
  coderay (1.1.3)
16
16
  colorize (0.8.1)
17
- concurrent-ruby (1.1.8)
17
+ concurrent-ruby (1.1.9)
18
18
  diff-lcs (1.4.4)
19
19
  dnsruby (1.61.5)
20
20
  simpleidn (~> 0.1)
@@ -30,9 +30,10 @@ GEM
30
30
  json (2.5.1)
31
31
  kwalify (0.7.2)
32
32
  method_source (1.0.0)
33
- overcommit (0.57.0)
33
+ overcommit (0.58.0)
34
34
  childprocess (>= 0.6.3, < 5)
35
35
  iniparse (~> 1.4)
36
+ rexml (~> 3.2)
36
37
  parallel (1.20.1)
37
38
  parser (3.0.1.1)
38
39
  ast (~> 2.4.1)
@@ -69,21 +70,21 @@ GEM
69
70
  diff-lcs (>= 1.2.0, < 2.0)
70
71
  rspec-support (~> 3.10.0)
71
72
  rspec-support (3.10.2)
72
- rubocop (1.15.0)
73
+ rubocop (1.16.1)
73
74
  parallel (~> 1.10)
74
75
  parser (>= 3.0.0.0)
75
76
  rainbow (>= 2.2.2, < 4.0)
76
77
  regexp_parser (>= 1.8, < 3.0)
77
78
  rexml
78
- rubocop-ast (>= 1.5.0, < 2.0)
79
+ rubocop-ast (>= 1.7.0, < 2.0)
79
80
  ruby-progressbar (~> 1.7)
80
81
  unicode-display_width (>= 1.4.0, < 3.0)
81
- rubocop-ast (1.5.0)
82
+ rubocop-ast (1.7.0)
82
83
  parser (>= 3.0.1.1)
83
84
  rubocop-performance (1.11.3)
84
85
  rubocop (>= 1.7.0, < 2.0)
85
86
  rubocop-ast (>= 0.4.0)
86
- rubocop-rspec (2.3.0)
87
+ rubocop-rspec (2.4.0)
87
88
  rubocop (~> 1.0)
88
89
  rubocop-ast (>= 1.1.0)
89
90
  ruby-progressbar (1.11.0)
@@ -107,21 +108,21 @@ PLATFORMS
107
108
  x86_64-darwin-19
108
109
 
109
110
  DEPENDENCIES
110
- bundler (~> 2.2, >= 2.2.17)
111
+ bundler (~> 2.2, >= 2.2.20)
111
112
  bundler-audit (~> 0.8.0)
112
113
  dns_mock!
113
114
  faker (~> 2.18)
114
115
  fasterer (~> 0.9.0)
115
- overcommit (~> 0.57.0)
116
+ overcommit (~> 0.58.0)
116
117
  pry-byebug (~> 3.9)
117
118
  rake (~> 13.0, >= 13.0.3)
118
119
  reek (~> 6.0, >= 6.0.4)
119
120
  rspec (~> 3.10)
120
121
  rspec-dns (~> 0.1.8)
121
- rubocop (~> 1.15)
122
+ rubocop (~> 1.16, >= 1.16.1)
122
123
  rubocop-performance (~> 1.11, >= 1.11.3)
123
- rubocop-rspec (~> 2.3)
124
+ rubocop-rspec (~> 2.4)
124
125
  simplecov (~> 0.17.1)
125
126
 
126
127
  BUNDLED WITH
127
- 2.2.17
128
+ 2.2.20
data/README.md CHANGED
@@ -90,7 +90,9 @@ records = {
90
90
  # are optional params. By default creates dns mock server with
91
91
  # empty records. A free port for server will be randomly assigned
92
92
  # in the range from 49152 to 65535, if record not found exception
93
- # won't raises. Returns current dns mock server
93
+ # won't raises. Please note if you specify zero port number,
94
+ # free port number will be randomly assigned as a server port too.
95
+ # Returns current dns mock server
94
96
  dns_mock_server = DnsMock.start_server(records: records) # => DnsMock::Server instance
95
97
 
96
98
  # returns current dns mock server port
data/dns_mock.gemspec CHANGED
@@ -31,18 +31,18 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ['lib']
33
33
 
34
- spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.17'
34
+ spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.20'
35
35
  spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
36
36
  spec.add_development_dependency 'faker', '~> 2.18'
37
37
  spec.add_development_dependency 'fasterer', '~> 0.9.0'
38
- spec.add_development_dependency 'overcommit', '~> 0.57.0'
38
+ spec.add_development_dependency 'overcommit', '~> 0.58.0'
39
39
  spec.add_development_dependency 'pry-byebug', '~> 3.9'
40
40
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
41
41
  spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
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.15'
44
+ spec.add_development_dependency 'rubocop', '~> 1.16', '>= 1.16.1'
45
45
  spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
46
- spec.add_development_dependency 'rubocop-rspec', '~> 2.3'
46
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.4'
47
47
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
48
48
  end
data/lib/dns_mock/core.rb CHANGED
@@ -53,6 +53,5 @@ module DnsMock
53
53
 
54
54
  require_relative '../dns_mock/version'
55
55
  require_relative '../dns_mock/server/records_dictionary_builder'
56
- require_relative '../dns_mock/server/random_available_port'
57
56
  require_relative '../dns_mock/server'
58
57
  end
@@ -4,6 +4,8 @@ module DnsMock
4
4
  class Server
5
5
  include DnsMock::Error::Helper
6
6
 
7
+ CURRENT_HOST_NAME = 'localhost'
8
+ CURRENT_HOST_ADDRESS = '127.0.0.1'
7
9
  WARMUP_DELAY = 0.1
8
10
  PACKET_MAX_BYTES_SIZE = 65_535
9
11
 
@@ -12,7 +14,6 @@ module DnsMock
12
14
  def initialize( # rubocop:disable Metrics/ParameterLists
13
15
  socket = ::UDPSocket.new,
14
16
  records_dictionary_builder = DnsMock::Server::RecordsDictionaryBuilder,
15
- random_available_port = DnsMock::Server::RandomAvailablePort,
16
17
  thread_class = ::Thread,
17
18
  records: nil,
18
19
  port: nil,
@@ -22,13 +23,14 @@ module DnsMock
22
23
  @records_dictionary_builder = records_dictionary_builder
23
24
  @thread_class = thread_class
24
25
  @records = records_dictionary_builder.call(records || {})
25
- @port = port || random_available_port.call
26
+ @port = port || 0
26
27
  @exception_if_not_found = exception_if_not_found
27
28
  prepare_server_thread
28
29
  end
29
30
 
30
31
  def run
31
32
  prepare_socket_for_session
33
+ update_server_port
32
34
 
33
35
  begin
34
36
  loop do
@@ -66,6 +68,7 @@ module DnsMock
66
68
  private
67
69
 
68
70
  attr_reader :socket, :records_dictionary_builder, :thread_class, :exception_if_not_found
71
+ attr_writer :port
69
72
  attr_accessor :records, :thread
70
73
 
71
74
  def prepare_socket_for_session
@@ -76,6 +79,10 @@ module DnsMock
76
79
  raise DnsMock::Error::PortInUse.new(DnsMock::Server::CURRENT_HOST_NAME, port)
77
80
  end
78
81
 
82
+ def update_server_port
83
+ self.port = socket.addr[1] if port.zero?
84
+ end
85
+
79
86
  def prepare_server_thread
80
87
  self.thread = thread_class.new { run }
81
88
  thread.join(DnsMock::Server::WARMUP_DELAY)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DnsMock
4
- VERSION = '1.2.4'
4
+ VERSION = '1.3.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: 1.2.4
4
+ version: 1.3.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-05-25 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '2.2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 2.2.17
22
+ version: 2.2.20
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '2.2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 2.2.17
32
+ version: 2.2.20
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 0.57.0
81
+ version: 0.58.0
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: 0.57.0
88
+ version: 0.58.0
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pry-byebug
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -174,14 +174,20 @@ dependencies:
174
174
  requirements:
175
175
  - - "~>"
176
176
  - !ruby/object:Gem::Version
177
- version: '1.15'
177
+ version: '1.16'
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: 1.16.1
178
181
  type: :development
179
182
  prerelease: false
180
183
  version_requirements: !ruby/object:Gem::Requirement
181
184
  requirements:
182
185
  - - "~>"
183
186
  - !ruby/object:Gem::Version
184
- version: '1.15'
187
+ version: '1.16'
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: 1.16.1
185
191
  - !ruby/object:Gem::Dependency
186
192
  name: rubocop-performance
187
193
  requirement: !ruby/object:Gem::Requirement
@@ -208,14 +214,14 @@ dependencies:
208
214
  requirements:
209
215
  - - "~>"
210
216
  - !ruby/object:Gem::Version
211
- version: '2.3'
217
+ version: '2.4'
212
218
  type: :development
213
219
  prerelease: false
214
220
  version_requirements: !ruby/object:Gem::Requirement
215
221
  requirements:
216
222
  - - "~>"
217
223
  - !ruby/object:Gem::Version
218
- version: '2.3'
224
+ version: '2.4'
219
225
  - !ruby/object:Gem::Dependency
220
226
  name: simplecov
221
227
  requirement: !ruby/object:Gem::Requirement
@@ -296,7 +302,6 @@ files:
296
302
  - lib/dns_mock/response/answer.rb
297
303
  - lib/dns_mock/response/message.rb
298
304
  - lib/dns_mock/server.rb
299
- - lib/dns_mock/server/random_available_port.rb
300
305
  - lib/dns_mock/server/records_dictionary_builder.rb
301
306
  - lib/dns_mock/test_framework/rspec.rb
302
307
  - lib/dns_mock/test_framework/rspec/helper.rb
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module DnsMock
4
- class Server
5
- CURRENT_HOST_NAME = 'localhost'
6
- CURRENT_HOST_ADDRESS = '127.0.0.1'
7
-
8
- class RandomAvailablePort
9
- ATTEMPTS = 100
10
- MIN_DYNAMIC_PORT_NUMBER = 49_152
11
- MAX_DYNAMIC_PORT_NUMBER = 65_535
12
-
13
- class << self
14
- def call
15
- DnsMock::Server::RandomAvailablePort::ATTEMPTS.times do
16
- port = rand(
17
- DnsMock::Server::RandomAvailablePort::MIN_DYNAMIC_PORT_NUMBER..DnsMock::Server::RandomAvailablePort::MAX_DYNAMIC_PORT_NUMBER
18
- )
19
- return port if port_free?(port)
20
- end
21
- raise DnsMock::Error::RandomFreePort, DnsMock::Server::RandomAvailablePort::ATTEMPTS
22
- end
23
-
24
- private
25
-
26
- def udp_port_free?(port, socket = ::UDPSocket.new)
27
- socket.bind(DnsMock::Server::CURRENT_HOST_NAME, port)
28
- socket.close
29
- true
30
- rescue ::Errno::EADDRINUSE
31
- false
32
- end
33
-
34
- def tcp_port_free?(port, socket = ::Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, 0))
35
- socket.bind(::Socket.sockaddr_in(port, DnsMock::Server::CURRENT_HOST_ADDRESS))
36
- socket.close
37
- true
38
- rescue ::Errno::EADDRINUSE
39
- false
40
- end
41
-
42
- def port_free?(port)
43
- udp_port_free?(port) && tcp_port_free?(port)
44
- end
45
- end
46
- end
47
- end
48
- end