7 describe "#loadconfig" do
8 it "should only test that libdirs are absolute paths" do
9 Util.expects(:absolute_path?).with("/one").returns(true)
10 Util.expects(:absolute_path?).with("/two").returns(true)
11 Util.expects(:absolute_path?).with("/three").returns(true)
12 Util.expects(:absolute_path?).with("four").returns(false)
14 File.stubs(:exists?).with("/nonexisting").returns(true)
15 File.stubs(:exists?).with(File.join(File.dirname("/nonexisting"), "rpc-help.erb")).returns(true)
17 ["/one:/two", "/three"].each do |path|
18 File.stubs(:open).with("/nonexisting", "r").returns(StringIO.new("libdir = #{path}"))
20 Config.instance.loadconfig("/nonexisting")
25 File.stubs(:open).with("/nonexisting", "r").returns(StringIO.new("libdir = four"))
27 expect { Config.instance.loadconfig("/nonexisting") }.to raise_error(/should be absolute paths/)
30 it "should not allow any path like construct for identities" do
31 # Taken from puppet test cases
32 ['../foo', '..\\foo', './../foo', '.\\..\\foo',
33 '/foo', '//foo', '\\foo', '\\\\goo',
34 "test\0/../bar", "test\0\\..\\bar",
35 "..\\/bar", "/tmp/bar", "/tmp\\bar", "tmp\\bar",
36 " / bar", " /../ bar", " \\..\\ bar",
37 "c:\\foo", "c:/foo", "\\\\?\\UNC\\bar", "\\\\foo\\bar",
38 "\\\\?\\c:\\foo", "//?/UNC/bar", "//foo/bar",
41 File.expects(:open).with("/nonexisting", "r").returns(StringIO.new("identity = #{input}"))
42 File.expects(:exists?).with("/nonexisting").returns(true)
43 File.expects(:exists?).with(File.join(File.dirname("/nonexisting"), "rpc-help.erb")).returns(true)
46 Config.instance.loadconfig("/nonexisting")
47 }.to raise_error('Identities can only match /\w\.\-/')
51 it "should allow valid identities" do
52 ["foo", "foo_bar", "foo-bar", "foo-bar-123", "foo.bar", "foo_bar_123"].each do |input|
53 File.expects(:open).with("/nonexisting", "r").returns(StringIO.new("identity = #{input}"))
54 File.expects(:exists?).with("/nonexisting").returns(true)
55 File.expects(:exists?).with(File.join(File.dirname("/nonexisting"), "rpc-help.erb")).returns(true)
56 PluginManager.stubs(:loadclass)
57 PluginManager.stubs("<<")
59 Config.instance.loadconfig("/nonexisting")
63 it "should not allow the syslog logger type on windows" do
64 Util.expects("windows?").returns(true).twice
65 File.expects(:open).with("/nonexisting", "r").returns(StringIO.new("logger_type = syslog"))
66 File.expects(:exists?).with("/nonexisting").returns(true)
67 File.expects(:exists?).with(File.join(File.dirname("/nonexisting"), "rpc-help.erb")).returns(true)
68 PluginManager.stubs(:loadclass)
69 PluginManager.stubs("<<")
71 expect { Config.instance.loadconfig("/nonexisting") }.to raise_error("The sylog logger is not usable on the Windows platform")
74 it "should default to finding the help template in the same dir as the config file" do
75 path = File.join(File.dirname("/nonexisting"), "rpc-help.erb")
77 File.expects(:open).with("/nonexisting", "r").returns(StringIO.new(""))
78 File.expects(:exists?).with("/nonexisting").returns(true)
79 PluginManager.stubs(:loadclass)
80 PluginManager.stubs("<<")
82 File.expects(:exists?).with(path).returns(true)
84 Config.instance.loadconfig("/nonexisting")
85 Config.instance.rpchelptemplate.should == path
88 it "should fall back to old behavior if the help template file does not exist in the config dir" do
89 path = File.join(File.dirname("/nonexisting"), "rpc-help.erb")
91 File.expects(:open).with("/nonexisting", "r").returns(StringIO.new(""))
92 File.expects(:exists?).with("/nonexisting").returns(true)
93 File.expects(:exists?).with(path).returns(false)
94 PluginManager.stubs(:loadclass)
95 PluginManager.stubs("<<")
97 Config.instance.loadconfig("/nonexisting")
98 Config.instance.rpchelptemplate.should == "/etc/mcollective/rpc-help.erb"
101 it "should support multiple default_discovery_options" do
102 File.expects(:open).with("/nonexisting", "r").returns(StringIO.new("default_discovery_options = 1\ndefault_discovery_options = 2"))
103 File.expects(:exists?).with("/nonexisting").returns(true)
104 File.expects(:exists?).with(File.join(File.dirname("/nonexisting"), "rpc-help.erb")).returns(true)
105 PluginManager.stubs(:loadclass)
106 PluginManager.stubs("<<")
108 Config.instance.loadconfig("/nonexisting")
109 Config.instance.default_discovery_options.should == ["1", "2"]
113 describe "#read_plugin_config_dir" do
115 @plugindir = File.join("/", "nonexisting", "plugin.d")
117 File.stubs(:directory?).with(@plugindir).returns(true)
119 Config.instance.set_config_defaults("")
122 it "should not fail if the supplied directory is missing" do
123 File.expects(:directory?).with(@plugindir).returns(false)
124 Config.instance.read_plugin_config_dir(@plugindir)
125 Config.instance.pluginconf.should == {}
128 it "should skip files that do not match the expected filename pattern" do
129 Dir.expects(:new).with(@plugindir).returns(["foo.txt"])
131 IO.expects(:open).with(File.join(@plugindir, "foo.txt")).never
133 Config.instance.read_plugin_config_dir(@plugindir)
136 it "should load the config files" do
137 Dir.expects(:new).with(@plugindir).returns(["foo.cfg"])
138 File.expects(:open).with(File.join(@plugindir, "foo.cfg"), "r").returns([]).once
139 Config.instance.read_plugin_config_dir(@plugindir)
142 it "should set config parameters correctly" do
143 Dir.expects(:new).with(@plugindir).returns(["foo.cfg"])
144 File.expects(:open).with(File.join(@plugindir, "foo.cfg"), "r").returns(["rspec = test"])
145 Config.instance.read_plugin_config_dir(@plugindir)
146 Config.instance.pluginconf.should == {"foo.rspec" => "test"}
149 it "should override main config file" do
150 configfile = File.join(@plugindir, "foo.cfg")
151 servercfg = File.join(File.dirname(@plugindir), "server.cfg")
153 PluginManager.stubs(:loadclass)
155 File.stubs(:exists?).returns(true)
156 File.stubs(:directory?).with(@plugindir).returns(true)
157 File.stubs(:exists?).with(servercfg).returns(true)
158 File.expects(:open).with(servercfg, "r").returns(["plugin.rspec.key = default"])
160 Dir.expects(:new).with(@plugindir).returns(["rspec.cfg"])
161 File.expects(:open).with(File.join(@plugindir, "rspec.cfg"), "r").returns(["key = overridden"])
163 Config.instance.loadconfig(servercfg)
164 Config.instance.pluginconf.should == {"rspec.key" => "overridden"}