dns_mock 1.2.4 → 1.4.1

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: f80d58ba0e1a3da7fb429471d2c85ff3fb7f7730172337fbf13a96fbd751c8ad
4
+ data.tar.gz: d93868cd157eba9699b5578b8f76e08a11c2d9fa6de33a6151b64c401e1533cd
5
5
  SHA512:
6
- metadata.gz: 2b679e4f84f3f465e05e0d4c4c2a7507899fdd2c4acef4ea2f82ff69f837f9086f2a2d238dbf67548d1c5309e4ca715859ab1877de28fdf471c80c33ae79b616
7
- data.tar.gz: fe8fd0cf5723bc58c3dc72e1f528e8379546f1c9def076413de47a28e025956a4e972f3ac885f77f6dd51675c6d39a7308b6490f637bf4f53f9b7fc406a6b15c
6
+ metadata.gz: 258cf718520472f5612a43bc4b2395b4cdb8e82ded3f0f1f911baa3ad1ca0b02b1e78d16f1406c5bf2044dfd77beaa00d0f0a61ffc64dfc267fc1f3a3f8b8dfe
7
+ data.tar.gz: abf8242a9cf9b68d4e0770860a3bab88c7b8704429685647939465b87b7ae7699942fbfc776bf19efecfc92c1e5f9e68118c2de5bf57819b0726a5242c6cfc2c
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-19
11
11
 
12
12
  reek:
13
13
  enabled: true
data/.reek.yml CHANGED
@@ -17,17 +17,23 @@ detectors:
17
17
  - DnsMock::ContextGeneratorHelper#random_ip_v4_address
18
18
  - DnsMock::ContextGeneratorHelper#random_ip_v6_address
19
19
  - DnsMock::ContextGeneratorHelper#random_txt_record_context
20
+ - DnsMock::ContextGeneratorHelper#to_punycode_hostname
20
21
  - DnsMock::RecordsDictionaryHelper#create_records_dictionary_by_records
21
22
  - DnsMock::ServerHelper#start_random_server
22
23
  - DnsMock::ServerHelper#stop_all_running_servers
23
- - DnsMock::Server::RecordsDictionaryBuilder#rdns_lookup_prefix
24
24
  - DnsMock::ContextGeneratorHelper#random_port_number
25
25
  - DnsMock::TestFramework::RSpec::Helper#dns_mock_server
26
+ - DnsMock::ContextGeneratorHelper#to_rdns_hostaddress
27
+
28
+ DuplicateMethodCall:
29
+ exclude:
30
+ - DnsMock::ContextGeneratorHelper#create_records
26
31
 
27
32
  ControlParameter:
28
33
  exclude:
29
34
  - DnsMock::Error::Helper#raise_unless
30
35
  - DnsMock::Server#initialize
36
+ - DnsMock::ContextGeneratorHelper#to_punycode_hostname
31
37
 
32
38
  MissingSafeMethod:
33
39
  exclude:
data/.rubocop.yml CHANGED
@@ -28,6 +28,9 @@ Naming/VariableNumber:
28
28
  Naming/RescuedExceptionsVariableName:
29
29
  Enabled: false
30
30
 
31
+ Naming/InclusiveLanguage:
32
+ Enabled: false
33
+
31
34
  Style/Documentation:
32
35
  Enabled: false
33
36
 
@@ -127,6 +130,18 @@ Style/HashConversion:
127
130
  Style/StringChars:
128
131
  Enabled: true
129
132
 
133
+ Style/InPatternThen:
134
+ Enabled: true
135
+
136
+ Style/MultilineInPatternThen:
137
+ Enabled: true
138
+
139
+ Style/QuotedSymbols:
140
+ Enabled: true
141
+
142
+ Style/RedundantSelfAssignmentBranch:
143
+ Enabled: true
144
+
130
145
  Layout/LineLength:
131
146
  Max: 150
132
147
 
@@ -158,6 +173,9 @@ Layout/EmptyLineAfterGuardClause:
158
173
  Layout/SpaceBeforeBrackets:
159
174
  Enabled: true
160
175
 
176
+ Layout/LineEndStringConcatenationIndentation:
177
+ Enabled: true
178
+
161
179
  Lint/NonDeterministicRequireOrder:
162
180
  Enabled: true
163
181
 
@@ -224,6 +242,12 @@ Lint/SymbolConversion:
224
242
  Lint/TripleQuotes:
225
243
  Enabled: true
226
244
 
245
+ Lint/EmptyInPattern:
246
+ Enabled: true
247
+
248
+ Lint/AmbiguousRange:
249
+ Enabled: true
250
+
227
251
  Gemspec/DateAssignment:
228
252
  Enabled: true
229
253
 
@@ -304,3 +328,9 @@ RSpec/MultipleMemoizedHelpers:
304
328
 
305
329
  RSpec/StubbedMock:
306
330
  Enabled: false
331
+
332
+ RSpec/IdenticalEqualityAssertion:
333
+ Enabled: true
334
+
335
+ RSpec/Rails/AvoidSetupHook:
336
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -2,6 +2,104 @@
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.4.1] - 2021-08-16
6
+
7
+ ### Updated
8
+
9
+ - Updated gem development dependencies
10
+ - Updated gem version
11
+
12
+ ### Changed
13
+
14
+ - `faker` to `ffaker` development dependency
15
+
16
+ ## [1.4.0] - 2021-07-13
17
+
18
+ ### Added
19
+
20
+ - Added ability to use internationalized hostnames. All hostnames in UTF-8 will be represented as [Punycode](https://en.wikipedia.org/wiki/Punycode)
21
+ - Added `simpleidn` as runtime dependency
22
+ - Added `DnsMock::Representer::Punycode`, tests
23
+
24
+ ```ruby
25
+ records = {
26
+ 'mañana.com' => {
27
+ mx: %w[másletras.mañana.com]
28
+ }
29
+ }
30
+
31
+ DnsMock.start_server(port: 5300, records: records)
32
+ ```
33
+
34
+ ```bash
35
+ dig @localhost -p 5300 MX xn--maana-pta.com
36
+ ```
37
+
38
+ ```
39
+ ; <<>> DiG 9.10.6 <<>> @localhost -p 5300 MX xn--maana-pta.com
40
+ ; (2 servers found)
41
+ ;; global options: +cmd
42
+ ;; Got answer:
43
+ ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4612
44
+ ;; flags: rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
45
+ ;; WARNING: recursion requested but not available
46
+
47
+ ;; OPT PSEUDOSECTION:
48
+ ; EDNS: version: 0, flags:; udp: 4096
49
+ ;; QUESTION SECTION:
50
+ ;xn--maana-pta.com. IN MX
51
+
52
+ ;; ANSWER SECTION:
53
+ xn--maana-pta.com. 1 IN MX 10 xn--msletras-8ya.xn--maana-pta.com.
54
+
55
+ ;; Query time: 0 msec
56
+ ;; SERVER: 127.0.0.1#5300(127.0.0.1)
57
+ ;; WHEN: Tue Jul 13 15:38:47 EEST 2021
58
+ ;; MSG SIZE rcvd: 79
59
+ ```
60
+
61
+ ### Changed
62
+
63
+ - Refactored `DnsMock::Representer::RdnsLookup`, tests
64
+ - Updated `DnsMock::Record::Factory::Base`
65
+ - Updated `DnsMock::Server::RecordsDictionaryBuilder`, tests
66
+ - Updated `DnsMock::Record::Factory::Cname`, tests
67
+ - Updated `DnsMock::Record::Factory::Mx`, tests
68
+ - Updated `DnsMock::Record::Factory::Ns`, tests
69
+ - Updated `DnsMock::Record::Factory::Ptr`, tests
70
+ - Updated `DnsMock::Record::Factory::Soa`, tests
71
+ - Updated `DnsMock::ContextGeneratorHelper`, tests
72
+ - Updated reek config
73
+ - Updated gem documentation, version
74
+
75
+ ## [1.3.1] - 2021-07-07
76
+
77
+ ### Changed
78
+
79
+ - Updated gem development dependencies
80
+ - Updated rubocop/codeclimate config
81
+ - Updated gem documentation, version
82
+
83
+ ## [1.3.0] - 2021-06-14
84
+
85
+ ### Added
86
+
87
+ - Detecting random available port via OS features. Thanks [@ioquatix](https://github.com/ioquatix) for [suggestion](https://github.com/mocktools/ruby-dns-mock/issues/42) 🚀
88
+
89
+ ### Removed
90
+
91
+ - Removed `DnsMock::Server::RandomAvailablePort`, tests
92
+
93
+ ### Changed
94
+
95
+ - Updated `DnsMock::Server` class
96
+ - Updated tests helpers/tests
97
+ - Updated gem development dependencies
98
+
99
+ ### Fixed
100
+
101
+ - Test coverage issues
102
+
5
103
  ## [1.2.4] - 2021-05-25
6
104
 
7
105
  ### Changed
@@ -35,9 +133,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
35
133
 
36
134
  ## [1.2.0] - 2021-02-04
37
135
 
38
- ### Ability to specify MX record priority
136
+ ### Added
39
137
 
40
- Added ability to specify custom priority of MX record if it needed. Now it impossible to define null or backup MX records. Please note, if you haven't specified a priority of MX record, it will be assigned automatically. MX records builder is assigning priority with step 10 from first item of defined MX records array.
138
+ - Ability to specify custom priority of MX record if it needed
139
+
140
+ Now is possible to define null or backup MX records. Please note, if you haven't specified a priority of MX record, it will be assigned automatically. MX records builder is assigning priority with step 10 from first item of defined MX records array.
41
141
 
42
142
  ```ruby
43
143
  records = {
@@ -70,9 +170,9 @@ example.com. 1 IN MX 40 mx3.domain.com.
70
170
 
71
171
  ## [1.1.0] - 2021-02-01
72
172
 
73
- ### RSpec native support
173
+ ### Added
74
174
 
75
- Added DnsMock helper which can simplify integration with RSpec.
175
+ - RSpec native support. DnsMock helper help you to simplify integration with RSpec
76
176
 
77
177
  ```ruby
78
178
  # spec/support/config/dns_mock.rb
@@ -104,9 +204,11 @@ end
104
204
 
105
205
  ## [1.0.0] - 2021-01-29
106
206
 
107
- ### Configurable record not found behaviour
207
+ ### Added
208
+
209
+ - Configurable strategy for record not found case
108
210
 
109
- 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:
211
+ By default it won't raise an exception when DNS record not found in mocked records dictionary:
110
212
 
111
213
  ```ruby
112
214
  DnsMock.start_server(port: 5300)
@@ -150,19 +252,21 @@ DnsMock.start_server(exception_if_not_found: true)
150
252
 
151
253
  ## [0.2.1] - 2021-01-27
152
254
 
153
- ### Fixed RDNS lookup representation
255
+ ### Fixed
154
256
 
155
- Fixed RDNS lookup representatin for IP address in PTR record feature.
257
+ - RDNS lookup representatin for IP address in PTR record feature.
156
258
 
157
259
  ## [0.2.0] - 2021-01-26
158
260
 
159
- ### PTR record support
261
+ ### Added
262
+
263
+ - PTR record support. Ability to mock PTR records
160
264
 
161
- Added ability to mock PTR records. Please note, you can define host address without RDNS lookup prefix (`.in-addr.arpa`). `DnsMock` will do it for you.
265
+ Please note, you can define host address without RDNS lookup prefix (`.in-addr.arpa`). `DnsMock` will do it for you.
162
266
 
163
267
  ```ruby
164
268
  records = {
165
- '1.1.1.1' => {
269
+ '1.2.3.4' => {
166
270
  ptr: %w[domain_1.com domain_2.com]
167
271
  }
168
272
  }
@@ -171,7 +275,7 @@ DnsMock.start_server(records: records)
171
275
  ```
172
276
 
173
277
  ```bash
174
- dig @localhost -p 5300 -x 1.1.1.1
278
+ dig @localhost -p 5300 -x 1.2.3.4
175
279
  ```
176
280
 
177
281
  ```
@@ -179,8 +283,8 @@ dig @localhost -p 5300 -x 1.1.1.1
179
283
  ; (2 servers found)
180
284
 
181
285
  ;; ANSWER SECTION:
182
- 1.1.1.1.in-addr.arpa. 1 IN PTR domain_1.com.
183
- 1.1.1.1.in-addr.arpa. 1 IN PTR domain_2.com.
286
+ 4.3.2.1.in-addr.arpa. 1 IN PTR domain_1.com.
287
+ 4.3.2.1.in-addr.arpa. 1 IN PTR domain_2.com.
184
288
 
185
289
  ;; Query time: 0 msec
186
290
  ;; SERVER: 127.0.0.1#5300(127.0.0.1)
@@ -190,6 +294,6 @@ dig @localhost -p 5300 -x 1.1.1.1
190
294
 
191
295
  ## [0.1.0] - 2021-01-19
192
296
 
193
- ### First release
297
+ ### Added
194
298
 
195
- Implemented first version of `DnsMock`. Thanks [@le0pard](https://github.com/le0pard) for idea & support 🚀
299
+ - First release of `DnsMock`. Thanks [@le0pard](https://github.com/le0pard) for idea & support 🚀
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dns_mock (1.2.4)
4
+ dns_mock (1.4.1)
5
+ simpleidn (~> 0.2.1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -11,30 +12,27 @@ GEM
11
12
  bundler (>= 1.2.0, < 3)
12
13
  thor (~> 1.0)
13
14
  byebug (11.1.3)
14
- childprocess (4.0.0)
15
+ childprocess (4.1.0)
15
16
  coderay (1.1.3)
16
17
  colorize (0.8.1)
17
- concurrent-ruby (1.1.8)
18
18
  diff-lcs (1.4.4)
19
- dnsruby (1.61.5)
19
+ dnsruby (1.61.7)
20
20
  simpleidn (~> 0.1)
21
21
  docile (1.4.0)
22
- faker (2.18.0)
23
- i18n (>= 1.6, < 2)
24
22
  fasterer (0.9.0)
25
23
  colorize (~> 0.7)
26
24
  ruby_parser (>= 3.14.1)
27
- i18n (1.8.10)
28
- concurrent-ruby (~> 1.0)
25
+ ffaker (2.18.0)
29
26
  iniparse (1.5.0)
30
27
  json (2.5.1)
31
28
  kwalify (0.7.2)
32
29
  method_source (1.0.0)
33
- overcommit (0.57.0)
30
+ overcommit (0.58.0)
34
31
  childprocess (>= 0.6.3, < 5)
35
32
  iniparse (~> 1.4)
33
+ rexml (~> 3.2)
36
34
  parallel (1.20.1)
37
- parser (3.0.1.1)
35
+ parser (3.0.2.0)
38
36
  ast (~> 2.4.1)
39
37
  pry (0.13.1)
40
38
  coderay (~> 1.1)
@@ -42,13 +40,11 @@ GEM
42
40
  pry-byebug (3.9.0)
43
41
  byebug (~> 11.0)
44
42
  pry (~> 0.13.0)
45
- psych (3.3.2)
46
43
  rainbow (3.0.0)
47
- rake (13.0.3)
48
- reek (6.0.4)
44
+ rake (13.0.6)
45
+ reek (6.0.6)
49
46
  kwalify (~> 0.7.0)
50
47
  parser (~> 3.0.0)
51
- psych (~> 3.1)
52
48
  rainbow (>= 2.0, < 4.0)
53
49
  regexp_parser (2.1.1)
54
50
  rexml (3.2.5)
@@ -69,25 +65,25 @@ GEM
69
65
  diff-lcs (>= 1.2.0, < 2.0)
70
66
  rspec-support (~> 3.10.0)
71
67
  rspec-support (3.10.2)
72
- rubocop (1.15.0)
68
+ rubocop (1.19.0)
73
69
  parallel (~> 1.10)
74
70
  parser (>= 3.0.0.0)
75
71
  rainbow (>= 2.2.2, < 4.0)
76
72
  regexp_parser (>= 1.8, < 3.0)
77
73
  rexml
78
- rubocop-ast (>= 1.5.0, < 2.0)
74
+ rubocop-ast (>= 1.9.1, < 2.0)
79
75
  ruby-progressbar (~> 1.7)
80
76
  unicode-display_width (>= 1.4.0, < 3.0)
81
- rubocop-ast (1.5.0)
77
+ rubocop-ast (1.10.0)
82
78
  parser (>= 3.0.1.1)
83
- rubocop-performance (1.11.3)
79
+ rubocop-performance (1.11.4)
84
80
  rubocop (>= 1.7.0, < 2.0)
85
81
  rubocop-ast (>= 0.4.0)
86
- rubocop-rspec (2.3.0)
82
+ rubocop-rspec (2.4.0)
87
83
  rubocop (~> 1.0)
88
84
  rubocop-ast (>= 1.1.0)
89
85
  ruby-progressbar (1.11.0)
90
- ruby_parser (3.16.0)
86
+ ruby_parser (3.17.0)
91
87
  sexp_processor (~> 4.15, >= 4.15.1)
92
88
  sexp_processor (4.15.3)
93
89
  simplecov (0.17.1)
@@ -104,24 +100,24 @@ GEM
104
100
  unicode-display_width (2.0.0)
105
101
 
106
102
  PLATFORMS
107
- x86_64-darwin-19
103
+ x86_64-darwin-20
108
104
 
109
105
  DEPENDENCIES
110
- bundler (~> 2.2, >= 2.2.17)
106
+ bundler (~> 2.2, >= 2.2.25)
111
107
  bundler-audit (~> 0.8.0)
112
108
  dns_mock!
113
- faker (~> 2.18)
114
109
  fasterer (~> 0.9.0)
115
- overcommit (~> 0.57.0)
110
+ ffaker (~> 2.18)
111
+ overcommit (~> 0.58.0)
116
112
  pry-byebug (~> 3.9)
117
- rake (~> 13.0, >= 13.0.3)
118
- reek (~> 6.0, >= 6.0.4)
113
+ rake (~> 13.0, >= 13.0.6)
114
+ reek (~> 6.0, >= 6.0.6)
119
115
  rspec (~> 3.10)
120
116
  rspec-dns (~> 0.1.8)
121
- rubocop (~> 1.15)
122
- rubocop-performance (~> 1.11, >= 1.11.3)
123
- rubocop-rspec (~> 2.3)
117
+ rubocop (~> 1.19)
118
+ rubocop-performance (~> 1.11, >= 1.11.4)
119
+ rubocop-rspec (~> 2.4)
124
120
  simplecov (~> 0.17.1)
125
121
 
126
122
  BUNDLED WITH
127
- 2.2.17
123
+ 2.2.25
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ruby DnsMock
1
+ # ![Ruby DnsMock - mimic any DNS records for your test environment and even more!](https://repository-images.githubusercontent.com/323097031/ba2a0780-df26-11eb-954b-5e3204587eb2)
2
2
 
3
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/5ea9da61ef468b8ad4c4/maintainability)](https://codeclimate.com/github/mocktools/ruby-dns-mock/maintainability)
4
4
  [![Test Coverage](https://api.codeclimate.com/v1/badges/5ea9da61ef468b8ad4c4/test_coverage)](https://codeclimate.com/github/mocktools/ruby-dns-mock/test_coverage)
@@ -29,10 +29,11 @@
29
29
  ## Features
30
30
 
31
31
  - Ability to mimic any DNS records (`A`, `AAAA`, `CNAME`, `MX`, `NS`, `PTR`, `SOA` and `TXT`)
32
- - Zero runtime dependencies
32
+ - Automatically converts hostnames to RDNS/[Punycode](https://en.wikipedia.org/wiki/Punycode) representation
33
33
  - Lightweight UDP DNS mock server with dynamic/manual port assignment
34
34
  - Test framework agnostic (it's PORO, so you can use it outside of `RSpec`, `Test::Unit` or `MiniTest`)
35
35
  - Simple and intuitive DSL
36
+ - Only one runtime dependency
36
37
 
37
38
  ## Requirements
38
39
 
@@ -67,7 +68,7 @@ records = {
67
68
  ns: %w[ns1.domain.com ns2.domain.com],
68
69
  mx: %w[mx1.domain.com mx2.domain.com:50], # you can specify host(s) or host(s) with priority, use '.:0' for definition null MX record
69
70
  txt: %w[txt_record_1 txt_record_2],
70
- cname: 'some.domain.com',
71
+ cname: 'mañana.com', # you can specify hostname in UTF-8. It will be converted to xn--maana-pta.com automatically
71
72
  soa: [
72
73
  {
73
74
  mname: 'dns1.domain.com',
@@ -80,17 +81,19 @@ records = {
80
81
  }
81
82
  ]
82
83
  },
83
- '1.2.3.4' => {
84
+ '1.2.3.4' => { # You can define RDNS host address without lookup prefix. It will be converted to 4.3.2.1.in-addr.arpa automatically
84
85
  ptr: %w[domain_1.com domain_2.com]
85
86
  }
86
87
  }
87
88
 
88
- # Main DnsMock interface
89
+ # Public DnsMock interface
89
90
  # records:Hash, port:Integer, exception_if_not_found:Boolean
90
91
  # are optional params. By default creates dns mock server with
91
92
  # empty records. A free port for server will be randomly assigned
92
93
  # in the range from 49152 to 65535, if record not found exception
93
- # won't raises. Returns current dns mock server
94
+ # won't raises. Please note if you specify zero port number,
95
+ # free port number will be randomly assigned as a server port too.
96
+ # Returns current dns mock server
94
97
  dns_mock_server = DnsMock.start_server(records: records) # => DnsMock::Server instance
95
98
 
96
99
  # returns current dns mock server port
@@ -134,7 +137,7 @@ require 'dns_mock/test_framework/rspec'
134
137
 
135
138
  #### DnsMock RSpec helper
136
139
 
137
- Just add `DnsMock::TestFramework::RSpec::Helper` if you wanna use shortcut `dns_mock_server` for DnsMock server instance into your `RSpec.describe` blocks:
140
+ Just add `DnsMock::TestFramework::RSpec::Helper` if you wanna use shortcut `dns_mock_server` for DnsMock server instance inside of your `RSpec.describe` blocks:
138
141
 
139
142
  ```ruby
140
143
  # spec/support/config/dns_mock.rb
data/dns_mock.gemspec CHANGED
@@ -31,18 +31,20 @@ 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_runtime_dependency 'simpleidn', '~> 0.2.1'
35
+
36
+ spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.25'
35
37
  spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
36
- spec.add_development_dependency 'faker', '~> 2.18'
37
38
  spec.add_development_dependency 'fasterer', '~> 0.9.0'
38
- spec.add_development_dependency 'overcommit', '~> 0.57.0'
39
+ spec.add_development_dependency 'ffaker', '~> 2.18'
40
+ spec.add_development_dependency 'overcommit', '~> 0.58.0'
39
41
  spec.add_development_dependency 'pry-byebug', '~> 3.9'
40
- spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
41
- spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
42
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
43
+ spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.6'
42
44
  spec.add_development_dependency 'rspec', '~> 3.10'
43
45
  spec.add_development_dependency 'rspec-dns', '~> 0.1.8'
44
- spec.add_development_dependency 'rubocop', '~> 1.15'
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', '~> 1.19'
47
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.4'
48
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.4'
47
49
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
48
50
  end
data/lib/dns_mock/core.rb CHANGED
@@ -18,6 +18,11 @@ module DnsMock
18
18
  require_relative '../dns_mock/error/helper'
19
19
  end
20
20
 
21
+ module Representer
22
+ require_relative '../dns_mock/representer/punycode'
23
+ require_relative '../dns_mock/representer/rdns_lookup'
24
+ end
25
+
21
26
  module Record
22
27
  module Factory
23
28
  require_relative '../dns_mock/record/factory/base'
@@ -53,6 +58,5 @@ module DnsMock
53
58
 
54
59
  require_relative '../dns_mock/version'
55
60
  require_relative '../dns_mock/server/records_dictionary_builder'
56
- require_relative '../dns_mock/server/random_available_port'
57
61
  require_relative '../dns_mock/server'
58
62
  end
@@ -23,8 +23,13 @@ module DnsMock
23
23
  end
24
24
  end
25
25
 
26
- def initialize(dns_name = ::Resolv::DNS::Name, record_data:)
26
+ def initialize(
27
+ dns_name = ::Resolv::DNS::Name,
28
+ punycode_representer = DnsMock::Representer::Punycode,
29
+ record_data:
30
+ )
27
31
  @dns_name = dns_name
32
+ @punycode_representer = punycode_representer
28
33
  @record_data = record_data
29
34
  end
30
35
 
@@ -38,7 +43,7 @@ module DnsMock
38
43
 
39
44
  private
40
45
 
41
- attr_reader :dns_name, :record_data
46
+ attr_reader :dns_name, :punycode_representer, :record_data
42
47
 
43
48
  def record_type
44
49
  self.class.name.split('::').last.upcase
@@ -46,7 +51,7 @@ module DnsMock
46
51
 
47
52
  def create_dns_name(hostname)
48
53
  raise ::ArgumentError, "cannot interpret as DNS name: #{hostname}" unless hostname.is_a?(::String)
49
- dns_name.create("#{hostname}.")
54
+ dns_name.create("#{punycode_representer.call(hostname)}.")
50
55
  end
51
56
  end
52
57
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DnsMock
4
+ module Representer
5
+ Punycode = ::Class.new do
6
+ require 'simpleidn'
7
+
8
+ def self.call(hostname)
9
+ return hostname if hostname.ascii_only?
10
+
11
+ SimpleIDN.to_ascii(hostname)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DnsMock
4
+ module Representer
5
+ class RdnsLookup
6
+ IP_OCTET_GROUPS = /(\d+).(\d+).(\d+).(\d+)/.freeze
7
+ RDNS_LOOKUP_REPRESENTATION = '\4.\3.\2.\1.in-addr.arpa'
8
+
9
+ def self.call(host_address)
10
+ host_address.gsub(
11
+ DnsMock::Representer::RdnsLookup::IP_OCTET_GROUPS,
12
+ DnsMock::Representer::RdnsLookup::RDNS_LOOKUP_REPRESENTATION
13
+ )
14
+ end
15
+ end
16
+ end
17
+ 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)
@@ -6,8 +6,6 @@ module DnsMock
6
6
  include DnsMock::Error::Helper
7
7
 
8
8
  IP_ADDRESS_PATTERN = /\A((1\d|[1-9]|2[0-4])?\d|25[0-5])(\.\g<1>){3}\z/.freeze
9
- IP_OCTET_GROUPS = /(\d+).(\d+).(\d+).(\d+)/.freeze
10
- RDNS_LOOKUP_REPRESENTATION = '\4.\3.\2.\1.in-addr.arpa'
11
9
  TYPE_MAPPER = DnsMock::AVAILABLE_DNS_RECORD_TYPES.zip(
12
10
  [
13
11
  [DnsMock::Record::Builder::A, DnsMock::Record::Factory::A, ::Array],
@@ -27,7 +25,12 @@ module DnsMock
27
25
 
28
26
  attr_reader :records
29
27
 
30
- def initialize
28
+ def initialize(
29
+ punycode_representer = DnsMock::Representer::Punycode,
30
+ rdns_lookup_representer = DnsMock::Representer::RdnsLookup
31
+ )
32
+ @punycode_representer = punycode_representer
33
+ @rdns_lookup_representer = rdns_lookup_representer
31
34
  @records = {}
32
35
  end
33
36
 
@@ -35,7 +38,7 @@ module DnsMock
35
38
  raise_unless(DnsMock::Error::ArgumentType.new(records_to_build.class), records_to_build.is_a?(::Hash))
36
39
  records_to_build.each do |hostname, dns_records|
37
40
  raise_unless(DnsMock::Error::RecordHostType.new(hostname, hostname.class), hostname.is_a?(::String))
38
- records[rdns_lookup_prefix(hostname)] = dns_records.each_with_object({}) do |(record_type, records_data), records_instances_by_type|
41
+ records[representer(hostname)] = dns_records.each_with_object({}) do |(record_type, records_data), records_instances_by_type|
39
42
  records_instances_by_type[record_type] = build_records_instances_by_type(record_type, records_data)
40
43
  end
41
44
  end
@@ -45,13 +48,12 @@ module DnsMock
45
48
 
46
49
  private
47
50
 
48
- def rdns_lookup_prefix(hostname)
49
- return hostname unless hostname[DnsMock::Server::RecordsDictionaryBuilder::IP_ADDRESS_PATTERN]
51
+ attr_reader :punycode_representer, :rdns_lookup_representer
50
52
 
51
- hostname.gsub(
52
- DnsMock::Server::RecordsDictionaryBuilder::IP_OCTET_GROUPS,
53
- DnsMock::Server::RecordsDictionaryBuilder::RDNS_LOOKUP_REPRESENTATION
54
- )
53
+ def representer(hostname)
54
+ return rdns_lookup_representer.call(hostname) if hostname[DnsMock::Server::RecordsDictionaryBuilder::IP_ADDRESS_PATTERN]
55
+
56
+ punycode_representer.call(hostname)
55
57
  end
56
58
 
57
59
  def build_records_instances_by_type(record_type, records_to_build)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DnsMock
4
- VERSION = '1.2.4'
4
+ VERSION = '1.4.1'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
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.4.1
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-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simpleidn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -19,7 +33,7 @@ dependencies:
19
33
  version: '2.2'
20
34
  - - ">="
21
35
  - !ruby/object:Gem::Version
22
- version: 2.2.17
36
+ version: 2.2.25
23
37
  type: :development
24
38
  prerelease: false
25
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +43,7 @@ dependencies:
29
43
  version: '2.2'
30
44
  - - ">="
31
45
  - !ruby/object:Gem::Version
32
- version: 2.2.17
46
+ version: 2.2.25
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: bundler-audit
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -45,47 +59,47 @@ dependencies:
45
59
  - !ruby/object:Gem::Version
46
60
  version: 0.8.0
47
61
  - !ruby/object:Gem::Dependency
48
- name: faker
62
+ name: fasterer
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - "~>"
52
66
  - !ruby/object:Gem::Version
53
- version: '2.18'
67
+ version: 0.9.0
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
- version: '2.18'
74
+ version: 0.9.0
61
75
  - !ruby/object:Gem::Dependency
62
- name: fasterer
76
+ name: ffaker
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - "~>"
66
80
  - !ruby/object:Gem::Version
67
- version: 0.9.0
81
+ version: '2.18'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
86
  - - "~>"
73
87
  - !ruby/object:Gem::Version
74
- version: 0.9.0
88
+ version: '2.18'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: overcommit
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - "~>"
80
94
  - !ruby/object:Gem::Version
81
- version: 0.57.0
95
+ version: 0.58.0
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
100
  - - "~>"
87
101
  - !ruby/object:Gem::Version
88
- version: 0.57.0
102
+ version: 0.58.0
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: pry-byebug
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +123,7 @@ dependencies:
109
123
  version: '13.0'
110
124
  - - ">="
111
125
  - !ruby/object:Gem::Version
112
- version: 13.0.3
126
+ version: 13.0.6
113
127
  type: :development
114
128
  prerelease: false
115
129
  version_requirements: !ruby/object:Gem::Requirement
@@ -119,7 +133,7 @@ dependencies:
119
133
  version: '13.0'
120
134
  - - ">="
121
135
  - !ruby/object:Gem::Version
122
- version: 13.0.3
136
+ version: 13.0.6
123
137
  - !ruby/object:Gem::Dependency
124
138
  name: reek
125
139
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +143,7 @@ dependencies:
129
143
  version: '6.0'
130
144
  - - ">="
131
145
  - !ruby/object:Gem::Version
132
- version: 6.0.4
146
+ version: 6.0.6
133
147
  type: :development
134
148
  prerelease: false
135
149
  version_requirements: !ruby/object:Gem::Requirement
@@ -139,7 +153,7 @@ dependencies:
139
153
  version: '6.0'
140
154
  - - ">="
141
155
  - !ruby/object:Gem::Version
142
- version: 6.0.4
156
+ version: 6.0.6
143
157
  - !ruby/object:Gem::Dependency
144
158
  name: rspec
145
159
  requirement: !ruby/object:Gem::Requirement
@@ -174,14 +188,14 @@ dependencies:
174
188
  requirements:
175
189
  - - "~>"
176
190
  - !ruby/object:Gem::Version
177
- version: '1.15'
191
+ version: '1.19'
178
192
  type: :development
179
193
  prerelease: false
180
194
  version_requirements: !ruby/object:Gem::Requirement
181
195
  requirements:
182
196
  - - "~>"
183
197
  - !ruby/object:Gem::Version
184
- version: '1.15'
198
+ version: '1.19'
185
199
  - !ruby/object:Gem::Dependency
186
200
  name: rubocop-performance
187
201
  requirement: !ruby/object:Gem::Requirement
@@ -191,7 +205,7 @@ dependencies:
191
205
  version: '1.11'
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
- version: 1.11.3
208
+ version: 1.11.4
195
209
  type: :development
196
210
  prerelease: false
197
211
  version_requirements: !ruby/object:Gem::Requirement
@@ -201,21 +215,21 @@ dependencies:
201
215
  version: '1.11'
202
216
  - - ">="
203
217
  - !ruby/object:Gem::Version
204
- version: 1.11.3
218
+ version: 1.11.4
205
219
  - !ruby/object:Gem::Dependency
206
220
  name: rubocop-rspec
207
221
  requirement: !ruby/object:Gem::Requirement
208
222
  requirements:
209
223
  - - "~>"
210
224
  - !ruby/object:Gem::Version
211
- version: '2.3'
225
+ version: '2.4'
212
226
  type: :development
213
227
  prerelease: false
214
228
  version_requirements: !ruby/object:Gem::Requirement
215
229
  requirements:
216
230
  - - "~>"
217
231
  - !ruby/object:Gem::Version
218
- version: '2.3'
232
+ version: '2.4'
219
233
  - !ruby/object:Gem::Dependency
220
234
  name: simplecov
221
235
  requirement: !ruby/object:Gem::Requirement
@@ -293,10 +307,11 @@ files:
293
307
  - lib/dns_mock/record/factory/ptr.rb
294
308
  - lib/dns_mock/record/factory/soa.rb
295
309
  - lib/dns_mock/record/factory/txt.rb
310
+ - lib/dns_mock/representer/punycode.rb
311
+ - lib/dns_mock/representer/rdns_lookup.rb
296
312
  - lib/dns_mock/response/answer.rb
297
313
  - lib/dns_mock/response/message.rb
298
314
  - lib/dns_mock/server.rb
299
- - lib/dns_mock/server/random_available_port.rb
300
315
  - lib/dns_mock/server/records_dictionary_builder.rb
301
316
  - lib/dns_mock/test_framework/rspec.rb
302
317
  - lib/dns_mock/test_framework/rspec/helper.rb
@@ -326,8 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
341
  - !ruby/object:Gem::Version
327
342
  version: '0'
328
343
  requirements: []
329
- rubyforge_project:
330
- rubygems_version: 2.7.3
344
+ rubygems_version: 3.2.20
331
345
  signing_key:
332
346
  specification_version: 4
333
347
  summary: dns_mock
@@ -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