smart_proxy_dns_dnsmasq 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_version'
2
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_configuration'
3
+
4
+ module Proxy::Dns::Dnsmasq
5
+ class Plugin < ::Proxy::Provider
6
+ plugin :dns_dnsmasq, ::Proxy::Dns::Dnsmasq::VERSION
7
+
8
+ # Settings listed under default_settings are required.
9
+ # An exception will be raised if they are initialized with nil values.
10
+ # Settings not listed under default_settings are considered optional and by default have nil value.
11
+ default_settings :config_path => '/etc/dnsmasq.d/foreman.conf',
12
+ :reload_cmd => 'systemctl reload dnsmasq'
13
+
14
+ requires :dns, '>= 1.15'
15
+
16
+ # Verifies that a file exists and is readable.
17
+ # Uninitialized optional settings will not trigger validation errors.
18
+ validate_readable :config_path
19
+
20
+ # Loads plugin files and dependencies
21
+ load_classes ::Proxy::Dns::Dnsmasq::PluginConfiguration
22
+ # Loads plugin dependency injection wirings
23
+ load_dependency_injection_wirings ::Proxy::Dns::Dnsmasq::PluginConfiguration
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module Proxy
2
+ module Dns
3
+ module Dnsmasq
4
+ VERSION = '0.4'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_configuration'
3
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_plugin'
4
+
5
+ class DnsDnsmasqDefaultSettingsTest < Test::Unit::TestCase
6
+ def test_default_settings
7
+ Proxy::Dns::Dnsmasq::Plugin.load_test_settings({})
8
+ assert_equal "default_value", Proxy::Dns::Dnsmasq::Plugin.settings.required_setting
9
+ assert_equal "/must/exist", Proxy::Dns::Dnsmasq::Plugin.settings.required_path
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_configuration'
3
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_main'
4
+
5
+ class DnsDnsmasqProductionWiringTest < Test::Unit::TestCase
6
+ def setup
7
+ @container = ::Proxy::DependencyInjection::Container.new
8
+ @config = ::Proxy::Dns::Dnsmasq::PluginConfiguration.new
9
+ end
10
+
11
+ def test_dns_provider_initialization_default
12
+ @config.load_dependency_injection_wirings(@container, :dns_ttl => 999,
13
+ :config_path => '/etc/dnsmasq.conf',
14
+ :reload_cmd => 'systemctl reload dnsmasq')
15
+
16
+ provider = @container.get_dependency(:dns_provider)
17
+
18
+ assert_not_nil provider
19
+ assert_equal provider.class, Proxy::Dns::Dnsmasq::Default
20
+ assert_equal '/etc/dnsmasq.conf', provider.config_file
21
+ assert_equal 'systemctl reload dnsmasq', provider.reload_cmd
22
+ assert_equal 999, provider.ttl
23
+ end
24
+
25
+ def test_dns_provider_initialization
26
+ @config.load_dependency_injection_wirings(@container, :dns_ttl => 999,
27
+ :backend => 'openwrt',
28
+ :config_path => '/etc/config/dhcp',
29
+ :reload_cmd => '/etc/init.d/dnsmasq reload')
30
+
31
+ provider = @container.get_dependency(:dns_provider)
32
+
33
+ assert_not_nil provider
34
+ assert_equal provider.class, Proxy::Dns::Dnsmasq::Openwrt
35
+ assert_equal '/etc/config/dhcp', provider.config_file
36
+ assert_equal '/etc/init.d/dnsmasq reload', provider.reload_cmd
37
+ assert_equal 999, provider.ttl
38
+ end
39
+ end
@@ -0,0 +1,114 @@
1
+ require 'test_helper'
2
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_main'
3
+ require 'smart_proxy_dns_dnsmasq/backend/default'
4
+
5
+ class DnsDnsmasqRecordDefaultTest < Test::Unit::TestCase
6
+ def setup
7
+ @provider = Proxy::Dns::Dnsmasq::Default.new('/etc/dnsmasq.d/foreman.conf', 'systemctl reload dnsmasq', 999)
8
+
9
+ @provider.expects(:update!).returns(true)
10
+ @configuration = mock()
11
+ @provider.stubs(:configuration).returns(@configuration)
12
+ end
13
+
14
+ # Test A record creation
15
+ def test_create_a
16
+ fqdn = 'test.example.com'
17
+ ip = '10.1.1.1'
18
+
19
+ @configuration.expects(:<<).with { |val|
20
+ val.is_a?(Proxy::Dns::Dnsmasq::Default::AddressEntry) &&
21
+ val.fqdn == [fqdn] &&
22
+ val.ip == ip
23
+ }.returns(true)
24
+ assert @provider.do_create(fqdn, ip, 'A')
25
+ end
26
+
27
+ # Test AAAA record creation
28
+ def test_create_aaaa
29
+ fqdn = 'test.example.com'
30
+ ip = '2001:db8::1'
31
+
32
+ @configuration.expects(:<<).with { |val|
33
+ val.is_a?(Proxy::Dns::Dnsmasq::Default::AddressEntry) &&
34
+ val.fqdn == [fqdn] &&
35
+ val.ip == ip
36
+ }.returns(true)
37
+ assert @provider.do_create(fqdn, ip, 'AAAA')
38
+ end
39
+
40
+ # Test PTR record creation with an IPv4 address
41
+ def test_create_ptr_v4
42
+ fqdn = 'test.example.com'
43
+ ip = '3.2.1.10.in-addr.arpa'
44
+
45
+ @configuration.expects(:<<).with { |val|
46
+ val.is_a?(Proxy::Dns::Dnsmasq::Default::PTREntry) &&
47
+ val.fqdn == fqdn &&
48
+ val.ip == ip
49
+ }.returns(true)
50
+ assert @provider.do_create(ip, fqdn, 'PTR')
51
+ end
52
+
53
+ # Test PTR record creation with an IPv6 address
54
+ def test_create_ptr_v6
55
+ fqdn = 'test.example.com'
56
+ ip = '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
57
+
58
+ @configuration.expects(:<<).with { |val|
59
+ val.is_a?(Proxy::Dns::Dnsmasq::Default::PTREntry) &&
60
+ val.fqdn == fqdn &&
61
+ val.ip == ip
62
+ }.returns(true)
63
+ assert @provider.do_create(ip, fqdn, 'PTR')
64
+ end
65
+
66
+ # Test CNAME record creation
67
+ def test_create_cname
68
+ name = 'test.example.com'
69
+ target = 'target.example.com'
70
+
71
+ @configuration.expects(:find).returns(nil)
72
+ @configuration.expects(:<<).with { |val|
73
+ val.is_a?(Proxy::Dns::Dnsmasq::Default::CNAMEEntry) &&
74
+ val.name == name &&
75
+ val.target == target
76
+ }.returns(true)
77
+ assert @provider.do_create(name, target, 'CNAME')
78
+ end
79
+
80
+ # Test A record removal
81
+ def test_remove_a
82
+ @configuration.expects(:find).returns(Proxy::Dns::Dnsmasq::Default::AddressEntry.new)
83
+ @configuration.expects(:delete).with { |v| v.is_a? Proxy::Dns::Dnsmasq::Default::AddressEntry }.returns(true)
84
+ assert @provider.do_remove('test.example.com', 'A')
85
+ end
86
+
87
+ # Test AAAA record removal
88
+ def test_remove_aaaa
89
+ @configuration.expects(:find).returns(Proxy::Dns::Dnsmasq::Default::AddressEntry.new)
90
+ @configuration.expects(:delete).with { |v| v.is_a? Proxy::Dns::Dnsmasq::Default::AddressEntry }.returns(true)
91
+ assert @provider.do_remove('test.example.com', 'AAAA')
92
+ end
93
+
94
+ # Test PTR record removal with an IPv4 address
95
+ def test_remove_ptr_v4
96
+ @configuration.expects(:find).returns(Proxy::Dns::Dnsmasq::Default::PTREntry.new)
97
+ @configuration.expects(:delete).with { |v| v.is_a? Proxy::Dns::Dnsmasq::Default::PTREntry }.returns(true)
98
+ assert @provider.do_remove('3.2.1.10.in-addr.arpa', 'PTR')
99
+ end
100
+
101
+ # Test PTR record removal with an IPv6 address
102
+ def test_remove_ptr_v6
103
+ @configuration.expects(:find).returns(Proxy::Dns::Dnsmasq::Default::PTREntry.new)
104
+ @configuration.expects(:delete).with { |v| v.is_a? Proxy::Dns::Dnsmasq::Default::PTREntry }.returns(true)
105
+ assert @provider.do_remove('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa', 'PTR')
106
+ end
107
+
108
+ # Test CNAME record removal
109
+ def test_remove_cname
110
+ @configuration.expects(:find).returns(Proxy::Dns::Dnsmasq::Default::CNAMEEntry.new)
111
+ @configuration.expects(:delete).with { |v| v.is_a? Proxy::Dns::Dnsmasq::Default::CNAMEEntry }.returns(true)
112
+ assert @provider.do_remove('test.example.com', 'CNAME')
113
+ end
114
+ end
@@ -0,0 +1,79 @@
1
+ require 'test_helper'
2
+ require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_main'
3
+ require 'smart_proxy_dns_dnsmasq/backend/openwrt'
4
+
5
+ class DnsDnsmasqRecordOpenwrtTest < Test::Unit::TestCase
6
+ def setup
7
+ @provider = Proxy::Dns::Dnsmasq::Openwrt.new('/etc/config/dhcp', '/etc/init.d/dnsmasq reload', 999)
8
+
9
+ @provider.expects(:update!).returns(true)
10
+ @configuration = mock()
11
+ @provider.stubs(:configuration).returns(@configuration)
12
+ end
13
+
14
+ # Test A record creation
15
+ def test_create_a
16
+ @provider.expects(:find_type).with(:domain, :name, 'test.example.com').returns(false)
17
+ @configuration.expects(:<<).with { |val|
18
+ val.is_a?(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config) &&
19
+ val.type == :domain &&
20
+ val.options[:name] == 'test.example.com' &&
21
+ val.options[:ip] == '10.1.1.1'
22
+ }.returns(true)
23
+ assert @provider.do_create('test.example.com', '10.1.1.1', 'A')
24
+ end
25
+
26
+ # Test PTR record creation with an IPv4 address
27
+ def test_create_ptr_v4
28
+ @provider.expects(:find_type).with(:domain, :name, 'test.example.com').returns(false)
29
+ @configuration.expects(:<<).with { |val|
30
+ val.is_a?(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config) &&
31
+ val.type == :domain &&
32
+ val.options[:name] == 'test.example.com' &&
33
+ val.options[:ip] == '10.1.2.3'
34
+ }.returns(true)
35
+ assert @provider.do_create('3.2.1.10.in-addr.arpa', 'test.example.com', 'PTR')
36
+ end
37
+
38
+ # Test CNAME record creation
39
+ def test_create_cname
40
+ @provider.expects(:find_type).with(:cname, :name, 'test.example.com').returns(false)
41
+ @configuration.expects(:<<).with { |val|
42
+ val.is_a?(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config) &&
43
+ val.type == :cname &&
44
+ val.options[:cname] == 'test.example.com' &&
45
+ val.options[:target] == 'target.example.com'
46
+ }.returns(true)
47
+ assert @provider.do_create('test.example.com', 'target.example.com', 'CNAME')
48
+ end
49
+
50
+ # Test A record removal
51
+ def test_remove_a
52
+ @provider.expects(:find_type).with(:domain, :name, 'test.example.com').returns(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config.new(:domain))
53
+ @configuration.expects(:delete).with { |val|
54
+ val.is_a?(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config) &&
55
+ val.type == :domain
56
+ }.returns(true)
57
+ assert @provider.do_remove('test.example.com', 'A')
58
+ end
59
+
60
+ # Test PTR record removal with an IPv4 address
61
+ def test_remove_ptr_v4
62
+ @provider.expects(:find_type).with(:domain, :ip, '10.1.2.3').returns(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config.new(:domain))
63
+ @configuration.expects(:delete).with { |val|
64
+ val.is_a?(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config) &&
65
+ val.type == :domain
66
+ }.returns(true)
67
+ assert @provider.do_remove('3.2.1.10.in-addr.arpa', 'PTR')
68
+ end
69
+
70
+ # Test CNAME record removal
71
+ def test_remove_cname
72
+ @provider.expects(:find_type).with(:cname, :name, 'test.example.com').returns(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config.new(:cname))
73
+ @configuration.expects(:delete).with { |val|
74
+ val.is_a?(Proxy::Dns::Dnsmasq::Openwrt::DSL::Config) &&
75
+ val.type == :cname
76
+ }.returns(true)
77
+ assert @provider.do_remove('test.example.com', 'CNAME')
78
+ end
79
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+ require 'mocha/setup'
3
+ require 'json'
4
+ require 'ostruct'
5
+
6
+ require 'smart_proxy_for_testing'
7
+
8
+ # create log directory in our (not smart-proxy) directory
9
+ FileUtils.mkdir_p File.dirname(Proxy::SETTINGS.log_file)
@@ -0,0 +1,43 @@
1
+
2
+ config dnsmasq
3
+ option domainneeded '1'
4
+ option boguspriv '1'
5
+ option localise_queries '1'
6
+ option rebind_protection '1'
7
+ option rebind_localhost '1'
8
+ option expandhosts '1'
9
+ option authoritative '1'
10
+ option readethers '1'
11
+ option leasefile '/tmp/dhcp.leases'
12
+ option resolvfile '/tmp/resolv.conf.auto'
13
+ option localservice '1'
14
+ option port '0'
15
+ option local '/introvert.software/'
16
+ option domain 'introvert.software'
17
+ option nonwildcard '0'
18
+
19
+ config dhcp 'lan'
20
+ option interface 'lan'
21
+ option start '100'
22
+ option limit '150'
23
+ option leasetime '12h'
24
+ option dhcpv6 'server'
25
+ option ra 'server'
26
+ option ignore '0'
27
+ list dhcp_option '6,192.168.0.1'
28
+
29
+ config dhcp 'wan'
30
+ option interface 'wan'
31
+ option ignore '1'
32
+
33
+ config odhcpd 'odhcpd'
34
+ option maindhcp '0'
35
+ option leasefile '/tmp/hosts/odhcpd'
36
+ option leasetrigger '/usr/sbin/odhcpd-update'
37
+
38
+ config host
39
+ option name 'Potatis'
40
+ option mac '01:02:03:04:05:06'
41
+ option ip '1.2.3.4'
42
+
43
+
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_proxy_dns_dnsmasq
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.4'
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Olofsson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: dnamasq DNS provider plugin for Foreman's smart proxy
56
+ email:
57
+ - alexander.olofsson@liu.se
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - bundler.d/dns_dnsmasq.rb
65
+ - config/dns_dnsmasq.yml
66
+ - lib/smart_proxy_dns_dnsmasq.rb
67
+ - lib/smart_proxy_dns_dnsmasq/backend/default.rb
68
+ - lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb
69
+ - lib/smart_proxy_dns_dnsmasq/dns_dnsmasq_configuration.rb
70
+ - lib/smart_proxy_dns_dnsmasq/dns_dnsmasq_main.rb
71
+ - lib/smart_proxy_dns_dnsmasq/dns_dnsmasq_plugin.rb
72
+ - lib/smart_proxy_dns_dnsmasq/dns_dnsmasq_version.rb
73
+ - test/dns_dnsmasq_default_settings_test.rb
74
+ - test/dns_dnsmasq_production_wiring_test.rb
75
+ - test/dns_dnsmasq_record_default_test.rb
76
+ - test/dns_dnsmasq_record_openwrt_test.rb
77
+ - test/test_helper.rb
78
+ - test/testdata.openwrt
79
+ homepage: https://github.com/ace13/smart_proxy_dns_dnsmasq
80
+ licenses:
81
+ - GPL-3.0
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.6.8
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: dnsmasq DNS provider plugin for Foreman's smart proxy
103
+ test_files:
104
+ - test/test_helper.rb
105
+ - test/dns_dnsmasq_default_settings_test.rb
106
+ - test/dns_dnsmasq_production_wiring_test.rb
107
+ - test/testdata.openwrt
108
+ - test/dns_dnsmasq_record_openwrt_test.rb
109
+ - test/dns_dnsmasq_record_default_test.rb