pantry 0.0.0 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +19 -0
- data/Gemfile +15 -0
- data/Guardfile +16 -0
- data/LICENSE +20 -0
- data/README.md +53 -0
- data/Rakefile +18 -0
- data/Vagrantfile +86 -0
- data/bin/pantry +11 -0
- data/bin/pantry-client +38 -0
- data/bin/pantry-server +33 -0
- data/dist/client.yml +79 -0
- data/dist/server.yml +56 -0
- data/dist/upstart/pantry-client.conf +12 -0
- data/dist/upstart/pantry-server.conf +12 -0
- data/doc/message_packet.dot +19 -0
- data/doc/message_packet.dot.png +0 -0
- data/doc/network_topology.dot +42 -0
- data/doc/network_topology.dot.png +0 -0
- data/lib/celluloid_zmq_patches.rb +16 -0
- data/lib/opt_parse_plus.rb +184 -0
- data/lib/pantry.rb +197 -0
- data/lib/pantry/cli.rb +154 -0
- data/lib/pantry/client.rb +131 -0
- data/lib/pantry/client_info.rb +34 -0
- data/lib/pantry/client_registry.rb +104 -0
- data/lib/pantry/command.rb +194 -0
- data/lib/pantry/command_handler.rb +53 -0
- data/lib/pantry/command_line.rb +115 -0
- data/lib/pantry/commands/create_client.rb +30 -0
- data/lib/pantry/commands/download_directory.rb +35 -0
- data/lib/pantry/commands/echo.rb +32 -0
- data/lib/pantry/commands/edit_application.rb +60 -0
- data/lib/pantry/commands/register_client.rb +38 -0
- data/lib/pantry/commands/status.rb +78 -0
- data/lib/pantry/commands/sync_directory.rb +50 -0
- data/lib/pantry/commands/update_application.rb +45 -0
- data/lib/pantry/commands/upload_file.rb +68 -0
- data/lib/pantry/communication.rb +20 -0
- data/lib/pantry/communication/client.rb +75 -0
- data/lib/pantry/communication/client_filter.rb +117 -0
- data/lib/pantry/communication/file_service.rb +125 -0
- data/lib/pantry/communication/file_service/file_progress.rb +164 -0
- data/lib/pantry/communication/file_service/receive_file.rb +97 -0
- data/lib/pantry/communication/file_service/send_file.rb +74 -0
- data/lib/pantry/communication/publish_socket.rb +20 -0
- data/lib/pantry/communication/reading_socket.rb +89 -0
- data/lib/pantry/communication/receive_socket.rb +23 -0
- data/lib/pantry/communication/security.rb +44 -0
- data/lib/pantry/communication/security/authentication.rb +98 -0
- data/lib/pantry/communication/security/curve_key_store.rb +120 -0
- data/lib/pantry/communication/security/curve_security.rb +70 -0
- data/lib/pantry/communication/security/null_security.rb +32 -0
- data/lib/pantry/communication/send_socket.rb +19 -0
- data/lib/pantry/communication/serialize_message.rb +84 -0
- data/lib/pantry/communication/server.rb +97 -0
- data/lib/pantry/communication/subscribe_socket.rb +33 -0
- data/lib/pantry/communication/wait_list.rb +45 -0
- data/lib/pantry/communication/writing_socket.rb +46 -0
- data/lib/pantry/config.rb +182 -0
- data/lib/pantry/file_editor.rb +67 -0
- data/lib/pantry/logger.rb +78 -0
- data/lib/pantry/message.rb +134 -0
- data/lib/pantry/multi_command.rb +36 -0
- data/lib/pantry/server.rb +132 -0
- data/lib/pantry/test/acceptance.rb +83 -0
- data/lib/pantry/test/support/fake_fs.rb +31 -0
- data/lib/pantry/test/support/matchers.rb +13 -0
- data/lib/pantry/test/support/minitest.rb +13 -0
- data/lib/pantry/test/support/mock_ui.rb +23 -0
- data/lib/pantry/test/unit.rb +13 -0
- data/lib/pantry/ui.rb +68 -0
- data/lib/pantry/version.rb +3 -0
- data/pantry.gemspec +40 -0
- data/test/acceptance/cli/error_handling_test.rb +7 -0
- data/test/acceptance/cli/execute_command_on_clients_test.rb +32 -0
- data/test/acceptance/cli/request_info_from_server_test.rb +44 -0
- data/test/acceptance/communication/client_requests_info_from_server_test.rb +28 -0
- data/test/acceptance/communication/heartbeat_test.rb +19 -0
- data/test/acceptance/communication/pub_sub_communication_test.rb +53 -0
- data/test/acceptance/communication/security_test.rb +117 -0
- data/test/acceptance/communication/server_requests_info_from_client_test.rb +41 -0
- data/test/acceptance/test_helper.rb +25 -0
- data/test/fixtures/config.yml +22 -0
- data/test/fixtures/empty.yml +2 -0
- data/test/fixtures/file_to_upload +3 -0
- data/test/root_dir/.gitkeep +0 -0
- data/test/unit/cli_test.rb +173 -0
- data/test/unit/client_registry_test.rb +61 -0
- data/test/unit/client_test.rb +128 -0
- data/test/unit/command_handler_test.rb +79 -0
- data/test/unit/command_line_test.rb +5 -0
- data/test/unit/command_test.rb +206 -0
- data/test/unit/commands/create_client_test.rb +25 -0
- data/test/unit/commands/download_directory_test.rb +58 -0
- data/test/unit/commands/echo_test.rb +22 -0
- data/test/unit/commands/edit_application_test.rb +84 -0
- data/test/unit/commands/register_client_test.rb +41 -0
- data/test/unit/commands/status_test.rb +81 -0
- data/test/unit/commands/sync_directory_test.rb +75 -0
- data/test/unit/commands/update_application_test.rb +35 -0
- data/test/unit/commands/upload_file_test.rb +51 -0
- data/test/unit/communication/client_filter_test.rb +262 -0
- data/test/unit/communication/client_test.rb +99 -0
- data/test/unit/communication/file_service/receive_file_test.rb +214 -0
- data/test/unit/communication/file_service/send_file_test.rb +110 -0
- data/test/unit/communication/file_service_test.rb +56 -0
- data/test/unit/communication/publish_socket_test.rb +19 -0
- data/test/unit/communication/reading_socket_test.rb +110 -0
- data/test/unit/communication/receive_socket_test.rb +20 -0
- data/test/unit/communication/security/authentication_test.rb +97 -0
- data/test/unit/communication/security/curve_key_store_test.rb +110 -0
- data/test/unit/communication/security/curve_security_test.rb +44 -0
- data/test/unit/communication/security/null_security_test.rb +15 -0
- data/test/unit/communication/security_test.rb +49 -0
- data/test/unit/communication/send_socket_test.rb +19 -0
- data/test/unit/communication/serialize_message_test.rb +128 -0
- data/test/unit/communication/server_test.rb +106 -0
- data/test/unit/communication/subscribe_socket_test.rb +46 -0
- data/test/unit/communication/wait_list_test.rb +60 -0
- data/test/unit/communication/writing_socket_test.rb +46 -0
- data/test/unit/config_test.rb +150 -0
- data/test/unit/logger_test.rb +79 -0
- data/test/unit/message_test.rb +179 -0
- data/test/unit/multi_command_test.rb +45 -0
- data/test/unit/opt_parse_plus_test.rb +218 -0
- data/test/unit/pantry_test.rb +82 -0
- data/test/unit/server_test.rb +166 -0
- data/test/unit/test_helper.rb +25 -0
- data/test/unit/ui_test.rb +58 -0
- metadata +389 -13
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::PublishSocket do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
Celluloid.boot
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:security) { Pantry::Communication::Security.new_client }
|
|
10
|
+
|
|
11
|
+
it "opens a ZMQ PubSocket, bound to host / port" do
|
|
12
|
+
Celluloid::ZMQ::PubSocket.any_instance.expects(:linger=).with(0)
|
|
13
|
+
Celluloid::ZMQ::PubSocket.any_instance.expects(:bind).with("tcp://host:1234")
|
|
14
|
+
|
|
15
|
+
socket = Pantry::Communication::PublishSocket.new("host", 1234, security)
|
|
16
|
+
socket.open
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::ReadingSocket do
|
|
4
|
+
|
|
5
|
+
class TestSocket < Pantry::Communication::ReadingSocket
|
|
6
|
+
attr_accessor :socket_impl
|
|
7
|
+
attr_accessor :has_source_header
|
|
8
|
+
|
|
9
|
+
def build_socket
|
|
10
|
+
@socket_impl
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def open_socket(socket)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def process_next_message
|
|
17
|
+
@socket = @socket_impl
|
|
18
|
+
super
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def has_source_header?
|
|
22
|
+
@has_source_header
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
before do
|
|
27
|
+
Celluloid.init
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
let(:security) { Pantry::Communication::Security.new_client }
|
|
31
|
+
|
|
32
|
+
it "builds messages and passes each message to a listener" do
|
|
33
|
+
zmq_socket = Class.new do
|
|
34
|
+
def read
|
|
35
|
+
@buffer ||= [
|
|
36
|
+
"stream",
|
|
37
|
+
{:type => "message_type", :from => "zee client", :to => "stream", :requires_response => false}.to_json,
|
|
38
|
+
"body part 1",
|
|
39
|
+
"body part 2"
|
|
40
|
+
]
|
|
41
|
+
@buffer.shift
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def more_parts?
|
|
45
|
+
@responses ||= [true, true, true, false]
|
|
46
|
+
@responses.shift
|
|
47
|
+
end
|
|
48
|
+
end.new
|
|
49
|
+
|
|
50
|
+
listener = Class.new do
|
|
51
|
+
attr_reader :handled_message
|
|
52
|
+
def handle_message(message)
|
|
53
|
+
@handled_message = message
|
|
54
|
+
end
|
|
55
|
+
end.new
|
|
56
|
+
|
|
57
|
+
reader = TestSocket.new("host", 1235, security)
|
|
58
|
+
reader.add_listener(listener)
|
|
59
|
+
reader.socket_impl = zmq_socket
|
|
60
|
+
|
|
61
|
+
reader.process_next_message
|
|
62
|
+
|
|
63
|
+
message = listener.handled_message
|
|
64
|
+
assert_equal "stream", message.to
|
|
65
|
+
assert_equal "zee client", message.from
|
|
66
|
+
assert_equal "message_type", message.type
|
|
67
|
+
assert_false message.requires_response?
|
|
68
|
+
assert_equal ["body part 1", "body part 2"], message.body
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "ignores the first token (ZMQ source identity) if configured to do so" do
|
|
72
|
+
zmq_socket = Class.new do
|
|
73
|
+
def read
|
|
74
|
+
@buffer ||= [
|
|
75
|
+
"Source",
|
|
76
|
+
"stream",
|
|
77
|
+
{:type => "message_type", :source => nil, :requires_response => false}.to_json,
|
|
78
|
+
"body part 1",
|
|
79
|
+
"body part 2"
|
|
80
|
+
]
|
|
81
|
+
@buffer.shift
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def more_parts?
|
|
85
|
+
@responses ||= [true, true, true, false]
|
|
86
|
+
@responses.shift
|
|
87
|
+
end
|
|
88
|
+
end.new
|
|
89
|
+
|
|
90
|
+
listener = Class.new do
|
|
91
|
+
attr_reader :handled_message
|
|
92
|
+
def handle_message(message)
|
|
93
|
+
@handled_message = message
|
|
94
|
+
end
|
|
95
|
+
end.new
|
|
96
|
+
|
|
97
|
+
reader = TestSocket.new("host", 1235, security)
|
|
98
|
+
reader.has_source_header = true
|
|
99
|
+
reader.add_listener(listener)
|
|
100
|
+
reader.socket_impl = zmq_socket
|
|
101
|
+
|
|
102
|
+
reader.process_next_message
|
|
103
|
+
|
|
104
|
+
message = listener.handled_message
|
|
105
|
+
assert_equal "message_type", message.type
|
|
106
|
+
assert_false message.requires_response?
|
|
107
|
+
assert_equal ["body part 1", "body part 2"], message.body
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::ReceiveSocket do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
Celluloid.init
|
|
7
|
+
|
|
8
|
+
Celluloid::ZMQ::RouterSocket.any_instance.stubs(:bind)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let(:security) { Pantry::Communication::Security.new_client }
|
|
12
|
+
|
|
13
|
+
it "binds and subscribes to the given host and port" do
|
|
14
|
+
Celluloid::ZMQ::RouterSocket.any_instance.expects(:bind).with("tcp://host:4567")
|
|
15
|
+
|
|
16
|
+
socket = Pantry::Communication::ReceiveSocket.new("host", 4567, security)
|
|
17
|
+
socket.open
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::Security::Authentication do
|
|
4
|
+
|
|
5
|
+
break unless Pantry::Communication::Security.curve_supported?
|
|
6
|
+
|
|
7
|
+
let(:key_store) { Pantry::Communication::Security::CurveKeyStore.new("server_keys") }
|
|
8
|
+
let(:auth) { Pantry::Communication::Security::Authentication.new(key_store) }
|
|
9
|
+
|
|
10
|
+
class BogusZapSocket
|
|
11
|
+
def initialize(client_key: nil, mechanism: "CURVE")
|
|
12
|
+
@client_key = client_key
|
|
13
|
+
@mechanism = mechanism
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def read
|
|
17
|
+
@buffer ||= [
|
|
18
|
+
"1.0",
|
|
19
|
+
"1",
|
|
20
|
+
"domain",
|
|
21
|
+
"127.0.0.1",
|
|
22
|
+
"identity",
|
|
23
|
+
@mechanism,
|
|
24
|
+
@client_key
|
|
25
|
+
]
|
|
26
|
+
@buffer.shift
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def more_parts?
|
|
30
|
+
@buffer.length > 0
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
attr_reader :message
|
|
34
|
+
def write(message)
|
|
35
|
+
@message = message
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def assert_response_valid(response)
|
|
40
|
+
assert_equal 6, response.length, "Response message wasn't long enough"
|
|
41
|
+
assert_equal "1.0", response[0], "Invalid version code"
|
|
42
|
+
assert_equal "1", response[1], "Invalid sequence in response"
|
|
43
|
+
assert_equal "", response[4] # username
|
|
44
|
+
assert_equal "", response[5] # metadata
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def assert_authorized(response)
|
|
48
|
+
assert_response_valid(response)
|
|
49
|
+
assert_equal "200", response[2], "Invalid response code"
|
|
50
|
+
assert_equal "OK", response[3], "Invalid response message"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def assert_not_authorized(response, expected_message)
|
|
54
|
+
assert_response_valid(response)
|
|
55
|
+
assert_equal "400", response[2], "Invalid response code"
|
|
56
|
+
assert_equal expected_message, response[3], "Invalid response message"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "authenticates a client with a known client public key" do
|
|
60
|
+
key_store.expects(:known_client?).with("client_key").returns(true)
|
|
61
|
+
zmq_socket = BogusZapSocket.new(client_key: "client_key")
|
|
62
|
+
|
|
63
|
+
auth.instance_variable_set("@socket", zmq_socket)
|
|
64
|
+
auth.process_next_request
|
|
65
|
+
|
|
66
|
+
assert_authorized(zmq_socket.message)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "rejects a client with an unknown public key" do
|
|
70
|
+
key_store.expects(:known_client?).with("client_key").returns(false)
|
|
71
|
+
zmq_socket = BogusZapSocket.new(client_key: "client_key")
|
|
72
|
+
|
|
73
|
+
auth.instance_variable_set("@socket", zmq_socket)
|
|
74
|
+
auth.process_next_request
|
|
75
|
+
|
|
76
|
+
assert_not_authorized(zmq_socket.message, "Unknown Client")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "rejects auth attempts for PLAIN security" do
|
|
80
|
+
zmq_socket = BogusZapSocket.new(client_key: "client_key", mechanism: "PLAIN")
|
|
81
|
+
|
|
82
|
+
auth.instance_variable_set("@socket", zmq_socket)
|
|
83
|
+
auth.process_next_request
|
|
84
|
+
|
|
85
|
+
assert_not_authorized(zmq_socket.message, "Invalid Mechanism")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "rejects auth attempts for NULL security" do
|
|
89
|
+
zmq_socket = BogusZapSocket.new(client_key: "client_key", mechanism: "NULL")
|
|
90
|
+
|
|
91
|
+
auth.instance_variable_set("@socket", zmq_socket)
|
|
92
|
+
auth.process_next_request
|
|
93
|
+
|
|
94
|
+
assert_not_authorized(zmq_socket.message, "Invalid Mechanism")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::Security::CurveKeyStore do
|
|
4
|
+
|
|
5
|
+
break unless Pantry::Communication::Security.curve_supported?
|
|
6
|
+
|
|
7
|
+
let(:key_store) { Pantry::Communication::Security::CurveKeyStore.new("my_keys") }
|
|
8
|
+
let(:curve_dir) { Pantry.root.join("security", "curve") }
|
|
9
|
+
|
|
10
|
+
def write_test_keys(known_client_keys = nil)
|
|
11
|
+
security_dir = Pantry.root.join("security", "curve")
|
|
12
|
+
keys_file = security_dir.join("my_keys.yml")
|
|
13
|
+
FileUtils.mkdir_p security_dir
|
|
14
|
+
File.open(keys_file, "w+") do |f|
|
|
15
|
+
f.write(YAML.dump({
|
|
16
|
+
"private_key" => "private key", "public_key" => "public key",
|
|
17
|
+
"server_public_key" => "server key",
|
|
18
|
+
"client_keys" => known_client_keys || ["client1", "client2"]
|
|
19
|
+
}))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
keys_file
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "sets up directory structure in Pantry.root for storing credentials" do
|
|
26
|
+
key_store
|
|
27
|
+
|
|
28
|
+
assert File.directory?(curve_dir), "Storage stucture not set up"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "generates a new set of public/private keys if none exist" do
|
|
32
|
+
key_store
|
|
33
|
+
|
|
34
|
+
assert File.exists?(curve_dir.join("my_keys.yml")), "Did not generate my keys"
|
|
35
|
+
|
|
36
|
+
keys = YAML.load_file(curve_dir.join("my_keys.yml"))
|
|
37
|
+
assert_not_nil keys["private_key"], "Did not generate a private key"
|
|
38
|
+
assert_not_nil keys["public_key"], "Did not generate a public key"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "generates a new set of public/private keys even if a server public key is set" do
|
|
42
|
+
keys_file = write_test_keys([])
|
|
43
|
+
File.open(keys_file, "w+") do |f|
|
|
44
|
+
f.write(YAML.dump({ "server_public_key" => "server key" }))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
key_store
|
|
48
|
+
|
|
49
|
+
full_keys = YAML.load_file(keys_file)
|
|
50
|
+
assert_equal "server key", full_keys["server_public_key"], "Chomped the pre-set server public key"
|
|
51
|
+
assert_not_nil full_keys["private_key"], "Did not write out a new private key"
|
|
52
|
+
assert_not_nil full_keys["public_key"], "Did not write out a new public key"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "can read back the public key" do
|
|
56
|
+
write_test_keys
|
|
57
|
+
assert_equal "public key", key_store.public_key
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "can read back the private key" do
|
|
61
|
+
write_test_keys
|
|
62
|
+
assert_equal "private key", key_store.private_key
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "can read back the server public key" do
|
|
66
|
+
write_test_keys
|
|
67
|
+
assert_equal "server key", key_store.server_public_key
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "encodes binary client public key for checking against known list" do
|
|
71
|
+
client_pub, priv = ZMQ::Util.curve_keypair
|
|
72
|
+
write_test_keys([client_pub])
|
|
73
|
+
|
|
74
|
+
decoded = FFI::MemoryPointer.from_string(' ' * 32)
|
|
75
|
+
binary_pub = LibZMQ.zmq_z85_decode(decoded, client_pub)
|
|
76
|
+
assert key_store.known_client?(binary_pub), "Should have matched binary with z85 encoded"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "stores the z85 encoded of the first client to auth to the server (no known clients)" do
|
|
80
|
+
write_test_keys([])
|
|
81
|
+
client_pub, _ = ZMQ::Util.curve_keypair
|
|
82
|
+
|
|
83
|
+
decoded = FFI::MemoryPointer.from_string(' ' * 32)
|
|
84
|
+
binary_pub = LibZMQ.zmq_z85_decode(decoded, client_pub)
|
|
85
|
+
assert key_store.known_client?(binary_pub), "Should have allowed the first Client"
|
|
86
|
+
|
|
87
|
+
all_keys = YAML.load_file(curve_dir.join("my_keys.yml"))
|
|
88
|
+
assert_equal [client_pub], all_keys["client_keys"]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "generates a new set of client keys, storing the new public and returning the lot" do
|
|
92
|
+
write_test_keys
|
|
93
|
+
|
|
94
|
+
new_client_keys = key_store.create_client
|
|
95
|
+
|
|
96
|
+
assert_equal "public key", new_client_keys[:server_public_key]
|
|
97
|
+
assert_not_nil new_client_keys[:public_key], "Didn't generate a client public key"
|
|
98
|
+
assert_not_nil new_client_keys[:private_key], "Didn't generate a client private key"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "stores the newly generated client public key in the key store" do
|
|
102
|
+
write_test_keys([])
|
|
103
|
+
|
|
104
|
+
new_client_keys = key_store.create_client
|
|
105
|
+
|
|
106
|
+
all_keys = YAML.load_file(curve_dir.join("my_keys.yml"))
|
|
107
|
+
assert_equal [new_client_keys[:public_key]], all_keys["client_keys"]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::Security::CurveSecurity do
|
|
4
|
+
|
|
5
|
+
break unless Pantry::Communication::Security.curve_supported?
|
|
6
|
+
|
|
7
|
+
fake_fs!
|
|
8
|
+
|
|
9
|
+
describe "Client" do
|
|
10
|
+
|
|
11
|
+
it "configures the client with the stored server's public key and client keys" do
|
|
12
|
+
client = Pantry::Communication::Security::CurveSecurity.client
|
|
13
|
+
|
|
14
|
+
curve_dir = Pantry.root.join("security", "curve")
|
|
15
|
+
client_keys = YAML.load_file(curve_dir.join("client_keys.yml"))
|
|
16
|
+
|
|
17
|
+
socket = mock
|
|
18
|
+
socket.expects(:set).with(::ZMQ::CURVE_SERVERKEY, client_keys["server_public_key"])
|
|
19
|
+
socket.expects(:set).with(::ZMQ::CURVE_PUBLICKEY, client_keys["public_key"])
|
|
20
|
+
socket.expects(:set).with(::ZMQ::CURVE_SECRETKEY, client_keys["private_key"])
|
|
21
|
+
|
|
22
|
+
client.configure_socket(socket)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "Server" do
|
|
28
|
+
|
|
29
|
+
it "configures the socket with the stored server private key" do
|
|
30
|
+
server = Pantry::Communication::Security::CurveSecurity.server
|
|
31
|
+
|
|
32
|
+
curve_dir = Pantry.root.join("security", "curve")
|
|
33
|
+
server_keys = YAML.load_file(curve_dir.join("server_keys.yml"))
|
|
34
|
+
|
|
35
|
+
socket = mock
|
|
36
|
+
socket.expects(:set).with(::ZMQ::CURVE_SERVER, 1)
|
|
37
|
+
socket.expects(:set).with(::ZMQ::CURVE_SECRETKEY, server_keys["private_key"])
|
|
38
|
+
|
|
39
|
+
server.configure_socket(socket)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::Security::NullSecurity do
|
|
4
|
+
|
|
5
|
+
it "exists" do
|
|
6
|
+
client = Pantry::Communication::Security::NullSecurity.new
|
|
7
|
+
assert_not_nil client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "does nothing for configuring sockets" do
|
|
11
|
+
client = Pantry::Communication::Security::NullSecurity.new
|
|
12
|
+
client.configure_socket("something")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::Security do
|
|
4
|
+
|
|
5
|
+
describe ".new_client" do
|
|
6
|
+
it "returns the Client side of the configured security model" do
|
|
7
|
+
config = Pantry::Config.new
|
|
8
|
+
config.security = nil
|
|
9
|
+
|
|
10
|
+
client_handler = Pantry::Communication::Security.new_client(config)
|
|
11
|
+
|
|
12
|
+
assert_not_nil client_handler
|
|
13
|
+
assert client_handler.is_a?(Pantry::Communication::Security::NullSecurity),
|
|
14
|
+
"Returned the wrong kind of client handler"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "raises if given security type is unknown" do
|
|
18
|
+
config = Pantry::Config.new
|
|
19
|
+
config.security = "--unknown--"
|
|
20
|
+
|
|
21
|
+
assert_raises(Pantry::Communication::Security::UnknownSecurityStrategyError) do
|
|
22
|
+
Pantry::Communication::Security.new_client(config)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe ".new_server" do
|
|
28
|
+
it "returns the Server side of the configured security model" do
|
|
29
|
+
config = Pantry::Config.new
|
|
30
|
+
config.security = nil
|
|
31
|
+
|
|
32
|
+
server_handler = Pantry::Communication::Security.new_server(config)
|
|
33
|
+
|
|
34
|
+
assert_not_nil server_handler
|
|
35
|
+
assert server_handler.is_a?(Pantry::Communication::Security::NullSecurity),
|
|
36
|
+
"Returned the wrong kind of server handler"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "raises if given security type is unknown" do
|
|
40
|
+
config = Pantry::Config.new
|
|
41
|
+
config.security = "--unknown--"
|
|
42
|
+
|
|
43
|
+
assert_raises(Pantry::Communication::Security::UnknownSecurityStrategyError) do
|
|
44
|
+
Pantry::Communication::Security.new_server(config)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|