wamupd 1.1.1
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.
- data/.gitignore +1 -0
- data/CHANGELOG.md +0 -0
- data/LICENSE +20 -0
- data/README.md +97 -0
- data/Rakefile +24 -0
- data/bin/wamupd +314 -0
- data/lib/wamupd/action.rb +40 -0
- data/lib/wamupd/avahi_model.rb +210 -0
- data/lib/wamupd/avahi_service.rb +112 -0
- data/lib/wamupd/avahi_service_file.rb +160 -0
- data/lib/wamupd/dns_avahi_controller.rb +230 -0
- data/lib/wamupd/dns_ip_controller.rb +95 -0
- data/lib/wamupd/dns_update.rb +154 -0
- data/lib/wamupd/lease_update.rb +29 -0
- data/lib/wamupd/main_settings.rb +202 -0
- data/lib/wamupd/signals.rb +52 -0
- data/lib/wamupd.rb +10 -0
- data/test/data/config.yaml +9 -0
- data/test/data/simple.service +16 -0
- data/test/data/ssh.service +12 -0
- data/test/test.rb +36 -0
- data/test/test_action.rb +28 -0
- data/test/test_avahi_model.rb +29 -0
- data/test/test_avahi_service.rb +50 -0
- data/test/test_avahi_service_file.rb +78 -0
- data/test/test_dns_avahi_controller.rb +69 -0
- data/test/test_dns_ip_controller.rb +30 -0
- data/test/test_main_settings.rb +43 -0
- data/test/test_signals.rb +58 -0
- data/wamupd.gemspec +29 -0
- metadata +165 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
3
|
+
#
|
4
|
+
# This file is part of wamupd.
|
5
|
+
#
|
6
|
+
# wamupd is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# wamupd is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require "dnsruby"
|
20
|
+
require "ipaddr"
|
21
|
+
require "singleton"
|
22
|
+
require "socket"
|
23
|
+
require "psych"
|
24
|
+
|
25
|
+
# Wamupd is a module that is used to namespace all of the wamupd code.
|
26
|
+
module Wamupd
|
27
|
+
# Simple singleton for storing app-side configuration-type
|
28
|
+
# things
|
29
|
+
class MainSettings
|
30
|
+
include Singleton
|
31
|
+
|
32
|
+
# The current hostname, or, if present, the
|
33
|
+
# host name desired from the YAML
|
34
|
+
attr_reader :hostname
|
35
|
+
|
36
|
+
# DNS server to try and update
|
37
|
+
attr_reader :dns_server
|
38
|
+
|
39
|
+
# Port to use when talking to the DNS server
|
40
|
+
attr_reader :dns_port
|
41
|
+
|
42
|
+
# DNSSEC key name (if nil, do not use DNSSEC)
|
43
|
+
attr_reader :dnssec_key_name
|
44
|
+
|
45
|
+
# DNSSEC key value (usually, a HMAC-MD5 private key)
|
46
|
+
attr_reader :dnssec_key_value
|
47
|
+
|
48
|
+
# Zone
|
49
|
+
attr_reader :zone
|
50
|
+
|
51
|
+
# Default TTL of records
|
52
|
+
attr_reader :ttl
|
53
|
+
|
54
|
+
# Default priority of SRV records
|
55
|
+
attr_reader :priority
|
56
|
+
|
57
|
+
# Default weight of SRV records
|
58
|
+
attr_reader :weight
|
59
|
+
|
60
|
+
# Current IPv4 address
|
61
|
+
attr_reader :ipv4
|
62
|
+
|
63
|
+
# Current IPv6 address
|
64
|
+
attr_reader :ipv6
|
65
|
+
|
66
|
+
# Minimum time to sleep between lease renewal checks
|
67
|
+
attr_reader :sleep_time
|
68
|
+
|
69
|
+
# Maximum time to wait for DNS
|
70
|
+
attr_reader :max_dns_response_time
|
71
|
+
|
72
|
+
# The lease renewal time. By default, ttl * (2/3)
|
73
|
+
def lease_time
|
74
|
+
return (0.667 * @ttl).to_i
|
75
|
+
end
|
76
|
+
|
77
|
+
# Constructor. Use the instance() function
|
78
|
+
# to actually initialize
|
79
|
+
def initialize
|
80
|
+
@hostname = Socket.gethostname()
|
81
|
+
@dns_port = 53
|
82
|
+
@ttl = 7200
|
83
|
+
@priority = 1
|
84
|
+
@weight = 5
|
85
|
+
@resolver = nil
|
86
|
+
@ipv4 = nil
|
87
|
+
@ipv6 = nil
|
88
|
+
@sleep_time = 60
|
89
|
+
@max_dns_response_time=10
|
90
|
+
@zone = ""
|
91
|
+
@transport = :udp
|
92
|
+
end
|
93
|
+
|
94
|
+
# Are we using DNSSEC?
|
95
|
+
def using_dnssec?
|
96
|
+
return (not @dnssec_key_name.nil?)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Target for ops
|
100
|
+
def target
|
101
|
+
t = ""
|
102
|
+
t += @hostname
|
103
|
+
t += "."
|
104
|
+
t += @zone
|
105
|
+
return t
|
106
|
+
end
|
107
|
+
|
108
|
+
# Load some more settings from a YAML file
|
109
|
+
def load_from_yaml(yaml_file)
|
110
|
+
y = Psych.load_file(yaml_file)
|
111
|
+
properties_map = {
|
112
|
+
"hostname" => :@hostname,
|
113
|
+
"dns_server" => :@dns_server,
|
114
|
+
"dns_port" => :@dns_port,
|
115
|
+
"dnssec_key_name" => :@dnssec_key_name,
|
116
|
+
"dnssec_key_hmac" => :@dnssec_key_value,
|
117
|
+
"zone" => :@zone,
|
118
|
+
"ttl" => :@ttl,
|
119
|
+
"srv_priority" => :@priority,
|
120
|
+
"srv_weight" => :@weight,
|
121
|
+
"sleep_time" => :@sleep_time,
|
122
|
+
"transport" => :@transport,
|
123
|
+
"max_dns_response_time" => :@max_dns_response_time,
|
124
|
+
}
|
125
|
+
properties_map.each { |k,v|
|
126
|
+
if (y.has_key?(k))
|
127
|
+
self.instance_variable_set(v, y[k])
|
128
|
+
end
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
# Reset the MainSettings
|
133
|
+
def clear
|
134
|
+
initialize
|
135
|
+
end
|
136
|
+
|
137
|
+
# Get a Dnsruby::Resolver
|
138
|
+
def resolver
|
139
|
+
if (@resolver.nil?)
|
140
|
+
make_resolver
|
141
|
+
end
|
142
|
+
return @resolver
|
143
|
+
end
|
144
|
+
|
145
|
+
# Should we be using TCP as our transport?
|
146
|
+
def using_tcp?
|
147
|
+
return (@transport == "tcp" || @transport == :tcp)
|
148
|
+
end
|
149
|
+
|
150
|
+
def make_resolver
|
151
|
+
if self.using_dnssec?
|
152
|
+
ts = Dnsruby::RR.new_from_hash({
|
153
|
+
:type=>Dnsruby::Types.TSIG,
|
154
|
+
:klass=>Dnsruby::Classes.ANY,
|
155
|
+
:name=>self.dnssec_key_name,
|
156
|
+
:key=>self.dnssec_key_value,
|
157
|
+
:algorithm=>Dnsruby::RR::TSIG::HMAC_MD5
|
158
|
+
})
|
159
|
+
end
|
160
|
+
@resolver = Dnsruby::Resolver.new({
|
161
|
+
:nameserver => self.dns_server,
|
162
|
+
:port => self.dns_port,
|
163
|
+
:tsig => ts,
|
164
|
+
:dnssec => false,
|
165
|
+
:use_tcp => self.using_tcp?,
|
166
|
+
})
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
# Get IPv4 and IPv6 addresses
|
171
|
+
def get_ip_addresses
|
172
|
+
sa = MainSettings.instance
|
173
|
+
begin
|
174
|
+
s = UDPSocket.new(Socket::AF_INET)
|
175
|
+
s.connect("8.8.8.8", 1)
|
176
|
+
if (s.addr[0] == "AF_INET")
|
177
|
+
@ipv4 = IPAddr.new(s.addr.last)
|
178
|
+
end
|
179
|
+
rescue SocketError => e
|
180
|
+
$stderr.puts "Unable to determine IPv4 address: #{e}"
|
181
|
+
rescue Errno::ENETUNREACH => e
|
182
|
+
$stderr.puts "Unable to determine IPv4 address: #{e}"
|
183
|
+
end
|
184
|
+
puts "Finished acquiring IPv4 address" if $verbose
|
185
|
+
|
186
|
+
# begin
|
187
|
+
# s = UDPSocket.new(Socket::AF_INET6)
|
188
|
+
# s.connect("2001:4860:b006::2", 1)
|
189
|
+
# if (s.addr[0] == "AF_INET6")
|
190
|
+
# @ipv6 = IPAddr.new(s.addr.last)
|
191
|
+
# end
|
192
|
+
# rescue SocketError => e
|
193
|
+
# $stderr.puts "Unable to determine IPv6 address: #{e}"
|
194
|
+
# rescue Errno::ENETUNREACH => e
|
195
|
+
# $stderr.puts "Unable to determine IPv6 address: #{e}"
|
196
|
+
# end
|
197
|
+
# puts "Finished acquiring IPv6 address" if $verbose
|
198
|
+
end
|
199
|
+
|
200
|
+
private :make_resolver
|
201
|
+
end
|
202
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright (C) 2010 James Brown <roguelazer@roguelazer.com>.
|
2
|
+
#
|
3
|
+
# This file is part of wamupd.
|
4
|
+
#
|
5
|
+
# wamupd is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# wamupd is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
# Wamupd is a module that is used to namespace all of the wamupd code.
|
19
|
+
module Wamupd
|
20
|
+
# Mixin for basic event-driven processing. Listeners register using the
|
21
|
+
# on function. Classes which include Signals can raise a signal with the
|
22
|
+
# signal function.
|
23
|
+
module Signals
|
24
|
+
# Add a handler for the specified signal
|
25
|
+
#
|
26
|
+
# *Args:*
|
27
|
+
# [name] An atom of the signal name
|
28
|
+
def on(name, &action) # :yields: parameters
|
29
|
+
if (not @handlers)
|
30
|
+
@handlers = Hash.new
|
31
|
+
end
|
32
|
+
if (not @handlers.has_key?(name))
|
33
|
+
@handlers[name] = []
|
34
|
+
end
|
35
|
+
@handlers[name] << action
|
36
|
+
end
|
37
|
+
|
38
|
+
# Raise a signal. Any additional args will be passed to the handler
|
39
|
+
def signal(name, *args) #:doc:
|
40
|
+
if (not @handlers)
|
41
|
+
@handlers = Hash.new
|
42
|
+
end
|
43
|
+
if (@handlers.has_key?(name))
|
44
|
+
@handlers[name].each { |handler|
|
45
|
+
handler.call(*args)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private :signal
|
51
|
+
end
|
52
|
+
end
|
data/lib/wamupd.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "wamupd/action"
|
2
|
+
require "wamupd/avahi_model"
|
3
|
+
require "wamupd/avahi_service"
|
4
|
+
require "wamupd/avahi_service_file"
|
5
|
+
require "wamupd/dns_avahi_controller"
|
6
|
+
require "wamupd/dns_ip_controller"
|
7
|
+
require "wamupd/dns_update"
|
8
|
+
require "wamupd/lease_update"
|
9
|
+
require "wamupd/main_settings"
|
10
|
+
require "wamupd/signals"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0" standalone='no'?>
|
2
|
+
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
|
3
|
+
<service-group>
|
4
|
+
|
5
|
+
<name replace-wildcards="yes">%h</name>
|
6
|
+
|
7
|
+
<service>
|
8
|
+
<type>_simple</type>
|
9
|
+
<subtype>_complex</subtype>
|
10
|
+
<domain-name>localdomain</domain-name>
|
11
|
+
<host-name>localhost</host-name>
|
12
|
+
<port>0</port>
|
13
|
+
<txt-record>Simple Service</txt-record>
|
14
|
+
</service>
|
15
|
+
|
16
|
+
</service-group>
|
data/test/test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
3
|
+
#
|
4
|
+
# This file is part of wamupd.
|
5
|
+
#
|
6
|
+
# wamupd is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# wamupd is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
|
20
|
+
require "test/unit"
|
21
|
+
|
22
|
+
# Update load path to include main src directory
|
23
|
+
$:.push(File.join(File.dirname(__FILE__), "..", "src"))
|
24
|
+
$DATA_BASE=File.join(File.dirname(__FILE__), "data")
|
25
|
+
|
26
|
+
|
27
|
+
if (ARGV.size == 0)
|
28
|
+
# Require all of the test_*'s
|
29
|
+
Dir.glob("test_*.rb") { |f|
|
30
|
+
require f
|
31
|
+
}
|
32
|
+
else
|
33
|
+
ARGV.each { |arg|
|
34
|
+
require "test_#{arg}.rb"
|
35
|
+
}
|
36
|
+
end
|
data/test/test_action.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2010 James Brown <roguelazer@roguelazer.com>.
|
2
|
+
#
|
3
|
+
# This file is part of wamupd.
|
4
|
+
#
|
5
|
+
# wamupd is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# wamupd is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "action"
|
19
|
+
|
20
|
+
class TestAction < Test::Unit::TestCase
|
21
|
+
def test_basic
|
22
|
+
assert_not_nil(Wamupd::ActionType::ADD)
|
23
|
+
assert_not_nil(Wamupd::ActionType::DELETE)
|
24
|
+
assert_nothing_raised {
|
25
|
+
a = Wamupd::Action.new(Wamupd::ActionType::ADD, "")
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
3
|
+
#
|
4
|
+
# This file is part of wamupd.
|
5
|
+
#
|
6
|
+
# wamupd is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# wamupd is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'test/unit'
|
20
|
+
require 'main_settings'
|
21
|
+
require 'avahi_model'
|
22
|
+
|
23
|
+
class Test::AvahiModel < Test::Unit::TestCase
|
24
|
+
def test_pack
|
25
|
+
array = [[102,97,99,101],[99,97,98]]
|
26
|
+
#assert_equal("\004face\003cab", Wamupd::AvahiModel.pack_txt_param(array))
|
27
|
+
assert_equal("\"face\" \"cab\"", Wamupd::AvahiModel.pack_txt_param(array))
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
3
|
+
#
|
4
|
+
# This file is part of wamupd.
|
5
|
+
#
|
6
|
+
# wamupd is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# wamupd is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'test/unit'
|
20
|
+
require 'main_settings'
|
21
|
+
require 'avahi_service'
|
22
|
+
|
23
|
+
class Test::AvahiService < Test::Unit::TestCase
|
24
|
+
def test_hash_construct
|
25
|
+
a = Wamupd::AvahiService.new("test", {
|
26
|
+
:type=>"t",
|
27
|
+
:subtype=>"s",
|
28
|
+
:hostname=>"h",
|
29
|
+
:domainname=>"d",
|
30
|
+
:port=>10,
|
31
|
+
:txt=>"txt"
|
32
|
+
})
|
33
|
+
assert_equal("test", a.name)
|
34
|
+
assert_equal("t", a.type)
|
35
|
+
assert_equal("s", a.subtype)
|
36
|
+
assert_equal("h", a.hostname)
|
37
|
+
assert_equal("d", a.domainname)
|
38
|
+
assert_equal(10, a.port)
|
39
|
+
assert_equal("txt", a.txt)
|
40
|
+
|
41
|
+
a = Wamupd::AvahiService.new("", {})
|
42
|
+
assert_equal("", a.name)
|
43
|
+
assert_nil(a.type)
|
44
|
+
assert_nil(a.subtype)
|
45
|
+
assert_nil(a.hostname)
|
46
|
+
assert_nil(a.domainname)
|
47
|
+
assert_nil(a.port)
|
48
|
+
assert_equal(false, a.txt)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
3
|
+
#
|
4
|
+
# This file is part of wamupd.
|
5
|
+
#
|
6
|
+
# wamupd is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# wamupd is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'test/unit'
|
20
|
+
require 'main_settings'
|
21
|
+
require 'avahi_service'
|
22
|
+
require 'avahi_service_file'
|
23
|
+
|
24
|
+
class Test::AvahiServiceFile < Test::Unit::TestCase
|
25
|
+
def setup
|
26
|
+
@settings = Wamupd::MainSettings.instance()
|
27
|
+
@ssh = Wamupd::AvahiServiceFile.new(File.join($DATA_BASE, "ssh.service"))
|
28
|
+
@simple = Wamupd::AvahiServiceFile.new(File.join($DATA_BASE, "simple.service"))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_ssh
|
32
|
+
assert(@ssh.valid?)
|
33
|
+
assert_equal("Terminal Service", @ssh.name)
|
34
|
+
assert_equal(1, @ssh.count)
|
35
|
+
assert_equal(1, @ssh.size)
|
36
|
+
@ssh.each { |s|
|
37
|
+
assert_equal("_ssh._tcp", s.type)
|
38
|
+
assert_equal(22, s.port)
|
39
|
+
assert_nil(s.subtype)
|
40
|
+
assert_nil(s.hostname)
|
41
|
+
assert_equal(false, s.txt)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_substution
|
46
|
+
assert(@simple.valid?)
|
47
|
+
assert_equal(@settings.hostname, @simple.name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_txt
|
51
|
+
assert_equal("Simple Service", @simple.first.txt)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_subtype_formatting
|
55
|
+
assert_equal("_simple,_complex", @simple.first.subtype_display)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_dir
|
59
|
+
d = Wamupd::AvahiServiceFile.load_from_directory($DATA_BASE)
|
60
|
+
assert_equal(2, d.size)
|
61
|
+
assert_equal(1, (d.find_all { |c| c.name == "Terminal Service"}).count)
|
62
|
+
assert_equal(1, (d.find_all { |c| c.name == @settings.hostname}).count)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_in_zone
|
66
|
+
@settings.clear
|
67
|
+
@settings.load_from_yaml(File.join($DATA_BASE, "config.yaml"))
|
68
|
+
assert_equal("_ssh._tcp.browse.test.example.com", @ssh.first.type_in_zone)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_target
|
72
|
+
@settings.clear
|
73
|
+
@settings.load_from_yaml(File.join($DATA_BASE, "config.yaml"))
|
74
|
+
assert_equal("test.browse.test.example.com", @ssh.first.target)
|
75
|
+
assert_equal("localhost.localdomain", @simple.first.target)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
2
|
+
#
|
3
|
+
# This file is part of wamupd.
|
4
|
+
#
|
5
|
+
# wamupd is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# wamupd is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "test/unit"
|
19
|
+
require "thread"
|
20
|
+
require "avahi_service_file"
|
21
|
+
require "dns_avahi_controller"
|
22
|
+
|
23
|
+
class TestDNSAvahiStaticController < Test::Unit::TestCase
|
24
|
+
def test_1
|
25
|
+
service = nil
|
26
|
+
dc = nil
|
27
|
+
assert_nothing_raised() {
|
28
|
+
service = Wamupd::AvahiServiceFile.new(File.join($DATA_BASE, "ssh.service"))
|
29
|
+
dc = Wamupd::DNSAvahiController.new()
|
30
|
+
dc.add_services(service)
|
31
|
+
}
|
32
|
+
assert_not_nil(service)
|
33
|
+
assert_not_nil(dc)
|
34
|
+
assert_equal(1, dc.size)
|
35
|
+
assert_equal("_ssh._tcp-22", dc.keys[0])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_parallel
|
39
|
+
d = Wamupd::DNSAvahiController.new()
|
40
|
+
i = 0
|
41
|
+
dt = Thread.new {
|
42
|
+
d.on(:added) {
|
43
|
+
i += 1
|
44
|
+
}
|
45
|
+
d.on(:quit) {
|
46
|
+
Thread.exit
|
47
|
+
}
|
48
|
+
d.run
|
49
|
+
}
|
50
|
+
ct = Thread.new {
|
51
|
+
d.queue.push(Wamupd::Action.new(Wamupd::ActionType::ADD, Wamupd::AvahiService.new("", {:type=>"test"})))
|
52
|
+
d.queue.push(Wamupd::Action.new(Wamupd::ActionType::ADD, Wamupd::AvahiService.new("", {:type=>"test2"})))
|
53
|
+
d.queue.push(Wamupd::Action.new(Wamupd::ActionType::QUIT))
|
54
|
+
}
|
55
|
+
dt.join
|
56
|
+
ct.join
|
57
|
+
assert_equal(2, i)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def test_raise
|
62
|
+
d = Wamupd::DNSAvahiController.new
|
63
|
+
service = Wamupd::AvahiServiceFile.new(File.join($DATA_BASE, "ssh.service"))
|
64
|
+
service2 = Wamupd::AvahiService.new("NOT SSH", {:type=>"_ssh._tcp", :port=>22})
|
65
|
+
assert_nothing_raised { d.add_service(service) }
|
66
|
+
assert_raise(Wamupd::DuplicateServiceError) { d.add_service(service) }
|
67
|
+
assert_raise(Wamupd::DuplicateServiceError) { d.add_service(service2) }
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
3
|
+
#
|
4
|
+
# This file is part of wamupd.
|
5
|
+
#
|
6
|
+
# wamupd is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# wamupd is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require "test/unit"
|
20
|
+
require "dns_ip_controller"
|
21
|
+
|
22
|
+
class TestDNSAvahiController < Test::Unit::TestCase
|
23
|
+
def test_1
|
24
|
+
dc = nil
|
25
|
+
assert_nothing_raised {
|
26
|
+
dc = Wamupd::DNSIpController.new()
|
27
|
+
}
|
28
|
+
assert_not_nil(dc)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright (C) 2009-2010 James Brown <roguelazer@roguelazer.com>.
|
3
|
+
#
|
4
|
+
# This file is part of wamupd.
|
5
|
+
#
|
6
|
+
# wamupd is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# wamupd is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wamupd. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require "test/unit"
|
20
|
+
require "main_settings"
|
21
|
+
require "socket"
|
22
|
+
|
23
|
+
class TestMainSettings < Test::Unit::TestCase
|
24
|
+
def test_main
|
25
|
+
sa = Wamupd::MainSettings.instance()
|
26
|
+
sa.clear
|
27
|
+
hostname = Socket.gethostname
|
28
|
+
assert_equal(hostname, sa.hostname)
|
29
|
+
assert_equal(7200, sa.ttl)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_yaml
|
33
|
+
sa = Wamupd::MainSettings.instance()
|
34
|
+
sa.clear
|
35
|
+
sa.load_from_yaml(File.join($DATA_BASE, "config.yaml"))
|
36
|
+
assert_equal("test", sa.hostname)
|
37
|
+
assert_equal(5352, sa.dns_port)
|
38
|
+
assert_equal("test.example.com", sa.dns_server)
|
39
|
+
assert_equal("test.example.com", sa.dnssec_key_name)
|
40
|
+
assert_equal("qvdra/qmRNop12eD/1Ez4Dr==", sa.dnssec_key_value)
|
41
|
+
assert_equal(8640, sa.ttl)
|
42
|
+
end
|
43
|
+
end
|