devdnsd 2.4.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rbx/8b/8b2d1928657c1eeac610d1207ff1bee6e918287c +857 -0
- data/.rbx/db/dbd6130694811dcd0359863bd5380c673db0fe71 +288 -0
- data/.travis-gemfile +1 -2
- data/.travis.yml +1 -0
- data/Gemfile +2 -3
- data/README.md +3 -1
- data/Rakefile +1 -1
- data/bin/devdnsd +29 -5
- data/config/devdnsd_config.sample +2 -5
- data/devdnsd.gemspec +6 -5
- data/doc/DevDNSd.html +4 -4
- data/doc/DevDNSd/Application.html +560 -520
- data/doc/DevDNSd/ApplicationMethods.html +4 -4
- data/doc/DevDNSd/ApplicationMethods/Aliases.html +780 -0
- data/doc/DevDNSd/ApplicationMethods/Server.html +46 -46
- data/doc/DevDNSd/ApplicationMethods/System.html +222 -20
- data/doc/DevDNSd/ApplicationMethods/System/ClassMethods.html +3 -3
- data/doc/DevDNSd/Configuration.html +20 -20
- data/doc/DevDNSd/Errors.html +3 -3
- data/doc/DevDNSd/Errors/InvalidRule.html +3 -3
- data/doc/DevDNSd/Rule.html +15 -15
- data/doc/DevDNSd/Version.html +5 -5
- data/doc/_index.html +11 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +6 -4
- data/doc/frames.html +1 -1
- data/doc/index.html +6 -4
- data/doc/method_list.html +73 -31
- data/doc/top-level-namespace.html +3 -3
- data/lib/devdnsd.rb +6 -3
- data/lib/devdnsd/application.rb +220 -11
- data/lib/devdnsd/configuration.rb +19 -1
- data/lib/devdnsd/errors.rb +1 -1
- data/lib/devdnsd/rule.rb +2 -2
- data/lib/devdnsd/version.rb +3 -3
- data/locales/en.yml +28 -2
- data/locales/it.yml +29 -2
- data/spec/coverage_helper.rb +3 -3
- data/spec/devdnsd/application_spec.rb +202 -51
- data/spec/devdnsd/configuration_spec.rb +1 -1
- data/spec/devdnsd/rule_spec.rb +1 -1
- data/spec/resolver_helper.rb +51 -0
- data/spec/spec_helper.rb +3 -5
- metadata +34 -26
data/locales/it.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
#
|
|
3
|
-
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@
|
|
3
|
+
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@cowtech.it>.
|
|
4
4
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
|
5
5
|
#
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
rule_invalid_call: "Devi specificare almeno una regola e un host (anche tramite un blocco). Opzionalmente puoi aggiungere un tipo di record (default: A) e le opzioni."
|
|
10
10
|
rule_invalid_options: "Puoi usare solo hash per le opzioni."
|
|
11
11
|
rule_invalid_resource: "Classe di risorsa %1 non valida."
|
|
12
|
-
|
|
12
|
+
no_jruby: "DevDNSd non è disponibile per JRuby."
|
|
13
13
|
no_fork: "Il forking non è disponibile per questa piattaforma. Eseguo foreground ..."
|
|
14
14
|
dns_update: "Cancello la cache dei DNS e dei resolver ..."
|
|
15
15
|
starting: "Avvio DevDNSd ..."
|
|
@@ -38,11 +38,38 @@
|
|
|
38
38
|
application_help_log_file: "Il file di log da utilizzare. Non usato se eseguito in foreground. Il valore predefinito è \"/var/log/devdnsd.log\"."
|
|
39
39
|
application_help_log_level: "Il livello di log da utilizzare. I valori validi sono da 0 a 5 dove 0 significa \"tutti i messaggi\". Il valore predefinito è 1."
|
|
40
40
|
application_help_foreground: "Non eseguire in background."
|
|
41
|
+
application_help_interface: "L'interfaccia da gestire. L'interfaccia predefinita è \"lo0\"."
|
|
42
|
+
application_help_addresses: "La lista di indirizzi da aggiungere. Sovrascrive la lista sequenziale."
|
|
43
|
+
application_help_start_address: "L'indirizzo iniziale per gli indirizzi sequenziali. L'indirizzo predefinito è \"10.0.0.1\"."
|
|
44
|
+
application_help_aliases: "Il numero di indirizzi da aggiungere. Il numero predefinito è 5."
|
|
45
|
+
application_help_add_command: "Il comando da eseguire per aggiungere un indirizzo. Il comando predefinito è \"sudo ifconfig {{interface}} alias {{address}}\"."
|
|
46
|
+
application_help_remove_command: "Il comando da eseguire per rimuovere un indirizzo. Il comando predefinito è \"sudo ifconfig {{interface}} -alias {{address}}\"."
|
|
47
|
+
application_help_dry_run: "Mostra solo quali modifiche sarebbero applicato"
|
|
48
|
+
application_help_quiet: "Non mostra alcun messaggio"
|
|
41
49
|
application_meta_file: "FILE"
|
|
42
50
|
application_meta_domain: "DOMINIO"
|
|
43
51
|
application_meta_level: "LIVELLO"
|
|
44
52
|
application_meta_port: "PORTA"
|
|
53
|
+
application_meta_interface: "INTERFACCIA"
|
|
54
|
+
application_meta_address: "INDIRIZZO"
|
|
55
|
+
application_meta_addresses: "INDIRIZZI"
|
|
56
|
+
application_meta_aliases: "ALIAS"
|
|
57
|
+
application_meta_command: "COMANDO"
|
|
45
58
|
command_start: "Avvia server."
|
|
46
59
|
command_install: "Installa il server."
|
|
47
60
|
command_uninstall: "Disinstalla il server."
|
|
48
61
|
command_stop: "Ferma il server."
|
|
62
|
+
command_aliases: "Aggiunge or rimuove indirizzi dalle interfacce di rete."
|
|
63
|
+
command_add: "Aggiungi indirizzi"
|
|
64
|
+
command_remove: "Rimuovi indirizzi."
|
|
65
|
+
removing: "Rimuovo"
|
|
66
|
+
adding: "Aggiungo"
|
|
67
|
+
remove: "rimuovere"
|
|
68
|
+
add: "aggiungere"
|
|
69
|
+
to: "all'"
|
|
70
|
+
from: "dall'"
|
|
71
|
+
general_error: "Impossibile {mark=bright}%1{/mark} l'indirizzo {mark=bright}%2{/mark} %3interfaccia {mark=bright}%4{/mark}."
|
|
72
|
+
add_empty: "Nessun indirizzo valido da aggiungere all'interfaccia trovato."
|
|
73
|
+
remove_empty: "Nessun indirizzo valido da rimuovere dall'interfaccia trovato."
|
|
74
|
+
run: "%1 {mark=bright}%2{/mark} l'indirizzo {mark=bright}%3{/mark} %4interfaccia {mark=bright}%5{/mark}..."
|
|
75
|
+
dry_run: "%1 Sto per {mark=bright}%2{/mark} l'indirizzo {mark=bright}%3{/mark} %4interfaccia {mark=bright}%5{/mark}..."
|
data/spec/coverage_helper.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
#
|
|
3
|
-
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@
|
|
3
|
+
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@cowtech.it>.
|
|
4
4
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
|
5
5
|
#
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ require "pathname"
|
|
|
8
8
|
require "simplecov"
|
|
9
9
|
require "coveralls"
|
|
10
10
|
|
|
11
|
-
Coveralls.wear!
|
|
11
|
+
Coveralls.wear! if ENV["CI"] || ENV["JENKINS_URL"]
|
|
12
12
|
|
|
13
13
|
SimpleCov.start do
|
|
14
14
|
root = Pathname.new(File.dirname(__FILE__)) + ".."
|
|
@@ -17,4 +17,4 @@ SimpleCov.start do
|
|
|
17
17
|
path = Pathname.new(src_file.filename).relative_path_from(root).to_s
|
|
18
18
|
path =~ /^lib\/devdnsd\/patches/ || path !~ /^(bin|lib)/
|
|
19
19
|
end
|
|
20
|
-
end
|
|
20
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
#
|
|
3
|
-
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@
|
|
3
|
+
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@cowtech.it>.
|
|
4
4
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
|
5
5
|
#
|
|
6
6
|
|
|
@@ -13,16 +13,14 @@ describe DevDNSd::Application do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def create_application(overrides = {})
|
|
16
|
-
|
|
16
|
+
DevDNSd::Application.new(Bovem::Application.create(run: false) {
|
|
17
17
|
option :configuration, [], {default: overrides["configuration"] || "/dev/null"}
|
|
18
18
|
option :tld, [], {default: overrides["tld"] || "dev"}
|
|
19
19
|
option :port, [], {type: Integer, default: overrides["port"] || 7771}
|
|
20
20
|
option :pid_file, [:P, "pid-file"], {type: String, default: "/var/run/devdnsd.pid"}
|
|
21
21
|
option :log_file, [:l, "log-file"], {default: overrides["log_file"] || "/dev/null"}
|
|
22
22
|
option :log_level, [:L, "log-level"], {type: Integer, default: overrides["log_level"] || 1}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
DevDNSd::Application.new(mamertes_app, :en)
|
|
23
|
+
}, :en)
|
|
26
24
|
end
|
|
27
25
|
|
|
28
26
|
let(:log_file) { "/tmp/devdnsd-test-log-#{Time.now.strftime("%Y%m%d-%H%M%S")}" }
|
|
@@ -61,19 +59,18 @@ describe DevDNSd::Application do
|
|
|
61
59
|
|
|
62
60
|
describe ".quit" do
|
|
63
61
|
it "should quit the application" do
|
|
64
|
-
|
|
62
|
+
allow(EM).to receive(:add_timer).and_yield
|
|
63
|
+
expect(EM).to receive(:stop)
|
|
65
64
|
DevDNSd::Application.quit
|
|
66
65
|
end
|
|
67
|
-
end
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
expect(Kernel).to receive(:exit).with(0)
|
|
73
|
-
expect(Kernel).to receive(:puts)
|
|
74
|
-
DevDNSd::Application.check_ruby_implementation
|
|
67
|
+
it "should not blow up in case of errors" do
|
|
68
|
+
allow(EM).to receive(:add_timer).and_raise(RuntimeError)
|
|
69
|
+
expect { DevDNSd::Application.quit }.not_to raise_error
|
|
75
70
|
end
|
|
71
|
+
end
|
|
76
72
|
|
|
73
|
+
describe ".check_ruby_implementation" do
|
|
77
74
|
it "won't run on JRuby" do
|
|
78
75
|
stub_const("JRuby", true)
|
|
79
76
|
expect(Kernel).to receive(:exit).with(0)
|
|
@@ -87,8 +84,8 @@ describe DevDNSd::Application do
|
|
|
87
84
|
allow(DevDNSd::Application).to receive(:instance).and_call_original
|
|
88
85
|
end
|
|
89
86
|
|
|
90
|
-
let(:
|
|
91
|
-
|
|
87
|
+
let(:bovem) {
|
|
88
|
+
Bovem::Application.create(run: false) do
|
|
92
89
|
option :configuration, [], {default: "/dev/null"}
|
|
93
90
|
option :tld, [], {default: "dev"}
|
|
94
91
|
option :port, [], {type: Integer, default: 7771}
|
|
@@ -99,19 +96,19 @@ describe DevDNSd::Application do
|
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
it "should create a new instance" do
|
|
102
|
-
expect(DevDNSd::Application.instance(
|
|
99
|
+
expect(DevDNSd::Application.instance(bovem)).to be_a(DevDNSd::Application)
|
|
103
100
|
end
|
|
104
101
|
|
|
105
102
|
it "should always return the same instance" do
|
|
106
|
-
other = DevDNSd::Application.instance(
|
|
103
|
+
other = DevDNSd::Application.instance(bovem)
|
|
107
104
|
expect(DevDNSd::Application).not_to receive(:new)
|
|
108
|
-
expect(DevDNSd::Application.instance(
|
|
105
|
+
expect(DevDNSd::Application.instance(bovem)).to eq(other)
|
|
109
106
|
expect(DevDNSd::Application.instance).to eq(other)
|
|
110
107
|
end
|
|
111
108
|
|
|
112
109
|
it "should recreate an instance" do
|
|
113
|
-
other = DevDNSd::Application.instance(
|
|
114
|
-
expect(DevDNSd::Application.instance(
|
|
110
|
+
other = DevDNSd::Application.instance(bovem)
|
|
111
|
+
expect(DevDNSd::Application.instance(bovem, :en, true)).not_to be(other)
|
|
115
112
|
end
|
|
116
113
|
end
|
|
117
114
|
|
|
@@ -158,26 +155,19 @@ describe DevDNSd::Application do
|
|
|
158
155
|
let(:application){ create_application({"log_file" => log_file, "configuration" => sample_config}) }
|
|
159
156
|
|
|
160
157
|
def test_resolve(host = "match_1.dev", type = "ANY", nameserver = "127.0.0.1", port = 7771, logger = nil)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
else
|
|
173
|
-
application.perform_server
|
|
174
|
-
end
|
|
175
|
-
}
|
|
158
|
+
result = nil
|
|
159
|
+
|
|
160
|
+
EM.run do
|
|
161
|
+
EM.add_timer(0.01) { application.perform_server }
|
|
162
|
+
EM.add_timer(0.1) {
|
|
163
|
+
Fiber.new {
|
|
164
|
+
result = devdnsd_resolv(host, type, nameserver, port, logger)
|
|
165
|
+
EM.stop
|
|
166
|
+
}.resume
|
|
167
|
+
}
|
|
168
|
+
end
|
|
176
169
|
|
|
177
|
-
|
|
178
|
-
Thread.kill(Thread.current[:server])
|
|
179
|
-
Thread.main[:running] = false
|
|
180
|
-
Thread.main[:result]
|
|
170
|
+
result
|
|
181
171
|
end
|
|
182
172
|
|
|
183
173
|
it "should run the server" do
|
|
@@ -189,12 +179,10 @@ describe DevDNSd::Application do
|
|
|
189
179
|
expect_any_instance_of(RubyDNS::Server).to receive(:on).with(:start)
|
|
190
180
|
expect_any_instance_of(RubyDNS::Server).to receive(:on).with(:stop)
|
|
191
181
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
application.perform_server
|
|
182
|
+
EM.run do
|
|
183
|
+
EM.add_timer(0.01) { application.perform_server }
|
|
184
|
+
EM.add_timer(0.2) { DevDNSd::Application.quit }
|
|
185
|
+
end
|
|
198
186
|
end
|
|
199
187
|
|
|
200
188
|
it "should iterate the rules" do
|
|
@@ -223,12 +211,12 @@ describe DevDNSd::Application do
|
|
|
223
211
|
expect(test_resolve("match_1.dev")).to eq(["10.0.1.1", :A])
|
|
224
212
|
expect(test_resolve("match_2.dev")).to eq(["10.0.2.1", :MX])
|
|
225
213
|
expect(test_resolve("match_3.dev")).to eq(["10.0.3.1", :A])
|
|
226
|
-
expect(test_resolve("match_4.dev")).to eq(["
|
|
214
|
+
expect(test_resolve("match_4.dev")).to eq(["cowtech.it", :CNAME])
|
|
227
215
|
end
|
|
228
216
|
|
|
229
217
|
it "basing on a regexp pattern" do
|
|
230
|
-
expect(test_resolve("match_5_11.dev")).to eq(["
|
|
231
|
-
expect(test_resolve("match_5_22.dev")).to eq(["
|
|
218
|
+
expect(test_resolve("match_5_11.dev")).to eq(["ns.cowtech.it", :NS])
|
|
219
|
+
expect(test_resolve("match_5_22.dev")).to eq(["ns.cowtech.it", :NS])
|
|
232
220
|
expect(test_resolve("match_6_33.dev")).to eq(["10.0.6.33", :PTR])
|
|
233
221
|
expect(test_resolve("match_6_44.dev")).to eq(["10.0.6.44", :PTR])
|
|
234
222
|
expect(test_resolve("match_7_55.dev")).to eq(["10.0.7.55", :A])
|
|
@@ -243,8 +231,8 @@ describe DevDNSd::Application do
|
|
|
243
231
|
end
|
|
244
232
|
|
|
245
233
|
it "and reject invalid matches (with or without rules)" do
|
|
246
|
-
expect(test_resolve("match_9.dev")).to
|
|
247
|
-
expect(test_resolve("invalid.dev")).to
|
|
234
|
+
expect(test_resolve("match_9.dev")).to eq([])
|
|
235
|
+
expect(test_resolve("invalid.dev")).to eq([])
|
|
248
236
|
end
|
|
249
237
|
end
|
|
250
238
|
end
|
|
@@ -357,16 +345,165 @@ describe DevDNSd::Application do
|
|
|
357
345
|
end
|
|
358
346
|
end
|
|
359
347
|
|
|
348
|
+
describe "#manage_aliases" do
|
|
349
|
+
it "should override configuration" do
|
|
350
|
+
allow(application).to receive(:manage_address)
|
|
351
|
+
application.manage_aliases(:add, "MESSAGE", {aliases: 10})
|
|
352
|
+
expect(application.config.aliases).to eq(10)
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it "should log an error if no interfaces are found" do
|
|
356
|
+
allow(application).to receive(:compute_addresses).and_return([])
|
|
357
|
+
expect(application.logger).to receive(:error).with("MESSAGE")
|
|
358
|
+
expect(application.manage_aliases(:add, "MESSAGE", {aliases: 10})).to be_false
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
it "should call #manage_address for each address" do
|
|
362
|
+
expect(application).to receive(:manage_address).with("OPERATION", IPAddr.new("10.0.0.1"), "DRY_RUN").and_return(true)
|
|
363
|
+
expect(application).to receive(:manage_address).with("OPERATION", IPAddr.new("10.0.0.2"), "DRY_RUN").and_return(true)
|
|
364
|
+
expect(application).to receive(:manage_address).with("OPERATION", IPAddr.new("10.0.0.3"), "DRY_RUN").and_return(true)
|
|
365
|
+
expect(application.manage_aliases("OPERATION", "MESSAGE", {aliases: 3, dry_run: "DRY_RUN"})).to be_true
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
describe "#manage_address" do
|
|
370
|
+
it "should show a right message to the user" do
|
|
371
|
+
expect(application.logger).to receive(:info).with(/.+.*3.*\/.*5.*.+ *Adding.* address .*10.0.0.3.* to interface .*lo0.*/)
|
|
372
|
+
application.manage_address(:add, "10.0.0.3")
|
|
373
|
+
|
|
374
|
+
expect(application.logger).to receive(:info).with(/.+.*3.*\/.*5.*.+ *Removing.* address .*10.0.0.3.* from interface .*lo0.*/)
|
|
375
|
+
application.manage_address(:remove, "10.0.0.3")
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
it "should call the right system command" do
|
|
379
|
+
expect(application).to receive(:execute_command).with("sudo ifconfig lo0 alias 10.0.0.3 > /dev/null 2>&1")
|
|
380
|
+
application.manage_address(:add, "10.0.0.3")
|
|
381
|
+
|
|
382
|
+
expect(application).to receive(:execute_command).with("sudo ifconfig lo0 -alias 10.0.0.3 > /dev/null 2>&1")
|
|
383
|
+
application.manage_address(:remove, "10.0.0.3")
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
it "should return true if the command succeded" do
|
|
387
|
+
application.config.add_command = "echo {{interface}}"
|
|
388
|
+
expect(application.manage_address(:add, "10.0.0.3")).to be_true
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
it "should return false if the command failed" do
|
|
392
|
+
expect(application.manage_address(:add, "10.0.0.256")).to be_false
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
it "should respect dry-run mode" do
|
|
396
|
+
expect(application).not_to receive(:execute_command)
|
|
397
|
+
expect(application.logger).to receive(:info).with(/.+.*3.*\/.*5.*.+ I will .*add.* address .*10.0.0.3.* to interface .*lo0.*/)
|
|
398
|
+
expect(application.logger).to receive(:info).with(/.+.*3.*\/.*5.*.+ I will .*remove.* address .*10.0.0.3.* from interface .*lo0.*/)
|
|
399
|
+
|
|
400
|
+
application.manage_address(:add, "10.0.0.3", true)
|
|
401
|
+
application.manage_address(:remove, "10.0.0.3", true)
|
|
402
|
+
end
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
describe "#compute_addresses" do
|
|
406
|
+
describe "should use only the explicit list if given" do
|
|
407
|
+
before(:each) do
|
|
408
|
+
application.config.addresses = ["10.0.0.1", "::1", "INVALID 1", "10.0.0.2", "INVALID 2", "2001:0db8:0::0:1428:57ab"]
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
it "considering all address" do
|
|
412
|
+
expect(application.compute_addresses).to eq(["10.0.0.1", "::1", "10.0.0.2", "2001:0db8:0::0:1428:57ab"])
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
it "considering only IPv4" do
|
|
416
|
+
expect(application.compute_addresses(:ipv4)).to eq(["10.0.0.1", "10.0.0.2"])
|
|
417
|
+
application.config.addresses = ["::1", "INVALID 1"]
|
|
418
|
+
expect(application.compute_addresses(:ipv4)).to eq([])
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
it "considering only IPv6" do
|
|
422
|
+
expect(application.compute_addresses(:ipv6)).to eq(["::1", "2001:0db8:0::0:1428:57ab"])
|
|
423
|
+
application.config.addresses = ["10.0.0.1", "INVALID 1"]
|
|
424
|
+
expect(application.compute_addresses(:ipv6)).to eq([])
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
describe "should compute a sequential list of address" do
|
|
429
|
+
it "considering all address" do
|
|
430
|
+
application.config.start_address = "10.0.1.1"
|
|
431
|
+
expect(application.compute_addresses).to eq(["10.0.1.1", "10.0.1.2", "10.0.1.3", "10.0.1.4", "10.0.1.5"])
|
|
432
|
+
|
|
433
|
+
application.config.start_address = "10.0.0.1"
|
|
434
|
+
application.config.aliases = 3
|
|
435
|
+
expect(application.compute_addresses).to eq(["10.0.0.1", "10.0.0.2", "10.0.0.3"])
|
|
436
|
+
|
|
437
|
+
application.config.start_address = "10.0.1.1"
|
|
438
|
+
application.config.aliases = -1
|
|
439
|
+
expect(application.compute_addresses).to eq(["10.0.1.1"])
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
it "considering only IPv4" do
|
|
443
|
+
application.config.start_address = "::1"
|
|
444
|
+
expect(application.compute_addresses(:ipv4)).to eq([])
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
it "considering only IPv6" do
|
|
448
|
+
application.config.start_address = "10.0.0.1"
|
|
449
|
+
expect(application.compute_addresses(:ipv6)).to eq([])
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
describe "#is_ipv4?" do
|
|
455
|
+
it "correctly detects valid IPv4 address" do
|
|
456
|
+
expect(application.is_ipv4?("10.0.0.1")).to be_true
|
|
457
|
+
expect(application.is_ipv4?("255.0.0.1")).to be_true
|
|
458
|
+
expect(application.is_ipv4?("192.168.0.1")).to be_true
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
it "rejects other values" do
|
|
462
|
+
expect(application.is_ipv4?("10.0.0.256")).to be_false
|
|
463
|
+
expect(application.is_ipv4?("10.0.0.-1")).to be_false
|
|
464
|
+
expect(application.is_ipv4?("::1")).to be_false
|
|
465
|
+
expect(application.is_ipv4?("INVALID")).to be_false
|
|
466
|
+
expect(application.is_ipv4?(nil)).to be_false
|
|
467
|
+
end
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
describe "#is_ipv6?" do
|
|
471
|
+
it "correctly detects valid IPv4 address" do
|
|
472
|
+
expect(application.is_ipv6?("2001:0db8:0000:0000:0000:1428:57ab")).to be_true
|
|
473
|
+
expect(application.is_ipv6?("2001:0db8:0:000:00:1428:57ab")).to be_true
|
|
474
|
+
expect(application.is_ipv6?("2001:0db8:0::1428:57ab")).to be_true
|
|
475
|
+
expect(application.is_ipv6?("2001::")).to be_true
|
|
476
|
+
expect(application.is_ipv6?("::1")).to be_true
|
|
477
|
+
expect(application.is_ipv6?("::2:1")).to be_true
|
|
478
|
+
expect(application.is_ipv6?("2011::10.0.0.1")).to be_true
|
|
479
|
+
expect(application.is_ipv6?("2011::0:10.0.0.1")).to be_true
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
it "rejects other values" do
|
|
483
|
+
expect(application.is_ipv6?("::H")).to be_false
|
|
484
|
+
expect(application.is_ipv6?("192.168.0.256")).to be_false
|
|
485
|
+
expect(application.is_ipv6?("INVALID")).to be_false
|
|
486
|
+
expect(application.is_ipv6?(nil)).to be_false
|
|
487
|
+
end
|
|
488
|
+
end
|
|
489
|
+
|
|
360
490
|
describe "#action_start" do
|
|
361
491
|
it "should call perform_server in foreground" do
|
|
362
492
|
application = create_application({"log_file" => log_file})
|
|
363
|
-
application.
|
|
493
|
+
application.instance_variable_set(:@command, Bovem::Command.new {
|
|
494
|
+
option :foreground, [:n, "foreground"], {default: true}
|
|
495
|
+
})
|
|
496
|
+
|
|
364
497
|
expect(application).to receive(:perform_server)
|
|
365
498
|
application.action_start
|
|
366
499
|
end
|
|
367
500
|
|
|
368
501
|
it "should start the daemon" do
|
|
369
502
|
application = create_application({"log_file" => log_file})
|
|
503
|
+
application.instance_variable_set(:@command, Bovem::Command.new {
|
|
504
|
+
option :foreground, [:n, "foreground"], {default: false}
|
|
505
|
+
})
|
|
506
|
+
|
|
370
507
|
expect(::RExec::Daemon::Controller).to receive(:start)
|
|
371
508
|
application.action_start
|
|
372
509
|
end
|
|
@@ -579,4 +716,18 @@ describe DevDNSd::Application do
|
|
|
579
716
|
expect(application.action_uninstall).to be_false
|
|
580
717
|
end
|
|
581
718
|
end
|
|
719
|
+
|
|
720
|
+
describe "#action_add" do
|
|
721
|
+
it "should #manage_aliases" do
|
|
722
|
+
expect(application).to receive(:manage_aliases).with(:add, "No valid addresses to add to the interface found.", {a: 1})
|
|
723
|
+
application.action_add({a: 1})
|
|
724
|
+
end
|
|
725
|
+
end
|
|
726
|
+
|
|
727
|
+
describe "#action_remove" do
|
|
728
|
+
it "should #manage_aliases" do
|
|
729
|
+
expect(application).to receive(:manage_aliases).with(:remove, "No valid addresses to remove from the interface found.", {a: 1})
|
|
730
|
+
application.action_remove({a: 1})
|
|
731
|
+
end
|
|
732
|
+
end
|
|
582
733
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
#
|
|
3
|
-
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@
|
|
3
|
+
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@cowtech.it>.
|
|
4
4
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
|
5
5
|
#
|
|
6
6
|
|
data/spec/devdnsd/rule_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
#
|
|
3
|
-
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@
|
|
3
|
+
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun_panda@cowtech.it>.
|
|
4
4
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
|
5
5
|
#
|
|
6
6
|
|