dns_mock 1.2.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +13 -11
- data/.codeclimate.yml +1 -1
- data/.reek.yml +7 -1
- data/.rubocop.yml +24 -0
- data/CHANGELOG.md +117 -17
- data/Gemfile.lock +29 -27
- data/README.md +10 -7
- data/dns_mock.gemspec +9 -7
- data/lib/dns_mock/core.rb +5 -1
- data/lib/dns_mock/record/factory/base.rb +8 -3
- data/lib/dns_mock/representer/punycode.rb +15 -0
- data/lib/dns_mock/representer/rdns_lookup.rb +17 -0
- data/lib/dns_mock/server.rb +9 -2
- data/lib/dns_mock/server/records_dictionary_builder.rb +12 -10
- data/lib/dns_mock/version.rb +1 -1
- metadata +39 -19
- data/lib/dns_mock/server/random_available_port.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030004dfb97793bf507c84fbd56965bd5af1aa3c9652db58c20d40ec1467936f
|
4
|
+
data.tar.gz: b4b0d01e9750ac32c4f1577542a668393abb8780615930263765acbb810854a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e3a43b5a4519bca6e4909d8632081cac6699f57a5090223d97bbf95b32be684f8cb1437cf0ce64080a3476d787a874eb028e2416566d041dfba8211cb41ba60
|
7
|
+
data.tar.gz: 259b19d489e11ed66e4b9aa4e5aa55f88913edeb66ed5e767c378940c00bcc934dde3842eeaf5b2ee88456c69e221fd4d9d91ef28ac2fc6a2bfada0f05188e48
|
data/.circleci/config.yml
CHANGED
@@ -13,7 +13,7 @@ orbs:
|
|
13
13
|
references:
|
14
14
|
install_bundler: &install_bundler
|
15
15
|
run:
|
16
|
-
name: Installing
|
16
|
+
name: Installing Bundler
|
17
17
|
command: gem i bundler -v $(tail -1 Gemfile.lock | tr -d ' ')
|
18
18
|
|
19
19
|
restore_bundle_cache: &restore_bundle_cache
|
@@ -34,13 +34,13 @@ references:
|
|
34
34
|
|
35
35
|
install_codeclimate_reporter: &install_codeclimate_reporter
|
36
36
|
run:
|
37
|
-
name:
|
37
|
+
name: Installing CodeClimate test reporter
|
38
38
|
command: |
|
39
39
|
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
40
40
|
chmod +x ./cc-test-reporter
|
41
41
|
|
42
42
|
jobs:
|
43
|
-
linters-
|
43
|
+
linters-ruby:
|
44
44
|
parameters:
|
45
45
|
ruby-version:
|
46
46
|
type: string
|
@@ -56,12 +56,12 @@ jobs:
|
|
56
56
|
- <<: *save_bundle_cache
|
57
57
|
|
58
58
|
- run:
|
59
|
-
name: Running
|
59
|
+
name: Running Overcommit
|
60
60
|
command: |
|
61
61
|
bundle exec overcommit -s
|
62
62
|
SKIP=AuthorEmail,AuthorName bundle exec overcommit -r
|
63
63
|
|
64
|
-
tests-
|
64
|
+
tests-ruby:
|
65
65
|
parameters:
|
66
66
|
ruby-version:
|
67
67
|
type: string
|
@@ -78,25 +78,27 @@ jobs:
|
|
78
78
|
- <<: *install_codeclimate_reporter
|
79
79
|
|
80
80
|
- run:
|
81
|
-
name: Running
|
81
|
+
name: Running RSpec
|
82
82
|
command: |
|
83
83
|
./cc-test-reporter before-build
|
84
84
|
bundle exec rspec
|
85
85
|
|
86
86
|
- run:
|
87
|
-
name:
|
87
|
+
name: Creating CodeClimate test coverage report
|
88
88
|
command: |
|
89
89
|
./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
|
90
90
|
|
91
91
|
- store_artifacts:
|
92
|
+
name: Saving Simplecov coverage artifacts
|
92
93
|
path: ~/ruby-dns-mock/coverage
|
93
94
|
destination: coverage
|
94
95
|
|
95
96
|
- deploy:
|
97
|
+
name: Uploading CodeClimate test coverage report
|
96
98
|
command: |
|
97
99
|
./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
|
98
100
|
|
99
|
-
compatibility-
|
101
|
+
compatibility-ruby:
|
100
102
|
parameters:
|
101
103
|
ruby-version:
|
102
104
|
type: string
|
@@ -114,15 +116,15 @@ jobs:
|
|
114
116
|
workflows:
|
115
117
|
build_and_test:
|
116
118
|
jobs:
|
117
|
-
- linters-
|
119
|
+
- linters-ruby:
|
118
120
|
matrix:
|
119
121
|
parameters:
|
120
122
|
ruby-version: ["2.5"]
|
121
|
-
- tests-
|
123
|
+
- tests-ruby:
|
122
124
|
matrix:
|
123
125
|
parameters:
|
124
126
|
ruby-version: ["2.5"]
|
125
|
-
- compatibility-
|
127
|
+
- compatibility-ruby:
|
126
128
|
matrix:
|
127
129
|
parameters:
|
128
130
|
ruby-version: ["2.6", "2.7", "3.0"]
|
data/.codeclimate.yml
CHANGED
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,15 @@ 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
|
+
|
130
142
|
Layout/LineLength:
|
131
143
|
Max: 150
|
132
144
|
|
@@ -158,6 +170,9 @@ Layout/EmptyLineAfterGuardClause:
|
|
158
170
|
Layout/SpaceBeforeBrackets:
|
159
171
|
Enabled: true
|
160
172
|
|
173
|
+
Layout/LineEndStringConcatenationIndentation:
|
174
|
+
Enabled: true
|
175
|
+
|
161
176
|
Lint/NonDeterministicRequireOrder:
|
162
177
|
Enabled: true
|
163
178
|
|
@@ -224,6 +239,9 @@ Lint/SymbolConversion:
|
|
224
239
|
Lint/TripleQuotes:
|
225
240
|
Enabled: true
|
226
241
|
|
242
|
+
Lint/EmptyInPattern:
|
243
|
+
Enabled: true
|
244
|
+
|
227
245
|
Gemspec/DateAssignment:
|
228
246
|
Enabled: true
|
229
247
|
|
@@ -304,3 +322,9 @@ RSpec/MultipleMemoizedHelpers:
|
|
304
322
|
|
305
323
|
RSpec/StubbedMock:
|
306
324
|
Enabled: false
|
325
|
+
|
326
|
+
RSpec/IdenticalEqualityAssertion:
|
327
|
+
Enabled: true
|
328
|
+
|
329
|
+
RSpec/Rails/AvoidSetupHook:
|
330
|
+
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,100 @@
|
|
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.0] - 2021-07-13
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Added ability to use internationalized hostnames. All hostnames in UTF-8 will be represented as [Punycode](https://en.wikipedia.org/wiki/Punycode)
|
10
|
+
- Added `simpleidn` as runtime dependency
|
11
|
+
- Added `DnsMock::Representer::Punycode`, tests
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
records = {
|
15
|
+
'mañana.com' => {
|
16
|
+
mx: %w[másletras.mañana.com]
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
DnsMock.start_server(port: 5300, records: records)
|
21
|
+
```
|
22
|
+
|
23
|
+
```bash
|
24
|
+
dig @localhost -p 5300 MX xn--maana-pta.com
|
25
|
+
```
|
26
|
+
|
27
|
+
```
|
28
|
+
; <<>> DiG 9.10.6 <<>> @localhost -p 5300 MX xn--maana-pta.com
|
29
|
+
; (2 servers found)
|
30
|
+
;; global options: +cmd
|
31
|
+
;; Got answer:
|
32
|
+
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4612
|
33
|
+
;; flags: rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
|
34
|
+
;; WARNING: recursion requested but not available
|
35
|
+
|
36
|
+
;; OPT PSEUDOSECTION:
|
37
|
+
; EDNS: version: 0, flags:; udp: 4096
|
38
|
+
;; QUESTION SECTION:
|
39
|
+
;xn--maana-pta.com. IN MX
|
40
|
+
|
41
|
+
;; ANSWER SECTION:
|
42
|
+
xn--maana-pta.com. 1 IN MX 10 xn--msletras-8ya.xn--maana-pta.com.
|
43
|
+
|
44
|
+
;; Query time: 0 msec
|
45
|
+
;; SERVER: 127.0.0.1#5300(127.0.0.1)
|
46
|
+
;; WHEN: Tue Jul 13 15:38:47 EEST 2021
|
47
|
+
;; MSG SIZE rcvd: 79
|
48
|
+
```
|
49
|
+
|
50
|
+
### Changed
|
51
|
+
|
52
|
+
- Refactored `DnsMock::Representer::RdnsLookup`, tests
|
53
|
+
- Updated `DnsMock::Record::Factory::Base`
|
54
|
+
- Updated `DnsMock::Server::RecordsDictionaryBuilder`, tests
|
55
|
+
- Updated `DnsMock::Record::Factory::Cname`, tests
|
56
|
+
- Updated `DnsMock::Record::Factory::Mx`, tests
|
57
|
+
- Updated `DnsMock::Record::Factory::Ns`, tests
|
58
|
+
- Updated `DnsMock::Record::Factory::Ptr`, tests
|
59
|
+
- Updated `DnsMock::Record::Factory::Soa`, tests
|
60
|
+
- Updated `DnsMock::ContextGeneratorHelper`, tests
|
61
|
+
- Updated reek config
|
62
|
+
- Updated gem documentation, version
|
63
|
+
|
64
|
+
## [1.3.1] - 2021-07-07
|
65
|
+
|
66
|
+
### Changed
|
67
|
+
|
68
|
+
- Updated gem development dependencies
|
69
|
+
- Updated rubocop/codeclimate config
|
70
|
+
- Updated gem documentation, version
|
71
|
+
|
72
|
+
## [1.3.0] - 2021-06-14
|
73
|
+
|
74
|
+
### Added
|
75
|
+
|
76
|
+
- Detecting random available port via OS features. Thanks [@ioquatix](https://github.com/ioquatix) for [suggestion](https://github.com/mocktools/ruby-dns-mock/issues/42) 🚀
|
77
|
+
|
78
|
+
### Removed
|
79
|
+
|
80
|
+
- Removed `DnsMock::Server::RandomAvailablePort`, tests
|
81
|
+
|
82
|
+
### Changed
|
83
|
+
|
84
|
+
- Updated `DnsMock::Server` class
|
85
|
+
- Updated tests helpers/tests
|
86
|
+
- Updated gem development dependencies
|
87
|
+
|
88
|
+
### Fixed
|
89
|
+
|
90
|
+
- Test coverage issues
|
91
|
+
|
92
|
+
## [1.2.4] - 2021-05-25
|
93
|
+
|
94
|
+
### Changed
|
95
|
+
|
96
|
+
- Updated gem development dependencies
|
97
|
+
- Updated CircleCI config
|
98
|
+
|
5
99
|
## [1.2.3] - 2021-05-11
|
6
100
|
|
7
101
|
### Changed
|
@@ -15,7 +109,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
15
109
|
|
16
110
|
- Updated gem development dependencies
|
17
111
|
- Updated rubocop/codeclimate config
|
18
|
-
- Updated
|
112
|
+
- Updated CircleCI config
|
19
113
|
|
20
114
|
## [1.2.1] - 2021-03-23
|
21
115
|
|
@@ -28,9 +122,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
28
122
|
|
29
123
|
## [1.2.0] - 2021-02-04
|
30
124
|
|
31
|
-
###
|
125
|
+
### Added
|
32
126
|
|
33
|
-
|
127
|
+
- Ability to specify custom priority of MX record if it needed
|
128
|
+
|
129
|
+
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.
|
34
130
|
|
35
131
|
```ruby
|
36
132
|
records = {
|
@@ -63,9 +159,9 @@ example.com. 1 IN MX 40 mx3.domain.com.
|
|
63
159
|
|
64
160
|
## [1.1.0] - 2021-02-01
|
65
161
|
|
66
|
-
###
|
162
|
+
### Added
|
67
163
|
|
68
|
-
|
164
|
+
- RSpec native support. DnsMock helper help you to simplify integration with RSpec
|
69
165
|
|
70
166
|
```ruby
|
71
167
|
# spec/support/config/dns_mock.rb
|
@@ -97,9 +193,11 @@ end
|
|
97
193
|
|
98
194
|
## [1.0.0] - 2021-01-29
|
99
195
|
|
100
|
-
###
|
196
|
+
### Added
|
197
|
+
|
198
|
+
- Configurable strategy for record not found case
|
101
199
|
|
102
|
-
|
200
|
+
By default it won't raise an exception when DNS record not found in mocked records dictionary:
|
103
201
|
|
104
202
|
```ruby
|
105
203
|
DnsMock.start_server(port: 5300)
|
@@ -143,19 +241,21 @@ DnsMock.start_server(exception_if_not_found: true)
|
|
143
241
|
|
144
242
|
## [0.2.1] - 2021-01-27
|
145
243
|
|
146
|
-
### Fixed
|
244
|
+
### Fixed
|
147
245
|
|
148
|
-
|
246
|
+
- RDNS lookup representatin for IP address in PTR record feature.
|
149
247
|
|
150
248
|
## [0.2.0] - 2021-01-26
|
151
249
|
|
152
|
-
###
|
250
|
+
### Added
|
251
|
+
|
252
|
+
- PTR record support. Ability to mock PTR records
|
153
253
|
|
154
|
-
|
254
|
+
Please note, you can define host address without RDNS lookup prefix (`.in-addr.arpa`). `DnsMock` will do it for you.
|
155
255
|
|
156
256
|
```ruby
|
157
257
|
records = {
|
158
|
-
'1.
|
258
|
+
'1.2.3.4' => {
|
159
259
|
ptr: %w[domain_1.com domain_2.com]
|
160
260
|
}
|
161
261
|
}
|
@@ -164,7 +264,7 @@ DnsMock.start_server(records: records)
|
|
164
264
|
```
|
165
265
|
|
166
266
|
```bash
|
167
|
-
dig @localhost -p 5300 -x 1.
|
267
|
+
dig @localhost -p 5300 -x 1.2.3.4
|
168
268
|
```
|
169
269
|
|
170
270
|
```
|
@@ -172,8 +272,8 @@ dig @localhost -p 5300 -x 1.1.1.1
|
|
172
272
|
; (2 servers found)
|
173
273
|
|
174
274
|
;; ANSWER SECTION:
|
175
|
-
|
176
|
-
|
275
|
+
4.3.2.1.in-addr.arpa. 1 IN PTR domain_1.com.
|
276
|
+
4.3.2.1.in-addr.arpa. 1 IN PTR domain_2.com.
|
177
277
|
|
178
278
|
;; Query time: 0 msec
|
179
279
|
;; SERVER: 127.0.0.1#5300(127.0.0.1)
|
@@ -183,6 +283,6 @@ dig @localhost -p 5300 -x 1.1.1.1
|
|
183
283
|
|
184
284
|
## [0.1.0] - 2021-01-19
|
185
285
|
|
186
|
-
###
|
286
|
+
### Added
|
187
287
|
|
188
|
-
|
288
|
+
- 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.
|
4
|
+
dns_mock (1.4.0)
|
5
|
+
simpleidn (~> 0.2.1)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -11,15 +12,15 @@ GEM
|
|
11
12
|
bundler (>= 1.2.0, < 3)
|
12
13
|
thor (~> 1.0)
|
13
14
|
byebug (11.1.3)
|
14
|
-
childprocess (4.
|
15
|
+
childprocess (4.1.0)
|
15
16
|
coderay (1.1.3)
|
16
17
|
colorize (0.8.1)
|
17
|
-
concurrent-ruby (1.1.
|
18
|
+
concurrent-ruby (1.1.9)
|
18
19
|
diff-lcs (1.4.4)
|
19
|
-
dnsruby (1.61.
|
20
|
+
dnsruby (1.61.7)
|
20
21
|
simpleidn (~> 0.1)
|
21
|
-
docile (1.
|
22
|
-
faker (2.
|
22
|
+
docile (1.4.0)
|
23
|
+
faker (2.18.0)
|
23
24
|
i18n (>= 1.6, < 2)
|
24
25
|
fasterer (0.9.0)
|
25
26
|
colorize (~> 0.7)
|
@@ -30,11 +31,12 @@ GEM
|
|
30
31
|
json (2.5.1)
|
31
32
|
kwalify (0.7.2)
|
32
33
|
method_source (1.0.0)
|
33
|
-
overcommit (0.
|
34
|
+
overcommit (0.58.0)
|
34
35
|
childprocess (>= 0.6.3, < 5)
|
35
36
|
iniparse (~> 1.4)
|
37
|
+
rexml (~> 3.2)
|
36
38
|
parallel (1.20.1)
|
37
|
-
parser (3.0.
|
39
|
+
parser (3.0.2.0)
|
38
40
|
ast (~> 2.4.1)
|
39
41
|
pry (0.13.1)
|
40
42
|
coderay (~> 1.1)
|
@@ -42,9 +44,9 @@ GEM
|
|
42
44
|
pry-byebug (3.9.0)
|
43
45
|
byebug (~> 11.0)
|
44
46
|
pry (~> 0.13.0)
|
45
|
-
psych (3.3.
|
47
|
+
psych (3.3.2)
|
46
48
|
rainbow (3.0.0)
|
47
|
-
rake (13.0.
|
49
|
+
rake (13.0.6)
|
48
50
|
reek (6.0.4)
|
49
51
|
kwalify (~> 0.7.0)
|
50
52
|
parser (~> 3.0.0)
|
@@ -69,27 +71,27 @@ GEM
|
|
69
71
|
diff-lcs (>= 1.2.0, < 2.0)
|
70
72
|
rspec-support (~> 3.10.0)
|
71
73
|
rspec-support (3.10.2)
|
72
|
-
rubocop (1.
|
74
|
+
rubocop (1.18.3)
|
73
75
|
parallel (~> 1.10)
|
74
76
|
parser (>= 3.0.0.0)
|
75
77
|
rainbow (>= 2.2.2, < 4.0)
|
76
78
|
regexp_parser (>= 1.8, < 3.0)
|
77
79
|
rexml
|
78
|
-
rubocop-ast (>= 1.
|
80
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
79
81
|
ruby-progressbar (~> 1.7)
|
80
82
|
unicode-display_width (>= 1.4.0, < 3.0)
|
81
|
-
rubocop-ast (1.
|
83
|
+
rubocop-ast (1.7.0)
|
82
84
|
parser (>= 3.0.1.1)
|
83
|
-
rubocop-performance (1.11.
|
85
|
+
rubocop-performance (1.11.4)
|
84
86
|
rubocop (>= 1.7.0, < 2.0)
|
85
87
|
rubocop-ast (>= 0.4.0)
|
86
|
-
rubocop-rspec (2.
|
88
|
+
rubocop-rspec (2.4.0)
|
87
89
|
rubocop (~> 1.0)
|
88
90
|
rubocop-ast (>= 1.1.0)
|
89
91
|
ruby-progressbar (1.11.0)
|
90
|
-
ruby_parser (3.
|
91
|
-
sexp_processor (~> 4.
|
92
|
-
sexp_processor (4.15.
|
92
|
+
ruby_parser (3.16.0)
|
93
|
+
sexp_processor (~> 4.15, >= 4.15.1)
|
94
|
+
sexp_processor (4.15.3)
|
93
95
|
simplecov (0.17.1)
|
94
96
|
docile (~> 1.1)
|
95
97
|
json (>= 1.8, < 3)
|
@@ -104,24 +106,24 @@ GEM
|
|
104
106
|
unicode-display_width (2.0.0)
|
105
107
|
|
106
108
|
PLATFORMS
|
107
|
-
x86_64-darwin-
|
109
|
+
x86_64-darwin-20
|
108
110
|
|
109
111
|
DEPENDENCIES
|
110
|
-
bundler (~> 2.2, >= 2.2.
|
112
|
+
bundler (~> 2.2, >= 2.2.23)
|
111
113
|
bundler-audit (~> 0.8.0)
|
112
114
|
dns_mock!
|
113
|
-
faker (~> 2.
|
115
|
+
faker (~> 2.18)
|
114
116
|
fasterer (~> 0.9.0)
|
115
|
-
overcommit (~> 0.
|
117
|
+
overcommit (~> 0.58.0)
|
116
118
|
pry-byebug (~> 3.9)
|
117
|
-
rake (~> 13.0, >= 13.0.
|
119
|
+
rake (~> 13.0, >= 13.0.6)
|
118
120
|
reek (~> 6.0, >= 6.0.4)
|
119
121
|
rspec (~> 3.10)
|
120
122
|
rspec-dns (~> 0.1.8)
|
121
|
-
rubocop (~> 1.
|
122
|
-
rubocop-performance (~> 1.11, >= 1.11.
|
123
|
-
rubocop-rspec (~> 2.
|
123
|
+
rubocop (~> 1.18, >= 1.18.3)
|
124
|
+
rubocop-performance (~> 1.11, >= 1.11.4)
|
125
|
+
rubocop-rspec (~> 2.4)
|
124
126
|
simplecov (~> 0.17.1)
|
125
127
|
|
126
128
|
BUNDLED WITH
|
127
|
-
2.2.
|
129
|
+
2.2.23
|
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
|
-
-
|
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: '
|
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
|
-
#
|
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.
|
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
|
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.
|
34
|
+
spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'
|
35
|
+
|
36
|
+
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.23'
|
35
37
|
spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
|
36
|
-
spec.add_development_dependency 'faker', '~> 2.
|
38
|
+
spec.add_development_dependency 'faker', '~> 2.18'
|
37
39
|
spec.add_development_dependency 'fasterer', '~> 0.9.0'
|
38
|
-
spec.add_development_dependency 'overcommit', '~> 0.
|
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.
|
42
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
|
41
43
|
spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
|
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.
|
45
|
-
spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.
|
46
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 2.
|
46
|
+
spec.add_development_dependency 'rubocop', '~> 1.18', '>= 1.18.3'
|
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(
|
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
|
data/lib/dns_mock/server.rb
CHANGED
@@ -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 ||
|
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[
|
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
|
-
|
49
|
-
return hostname unless hostname[DnsMock::Server::RecordsDictionaryBuilder::IP_ADDRESS_PATTERN]
|
51
|
+
attr_reader :punycode_representer, :rdns_lookup_representer
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
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)
|
data/lib/dns_mock/version.rb
CHANGED
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.
|
4
|
+
version: 1.4.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-
|
11
|
+
date: 2021-07-13 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.
|
36
|
+
version: 2.2.23
|
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.
|
46
|
+
version: 2.2.23
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: bundler-audit
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +64,14 @@ dependencies:
|
|
50
64
|
requirements:
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version: '2.
|
67
|
+
version: '2.18'
|
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.
|
74
|
+
version: '2.18'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: fasterer
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,14 +92,14 @@ dependencies:
|
|
78
92
|
requirements:
|
79
93
|
- - "~>"
|
80
94
|
- !ruby/object:Gem::Version
|
81
|
-
version: 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.
|
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.
|
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.
|
136
|
+
version: 13.0.6
|
123
137
|
- !ruby/object:Gem::Dependency
|
124
138
|
name: reek
|
125
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,14 +188,20 @@ dependencies:
|
|
174
188
|
requirements:
|
175
189
|
- - "~>"
|
176
190
|
- !ruby/object:Gem::Version
|
177
|
-
version: '1.
|
191
|
+
version: '1.18'
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 1.18.3
|
178
195
|
type: :development
|
179
196
|
prerelease: false
|
180
197
|
version_requirements: !ruby/object:Gem::Requirement
|
181
198
|
requirements:
|
182
199
|
- - "~>"
|
183
200
|
- !ruby/object:Gem::Version
|
184
|
-
version: '1.
|
201
|
+
version: '1.18'
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: 1.18.3
|
185
205
|
- !ruby/object:Gem::Dependency
|
186
206
|
name: rubocop-performance
|
187
207
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,7 +211,7 @@ dependencies:
|
|
191
211
|
version: '1.11'
|
192
212
|
- - ">="
|
193
213
|
- !ruby/object:Gem::Version
|
194
|
-
version: 1.11.
|
214
|
+
version: 1.11.4
|
195
215
|
type: :development
|
196
216
|
prerelease: false
|
197
217
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -201,21 +221,21 @@ dependencies:
|
|
201
221
|
version: '1.11'
|
202
222
|
- - ">="
|
203
223
|
- !ruby/object:Gem::Version
|
204
|
-
version: 1.11.
|
224
|
+
version: 1.11.4
|
205
225
|
- !ruby/object:Gem::Dependency
|
206
226
|
name: rubocop-rspec
|
207
227
|
requirement: !ruby/object:Gem::Requirement
|
208
228
|
requirements:
|
209
229
|
- - "~>"
|
210
230
|
- !ruby/object:Gem::Version
|
211
|
-
version: '2.
|
231
|
+
version: '2.4'
|
212
232
|
type: :development
|
213
233
|
prerelease: false
|
214
234
|
version_requirements: !ruby/object:Gem::Requirement
|
215
235
|
requirements:
|
216
236
|
- - "~>"
|
217
237
|
- !ruby/object:Gem::Version
|
218
|
-
version: '2.
|
238
|
+
version: '2.4'
|
219
239
|
- !ruby/object:Gem::Dependency
|
220
240
|
name: simplecov
|
221
241
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,10 +313,11 @@ files:
|
|
293
313
|
- lib/dns_mock/record/factory/ptr.rb
|
294
314
|
- lib/dns_mock/record/factory/soa.rb
|
295
315
|
- lib/dns_mock/record/factory/txt.rb
|
316
|
+
- lib/dns_mock/representer/punycode.rb
|
317
|
+
- lib/dns_mock/representer/rdns_lookup.rb
|
296
318
|
- lib/dns_mock/response/answer.rb
|
297
319
|
- lib/dns_mock/response/message.rb
|
298
320
|
- lib/dns_mock/server.rb
|
299
|
-
- lib/dns_mock/server/random_available_port.rb
|
300
321
|
- lib/dns_mock/server/records_dictionary_builder.rb
|
301
322
|
- lib/dns_mock/test_framework/rspec.rb
|
302
323
|
- lib/dns_mock/test_framework/rspec/helper.rb
|
@@ -326,8 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
326
347
|
- !ruby/object:Gem::Version
|
327
348
|
version: '0'
|
328
349
|
requirements: []
|
329
|
-
|
330
|
-
rubygems_version: 2.7.3
|
350
|
+
rubygems_version: 3.2.20
|
331
351
|
signing_key:
|
332
352
|
specification_version: 4
|
333
353
|
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
|