ezmobius-nanite 0.4.0 → 0.4.1.1

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.
Files changed (60) hide show
  1. data/README.rdoc +70 -20
  2. data/Rakefile +1 -1
  3. data/bin/nanite-agent +34 -8
  4. data/bin/nanite-mapper +18 -8
  5. data/lib/nanite.rb +71 -0
  6. data/lib/nanite/actor.rb +60 -0
  7. data/lib/nanite/actor_registry.rb +24 -0
  8. data/lib/nanite/admin.rb +138 -0
  9. data/lib/nanite/agent.rb +250 -0
  10. data/lib/nanite/amqp.rb +47 -0
  11. data/lib/nanite/cluster.rb +203 -0
  12. data/lib/nanite/config.rb +102 -0
  13. data/lib/nanite/console.rb +39 -0
  14. data/lib/nanite/daemonize.rb +13 -0
  15. data/lib/nanite/dispatcher.rb +90 -0
  16. data/lib/nanite/identity.rb +16 -0
  17. data/lib/nanite/job.rb +104 -0
  18. data/lib/nanite/local_state.rb +34 -0
  19. data/lib/nanite/log.rb +64 -0
  20. data/lib/nanite/log/formatter.rb +39 -0
  21. data/lib/nanite/mapper.rb +277 -0
  22. data/lib/nanite/mapper_proxy.rb +56 -0
  23. data/lib/nanite/packets.rb +231 -0
  24. data/lib/nanite/pid_file.rb +52 -0
  25. data/lib/nanite/reaper.rb +38 -0
  26. data/lib/nanite/security/cached_certificate_store_proxy.rb +24 -0
  27. data/lib/nanite/security/certificate.rb +55 -0
  28. data/lib/nanite/security/certificate_cache.rb +66 -0
  29. data/lib/nanite/security/distinguished_name.rb +34 -0
  30. data/lib/nanite/security/encrypted_document.rb +46 -0
  31. data/lib/nanite/security/rsa_key_pair.rb +53 -0
  32. data/lib/nanite/security/secure_serializer.rb +67 -0
  33. data/lib/nanite/security/signature.rb +40 -0
  34. data/lib/nanite/security/static_certificate_store.rb +35 -0
  35. data/lib/nanite/security_provider.rb +47 -0
  36. data/lib/nanite/serializer.rb +52 -0
  37. data/lib/nanite/state.rb +164 -0
  38. data/lib/nanite/streaming.rb +125 -0
  39. data/lib/nanite/util.rb +51 -0
  40. data/spec/actor_registry_spec.rb +62 -0
  41. data/spec/actor_spec.rb +59 -0
  42. data/spec/agent_spec.rb +235 -0
  43. data/spec/cached_certificate_store_proxy_spec.rb +34 -0
  44. data/spec/certificate_cache_spec.rb +49 -0
  45. data/spec/certificate_spec.rb +27 -0
  46. data/spec/cluster_spec.rb +300 -0
  47. data/spec/dispatcher_spec.rb +136 -0
  48. data/spec/distinguished_name_spec.rb +24 -0
  49. data/spec/encrypted_document_spec.rb +21 -0
  50. data/spec/job_spec.rb +219 -0
  51. data/spec/local_state_spec.rb +112 -0
  52. data/spec/packet_spec.rb +218 -0
  53. data/spec/rsa_key_pair_spec.rb +33 -0
  54. data/spec/secure_serializer_spec.rb +41 -0
  55. data/spec/serializer_spec.rb +107 -0
  56. data/spec/signature_spec.rb +30 -0
  57. data/spec/spec_helper.rb +23 -0
  58. data/spec/static_certificate_store_spec.rb +30 -0
  59. data/spec/util_spec.rb +63 -0
  60. metadata +63 -2
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Nanite::RsaKeyPair do
4
+
5
+ before(:all) do
6
+ @pair = Nanite::RsaKeyPair.new
7
+ end
8
+
9
+ it 'should create a private and a public keys' do
10
+ @pair.has_private?.should be_true
11
+ end
12
+
13
+ it 'should strip out private key in to_public' do
14
+ @pair.to_public.has_private?.should be_false
15
+ end
16
+
17
+ it 'should save' do
18
+ filename = File.join(File.dirname(__FILE__), "key.pem")
19
+ @pair.save(filename)
20
+ File.size(filename).should be > 0
21
+ File.delete(filename)
22
+ end
23
+
24
+ it 'should load' do
25
+ filename = File.join(File.dirname(__FILE__), "key.pem")
26
+ @pair.save(filename)
27
+ key = Nanite::RsaKeyPair.load(filename)
28
+ File.delete(filename)
29
+ key.should_not be_nil
30
+ key.data.should == @pair.data
31
+ end
32
+
33
+ end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ module Nanite
4
+
5
+ # Add the ability to compare pings for test purposes
6
+ class Ping
7
+ def ==(other)
8
+ @status == other.status && @identity == other.identity
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+ describe Nanite::SecureSerializer do
15
+
16
+ include SpecHelpers
17
+
18
+ before(:all) do
19
+ @certificate, @key = issue_cert
20
+ @store = Nanite::StaticCertificateStore.new(@certificate, @certificate)
21
+ @identity = "id"
22
+ @data = Nanite::Ping.new("Test", 0.5)
23
+ end
24
+
25
+ it 'should raise when not initialized' do
26
+ lambda { Nanite::SecureSerializer.dump(@data) }.should raise_error
27
+ end
28
+
29
+ it 'should deserialize signed data' do
30
+ Nanite::SecureSerializer.init(@identity, @certificate, @key, @store, false)
31
+ data = Nanite::SecureSerializer.dump(@data)
32
+ Nanite::SecureSerializer.load(data).should == @data
33
+ end
34
+
35
+ it 'should deserialize encrypted data' do
36
+ Nanite::SecureSerializer.init(@identity, @certificate, @key, @store, true)
37
+ data = Nanite::SecureSerializer.dump(@data)
38
+ Nanite::SecureSerializer.load(data).should == @data
39
+ end
40
+
41
+ end
@@ -0,0 +1,107 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Nanite::Serializer do
4
+
5
+ describe "Format" do
6
+
7
+ it "supports JSON format" do
8
+ [ :json, "json" ].each do |format|
9
+ serializer = Nanite::Serializer.new(format)
10
+ serializer.instance_eval { @serializers.first }.should == JSON
11
+ end
12
+ end
13
+
14
+ it "supports Marshal format" do
15
+ [ :marshal, "marshal" ].each do |format|
16
+ serializer = Nanite::Serializer.new(format)
17
+ serializer.instance_eval { @serializers.first }.should == Marshal
18
+ end
19
+ end
20
+
21
+ it "supports YAML format" do
22
+ [ :yaml, "yaml" ].each do |format|
23
+ serializer = Nanite::Serializer.new(format)
24
+ serializer.instance_eval { @serializers.first }.should == YAML
25
+ end
26
+ end
27
+
28
+ it "should default to Marshal format if not specified" do
29
+ serializer = Nanite::Serializer.new
30
+ serializer.instance_eval { @serializers.first }.should == Marshal
31
+ serializer = Nanite::Serializer.new(nil)
32
+ serializer.instance_eval { @serializers.first }.should == Marshal
33
+ end
34
+
35
+ end # Format
36
+
37
+ describe "Serialization of Packet" do
38
+
39
+ it "should cascade through available serializers" do
40
+ serializer = Nanite::Serializer.new
41
+ serializer.should_receive(:cascade_serializers).with(:dump, "hello")
42
+ serializer.dump("hello")
43
+ end
44
+
45
+ it "should try all three supported formats (JSON, Marshal, YAML)" do
46
+ JSON.should_receive(:dump).with("hello").and_raise(StandardError)
47
+ Marshal.should_receive(:dump).with("hello").and_raise(StandardError)
48
+ YAML.should_receive(:dump).with("hello").and_raise(StandardError)
49
+
50
+ lambda { Nanite::Serializer.new.dump("hello") }.should raise_error(Nanite::Serializer::SerializationError)
51
+ end
52
+
53
+ it "should raise SerializationError if packet could not be serialized" do
54
+ JSON.should_receive(:dump).with("hello").and_raise(StandardError)
55
+ Marshal.should_receive(:dump).with("hello").and_raise(StandardError)
56
+ YAML.should_receive(:dump).with("hello").and_raise(StandardError)
57
+
58
+ serializer = Nanite::Serializer.new
59
+ lambda { serializer.dump("hello") }.should raise_error(Nanite::Serializer::SerializationError)
60
+ end
61
+
62
+ it "should return serialized packet" do
63
+ serialized_packet = mock("Packet")
64
+ Marshal.should_receive(:dump).with("hello").and_return(serialized_packet)
65
+
66
+ serializer = Nanite::Serializer.new(:marshal)
67
+ serializer.dump("hello").should == serialized_packet
68
+ end
69
+
70
+ end # Serialization of Packet
71
+
72
+ describe "De-Serialization of Packet" do
73
+
74
+ it "should cascade through available serializers" do
75
+ serializer = Nanite::Serializer.new
76
+ serializer.should_receive(:cascade_serializers).with(:load, "olleh")
77
+ serializer.load("olleh")
78
+ end
79
+
80
+ it "should try all three supported formats (JSON, Marshal, YAML)" do
81
+ JSON.should_receive(:load).with("olleh").and_raise(StandardError)
82
+ Marshal.should_receive(:load).with("olleh").and_raise(StandardError)
83
+ YAML.should_receive(:load).with("olleh").and_raise(StandardError)
84
+
85
+ lambda { Nanite::Serializer.new.load("olleh") }.should raise_error(Nanite::Serializer::SerializationError)
86
+ end
87
+
88
+ it "should raise SerializationError if packet could not be de-serialized" do
89
+ JSON.should_receive(:load).with("olleh").and_raise(StandardError)
90
+ Marshal.should_receive(:load).with("olleh").and_raise(StandardError)
91
+ YAML.should_receive(:load).with("olleh").and_raise(StandardError)
92
+
93
+ serializer = Nanite::Serializer.new
94
+ lambda { serializer.load("olleh") }.should raise_error(Nanite::Serializer::SerializationError)
95
+ end
96
+
97
+ it "should return de-serialized packet" do
98
+ deserialized_packet = mock("Packet")
99
+ Marshal.should_receive(:load).with("olleh").and_return(deserialized_packet)
100
+
101
+ serializer = Nanite::Serializer.new(:marshal)
102
+ serializer.load("olleh").should == deserialized_packet
103
+ end
104
+
105
+ end # De-Serialization of Packet
106
+
107
+ end # Nanite::Serializer
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Nanite::Signature do
4
+
5
+ include SpecHelpers
6
+
7
+ before(:all) do
8
+ @test_data = "Test Data"
9
+ @cert, @key = issue_cert
10
+ @sig = Nanite::Signature.new(@test_data, @cert, @key)
11
+ end
12
+
13
+ it 'should create signed data' do
14
+ @sig.to_s.should_not be_empty
15
+ end
16
+
17
+ it 'should verify the signature' do
18
+ cert2, key2 = issue_cert
19
+
20
+ @sig.should be_a_match(@cert)
21
+ @sig.should_not be_a_match(cert2)
22
+ end
23
+
24
+ it 'should load from serialized signature' do
25
+ sig2 = Nanite::Signature.from_data(@sig.data)
26
+ sig2.should_not be_nil
27
+ sig2.should be_a_match(@cert)
28
+ end
29
+
30
+ end
@@ -0,0 +1,23 @@
1
+ $TESTING=true
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'rubygems'
5
+ require 'spec'
6
+ require 'nanite'
7
+
8
+ module SpecHelpers
9
+
10
+ # Create test certificate
11
+ def issue_cert
12
+ test_dn = { 'C' => 'US',
13
+ 'ST' => 'California',
14
+ 'L' => 'Santa Barbara',
15
+ 'O' => 'Nanite',
16
+ 'OU' => 'Certification Services',
17
+ 'CN' => 'Nanite test' }
18
+ dn = Nanite::DistinguishedName.new(test_dn)
19
+ key = Nanite::RsaKeyPair.new
20
+ [ Nanite::Certificate.new(key, dn, dn), key ]
21
+ end
22
+
23
+ end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Nanite::StaticCertificateStore do
4
+
5
+ include SpecHelpers
6
+
7
+ before(:all) do
8
+ @signer, key = issue_cert
9
+ @recipient, key = issue_cert
10
+ @cert, @key = issue_cert
11
+ @store = Nanite::StaticCertificateStore.new(@signer, @recipient)
12
+ end
13
+
14
+ it 'should not raise when passed nil objects' do
15
+ res = nil
16
+ lambda { res = @store.get_signer(nil) }.should_not raise_error
17
+ res.should == [ @signer ]
18
+ lambda { res = @store.get_recipients(nil) }.should_not raise_error
19
+ res.should == [ @recipient ]
20
+ end
21
+
22
+ it 'should return signer certificates' do
23
+ @store.get_signer('anything').should == [ @signer ]
24
+ end
25
+
26
+ it 'should return recipient certificates' do
27
+ @store.get_recipients('anything').should == [ @recipient ]
28
+ end
29
+
30
+ end
data/spec/util_spec.rb ADDED
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe String do
4
+
5
+ describe ".snake_case" do
6
+
7
+ it "should downcase single word" do
8
+ ["FOO", "Foo", "foo"].each do |w|
9
+ w.snake_case.should == "foo"
10
+ end
11
+ end
12
+
13
+ it "should not separate numbers from end of word" do
14
+ ["Foo1234", "foo1234"].each do |w|
15
+ w.snake_case.should == "foo1234"
16
+ end
17
+ end
18
+
19
+ it "should separate numbers from word it starts with uppercase letter" do
20
+ "1234Foo".snake_case.should == "1234_foo"
21
+ end
22
+
23
+ it "should not separate numbers from word starts with lowercase letter" do
24
+ "1234foo".snake_case.should == "1234foo"
25
+ end
26
+
27
+ it "should downcase camel-cased words and connect with underscore" do
28
+ ["FooBar", "fooBar"].each do |w|
29
+ w.snake_case.should == "foo_bar"
30
+ end
31
+ end
32
+
33
+ it "should start new word with uppercase letter before lower case letter" do
34
+ ["FooBARBaz", "fooBARBaz"].each do |w|
35
+ w.snake_case.should == "foo_bar_baz"
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ describe ".to_const_path" do
42
+
43
+ it "should snake-case the string" do
44
+ str = "hello"
45
+ str.should_receive(:snake_case).and_return("snake-cased hello")
46
+ str.to_const_path
47
+ end
48
+
49
+ it "should leave (snake-cased) string without '::' unchanged" do
50
+ "hello".to_const_path.should == "hello"
51
+ end
52
+
53
+ it "should replace single '::' with '/'" do
54
+ "hello::world".to_const_path.should == "hello/world"
55
+ end
56
+
57
+ it "should replace multiple '::' with '/'" do
58
+ "hello::nanite::world".to_const_path.should == "hello/nanite/world"
59
+ end
60
+
61
+ end
62
+
63
+ end # String
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezmobius-nanite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-25 00:00:00 -08:00
12
+ date: 2009-05-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,6 +39,67 @@ files:
39
39
  - README.rdoc
40
40
  - Rakefile
41
41
  - TODO
42
+ - lib/nanite.rb
43
+ - lib/nanite
44
+ - lib/nanite/streaming.rb
45
+ - lib/nanite/serializer.rb
46
+ - lib/nanite/pid_file.rb
47
+ - lib/nanite/mapper.rb
48
+ - lib/nanite/daemonize.rb
49
+ - lib/nanite/mapper_proxy.rb
50
+ - lib/nanite/security
51
+ - lib/nanite/security/distinguished_name.rb
52
+ - lib/nanite/security/secure_serializer.rb
53
+ - lib/nanite/security/certificate_cache.rb
54
+ - lib/nanite/security/signature.rb
55
+ - lib/nanite/security/certificate.rb
56
+ - lib/nanite/security/encrypted_document.rb
57
+ - lib/nanite/security/rsa_key_pair.rb
58
+ - lib/nanite/security/static_certificate_store.rb
59
+ - lib/nanite/security/cached_certificate_store_proxy.rb
60
+ - lib/nanite/config.rb
61
+ - lib/nanite/util.rb
62
+ - lib/nanite/log
63
+ - lib/nanite/log/formatter.rb
64
+ - lib/nanite/state.rb
65
+ - lib/nanite/cluster.rb
66
+ - lib/nanite/dispatcher.rb
67
+ - lib/nanite/security_provider.rb
68
+ - lib/nanite/packets.rb
69
+ - lib/nanite/actor.rb
70
+ - lib/nanite/console.rb
71
+ - lib/nanite/admin.rb
72
+ - lib/nanite/amqp.rb
73
+ - lib/nanite/agent.rb
74
+ - lib/nanite/local_state.rb
75
+ - lib/nanite/identity.rb
76
+ - lib/nanite/actor_registry.rb
77
+ - lib/nanite/log.rb
78
+ - lib/nanite/reaper.rb
79
+ - lib/nanite/job.rb
80
+ - bin/nanite-agent
81
+ - bin/nanite-admin
82
+ - bin/nanite-mapper
83
+ - spec/util_spec.rb
84
+ - spec/encrypted_document_spec.rb
85
+ - spec/agent_spec.rb
86
+ - spec/certificate_cache_spec.rb
87
+ - spec/cached_certificate_store_proxy_spec.rb
88
+ - spec/dispatcher_spec.rb
89
+ - spec/rsa_key_pair_spec.rb
90
+ - spec/cluster_spec.rb
91
+ - spec/spec_helper.rb
92
+ - spec/actor_registry_spec.rb
93
+ - spec/actor_spec.rb
94
+ - spec/packet_spec.rb
95
+ - spec/local_state_spec.rb
96
+ - spec/static_certificate_store_spec.rb
97
+ - spec/job_spec.rb
98
+ - spec/signature_spec.rb
99
+ - spec/secure_serializer_spec.rb
100
+ - spec/serializer_spec.rb
101
+ - spec/certificate_spec.rb
102
+ - spec/distinguished_name_spec.rb
42
103
  has_rdoc: true
43
104
  homepage: http://github.com/ezmobius/nanite
44
105
  post_install_message: