mcollective-client 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mcollective-client might be problematic. Click here for more details.
- data/bin/mc-call-agent +54 -0
- data/bin/mco +27 -0
- data/lib/mcollective.rb +70 -0
- data/lib/mcollective/agents.rb +160 -0
- data/lib/mcollective/application.rb +354 -0
- data/lib/mcollective/applications.rb +145 -0
- data/lib/mcollective/client.rb +292 -0
- data/lib/mcollective/config.rb +202 -0
- data/lib/mcollective/connector.rb +18 -0
- data/lib/mcollective/connector/base.rb +24 -0
- data/lib/mcollective/facts.rb +39 -0
- data/lib/mcollective/facts/base.rb +86 -0
- data/lib/mcollective/log.rb +103 -0
- data/lib/mcollective/logger.rb +5 -0
- data/lib/mcollective/logger/base.rb +73 -0
- data/lib/mcollective/logger/console_logger.rb +61 -0
- data/lib/mcollective/logger/file_logger.rb +46 -0
- data/lib/mcollective/logger/syslog_logger.rb +53 -0
- data/lib/mcollective/matcher.rb +16 -0
- data/lib/mcollective/matcher/parser.rb +93 -0
- data/lib/mcollective/matcher/scanner.rb +123 -0
- data/lib/mcollective/message.rb +201 -0
- data/lib/mcollective/monkey_patches.rb +104 -0
- data/lib/mcollective/optionparser.rb +164 -0
- data/lib/mcollective/pluginmanager.rb +180 -0
- data/lib/mcollective/pluginpackager.rb +26 -0
- data/lib/mcollective/pluginpackager/agent_definition.rb +79 -0
- data/lib/mcollective/pluginpackager/standard_definition.rb +59 -0
- data/lib/mcollective/registration.rb +16 -0
- data/lib/mcollective/registration/base.rb +75 -0
- data/lib/mcollective/rpc.rb +188 -0
- data/lib/mcollective/rpc/actionrunner.rb +142 -0
- data/lib/mcollective/rpc/agent.rb +441 -0
- data/lib/mcollective/rpc/audit.rb +38 -0
- data/lib/mcollective/rpc/client.rb +793 -0
- data/lib/mcollective/rpc/ddl.rb +258 -0
- data/lib/mcollective/rpc/helpers.rb +339 -0
- data/lib/mcollective/rpc/progress.rb +63 -0
- data/lib/mcollective/rpc/reply.rb +61 -0
- data/lib/mcollective/rpc/request.rb +51 -0
- data/lib/mcollective/rpc/result.rb +41 -0
- data/lib/mcollective/rpc/stats.rb +185 -0
- data/lib/mcollective/runnerstats.rb +90 -0
- data/lib/mcollective/security.rb +26 -0
- data/lib/mcollective/security/base.rb +237 -0
- data/lib/mcollective/shell.rb +87 -0
- data/lib/mcollective/ssl.rb +246 -0
- data/lib/mcollective/unix_daemon.rb +37 -0
- data/lib/mcollective/util.rb +274 -0
- data/lib/mcollective/vendor.rb +41 -0
- data/lib/mcollective/vendor/require_vendored.rb +2 -0
- data/lib/mcollective/windows_daemon.rb +25 -0
- data/spec/Rakefile +16 -0
- data/spec/fixtures/application/test.rb +7 -0
- data/spec/fixtures/test-cert.pem +15 -0
- data/spec/fixtures/test-private.pem +15 -0
- data/spec/fixtures/test-public.pem +6 -0
- data/spec/monkey_patches/instance_variable_defined.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/agents_spec.rb +280 -0
- data/spec/unit/application_spec.rb +636 -0
- data/spec/unit/applications_spec.rb +155 -0
- data/spec/unit/array.rb +30 -0
- data/spec/unit/config_spec.rb +148 -0
- data/spec/unit/facts/base_spec.rb +118 -0
- data/spec/unit/facts_spec.rb +39 -0
- data/spec/unit/log_spec.rb +71 -0
- data/spec/unit/logger/base_spec.rb +110 -0
- data/spec/unit/logger/syslog_logger_spec.rb +86 -0
- data/spec/unit/matcher/parser_spec.rb +106 -0
- data/spec/unit/matcher/scanner_spec.rb +71 -0
- data/spec/unit/message_spec.rb +401 -0
- data/spec/unit/optionparser_spec.rb +113 -0
- data/spec/unit/pluginmanager_spec.rb +173 -0
- data/spec/unit/pluginpackager/agent_definition_spec.rb +130 -0
- data/spec/unit/pluginpackager/standard_definition_spec.rb +75 -0
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +533 -0
- data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +34 -0
- data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +417 -0
- data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +229 -0
- data/spec/unit/plugins/mcollective/security/psk_spec.rb +156 -0
- data/spec/unit/registration/base_spec.rb +77 -0
- data/spec/unit/rpc/actionrunner_spec.rb +213 -0
- data/spec/unit/rpc/agent_spec.rb +155 -0
- data/spec/unit/rpc/client_spec.rb +523 -0
- data/spec/unit/rpc/ddl_spec.rb +388 -0
- data/spec/unit/rpc/helpers_spec.rb +55 -0
- data/spec/unit/rpc/reply_spec.rb +143 -0
- data/spec/unit/rpc/request_spec.rb +115 -0
- data/spec/unit/rpc/result_spec.rb +66 -0
- data/spec/unit/rpc/stats_spec.rb +288 -0
- data/spec/unit/runnerstats_spec.rb +40 -0
- data/spec/unit/security/base_spec.rb +279 -0
- data/spec/unit/shell_spec.rb +144 -0
- data/spec/unit/ssl_spec.rb +244 -0
- data/spec/unit/symbol.rb +11 -0
- data/spec/unit/unix_daemon.rb +41 -0
- data/spec/unit/util_spec.rb +342 -0
- data/spec/unit/vendor_spec.rb +34 -0
- data/spec/unit/windows_daemon.rb +43 -0
- data/spec/windows_spec.opts +1 -0
- metadata +242 -0
@@ -0,0 +1,229 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
MCollective::PluginManager.clear
|
6
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/pluginpackager/ospackage_packager.rb'
|
7
|
+
|
8
|
+
module MCollective
|
9
|
+
module PluginPackager
|
10
|
+
describe OspackagePackager do
|
11
|
+
before :all do
|
12
|
+
|
13
|
+
class OspackagePackager
|
14
|
+
ENV = {"PATH" => "."}
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestPlugin
|
18
|
+
attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :iteration
|
19
|
+
attr_accessor :postinstall
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@path = "/tmp"
|
23
|
+
@packagedata = {:testpackage => {:files => ["/tmp/test.rb"],
|
24
|
+
:dependencies => ["mcollective"],
|
25
|
+
:description => "testpackage"}}
|
26
|
+
@iteration = 1
|
27
|
+
@postinstall = "/tmp/test.sh"
|
28
|
+
@metadata = {:name => "testplugin",
|
29
|
+
:description => "A Test Plugin",
|
30
|
+
:author => "Psy",
|
31
|
+
:license => "Apache 2",
|
32
|
+
:version => "0",
|
33
|
+
:url => "http://foo.bar.com",
|
34
|
+
:timeout => 5}
|
35
|
+
@vendor = "Puppet Labs"
|
36
|
+
@target_path = "/tmp"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@testplugin = TestPlugin.new
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#initialize" do
|
44
|
+
it "should correctly identify a RedHat system" do
|
45
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
46
|
+
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
47
|
+
|
48
|
+
ospackage = OspackagePackager.new(@testplugin)
|
49
|
+
ospackage.libdir.should == "usr/libexec/mcollective/mcollective/"
|
50
|
+
ospackage.package_type.should == "RPM"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should correctly identify a Debian System" do
|
54
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
55
|
+
File.expects(:exists?).with("/etc/debian_version").returns(true)
|
56
|
+
OspackagePackager.any_instance.expects(:build_tool?).with("ar").returns(true)
|
57
|
+
|
58
|
+
ospackage = OspackagePackager.new(@testplugin)
|
59
|
+
ospackage.libdir.should == "usr/share/mcollective/plugins/mcollective"
|
60
|
+
ospackage.package_type.should == "Deb"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise an exception if it cannot identify the operating system" do
|
64
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
65
|
+
File.expects(:exists?).with("/etc/debian_version").returns(false)
|
66
|
+
|
67
|
+
expect{
|
68
|
+
ospackage = OspackagePackager.new(@testplugin)
|
69
|
+
}.to raise_exception "error: cannot identify operating system."
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should identify if rpmbuild is present for RedHat systems" do
|
73
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
74
|
+
File.expects(:exists?).with("./rpmbuild").returns(true)
|
75
|
+
ospackage = OspackagePackager.new(@testplugin)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should raise an exception if rpmbuild is not present for RedHat systems" do
|
79
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
80
|
+
File.expects(:exists?).with("./rpmbuild").returns(false)
|
81
|
+
expect{
|
82
|
+
ospackage = OspackagePackager.new(@testplugin)
|
83
|
+
}.to raise_error "error: package 'rpm-build' is not installed."
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should identify if ar is present for Debian systems" do
|
87
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
88
|
+
File.expects(:exists?).with("/etc/debian_version").returns(true)
|
89
|
+
File.expects(:exists?).with("./ar").returns(true)
|
90
|
+
|
91
|
+
ospackage = OspackagePackager.new(@testplugin)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should raise an exception if the build tool is not present" do
|
95
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
96
|
+
File.expects(:exists?).with("/etc/debian_version").returns(true)
|
97
|
+
File.expects(:exists?).with("./ar").returns(false)
|
98
|
+
expect{
|
99
|
+
ospackage = OspackagePackager.new(@testplugin)
|
100
|
+
}.to raise_error "error: package 'ar' is not installed."
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#create_packages" do
|
105
|
+
it "should prepare temp directories, create a package and clean up when done" do
|
106
|
+
OspackagePackager.any_instance.stubs(:gem).with("fpm", "= 0.4.3")
|
107
|
+
OspackagePackager.any_instance.stubs(:require).with("fpm")
|
108
|
+
OspackagePackager.any_instance.stubs(:require).with("tmpdir")
|
109
|
+
|
110
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
111
|
+
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
112
|
+
Dir.expects(:mktmpdir).with("mcollective_packager").returns("/tmp/mcollective_packager")
|
113
|
+
FileUtils.expects(:mkdir_p).with("/tmp/mcollective_packager/usr/libexec/mcollective/mcollective/")
|
114
|
+
|
115
|
+
ospackage = OspackagePackager.new(@testplugin)
|
116
|
+
ospackage.expects(:prepare_tmpdirs).once
|
117
|
+
ospackage.expects(:create_package).once
|
118
|
+
ospackage.expects(:cleanup_tmpdirs).once
|
119
|
+
|
120
|
+
ospackage.create_packages
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#create_package" do
|
125
|
+
before :all do
|
126
|
+
module ::FPM
|
127
|
+
class Package
|
128
|
+
class Dir
|
129
|
+
end
|
130
|
+
class RPM
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
@fpm_dir = mock
|
136
|
+
@fpm_type = mock
|
137
|
+
@package = mock
|
138
|
+
@fpm_dir.stubs(:convert).returns(@fpm_type)
|
139
|
+
@fpm_dir.stubs(:attributes).returns({:chdir => nil})
|
140
|
+
@fpm_dir.stubs(:input)
|
141
|
+
@package.stubs(:metadata).returns({:name => "testpackage", :version => "1"})
|
142
|
+
@package.stubs(:iteration).returns("1")
|
143
|
+
OspackagePackager.any_instance.stubs(:package).returns(@package)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should run fpm with the correct parameters" do
|
147
|
+
File.stubs(:exists?).returns(true)
|
148
|
+
OspackagePackager.any_instance.expects(:build_tool?).returns(true)
|
149
|
+
ospackage = OspackagePackager.new(@testpackage)
|
150
|
+
::FPM::Package::Dir.stubs(:new).returns(@fpm_dir)
|
151
|
+
ospackage.expects(:params)
|
152
|
+
ospackage.expects(:do_quietly?)
|
153
|
+
@fpm_dir.expects(:cleanup)
|
154
|
+
@fpm_type.expects(:cleanup)
|
155
|
+
ospackage.expects(:puts).with("Successfully built RPM 'mcollective-testpackage-testpackage-1-1.noarch.rpm'")
|
156
|
+
ospackage.create_package(:testpackage, {:files => ["/tmp/test.rb"], :description => "testpackage", :dependencies =>"dependencies"})
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#do_quietly?" do
|
161
|
+
it "should run a block quietly" do
|
162
|
+
require 'stringio'
|
163
|
+
|
164
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
165
|
+
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
166
|
+
ospackage = OspackagePackager.new(@testplugin)
|
167
|
+
|
168
|
+
old_stdout = $stdout
|
169
|
+
new_stdout = File.open("/tmp/output.txt", "w+")
|
170
|
+
$stdout = new_stdout
|
171
|
+
ospackage.do_quietly?{puts "teststring"}
|
172
|
+
$stdout = old_stdout
|
173
|
+
File.read("/tmp/output.txt").should == ""
|
174
|
+
FileUtils.rm("/tmp/output.txt")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "#params" do
|
179
|
+
it "should create all paramaters needed by fpm" do
|
180
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
181
|
+
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
182
|
+
ospackage = OspackagePackager.new(@testplugin)
|
183
|
+
|
184
|
+
fpm_type = mock
|
185
|
+
fpm_type.expects(:name=).with("mcollective-testplugin-testpackage")
|
186
|
+
fpm_type.expects(:maintainer=).with("Psy")
|
187
|
+
fpm_type.expects(:version=).with("0")
|
188
|
+
fpm_type.expects(:url=).with("http://foo.bar.com")
|
189
|
+
fpm_type.expects(:license=).with("Apache 2")
|
190
|
+
fpm_type.expects(:iteration=).with(1)
|
191
|
+
fpm_type.expects(:vendor=).with("Puppet Labs")
|
192
|
+
fpm_type.expects(:architecture=).with("all")
|
193
|
+
fpm_type.expects(:description=).with("A Test Plugin\n\ntestpackage")
|
194
|
+
fpm_type.expects(:dependencies=).with(["mcollective"])
|
195
|
+
fpm_type.expects(:scripts).returns({"post-install" => nil})
|
196
|
+
|
197
|
+
ospackage.params(fpm_type,:testpackage, @testplugin.packagedata[:testpackage])
|
198
|
+
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#prepare_tmpdirs" do
|
203
|
+
it "should create temp directories and copy package files" do
|
204
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
205
|
+
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
206
|
+
File.expects(:directory?).with("/tmp/mcollective_packager/").returns(false)
|
207
|
+
FileUtils.expects(:mkdir_p).with("/tmp/mcollective_packager/")
|
208
|
+
FileUtils.expects(:cp_r).with("/tmp/test.rb", "/tmp/mcollective_packager/")
|
209
|
+
|
210
|
+
ospackage = OspackagePackager.new(@testplugin)
|
211
|
+
ospackage.workingdir = "/tmp/mcollective_packager/"
|
212
|
+
ospackage.prepare_tmpdirs(@testplugin.packagedata[:testpackage])
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "#cleanup_tmpdirs" do
|
217
|
+
it "should remove temp directories" do
|
218
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
219
|
+
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
220
|
+
FileUtils.expects(:rm_r).with("/tmp/mcollective_packager/")
|
221
|
+
|
222
|
+
ospackage = OspackagePackager.new(@testplugin)
|
223
|
+
ospackage.tmpdir = "/tmp/mcollective_packager/"
|
224
|
+
ospackage.cleanup_tmpdirs
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/security/psk.rb'
|
5
|
+
|
6
|
+
module MCollective::Security
|
7
|
+
describe Psk do
|
8
|
+
before do
|
9
|
+
@config = mock("config")
|
10
|
+
@config.stubs(:identity).returns("test")
|
11
|
+
@config.stubs(:configured).returns(true)
|
12
|
+
@config.stubs(:pluginconf).returns({"psk" => "12345"})
|
13
|
+
|
14
|
+
@stats = mock("stats")
|
15
|
+
|
16
|
+
@time = Time.now.to_i
|
17
|
+
::Time.stubs(:now).returns(@time)
|
18
|
+
|
19
|
+
MCollective::Log.stubs(:debug).returns(true)
|
20
|
+
|
21
|
+
MCollective::PluginManager << {:type => "global_stats", :class => @stats}
|
22
|
+
MCollective::Config.stubs("instance").returns(@config)
|
23
|
+
MCollective::Util.stubs("empty_filter?").returns(false)
|
24
|
+
|
25
|
+
@plugin = Psk.new
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#decodemsg" do
|
29
|
+
it "should correctly decode a message" do
|
30
|
+
@plugin.stubs("validrequest?").returns(true).once
|
31
|
+
|
32
|
+
msg = mock("message")
|
33
|
+
msg.stubs(:payload).returns(Marshal.dump({:body => Marshal.dump("foo")}))
|
34
|
+
msg.stubs(:expected_msgid).returns(nil)
|
35
|
+
|
36
|
+
@plugin.decodemsg(msg).should == {:body=>"foo"}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return nil on failure" do
|
40
|
+
@plugin.stubs("validrequest?").raises("fail").once
|
41
|
+
|
42
|
+
msg = mock("message")
|
43
|
+
msg.stubs(:payload).returns(Marshal.dump({:body => Marshal.dump("foo"), :requestid => "123"}))
|
44
|
+
msg.stubs(:expected_msgid).returns(nil)
|
45
|
+
|
46
|
+
expect { @plugin.decodemsg(msg) }.to raise_error("fail")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not decode messages not addressed to us" do
|
50
|
+
msg = mock("message")
|
51
|
+
msg.stubs(:payload).returns(Marshal.dump({:body => Marshal.dump("foo"), :requestid => "456"}))
|
52
|
+
msg.stubs(:expected_msgid).returns("123")
|
53
|
+
|
54
|
+
expect {
|
55
|
+
@plugin.decodemsg(msg)
|
56
|
+
}.to raise_error("Got a message with id 456 but was expecting 123, ignoring message")
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should only decode messages addressed to us" do
|
61
|
+
@plugin.stubs("validrequest?").returns(true).once
|
62
|
+
|
63
|
+
msg = mock("message")
|
64
|
+
msg.stubs(:payload).returns(Marshal.dump({:body => Marshal.dump("foo"), :requestid => "456"}))
|
65
|
+
msg.stubs(:expected_msgid).returns("456")
|
66
|
+
|
67
|
+
@plugin.decodemsg(msg).should == {:body=>"foo", :requestid=>"456"}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#encodereply" do
|
72
|
+
it "should correctly Marshal encode the reply" do
|
73
|
+
@plugin.stubs("create_reply").returns({:test => "test"})
|
74
|
+
Marshal.stubs("dump").with("test message").returns("marshal_test_message").once
|
75
|
+
Marshal.stubs("dump").with({:hash => '2dbeb0d7938a08a34eacd2c1dab25602', :test => 'test'}).returns("marshal_test_reply").once
|
76
|
+
|
77
|
+
@plugin.encodereply("sender", "test message", "requestid", "callerid").should == "marshal_test_reply"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#encoderequest" do
|
82
|
+
it "should correctly Marshal encode the request" do
|
83
|
+
@plugin.stubs("create_request").returns({:test => "test"})
|
84
|
+
Marshal.stubs("dump").with("test message").returns("marshal_test_message").once
|
85
|
+
Marshal.stubs("dump").with({:hash => '2dbeb0d7938a08a34eacd2c1dab25602', :test => 'test'}).returns("marshal_test_request").once
|
86
|
+
|
87
|
+
@plugin.encoderequest("sender", "test message", "requestid", "filter", "agent", "collective").should == "marshal_test_request"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#validrequest?" do
|
92
|
+
it "should correctly validate requests" do
|
93
|
+
@stats.stubs(:validated).once
|
94
|
+
@stats.stubs(:unvalidated).never
|
95
|
+
@plugin.validrequest?({:body => "foo", :hash => "e83ac78027b77b659a49bccbbcfa4849"})
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should raise an exception on failure" do
|
99
|
+
@stats.stubs(:validated).never
|
100
|
+
@stats.stubs(:unvalidated).once
|
101
|
+
expect { @plugin.validrequest?({:body => "foo", :hash => ""}) }.to raise_error("Received an invalid signature in message")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#callerid" do
|
106
|
+
it "should do uid based callerid when unconfigured" do
|
107
|
+
@plugin.callerid.should == "uid=#{Process.uid}"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should support gid based callerids" do
|
111
|
+
@config.stubs(:pluginconf).returns({"psk.callertype" => "gid"})
|
112
|
+
@plugin.callerid.should == "gid=#{Process.gid}"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should support group based callerids", :unless => MCollective::Util.windows? do
|
116
|
+
@config.stubs(:pluginconf).returns({"psk.callertype" => "group"})
|
117
|
+
@plugin.callerid.should == "group=#{Etc.getgrgid(Process.gid).name}"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should raise an error if the group callerid type is used on windows" do
|
121
|
+
MCollective::Util.expects("windows?").returns(true)
|
122
|
+
@config.stubs(:pluginconf).returns({"psk.callertype" => "group"})
|
123
|
+
expect { @plugin.callerid }.to raise_error("Cannot use the 'group' callertype for the PSK security plugin on the Windows platform")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should support user based callerids" do
|
127
|
+
@config.stubs(:pluginconf).returns({"psk.callertype" => "user"})
|
128
|
+
@plugin.callerid.should == "user=#{Etc.getlogin}"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should support identity based callerids" do
|
132
|
+
@config.stubs(:pluginconf).returns({"psk.callertype" => "identity"})
|
133
|
+
@plugin.callerid.should == "identity=test"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "#makehash" do
|
138
|
+
it "should return the correct md5 digest" do
|
139
|
+
@plugin.send(:makehash, "foo").should == "e83ac78027b77b659a49bccbbcfa4849"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should fail if no PSK is configured" do
|
143
|
+
@config.stubs(:pluginconf).returns({})
|
144
|
+
expect { @plugin.send(:makehash, "foo") }.to raise_error("No plugin.psk configuration option specified")
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should support reading the PSK from the environment" do
|
148
|
+
ENV["MCOLLECTIVE_PSK"] = "54321"
|
149
|
+
|
150
|
+
@plugin.send(:makehash, "foo").should == "d3fb63cc6b1d47cc4b2012df926c2feb"
|
151
|
+
|
152
|
+
ENV.delete("MCOLLECTIVE_PSK")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Registration
|
7
|
+
describe Base do
|
8
|
+
before do
|
9
|
+
@config = mock
|
10
|
+
@config.stubs(:identity).returns("rspec")
|
11
|
+
@config.stubs(:main_collective).returns("main_collective")
|
12
|
+
Config.stubs(:instance).returns(@config)
|
13
|
+
|
14
|
+
@reg = Base.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#config" do
|
18
|
+
it "should provide access the main configuration class" do
|
19
|
+
@reg.config.should == @config
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#identity" do
|
25
|
+
it "should return the correct identity" do
|
26
|
+
@reg.config.identity.should == "rspec"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#msg_filter" do
|
31
|
+
it "should target the registration agent" do
|
32
|
+
@reg.msg_filter.should == {"agent" => "registration"}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#target_collective" do
|
37
|
+
it "should return the configured registration_collective" do
|
38
|
+
@config.expects(:registration_collective).returns("registration").once
|
39
|
+
@config.expects(:collectives).returns(["main_collective", "registration"]).once
|
40
|
+
@reg.target_collective.should == "registration"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should use the main collective if registration collective is not valid" do
|
44
|
+
@config.expects(:registration_collective).returns("registration").once
|
45
|
+
@config.expects(:collectives).returns(["main_collective"]).once
|
46
|
+
|
47
|
+
Log.expects(:warn).with("Sending registration to main_collective: registration is not a valid collective").once
|
48
|
+
|
49
|
+
@reg.target_collective.should == "main_collective"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#publish" do
|
54
|
+
it "should skip registration for empty messages" do
|
55
|
+
Log.expects(:debug).with("Skipping registration due to nil body")
|
56
|
+
@reg.publish(nil)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should publish via the message object" do
|
60
|
+
message = mock
|
61
|
+
message.expects(:encode!)
|
62
|
+
message.expects(:publish)
|
63
|
+
message.expects(:requestid).returns("123")
|
64
|
+
message.expects(:collective).returns("mcollective")
|
65
|
+
|
66
|
+
Message.expects(:new).returns(message)
|
67
|
+
|
68
|
+
Log.expects(:debug).with("Sending registration 123 to collective mcollective")
|
69
|
+
|
70
|
+
@reg.expects(:target_collective).returns("mcollective")
|
71
|
+
|
72
|
+
@reg.publish("message")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|