dns_mock 1.2.1 → 1.3.1
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 +59 -18
- data/.codeclimate.yml +1 -1
- data/.rubocop.yml +30 -0
- data/CHANGELOG.md +53 -5
- data/Gemfile.lock +34 -33
- data/README.md +5 -3
- data/dns_mock.gemspec +8 -8
- data/lib/dns_mock/core.rb +0 -1
- data/lib/dns_mock/server.rb +9 -2
- data/lib/dns_mock/version.rb +1 -1
- metadata +33 -23
- 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: cb90f7f7c21ba2fff7de8259e0ac994a0781c212d7de77c05eebbe209b2f7f4c
|
4
|
+
data.tar.gz: e6ac11bad8d86f035063f2b6ca09c681a66988a647c7051a2a80de5b3f0d0ff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a50714bf62ee1976954cd4cd351399b29d67d240a89e4da379e8da4a5b33c12f323bbed706e5233f23d9edafa609fce52a0f6f3454aab414254368a5069a552f
|
7
|
+
data.tar.gz: 1d2ad40b18259ba6132215bb486dd2d8e9c0e7cf1df195b1538589c0d8fbc034f2436f3d062fed9823e61df54c50c4c958340f9b8e4a04093044ce6bc708ded9
|
data/.circleci/config.yml
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
1
3
|
defaults: &defaults
|
2
4
|
working_directory: ~/ruby-dns-mock
|
3
5
|
docker:
|
4
|
-
- image:
|
6
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
5
7
|
environment:
|
6
8
|
CC_TEST_REPORTER_ID: 18fba9e7d6885c48453a80a0f019a60d9ffa3fd80467652a6b3c95fef5ea9a50
|
7
9
|
|
10
|
+
orbs:
|
11
|
+
ruby: circleci/ruby@1.1.3
|
12
|
+
|
8
13
|
references:
|
14
|
+
install_bundler: &install_bundler
|
15
|
+
run:
|
16
|
+
name: Installing Bundler
|
17
|
+
command: gem i bundler -v $(tail -1 Gemfile.lock | tr -d ' ')
|
18
|
+
|
9
19
|
restore_bundle_cache: &restore_bundle_cache
|
10
20
|
restore_cache:
|
11
21
|
keys:
|
@@ -24,66 +34,97 @@ references:
|
|
24
34
|
|
25
35
|
install_codeclimate_reporter: &install_codeclimate_reporter
|
26
36
|
run:
|
27
|
-
name:
|
37
|
+
name: Installing CodeClimate test reporter
|
28
38
|
command: |
|
29
39
|
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
30
40
|
chmod +x ./cc-test-reporter
|
31
41
|
|
32
|
-
version: 2
|
33
42
|
jobs:
|
34
|
-
linters:
|
43
|
+
linters-ruby:
|
44
|
+
parameters:
|
45
|
+
ruby-version:
|
46
|
+
type: string
|
47
|
+
|
35
48
|
<<: *defaults
|
36
49
|
|
37
50
|
steps:
|
38
51
|
- checkout
|
39
52
|
|
53
|
+
- <<: *install_bundler
|
40
54
|
- <<: *restore_bundle_cache
|
41
55
|
- <<: *bundle_install
|
42
56
|
- <<: *save_bundle_cache
|
43
57
|
|
44
58
|
- run:
|
45
|
-
name: Running
|
59
|
+
name: Running Overcommit
|
46
60
|
command: |
|
47
61
|
bundle exec overcommit -s
|
48
62
|
SKIP=AuthorEmail,AuthorName bundle exec overcommit -r
|
49
63
|
|
50
|
-
tests:
|
64
|
+
tests-ruby:
|
65
|
+
parameters:
|
66
|
+
ruby-version:
|
67
|
+
type: string
|
68
|
+
|
51
69
|
<<: *defaults
|
52
70
|
|
53
71
|
steps:
|
54
72
|
- checkout
|
55
73
|
|
74
|
+
- <<: *install_bundler
|
56
75
|
- <<: *restore_bundle_cache
|
57
76
|
- <<: *bundle_install
|
58
77
|
- <<: *save_bundle_cache
|
59
78
|
- <<: *install_codeclimate_reporter
|
60
79
|
|
61
80
|
- run:
|
62
|
-
name: Running
|
81
|
+
name: Running RSpec
|
63
82
|
command: |
|
64
|
-
mkdir /tmp/test-results
|
65
83
|
./cc-test-reporter before-build
|
66
84
|
bundle exec rspec
|
67
85
|
|
68
86
|
- run:
|
69
|
-
name:
|
87
|
+
name: Creating CodeClimate test coverage report
|
70
88
|
command: |
|
71
89
|
./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
|
72
90
|
|
73
|
-
- store_test_results:
|
74
|
-
path: /tmp/test-results
|
75
|
-
|
76
91
|
- store_artifacts:
|
77
|
-
|
78
|
-
|
92
|
+
name: Saving Simplecov coverage artifacts
|
93
|
+
path: ~/ruby-dns-mock/coverage
|
94
|
+
destination: coverage
|
79
95
|
|
80
96
|
- deploy:
|
97
|
+
name: Uploading CodeClimate test coverage report
|
81
98
|
command: |
|
82
99
|
./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
|
83
100
|
|
101
|
+
compatibility-ruby:
|
102
|
+
parameters:
|
103
|
+
ruby-version:
|
104
|
+
type: string
|
105
|
+
docker:
|
106
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
107
|
+
steps:
|
108
|
+
- checkout
|
109
|
+
- ruby/install-deps:
|
110
|
+
with-cache: false
|
111
|
+
path: './vendor/custom_bundle'
|
112
|
+
- run:
|
113
|
+
name: Running compatibility tests
|
114
|
+
command: bundle exec rspec
|
115
|
+
|
84
116
|
workflows:
|
85
|
-
|
86
|
-
build:
|
117
|
+
build_and_test:
|
87
118
|
jobs:
|
88
|
-
- linters
|
89
|
-
|
119
|
+
- linters-ruby:
|
120
|
+
matrix:
|
121
|
+
parameters:
|
122
|
+
ruby-version: ["2.5"]
|
123
|
+
- tests-ruby:
|
124
|
+
matrix:
|
125
|
+
parameters:
|
126
|
+
ruby-version: ["2.5"]
|
127
|
+
- compatibility-ruby:
|
128
|
+
matrix:
|
129
|
+
parameters:
|
130
|
+
ruby-version: ["2.6", "2.7", "3.0"]
|
data/.codeclimate.yml
CHANGED
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
|
|
@@ -124,6 +127,18 @@ Style/IfWithBooleanLiteralBranches:
|
|
124
127
|
Style/HashConversion:
|
125
128
|
Enabled: true
|
126
129
|
|
130
|
+
Style/StringChars:
|
131
|
+
Enabled: true
|
132
|
+
|
133
|
+
Style/InPatternThen:
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
Style/MultilineInPatternThen:
|
137
|
+
Enabled: true
|
138
|
+
|
139
|
+
Style/QuotedSymbols:
|
140
|
+
Enabled: true
|
141
|
+
|
127
142
|
Layout/LineLength:
|
128
143
|
Max: 150
|
129
144
|
|
@@ -155,6 +170,9 @@ Layout/EmptyLineAfterGuardClause:
|
|
155
170
|
Layout/SpaceBeforeBrackets:
|
156
171
|
Enabled: true
|
157
172
|
|
173
|
+
Layout/LineEndStringConcatenationIndentation:
|
174
|
+
Enabled: true
|
175
|
+
|
158
176
|
Lint/NonDeterministicRequireOrder:
|
159
177
|
Enabled: true
|
160
178
|
|
@@ -221,6 +239,9 @@ Lint/SymbolConversion:
|
|
221
239
|
Lint/TripleQuotes:
|
222
240
|
Enabled: true
|
223
241
|
|
242
|
+
Lint/EmptyInPattern:
|
243
|
+
Enabled: true
|
244
|
+
|
224
245
|
Gemspec/DateAssignment:
|
225
246
|
Enabled: true
|
226
247
|
|
@@ -269,6 +290,9 @@ Performance/RedundantEqualityComparisonBlock:
|
|
269
290
|
Performance/RedundantSplitRegexpArgument:
|
270
291
|
Enabled: true
|
271
292
|
|
293
|
+
Performance/MapCompact:
|
294
|
+
Enabled: true
|
295
|
+
|
272
296
|
RSpec/ExampleLength:
|
273
297
|
Enabled: false
|
274
298
|
|
@@ -298,3 +322,9 @@ RSpec/MultipleMemoizedHelpers:
|
|
298
322
|
|
299
323
|
RSpec/StubbedMock:
|
300
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,54 @@
|
|
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.1] - 2021-07-07
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- Updated gem development dependencies
|
10
|
+
- Updated rubocop/codeclimate config
|
11
|
+
- Updated gem documentation, version
|
12
|
+
|
13
|
+
## [1.3.0] - 2021-06-14
|
14
|
+
|
15
|
+
Detecting random available port via OS features. Thanks [@ioquatix](https://github.com/ioquatix) for [suggestion](https://github.com/mocktools/ruby-dns-mock/issues/42) 🚀
|
16
|
+
|
17
|
+
### Removed
|
18
|
+
|
19
|
+
- Removed `DnsMock::Server::RandomAvailablePort`
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- Updated `DnsMock::Server` class
|
24
|
+
- Updated tests helpers/tests
|
25
|
+
- Updated gem development dependencies
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
|
29
|
+
- Test coverage issues
|
30
|
+
|
31
|
+
## [1.2.4] - 2021-05-25
|
32
|
+
|
33
|
+
### Changed
|
34
|
+
|
35
|
+
- Updated gem development dependencies
|
36
|
+
- Updated CircleCI config
|
37
|
+
|
38
|
+
## [1.2.3] - 2021-05-11
|
39
|
+
|
40
|
+
### Changed
|
41
|
+
|
42
|
+
- Updated gem development dependencies
|
43
|
+
- Updated CircleCI config
|
44
|
+
|
45
|
+
## [1.2.2] - 2021-05-06
|
46
|
+
|
47
|
+
### Changed
|
48
|
+
|
49
|
+
- Updated gem development dependencies
|
50
|
+
- Updated rubocop/codeclimate config
|
51
|
+
- Updated CircleCI config
|
52
|
+
|
5
53
|
## [1.2.1] - 2021-03-23
|
6
54
|
|
7
55
|
### Changed
|
@@ -128,7 +176,7 @@ DnsMock.start_server(exception_if_not_found: true)
|
|
128
176
|
|
129
177
|
## [0.2.1] - 2021-01-27
|
130
178
|
|
131
|
-
### Fixed
|
179
|
+
### Fixed
|
132
180
|
|
133
181
|
Fixed RDNS lookup representatin for IP address in PTR record feature.
|
134
182
|
|
@@ -140,7 +188,7 @@ Added ability to mock PTR records. Please note, you can define host address with
|
|
140
188
|
|
141
189
|
```ruby
|
142
190
|
records = {
|
143
|
-
'1.
|
191
|
+
'1.2.3.4' => {
|
144
192
|
ptr: %w[domain_1.com domain_2.com]
|
145
193
|
}
|
146
194
|
}
|
@@ -149,7 +197,7 @@ DnsMock.start_server(records: records)
|
|
149
197
|
```
|
150
198
|
|
151
199
|
```bash
|
152
|
-
dig @localhost -p 5300 -x 1.
|
200
|
+
dig @localhost -p 5300 -x 1.2.3.4
|
153
201
|
```
|
154
202
|
|
155
203
|
```
|
@@ -157,8 +205,8 @@ dig @localhost -p 5300 -x 1.1.1.1
|
|
157
205
|
; (2 servers found)
|
158
206
|
|
159
207
|
;; ANSWER SECTION:
|
160
|
-
|
161
|
-
|
208
|
+
4.3.2.1.in-addr.arpa. 1 IN PTR domain_1.com.
|
209
|
+
4.3.2.1.in-addr.arpa. 1 IN PTR domain_2.com.
|
162
210
|
|
163
211
|
;; Query time: 0 msec
|
164
212
|
;; SERVER: 127.0.0.1#5300(127.0.0.1)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dns_mock (1.
|
4
|
+
dns_mock (1.3.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -11,30 +11,31 @@ GEM
|
|
11
11
|
bundler (>= 1.2.0, < 3)
|
12
12
|
thor (~> 1.0)
|
13
13
|
byebug (11.1.3)
|
14
|
-
childprocess (4.
|
14
|
+
childprocess (4.1.0)
|
15
15
|
coderay (1.1.3)
|
16
16
|
colorize (0.8.1)
|
17
|
-
concurrent-ruby (1.1.
|
17
|
+
concurrent-ruby (1.1.9)
|
18
18
|
diff-lcs (1.4.4)
|
19
|
-
dnsruby (1.61.
|
19
|
+
dnsruby (1.61.7)
|
20
20
|
simpleidn (~> 0.1)
|
21
|
-
docile (1.
|
22
|
-
faker (2.
|
21
|
+
docile (1.4.0)
|
22
|
+
faker (2.18.0)
|
23
23
|
i18n (>= 1.6, < 2)
|
24
24
|
fasterer (0.9.0)
|
25
25
|
colorize (~> 0.7)
|
26
26
|
ruby_parser (>= 3.14.1)
|
27
|
-
i18n (1.8.
|
27
|
+
i18n (1.8.10)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
29
|
iniparse (1.5.0)
|
30
30
|
json (2.5.1)
|
31
31
|
kwalify (0.7.2)
|
32
32
|
method_source (1.0.0)
|
33
|
-
overcommit (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
|
-
parser (3.0.
|
38
|
+
parser (3.0.1.1)
|
38
39
|
ast (~> 2.4.1)
|
39
40
|
pry (0.13.1)
|
40
41
|
coderay (~> 1.1)
|
@@ -42,16 +43,16 @@ GEM
|
|
42
43
|
pry-byebug (3.9.0)
|
43
44
|
byebug (~> 11.0)
|
44
45
|
pry (~> 0.13.0)
|
45
|
-
psych (3.3.
|
46
|
+
psych (3.3.2)
|
46
47
|
rainbow (3.0.0)
|
47
|
-
rake (13.0.
|
48
|
-
reek (6.0.
|
48
|
+
rake (13.0.4)
|
49
|
+
reek (6.0.4)
|
49
50
|
kwalify (~> 0.7.0)
|
50
51
|
parser (~> 3.0.0)
|
51
52
|
psych (~> 3.1)
|
52
53
|
rainbow (>= 2.0, < 4.0)
|
53
54
|
regexp_parser (2.1.1)
|
54
|
-
rexml (3.2.
|
55
|
+
rexml (3.2.5)
|
55
56
|
rspec (3.10.0)
|
56
57
|
rspec-core (~> 3.10.0)
|
57
58
|
rspec-expectations (~> 3.10.0)
|
@@ -69,27 +70,27 @@ 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.
|
73
|
+
rubocop (1.18.3)
|
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.
|
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.
|
82
|
-
parser (>=
|
83
|
-
rubocop-performance (1.
|
84
|
-
rubocop (>=
|
82
|
+
rubocop-ast (1.7.0)
|
83
|
+
parser (>= 3.0.1.1)
|
84
|
+
rubocop-performance (1.11.4)
|
85
|
+
rubocop (>= 1.7.0, < 2.0)
|
85
86
|
rubocop-ast (>= 0.4.0)
|
86
|
-
rubocop-rspec (2.
|
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)
|
90
|
-
ruby_parser (3.
|
91
|
-
sexp_processor (~> 4.
|
92
|
-
sexp_processor (4.15.
|
91
|
+
ruby_parser (3.16.0)
|
92
|
+
sexp_processor (~> 4.15, >= 4.15.1)
|
93
|
+
sexp_processor (4.15.3)
|
93
94
|
simplecov (0.17.1)
|
94
95
|
docile (~> 1.1)
|
95
96
|
json (>= 1.8, < 3)
|
@@ -104,24 +105,24 @@ GEM
|
|
104
105
|
unicode-display_width (2.0.0)
|
105
106
|
|
106
107
|
PLATFORMS
|
107
|
-
|
108
|
+
x86_64-darwin-20
|
108
109
|
|
109
110
|
DEPENDENCIES
|
110
|
-
bundler (~>
|
111
|
+
bundler (~> 2.2, >= 2.2.22)
|
111
112
|
bundler-audit (~> 0.8.0)
|
112
113
|
dns_mock!
|
113
|
-
faker (~> 2.
|
114
|
+
faker (~> 2.18)
|
114
115
|
fasterer (~> 0.9.0)
|
115
|
-
overcommit (~> 0.
|
116
|
+
overcommit (~> 0.58.0)
|
116
117
|
pry-byebug (~> 3.9)
|
117
|
-
rake (~> 13.0, >= 13.0.
|
118
|
-
reek (~> 6.0, >= 6.0.
|
118
|
+
rake (~> 13.0, >= 13.0.4)
|
119
|
+
reek (~> 6.0, >= 6.0.4)
|
119
120
|
rspec (~> 3.10)
|
120
121
|
rspec-dns (~> 0.1.8)
|
121
|
-
rubocop (~> 1.
|
122
|
-
rubocop-performance (~> 1.
|
123
|
-
rubocop-rspec (~> 2.
|
122
|
+
rubocop (~> 1.18, >= 1.18.3)
|
123
|
+
rubocop-performance (~> 1.11, >= 1.11.4)
|
124
|
+
rubocop-rspec (~> 2.4)
|
124
125
|
simplecov (~> 0.17.1)
|
125
126
|
|
126
127
|
BUNDLED WITH
|
127
|
-
|
128
|
+
2.2.22
|
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)
|
@@ -80,7 +80,7 @@ records = {
|
|
80
80
|
}
|
81
81
|
]
|
82
82
|
},
|
83
|
-
'1.2.3.4' => {
|
83
|
+
'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
84
|
ptr: %w[domain_1.com domain_2.com]
|
85
85
|
}
|
86
86
|
}
|
@@ -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.
|
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', '~>
|
34
|
+
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.22'
|
35
35
|
spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
|
36
|
-
spec.add_development_dependency 'faker', '~> 2.
|
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.
|
38
|
+
spec.add_development_dependency 'overcommit', '~> 0.58.0'
|
39
39
|
spec.add_development_dependency 'pry-byebug', '~> 3.9'
|
40
|
-
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.
|
41
|
-
spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.
|
40
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.4'
|
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.
|
45
|
-
spec.add_development_dependency 'rubocop-performance', '~> 1.
|
46
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 2.
|
44
|
+
spec.add_development_dependency 'rubocop', '~> 1.18', '>= 1.18.3'
|
45
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.4'
|
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
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)
|
data/lib/dns_mock/version.rb
CHANGED
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.
|
4
|
+
version: 1.3.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-
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.2.22
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '2.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.22
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler-audit
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +50,14 @@ dependencies:
|
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
53
|
+
version: '2.18'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
60
|
+
version: '2.18'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: fasterer
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +78,14 @@ dependencies:
|
|
72
78
|
requirements:
|
73
79
|
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
81
|
+
version: 0.58.0
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
86
|
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
88
|
+
version: 0.58.0
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
90
|
name: pry-byebug
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,7 +109,7 @@ dependencies:
|
|
103
109
|
version: '13.0'
|
104
110
|
- - ">="
|
105
111
|
- !ruby/object:Gem::Version
|
106
|
-
version: 13.0.
|
112
|
+
version: 13.0.4
|
107
113
|
type: :development
|
108
114
|
prerelease: false
|
109
115
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -113,7 +119,7 @@ dependencies:
|
|
113
119
|
version: '13.0'
|
114
120
|
- - ">="
|
115
121
|
- !ruby/object:Gem::Version
|
116
|
-
version: 13.0.
|
122
|
+
version: 13.0.4
|
117
123
|
- !ruby/object:Gem::Dependency
|
118
124
|
name: reek
|
119
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +129,7 @@ dependencies:
|
|
123
129
|
version: '6.0'
|
124
130
|
- - ">="
|
125
131
|
- !ruby/object:Gem::Version
|
126
|
-
version: 6.0.
|
132
|
+
version: 6.0.4
|
127
133
|
type: :development
|
128
134
|
prerelease: false
|
129
135
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -133,7 +139,7 @@ dependencies:
|
|
133
139
|
version: '6.0'
|
134
140
|
- - ">="
|
135
141
|
- !ruby/object:Gem::Version
|
136
|
-
version: 6.0.
|
142
|
+
version: 6.0.4
|
137
143
|
- !ruby/object:Gem::Dependency
|
138
144
|
name: rspec
|
139
145
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,48 +174,54 @@ dependencies:
|
|
168
174
|
requirements:
|
169
175
|
- - "~>"
|
170
176
|
- !ruby/object:Gem::Version
|
171
|
-
version: '1.
|
177
|
+
version: '1.18'
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.18.3
|
172
181
|
type: :development
|
173
182
|
prerelease: false
|
174
183
|
version_requirements: !ruby/object:Gem::Requirement
|
175
184
|
requirements:
|
176
185
|
- - "~>"
|
177
186
|
- !ruby/object:Gem::Version
|
178
|
-
version: '1.
|
187
|
+
version: '1.18'
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 1.18.3
|
179
191
|
- !ruby/object:Gem::Dependency
|
180
192
|
name: rubocop-performance
|
181
193
|
requirement: !ruby/object:Gem::Requirement
|
182
194
|
requirements:
|
183
195
|
- - "~>"
|
184
196
|
- !ruby/object:Gem::Version
|
185
|
-
version: '1.
|
197
|
+
version: '1.11'
|
186
198
|
- - ">="
|
187
199
|
- !ruby/object:Gem::Version
|
188
|
-
version: 1.
|
200
|
+
version: 1.11.4
|
189
201
|
type: :development
|
190
202
|
prerelease: false
|
191
203
|
version_requirements: !ruby/object:Gem::Requirement
|
192
204
|
requirements:
|
193
205
|
- - "~>"
|
194
206
|
- !ruby/object:Gem::Version
|
195
|
-
version: '1.
|
207
|
+
version: '1.11'
|
196
208
|
- - ">="
|
197
209
|
- !ruby/object:Gem::Version
|
198
|
-
version: 1.
|
210
|
+
version: 1.11.4
|
199
211
|
- !ruby/object:Gem::Dependency
|
200
212
|
name: rubocop-rspec
|
201
213
|
requirement: !ruby/object:Gem::Requirement
|
202
214
|
requirements:
|
203
215
|
- - "~>"
|
204
216
|
- !ruby/object:Gem::Version
|
205
|
-
version: '2.
|
217
|
+
version: '2.4'
|
206
218
|
type: :development
|
207
219
|
prerelease: false
|
208
220
|
version_requirements: !ruby/object:Gem::Requirement
|
209
221
|
requirements:
|
210
222
|
- - "~>"
|
211
223
|
- !ruby/object:Gem::Version
|
212
|
-
version: '2.
|
224
|
+
version: '2.4'
|
213
225
|
- !ruby/object:Gem::Dependency
|
214
226
|
name: simplecov
|
215
227
|
requirement: !ruby/object:Gem::Requirement
|
@@ -290,7 +302,6 @@ files:
|
|
290
302
|
- lib/dns_mock/response/answer.rb
|
291
303
|
- lib/dns_mock/response/message.rb
|
292
304
|
- lib/dns_mock/server.rb
|
293
|
-
- lib/dns_mock/server/random_available_port.rb
|
294
305
|
- lib/dns_mock/server/records_dictionary_builder.rb
|
295
306
|
- lib/dns_mock/test_framework/rspec.rb
|
296
307
|
- lib/dns_mock/test_framework/rspec/helper.rb
|
@@ -320,8 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
331
|
- !ruby/object:Gem::Version
|
321
332
|
version: '0'
|
322
333
|
requirements: []
|
323
|
-
|
324
|
-
rubygems_version: 2.7.3
|
334
|
+
rubygems_version: 3.2.20
|
325
335
|
signing_key:
|
326
336
|
specification_version: 4
|
327
337
|
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
|