right_agent 2.0.7-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +82 -0
- data/Rakefile +113 -0
- data/lib/right_agent.rb +59 -0
- data/lib/right_agent/actor.rb +182 -0
- data/lib/right_agent/actor_registry.rb +76 -0
- data/lib/right_agent/actors/agent_manager.rb +232 -0
- data/lib/right_agent/agent.rb +1149 -0
- data/lib/right_agent/agent_config.rb +480 -0
- data/lib/right_agent/agent_identity.rb +210 -0
- data/lib/right_agent/agent_tag_manager.rb +237 -0
- data/lib/right_agent/audit_formatter.rb +107 -0
- data/lib/right_agent/clients.rb +31 -0
- data/lib/right_agent/clients/api_client.rb +383 -0
- data/lib/right_agent/clients/auth_client.rb +247 -0
- data/lib/right_agent/clients/balanced_http_client.rb +369 -0
- data/lib/right_agent/clients/base_retry_client.rb +495 -0
- data/lib/right_agent/clients/right_http_client.rb +279 -0
- data/lib/right_agent/clients/router_client.rb +493 -0
- data/lib/right_agent/command.rb +30 -0
- data/lib/right_agent/command/agent_manager_commands.rb +150 -0
- data/lib/right_agent/command/command_client.rb +136 -0
- data/lib/right_agent/command/command_constants.rb +33 -0
- data/lib/right_agent/command/command_io.rb +126 -0
- data/lib/right_agent/command/command_parser.rb +87 -0
- data/lib/right_agent/command/command_runner.rb +118 -0
- data/lib/right_agent/command/command_serializer.rb +63 -0
- data/lib/right_agent/connectivity_checker.rb +179 -0
- data/lib/right_agent/console.rb +65 -0
- data/lib/right_agent/core_payload_types.rb +44 -0
- data/lib/right_agent/core_payload_types/cookbook.rb +61 -0
- data/lib/right_agent/core_payload_types/cookbook_position.rb +46 -0
- data/lib/right_agent/core_payload_types/cookbook_repository.rb +116 -0
- data/lib/right_agent/core_payload_types/cookbook_sequence.rb +70 -0
- data/lib/right_agent/core_payload_types/dev_repositories.rb +100 -0
- data/lib/right_agent/core_payload_types/dev_repository.rb +76 -0
- data/lib/right_agent/core_payload_types/event_categories.rb +38 -0
- data/lib/right_agent/core_payload_types/executable_bundle.rb +130 -0
- data/lib/right_agent/core_payload_types/login_policy.rb +72 -0
- data/lib/right_agent/core_payload_types/login_user.rb +79 -0
- data/lib/right_agent/core_payload_types/planned_volume.rb +94 -0
- data/lib/right_agent/core_payload_types/recipe_instantiation.rb +73 -0
- data/lib/right_agent/core_payload_types/repositories_bundle.rb +50 -0
- data/lib/right_agent/core_payload_types/right_script_attachment.rb +95 -0
- data/lib/right_agent/core_payload_types/right_script_instantiation.rb +94 -0
- data/lib/right_agent/core_payload_types/runlist_policy.rb +44 -0
- data/lib/right_agent/core_payload_types/secure_document.rb +66 -0
- data/lib/right_agent/core_payload_types/secure_document_location.rb +63 -0
- data/lib/right_agent/core_payload_types/software_repository_instantiation.rb +61 -0
- data/lib/right_agent/daemonize.rb +35 -0
- data/lib/right_agent/dispatched_cache.rb +109 -0
- data/lib/right_agent/dispatcher.rb +272 -0
- data/lib/right_agent/enrollment_result.rb +221 -0
- data/lib/right_agent/exceptions.rb +87 -0
- data/lib/right_agent/history.rb +145 -0
- data/lib/right_agent/log.rb +460 -0
- data/lib/right_agent/minimal.rb +46 -0
- data/lib/right_agent/monkey_patches.rb +30 -0
- data/lib/right_agent/monkey_patches/ruby_patch.rb +55 -0
- data/lib/right_agent/monkey_patches/ruby_patch/array_patch.rb +29 -0
- data/lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +30 -0
- data/lib/right_agent/monkey_patches/ruby_patch/object_patch.rb +49 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch.rb +32 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +60 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/process_patch.rb +63 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/stdio_patch.rb +27 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/time_patch.rb +55 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/win32ole_patch.rb +34 -0
- data/lib/right_agent/multiplexer.rb +102 -0
- data/lib/right_agent/offline_handler.rb +270 -0
- data/lib/right_agent/operation_result.rb +300 -0
- data/lib/right_agent/packets.rb +673 -0
- data/lib/right_agent/payload_formatter.rb +104 -0
- data/lib/right_agent/pending_requests.rb +128 -0
- data/lib/right_agent/pid_file.rb +159 -0
- data/lib/right_agent/platform.rb +770 -0
- data/lib/right_agent/platform/unix/darwin/platform.rb +102 -0
- data/lib/right_agent/platform/unix/linux/platform.rb +305 -0
- data/lib/right_agent/platform/unix/platform.rb +226 -0
- data/lib/right_agent/platform/windows/mingw/platform.rb +447 -0
- data/lib/right_agent/platform/windows/mswin/platform.rb +236 -0
- data/lib/right_agent/platform/windows/platform.rb +1808 -0
- data/lib/right_agent/protocol_version_mixin.rb +69 -0
- data/lib/right_agent/retryable_request.rb +195 -0
- data/lib/right_agent/scripts/agent_controller.rb +543 -0
- data/lib/right_agent/scripts/agent_deployer.rb +400 -0
- data/lib/right_agent/scripts/common_parser.rb +160 -0
- data/lib/right_agent/scripts/log_level_manager.rb +192 -0
- data/lib/right_agent/scripts/stats_manager.rb +268 -0
- data/lib/right_agent/scripts/usage.rb +58 -0
- data/lib/right_agent/secure_identity.rb +92 -0
- data/lib/right_agent/security.rb +32 -0
- data/lib/right_agent/security/cached_certificate_store_proxy.rb +77 -0
- data/lib/right_agent/security/certificate.rb +102 -0
- data/lib/right_agent/security/certificate_cache.rb +89 -0
- data/lib/right_agent/security/distinguished_name.rb +56 -0
- data/lib/right_agent/security/encrypted_document.rb +83 -0
- data/lib/right_agent/security/rsa_key_pair.rb +76 -0
- data/lib/right_agent/security/signature.rb +86 -0
- data/lib/right_agent/security/static_certificate_store.rb +85 -0
- data/lib/right_agent/sender.rb +792 -0
- data/lib/right_agent/serialize.rb +29 -0
- data/lib/right_agent/serialize/message_pack.rb +107 -0
- data/lib/right_agent/serialize/secure_serializer.rb +151 -0
- data/lib/right_agent/serialize/secure_serializer_initializer.rb +47 -0
- data/lib/right_agent/serialize/serializable.rb +151 -0
- data/lib/right_agent/serialize/serializer.rb +159 -0
- data/lib/right_agent/subprocess.rb +38 -0
- data/lib/right_agent/tracer.rb +124 -0
- data/right_agent.gemspec +101 -0
- data/spec/actor_registry_spec.rb +80 -0
- data/spec/actor_spec.rb +162 -0
- data/spec/agent_config_spec.rb +235 -0
- data/spec/agent_identity_spec.rb +78 -0
- data/spec/agent_spec.rb +734 -0
- data/spec/agent_tag_manager_spec.rb +319 -0
- data/spec/clients/api_client_spec.rb +423 -0
- data/spec/clients/auth_client_spec.rb +272 -0
- data/spec/clients/balanced_http_client_spec.rb +576 -0
- data/spec/clients/base_retry_client_spec.rb +635 -0
- data/spec/clients/router_client_spec.rb +594 -0
- data/spec/clients/spec_helper.rb +111 -0
- data/spec/command/agent_manager_commands_spec.rb +51 -0
- data/spec/command/command_io_spec.rb +93 -0
- data/spec/command/command_parser_spec.rb +79 -0
- data/spec/command/command_runner_spec.rb +107 -0
- data/spec/command/command_serializer_spec.rb +51 -0
- data/spec/connectivity_checker_spec.rb +83 -0
- data/spec/core_payload_types/dev_repositories_spec.rb +64 -0
- data/spec/core_payload_types/dev_repository_spec.rb +33 -0
- data/spec/core_payload_types/executable_bundle_spec.rb +67 -0
- data/spec/core_payload_types/login_user_spec.rb +102 -0
- data/spec/core_payload_types/recipe_instantiation_spec.rb +81 -0
- data/spec/core_payload_types/right_script_attachment_spec.rb +65 -0
- data/spec/core_payload_types/right_script_instantiation_spec.rb +79 -0
- data/spec/core_payload_types/spec_helper.rb +23 -0
- data/spec/dispatched_cache_spec.rb +136 -0
- data/spec/dispatcher_spec.rb +324 -0
- data/spec/enrollment_result_spec.rb +53 -0
- data/spec/history_spec.rb +246 -0
- data/spec/log_spec.rb +192 -0
- data/spec/monkey_patches/eventmachine_spec.rb +62 -0
- data/spec/multiplexer_spec.rb +48 -0
- data/spec/offline_handler_spec.rb +340 -0
- data/spec/operation_result_spec.rb +208 -0
- data/spec/packets_spec.rb +461 -0
- data/spec/pending_requests_spec.rb +136 -0
- data/spec/platform/spec_helper.rb +216 -0
- data/spec/platform/unix/darwin/platform_spec.rb +181 -0
- data/spec/platform/unix/linux/platform_spec.rb +540 -0
- data/spec/platform/unix/spec_helper.rb +149 -0
- data/spec/platform/windows/mingw/platform_spec.rb +222 -0
- data/spec/platform/windows/mswin/platform_spec.rb +259 -0
- data/spec/platform/windows/spec_helper.rb +720 -0
- data/spec/retryable_request_spec.rb +306 -0
- data/spec/secure_identity_spec.rb +50 -0
- data/spec/security/cached_certificate_store_proxy_spec.rb +62 -0
- data/spec/security/certificate_cache_spec.rb +71 -0
- data/spec/security/certificate_spec.rb +49 -0
- data/spec/security/distinguished_name_spec.rb +46 -0
- data/spec/security/encrypted_document_spec.rb +55 -0
- data/spec/security/rsa_key_pair_spec.rb +55 -0
- data/spec/security/signature_spec.rb +66 -0
- data/spec/security/static_certificate_store_spec.rb +58 -0
- data/spec/sender_spec.rb +1045 -0
- data/spec/serialize/message_pack_spec.rb +131 -0
- data/spec/serialize/secure_serializer_spec.rb +132 -0
- data/spec/serialize/serializable_spec.rb +90 -0
- data/spec/serialize/serializer_spec.rb +197 -0
- data/spec/spec.opts +2 -0
- data/spec/spec.win32.opts +1 -0
- data/spec/spec_helper.rb +130 -0
- data/spec/tracer_spec.rb +114 -0
- metadata +447 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
24
|
+
|
25
|
+
module RightScale
|
26
|
+
class TestClass
|
27
|
+
include Serializable
|
28
|
+
|
29
|
+
attr_accessor :var1, :var2
|
30
|
+
|
31
|
+
def initialize(*a)
|
32
|
+
@var1 = a[0]
|
33
|
+
@var2 = a[1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def serialized_members
|
37
|
+
[@var1, @var2]
|
38
|
+
end
|
39
|
+
|
40
|
+
def ==(rhs)
|
41
|
+
@var1 == rhs.var1 && @var2 == rhs.var2
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class NonSerializableTestClass
|
47
|
+
attr_accessor :var1
|
48
|
+
|
49
|
+
def initialize(*a)
|
50
|
+
@var1 = a[0]
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_msgpack(*a)
|
54
|
+
{
|
55
|
+
'msgpack_class' => self.class.name,
|
56
|
+
'data' => serialized_members
|
57
|
+
}.to_msgpack(*a)
|
58
|
+
end
|
59
|
+
|
60
|
+
def serialized_members
|
61
|
+
[@var1]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe MessagePack do
|
66
|
+
|
67
|
+
it "should serialize an object when dump and unserialize when load to produce equivalent object" do
|
68
|
+
object = [1, 3.14, {"key" => "value"}]
|
69
|
+
MessagePack.load(MessagePack.dump(object)).should == object
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should behave like JSON in terms of not preserving symbols" do
|
73
|
+
object = [1, 3.14, {:key => "value"}]
|
74
|
+
MessagePack.load(MessagePack.dump(object)).should == [1, 3.14, {"key" => "value"}]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should serialize arbitrary objects when dump and recreate when load" do
|
78
|
+
object = RightScale::TestClass.new({"key" => "value"}, [1, 2, "abc"])
|
79
|
+
data = MessagePack.dump(object)
|
80
|
+
(data =~ /msgpack_class.*RightScale::TestClass/).should be_true
|
81
|
+
MessagePack.load(data).should == object
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should do nested creation of objects within arrays" do
|
85
|
+
test = RightScale::TestClass.new({"key" => "value"}, [1, 2, "abc"])
|
86
|
+
object = [1, 3.14, test]
|
87
|
+
data = MessagePack.dump(object)
|
88
|
+
(data =~ /msgpack_class.*RightScale::TestClass/).should be_true
|
89
|
+
MessagePack.load(data).should == object
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should do nested creation of objects within hashes" do
|
93
|
+
test = RightScale::TestClass.new({"key" => "value"}, [1, 2, "abc"])
|
94
|
+
object = {"my_data" => [99, 4.3, 712345], "my_test" => test}
|
95
|
+
data = MessagePack.dump(object)
|
96
|
+
(data =~ /msgpack_class.*RightScale::TestClass/).should be_true
|
97
|
+
MessagePack.load(data).should == object
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should do nested creation of objects recursively" do
|
101
|
+
test1 = RightScale::TestClass.new("some", "test")
|
102
|
+
test2 = RightScale::TestClass.new({"key" => "value"}, [1, 2, "abc"])
|
103
|
+
object = [{"my_data" => [99, 4.3, 712345], "my_tests" => {"test1" => test1, "test2" => test2}}, test1, test2]
|
104
|
+
data = MessagePack.dump(object)
|
105
|
+
(data =~ /msgpack_class.*RightScale::TestClass/).should be_true
|
106
|
+
MessagePack.load(data).should == object
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should do nested creation of objects that are arguments in the creation of nested objects" do
|
110
|
+
test1 = RightScale::TestClass.new("some", "test")
|
111
|
+
test2 = RightScale::TestClass.new({"key" => "value"}, test1)
|
112
|
+
object = [{"my_data" => [99, 4.3, 712345], "my_tests" => {"test1" => test1, "test2" => test2}}, test1, test2]
|
113
|
+
data = MessagePack.dump(object)
|
114
|
+
(data =~ /msgpack_class.*RightScale::TestClass/).should be_true
|
115
|
+
MessagePack.load(data).should == object
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should raise an exception if it finds a msgpack_class but there is no msgpack_generate method" do
|
119
|
+
data = MessagePack.dump(NonSerializableTestClass.new(nil))
|
120
|
+
(data =~ /msgpack_class.*NonSerializableTestClass/).should be_true
|
121
|
+
lambda { MessagePack.load(data) }.should raise_error(ArgumentError, /missing msgpack_create method/)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should raise an exception if it cannot resolve a named msgpack_class" do
|
125
|
+
object = [1, 3.14, {"msgpack_class" => "RightScale::BogusClass"}]
|
126
|
+
data = MessagePack.dump(object)
|
127
|
+
(data =~ /msgpack_class.*RightScale::BogusClass/).should be_true
|
128
|
+
lambda { MessagePack.load(data) }.should raise_error(ArgumentError, /Cannot find const/)
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2013 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
24
|
+
|
25
|
+
module RightScale
|
26
|
+
|
27
|
+
# Add the ability to compare results for test purposes
|
28
|
+
class Result
|
29
|
+
def ==(other)
|
30
|
+
@token == other.token && @to == other.to && @from == other.from && @results == other.results
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe RightScale::SecureSerializer do
|
37
|
+
|
38
|
+
include RightScale::SpecHelper
|
39
|
+
|
40
|
+
before(:all) do
|
41
|
+
@dump_cert, @dump_key = issue_cert
|
42
|
+
@load_cert, @load_key = issue_cert
|
43
|
+
@dump_store = RightScale::StaticCertificateStore.new(@dump_cert, @dump_key, @load_cert, @load_cert)
|
44
|
+
@load_store = RightScale::StaticCertificateStore.new(@load_cert, @load_key, @dump_cert, @dump_cert)
|
45
|
+
@dump_id = RightScale::AgentIdentity.new("rs", "dump_agent", 1).to_s
|
46
|
+
@load_id = RightScale::AgentIdentity.new("rs", "load_agent", 1).to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
it "must be initialized before use" do
|
50
|
+
data = RightScale::Result.new("token", "to", ["results"], "from")
|
51
|
+
lambda { RightScale::SecureSerializer.dump(data) }.should raise_error(Exception, "Secure serializer not initialized")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "must specify agent identity" do
|
55
|
+
lambda { RightScale::SecureSerializer.init(RightScale::Serializer.new, nil, @load_store, false) }.
|
56
|
+
should raise_error(Exception, "Missing local agent identity")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "must specify a credentials store" do
|
60
|
+
lambda { RightScale::SecureSerializer.init(RightScale::Serializer.new, @load_id, nil, false) }.
|
61
|
+
should raise_error(Exception, "Missing credentials store")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "certificate store must contain certificate and key for agent" do
|
65
|
+
flexmock(@load_store).should_receive(:get_receiver).and_return([nil, nil]).once
|
66
|
+
lambda { RightScale::SecureSerializer.init(RightScale::Serializer.new, @load_id, @load_store, false) }.
|
67
|
+
should raise_error(Exception, "Missing local agent public certificate")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "data must be serialized with MessagePack or JSON" do
|
71
|
+
data = RightScale::Result.new("token", "to", ["results"], "from")
|
72
|
+
RightScale::SecureSerializer.init(RightScale::Serializer.new, @load_id, @load_store, false)
|
73
|
+
lambda { RightScale::SecureSerializer.load(Marshal.dump(data)) }.should raise_error(RightScale::Serializer::SerializationError)
|
74
|
+
lambda { RightScale::SecureSerializer.load(YAML.dump(data)) }.should raise_error(RightScale::Serializer::SerializationError)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Test with protocol versions on the boundary where msgpack was first supported
|
78
|
+
[[:msgpack, version_can_handle_msgpack_result, JSON],
|
79
|
+
[:json, version_cannot_handle_msgpack_result, MessagePack]].each do |type, version, other_class|
|
80
|
+
|
81
|
+
context "using #{type.inspect}" do
|
82
|
+
|
83
|
+
before(:each) do
|
84
|
+
flexmock(other_class).should_receive(:dump).never
|
85
|
+
flexmock(other_class).should_receive(:load).never
|
86
|
+
@data = RightScale::Result.new("token", "to", ["results"], "from", nil, nil, nil, nil, [version, version])
|
87
|
+
@serializer = RightScale::Serializer.new(type)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "unserializes signed data" do
|
91
|
+
RightScale::SecureSerializer.init(@serializer, @dump_id, @dump_store, false)
|
92
|
+
data = RightScale::SecureSerializer.dump(@data)
|
93
|
+
RightScale::SecureSerializer.init(@serializer, @load_id, @load_store, false)
|
94
|
+
RightScale::SecureSerializer.load(data).should == @data
|
95
|
+
end
|
96
|
+
|
97
|
+
it "unserializes encrypted data" do
|
98
|
+
RightScale::SecureSerializer.init(@serializer, @dump_id, @dump_store, true)
|
99
|
+
data = RightScale::SecureSerializer.dump(@data)
|
100
|
+
@serializer.load(data)["encrypted"].should be_true
|
101
|
+
RightScale::SecureSerializer.init(@serializer, @load_id, @load_store, false)
|
102
|
+
RightScale::SecureSerializer.load(data).should == @data
|
103
|
+
end
|
104
|
+
|
105
|
+
it "encrypt option on initialization overrides dump option" do
|
106
|
+
RightScale::SecureSerializer.init(@serializer, @dump_id, @dump_store, true)
|
107
|
+
data = RightScale::SecureSerializer.dump(@data, false)
|
108
|
+
@serializer.load(data)["encrypted"].should be_true
|
109
|
+
end
|
110
|
+
|
111
|
+
it "uses id when supplied to choose credentials" do
|
112
|
+
RightScale::SecureSerializer.init(@serializer, @dump_id, @dump_store, true)
|
113
|
+
data = RightScale::SecureSerializer.dump(@data)
|
114
|
+
RightScale::SecureSerializer.init(@serializer, @load_id, @load_store, false)
|
115
|
+
flexmock(@load_store).should_receive(:get_receiver).with("id").and_return([@load_cert, @load_key]).once
|
116
|
+
RightScale::SecureSerializer.load(data, "id").should == @data
|
117
|
+
end
|
118
|
+
|
119
|
+
it "must be able to retrieve certificate and key to decrypt message" do
|
120
|
+
RightScale::SecureSerializer.init(@serializer, @dump_id, @dump_store, true)
|
121
|
+
data = RightScale::SecureSerializer.dump(@data)
|
122
|
+
RightScale::SecureSerializer.init(@serializer, @dump_id, @load_store, false)
|
123
|
+
flexmock(@load_store).should_receive(:get_receiver).with("id").and_return([nil, @load_key], [@load_cert, nil]).twice
|
124
|
+
lambda { RightScale::SecureSerializer.load(data, "id") }.
|
125
|
+
should raise_error(RightScale::SecureSerializer::MissingCertificate, /Could not find a certificate/)
|
126
|
+
lambda { RightScale::SecureSerializer.load(data, "id") }.
|
127
|
+
should raise_error(RightScale::SecureSerializer::MissingPrivateKey, /Could not find a private key/)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
24
|
+
require 'json/ext'
|
25
|
+
|
26
|
+
class TestClass1
|
27
|
+
|
28
|
+
include RightScale::Serializable
|
29
|
+
|
30
|
+
attr_accessor :name, :array, :date
|
31
|
+
|
32
|
+
def initialize(*args)
|
33
|
+
@name = args[0] if args.size > 0
|
34
|
+
@array = args[1] if args.size > 1
|
35
|
+
@date = args[2] if args.size > 2
|
36
|
+
end
|
37
|
+
|
38
|
+
def serialized_members
|
39
|
+
[@name, @array, @date]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class TestClass2
|
44
|
+
|
45
|
+
include RightScale::Serializable
|
46
|
+
|
47
|
+
attr_accessor :attr1, :attr2
|
48
|
+
|
49
|
+
def initialize(*args)
|
50
|
+
attr1 = args[0]
|
51
|
+
attr2 = args[1] if args.size > 1
|
52
|
+
end
|
53
|
+
|
54
|
+
def serialized_members
|
55
|
+
[@attr1, @attr2]
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe RightScale::Serializable do
|
61
|
+
|
62
|
+
it 'should serialize using MessagePack' do
|
63
|
+
a1 = TestClass1.new
|
64
|
+
a1.name = "Test1"
|
65
|
+
a1.array = ["some", "stuff" ]
|
66
|
+
|
67
|
+
b1 = TestClass1.new
|
68
|
+
b1.name = "Test2"
|
69
|
+
b1.array = ["some", "more", "stuff"]
|
70
|
+
|
71
|
+
c = TestClass2.new([a1, b1], 1234)
|
72
|
+
a1.to_msgpack
|
73
|
+
TestClass2.msgpack_create(c.to_msgpack).should == c
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should serialize using JSON' do
|
77
|
+
a1 = TestClass1.new
|
78
|
+
a1.name = "Test1"
|
79
|
+
a1.array = ["some", "stuff" ]
|
80
|
+
|
81
|
+
b1 = TestClass1.new
|
82
|
+
b1.name = "Test2"
|
83
|
+
b1.array = ["some", "more", "stuff"]
|
84
|
+
|
85
|
+
c = TestClass2.new([a1, b1], 1234)
|
86
|
+
a1.to_json
|
87
|
+
TestClass2.json_create(c.to_msgpack).should == c
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2013 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
24
|
+
|
25
|
+
describe RightScale::Serializer do
|
26
|
+
|
27
|
+
describe "Format" do
|
28
|
+
|
29
|
+
it "supports MessagePack format" do
|
30
|
+
[ :msgpack, "msgpack" ].each do |format|
|
31
|
+
lambda { RightScale::Serializer.new(format).format.should == :msgpack }.should_not raise_error
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "supports JSON format" do
|
36
|
+
[ :json, "json" ].each do |format|
|
37
|
+
lambda { RightScale::Serializer.new(format).format.should == :json }.should_not raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "supports secure format" do
|
42
|
+
[ :secure, "secure" ].each do |format|
|
43
|
+
lambda { RightScale::Serializer.new(format).format.should == :secure }.should_not raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should default to MessagePack format if none specified" do
|
48
|
+
RightScale::Serializer.new.format.should == :msgpack
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise error if unsupported format specified" do
|
52
|
+
lambda { RightScale::Serializer.new(:yaml) }.should raise_error(ArgumentError)
|
53
|
+
end
|
54
|
+
|
55
|
+
end # Format
|
56
|
+
|
57
|
+
describe "Serialization" do
|
58
|
+
|
59
|
+
it "should use MessagePack as default serializer and not cascade to others" do
|
60
|
+
serializer = RightScale::Serializer.new
|
61
|
+
flexmock(serializer).should_receive(:cascade_serializers).with(:dump, "hello", [MessagePack]).once
|
62
|
+
serializer.dump("hello")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should use preferred serializer if specified and not cascade to others" do
|
66
|
+
serializer = RightScale::Serializer.new(:json)
|
67
|
+
flexmock(serializer).should_receive(:cascade_serializers).with(:dump, "hello", [JSON]).once
|
68
|
+
serializer.dump("hello")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise SerializationError if packet could not be serialized and not try other serializer" do
|
72
|
+
flexmock(MessagePack).should_receive(:dump).with("hello").and_raise(StandardError).once
|
73
|
+
flexmock(JSON).should_receive(:dump).with("hello").and_raise(StandardError).once
|
74
|
+
serializer = RightScale::Serializer.new(:msgpack)
|
75
|
+
lambda { serializer.dump("hello") }.should raise_error(RightScale::Serializer::SerializationError)
|
76
|
+
serializer = RightScale::Serializer.new(:json)
|
77
|
+
lambda { serializer.dump("hello") }.should raise_error(RightScale::Serializer::SerializationError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return serialized packet" do
|
81
|
+
serialized_packet = flexmock("Packet")
|
82
|
+
flexmock(MessagePack).should_receive(:dump).with("hello").and_return(serialized_packet).once
|
83
|
+
serializer = RightScale::Serializer.new
|
84
|
+
serializer.dump("hello").should == serialized_packet
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should be able to override preferred format" do
|
88
|
+
serializer = RightScale::Serializer.new(:json)
|
89
|
+
flexmock(serializer).should_receive(:cascade_serializers).with(:dump, "hello", [MessagePack]).once
|
90
|
+
flexmock(serializer).should_receive(:cascade_serializers).with(:dump, "hello", [JSON]).never
|
91
|
+
serializer.dump("hello", :msgpack)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not be able to override preferred format when secure" do
|
95
|
+
serializer = RightScale::Serializer.new(:secure)
|
96
|
+
flexmock(serializer).should_receive(:cascade_serializers).with(:dump, "hello", [RightScale::SecureSerializer]).once
|
97
|
+
flexmock(serializer).should_receive(:cascade_serializers).with(:dump, "hello", [MessagePack]).never
|
98
|
+
serializer.dump("hello", :msgpack)
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "MessagePack for common classes" do
|
102
|
+
|
103
|
+
it "should serialize Date object" do
|
104
|
+
serializer = RightScale::Serializer.new(:msgpack)
|
105
|
+
date = Date.today
|
106
|
+
data = serializer.dump(date)
|
107
|
+
Date.strptime(serializer.load(data), "%Y-%m-%d").should == date
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should serialize Time object" do
|
111
|
+
serializer = RightScale::Serializer.new(:msgpack)
|
112
|
+
time = Time.now
|
113
|
+
data = serializer.dump(time)
|
114
|
+
if RUBY_VERSION < "1.9.0"
|
115
|
+
Time.parse(serializer.load(data)).to_i.should == time.to_i
|
116
|
+
else
|
117
|
+
DateTime.parse(serializer.load(data)).to_time.to_i.should == time.to_i
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should serialize DateTime object" do
|
122
|
+
serializer = RightScale::Serializer.new(:msgpack)
|
123
|
+
date_time = DateTime.now
|
124
|
+
data = serializer.dump(date_time)
|
125
|
+
DateTime.parse(serializer.load(data)).to_s.should == date_time.to_s
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end # Serialization of Packet
|
131
|
+
|
132
|
+
describe "Unserialization" do
|
133
|
+
|
134
|
+
it "should cascade through available serializers" do
|
135
|
+
serializer = RightScale::Serializer.new
|
136
|
+
flexmock(serializer).should_receive(:cascade_serializers).with(:load, "olleh", [JSON, MessagePack], nil).once
|
137
|
+
serializer.load("olleh")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should try all supported formats (MessagePack, JSON)" do
|
141
|
+
flexmock(MessagePack).should_receive(:load).with("olleh").and_raise(StandardError).once
|
142
|
+
flexmock(JSON).should_receive(:load).with("olleh").and_raise(StandardError).once
|
143
|
+
lambda { RightScale::Serializer.new.load("olleh") }.should raise_error(RightScale::Serializer::SerializationError)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should try JSON format first if looks like JSON even if MessagePack preferred" do
|
147
|
+
object = [1, 2, 3]
|
148
|
+
serialized = object.to_json
|
149
|
+
flexmock(MessagePack).should_receive(:load).with(serialized).never
|
150
|
+
flexmock(JSON).should_receive(:load).with(serialized).and_return(object).once
|
151
|
+
RightScale::Serializer.new(:msgpack).load(serialized)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should try MessagePack format first if looks like MessagePack even if JSON preferred" do
|
155
|
+
object = [1, 2, 3]
|
156
|
+
serialized = object.to_msgpack
|
157
|
+
flexmock(JSON).should_receive(:load).with(serialized).never
|
158
|
+
flexmock(MessagePack).should_receive(:load).with(serialized).and_return(object).once
|
159
|
+
RightScale::Serializer.new(:json).load(serialized)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should pass optional id to SecureSerializer" do
|
163
|
+
object = [1, 2, 3]
|
164
|
+
serialized = "securely serialized"
|
165
|
+
flexmock(RightScale::SecureSerializer).should_receive(:load).with(serialized, "id").and_return(object).once
|
166
|
+
RightScale::Serializer.new(:secure).load(serialized, "id")
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should not pass optional id to MessagePack serializer" do
|
170
|
+
object = [1, 2, 3]
|
171
|
+
serialized = object.to_msgpack
|
172
|
+
RightScale::Serializer.new(:msgpack).load(serialized, "id").should == object
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should not pass optional id to JSON serializer" do
|
176
|
+
object = [1, 2, 3]
|
177
|
+
serialized = object.to_json
|
178
|
+
RightScale::Serializer.new(:json).load(serialized, "id").should == object
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should raise SerializationError if packet could not be unserialized" do
|
182
|
+
flexmock(MessagePack).should_receive(:load).with("olleh").and_raise(StandardError).once
|
183
|
+
flexmock(JSON).should_receive(:load).with("olleh").and_raise(StandardError).once
|
184
|
+
serializer = RightScale::Serializer.new
|
185
|
+
lambda { serializer.load("olleh") }.should raise_error(RightScale::Serializer::SerializationError)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return unserialized packet" do
|
189
|
+
unserialized_packet = flexmock("Packet")
|
190
|
+
flexmock(MessagePack).should_receive(:load).with("olleh").and_return(unserialized_packet).once
|
191
|
+
serializer = RightScale::Serializer.new(:msgpack)
|
192
|
+
serializer.load("olleh").should == unserialized_packet
|
193
|
+
end
|
194
|
+
|
195
|
+
end # De-Serialization of Packet
|
196
|
+
|
197
|
+
end # RightScale::Serializer
|