siffer 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +65 -0
  3. data/Rakefile +64 -0
  4. data/bin/siffer +71 -0
  5. data/doc/SIF ImplementationSpecification.pdf +0 -0
  6. data/doc/rdoc/classes/Siffer.html +374 -0
  7. data/doc/rdoc/classes/Siffer/Agent.html +296 -0
  8. data/doc/rdoc/classes/Siffer/Container.html +286 -0
  9. data/doc/rdoc/classes/Siffer/Messages.html +141 -0
  10. data/doc/rdoc/classes/Siffer/Messages/Ack.html +216 -0
  11. data/doc/rdoc/classes/Siffer/Messages/Acl.html +160 -0
  12. data/doc/rdoc/classes/Siffer/Messages/Error.html +248 -0
  13. data/doc/rdoc/classes/Siffer/Messages/Message.html +359 -0
  14. data/doc/rdoc/classes/Siffer/Messages/Message/Header.html +181 -0
  15. data/doc/rdoc/classes/Siffer/Messages/Register.html +257 -0
  16. data/doc/rdoc/classes/Siffer/Messages/RequestBody.html +300 -0
  17. data/doc/rdoc/classes/Siffer/Messages/Status.html +269 -0
  18. data/doc/rdoc/classes/Siffer/Messaging.html +331 -0
  19. data/doc/rdoc/classes/Siffer/Protocol.html +388 -0
  20. data/doc/rdoc/classes/Siffer/Protocol/NonPostRequest.html +111 -0
  21. data/doc/rdoc/classes/Siffer/Protocol/UnknownPath.html +111 -0
  22. data/doc/rdoc/classes/Siffer/Registration.html +391 -0
  23. data/doc/rdoc/classes/Siffer/Request.html +209 -0
  24. data/doc/rdoc/classes/Siffer/RequestLogger.html +211 -0
  25. data/doc/rdoc/classes/Siffer/Response.html +182 -0
  26. data/doc/rdoc/classes/Siffer/Server.html +242 -0
  27. data/doc/rdoc/created.rid +1 -0
  28. data/doc/rdoc/files/LICENSE.html +129 -0
  29. data/doc/rdoc/files/README_rdoc.html +184 -0
  30. data/doc/rdoc/files/lib/agent_rb.html +101 -0
  31. data/doc/rdoc/files/lib/container_rb.html +108 -0
  32. data/doc/rdoc/files/lib/messages/ack_rb.html +101 -0
  33. data/doc/rdoc/files/lib/messages/acl_rb.html +101 -0
  34. data/doc/rdoc/files/lib/messages/error_rb.html +101 -0
  35. data/doc/rdoc/files/lib/messages/message_rb.html +101 -0
  36. data/doc/rdoc/files/lib/messages/register_rb.html +101 -0
  37. data/doc/rdoc/files/lib/messages/request_body_rb.html +101 -0
  38. data/doc/rdoc/files/lib/messages/status_rb.html +101 -0
  39. data/doc/rdoc/files/lib/messages_rb.html +114 -0
  40. data/doc/rdoc/files/lib/messaging_rb.html +101 -0
  41. data/doc/rdoc/files/lib/protocol_rb.html +101 -0
  42. data/doc/rdoc/files/lib/registration_rb.html +101 -0
  43. data/doc/rdoc/files/lib/request_logger_rb.html +101 -0
  44. data/doc/rdoc/files/lib/request_rb.html +101 -0
  45. data/doc/rdoc/files/lib/response_rb.html +101 -0
  46. data/doc/rdoc/files/lib/server_rb.html +101 -0
  47. data/doc/rdoc/files/lib/siffer_rb.html +115 -0
  48. data/doc/rdoc/fr_class_index.html +47 -0
  49. data/doc/rdoc/fr_file_index.html +46 -0
  50. data/doc/rdoc/fr_method_index.html +96 -0
  51. data/doc/rdoc/index.html +24 -0
  52. data/doc/rdoc/rdoc-style.css +208 -0
  53. data/lib/agent.rb +43 -0
  54. data/lib/container.rb +96 -0
  55. data/lib/messages.rb +7 -0
  56. data/lib/messages/ack.rb +43 -0
  57. data/lib/messages/acl.rb +25 -0
  58. data/lib/messages/error.rb +174 -0
  59. data/lib/messages/message.rb +71 -0
  60. data/lib/messages/register.rb +60 -0
  61. data/lib/messages/request_body.rb +66 -0
  62. data/lib/messages/status.rb +55 -0
  63. data/lib/messaging.rb +96 -0
  64. data/lib/protocol.rb +159 -0
  65. data/lib/registration.rb +87 -0
  66. data/lib/request.rb +25 -0
  67. data/lib/request_logger.rb +31 -0
  68. data/lib/response.rb +26 -0
  69. data/lib/server.rb +40 -0
  70. data/lib/siffer.rb +44 -0
  71. data/spec/agent_spec.rb +53 -0
  72. data/spec/cli_spec.rb +40 -0
  73. data/spec/container_spec.rb +103 -0
  74. data/spec/default_agent +6 -0
  75. data/spec/default_server +5 -0
  76. data/spec/message_specs/ack_spec.rb +28 -0
  77. data/spec/message_specs/error_spec.rb +24 -0
  78. data/spec/message_specs/header_spec.rb +25 -0
  79. data/spec/message_specs/message_spec.rb +57 -0
  80. data/spec/message_specs/register_spec.rb +86 -0
  81. data/spec/message_specs/request_body_spec.rb +58 -0
  82. data/spec/message_specs/status_spec.rb +25 -0
  83. data/spec/messaging_spec.rb +88 -0
  84. data/spec/protocol_spec.rb +49 -0
  85. data/spec/registration_spec.rb +33 -0
  86. data/spec/request_logger_spec.rb +15 -0
  87. data/spec/request_spec.rb +10 -0
  88. data/spec/response_spec.rb +24 -0
  89. data/spec/server_spec.rb +35 -0
  90. data/spec/spec_helper.rb +26 -0
  91. metadata +191 -0
@@ -0,0 +1,40 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe "Siffer Command Line" do
4
+
5
+ before(:each) do
6
+ @options = eval `./bin/siffer start spec/default_agent -e test -d`
7
+ end
8
+
9
+ it "should specify config" do
10
+ @options.keys.should include(:config)
11
+ config = @options[:config]
12
+ config.keys.should include("agent")
13
+ config["agent"].keys.should include("host")
14
+ config["agent"].keys.should include("port")
15
+ config["agent"].keys.should include("name")
16
+ end
17
+
18
+ it "should specify component" do
19
+ @options[:component].should == "spec/default_agent"
20
+ end
21
+
22
+ it "should specify log directory" do
23
+ cwd = File.expand_path(File.dirname(__FILE__))
24
+ @options[:log].should == File.join(cwd,"default_agent.log")
25
+ end
26
+
27
+ it "should specify an environment" do
28
+ @options[:environment].should == "test"
29
+ end
30
+
31
+ it "should specify daemonization" do
32
+ @options[:daemonize].should == true
33
+ end
34
+
35
+ it "should specify pid" do
36
+ cwd = File.expand_path(File.dirname(__FILE__))
37
+ @options[:pid].should == File.join(cwd,"default_agent.pid")
38
+ end
39
+
40
+ end
@@ -0,0 +1,103 @@
1
+ require File.join(File.dirname(__FILE__),"spec_helper")
2
+
3
+ describe Siffer::Container do
4
+ it "should require an environment" do
5
+ lambda {
6
+ container = Siffer::Container.new(:config => {"name" => 'test'})
7
+ }.should raise_error("Environment missing")
8
+ end
9
+
10
+ it "should require component configuration" do
11
+ lambda {
12
+ container = Siffer::Container.new
13
+ }.should raise_error("Component Configuration missing")
14
+ end
15
+ end
16
+
17
+ describe Siffer::Container, "options" do
18
+
19
+ before(:each) do
20
+ @options = {
21
+ :environment => 'test',
22
+ :daemonize => true,
23
+ :pid => 'default_agent.pid',
24
+ :component => 'default_agent',
25
+ :log => 'default_agent.log',
26
+ :config => {
27
+ "agent" => {
28
+ "name" => 'Default Agent',
29
+ "host" => 'localhost',
30
+ "port" => 8200,
31
+ "admin" => 'http://localhost:3000/',
32
+ "servers" => 'http://localhost:4001/'
33
+ }
34
+ }
35
+ }
36
+ @container = Siffer::Container.new(@options)
37
+ end
38
+
39
+ it "should create component from config options" do
40
+ @container.component.should be_instance_of(Siffer::Agent)
41
+ @options[:config]["server"] = @options[:config].delete("agent")
42
+ @container = Siffer::Container.new(@options)
43
+ @container.component.should be_instance_of(Siffer::Server)
44
+ end
45
+
46
+ it "should create component that responds to call" do
47
+ @container.component.should respond_to("call")
48
+ end
49
+
50
+ it "should set name from options" do
51
+ @container.name.should == "Default Agent"
52
+ end
53
+
54
+ it "should set host from options" do
55
+ @container.host.should == "localhost"
56
+ end
57
+
58
+ it "should set port from options" do
59
+ @container.port.should == 8200
60
+ end
61
+
62
+ it "should set daemonization" do
63
+ @container.should be_daemonized
64
+ end
65
+
66
+ it "should set log file" do
67
+ @container.log.should == "default_agent.log"
68
+ end
69
+
70
+ it "should set pid file" do
71
+ @container.pid.should == "default_agent.pid"
72
+ end
73
+
74
+ end
75
+
76
+ describe Siffer::Container, "runtime" do
77
+
78
+ before(:each) do
79
+ @options = {
80
+ :environment => 'test',
81
+ :daemonize => true,
82
+ :pid => 'default_agent.pid',
83
+ :component => 'default_agent',
84
+ :log => 'default_agent.log',
85
+ :config => {
86
+ "agent" => {
87
+ "name" => 'Default Agent',
88
+ "host" => 'localhost',
89
+ "port" => 8210,
90
+ "admin" => 'http://localhost:3000/',
91
+ "servers" => 'http://localhost:4001/'
92
+ }
93
+ }
94
+ }
95
+ @container = Siffer::Container.new(@options)
96
+ end
97
+
98
+ it "should create a pid file" do
99
+ @container.send("write_pid_file")
100
+ File.exists?("default_agent.pid").should == true
101
+ File.delete("default_agent.pid") if File.exists?("default_agent.pid")
102
+ end
103
+ end
@@ -0,0 +1,6 @@
1
+ agent:
2
+ name: 'Clints Agent'
3
+ host: 'localhost'
4
+ port: 4002
5
+ servers: 'http://localhost:4001/'
6
+ admin: 'http://localhost:3000'
@@ -0,0 +1,5 @@
1
+ server:
2
+ name: 'Clints Server'
3
+ host: 'localhost'
4
+ port: 4001
5
+ admin: 'http://localhost:3000'
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+
3
+ include Siffer::Messages
4
+
5
+ describe Ack do
6
+ before(:each) do
7
+ @msg = Message.new("source")
8
+ @ack = Ack.new("ack-msg", @msg)
9
+ end
10
+
11
+ it "should have an original message" do
12
+ @ack.original_msg.should be(@msg)
13
+ end
14
+
15
+ it "should allow an error to be added through options" do
16
+ ack = Ack.new("ack-msg",Message.new("source"),:error => Error.new(3,2))
17
+ ack.read.should match(/SIF_Error/)
18
+ ack.read.should match(/SIF_Category>3<\/SIF_Category>/)
19
+ ack.read.should match(/SIF_Code>2<\/SIF_Code>/)
20
+ end
21
+
22
+ it "should allow a status to be added through options" do
23
+ ack = Ack.new("ack-msg",Message.new("source"), :status => Status.success)
24
+ ack.read.should match(/SIF_Status/)
25
+ ack.read.should match(/SIF_Code>0</)
26
+ ack.read.should match(/SIF_Description>Success</)
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__),"..","spec_helper")
2
+
3
+ describe Siffer::Messages::Error do
4
+
5
+ it "should properly match the SIF Spec (random crap test)" do
6
+ error = Siffer::Messages::Error.new(8,3)
7
+ error.category.should == "Request and Response"
8
+ error.code.should == "Invalid object"
9
+
10
+ error = Siffer::Messages::Error.new(5,2)
11
+ error.category.should == "Registration"
12
+ error.code.should == "The SIF_SourceId is invalid"
13
+ end
14
+
15
+ it "should output xml through read method" do
16
+ error = Siffer::Messages::Error.new(4,8, "Added Extended")
17
+ error.read.should match(/SIF_Error/)
18
+ error.read.should match(/SIF_Category>4<\/SIF_Category/)
19
+ error.read.should match(/SIF_Code>8<\/SIF_Code/)
20
+ error.read.should match(/SIF_Desc>#{error.code}<\/SIF_Desc/)
21
+ error.read.should match(/SIF_ExtendedDesc>Added Extended<\/SIF_Extended/)
22
+ end
23
+
24
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+
3
+ include Siffer::Messages
4
+
5
+ describe Message::Header do
6
+
7
+ before(:each) do
8
+ @header = Message::Header.new "source_name"
9
+ end
10
+
11
+ it "should have a timestamp" do
12
+ @header.timestamp.should_not be_nil
13
+ end
14
+
15
+ it "should have a GUID/UUID" do
16
+ @header.msg_id.should_not be_nil
17
+ end
18
+
19
+ it "should have a GUID/UUID that matches SIF textual format" do
20
+ @header = Message::Header.new "source_name"
21
+ @header.msg_id.should_not match(/^[a-z\-\s]+$/)
22
+ @header.msg_id.should match(/^[A-Z0-9]+$/)
23
+ end
24
+
25
+ end
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+
3
+ include Siffer::Messages
4
+
5
+ describe Message do
6
+
7
+ before(:each) do
8
+ @message = Message.new("source_name")
9
+ end
10
+
11
+ it "should have SIF version" do
12
+ @message.version.should == Siffer.sif_version
13
+ end
14
+
15
+ it "should have SIF xml namespace" do
16
+ @message.xmlns.should == Siffer.sif_xmlns
17
+ end
18
+
19
+ it "should have a header" do
20
+ @message.header.should_not be_nil
21
+ @message.header.source_id.should == "source_name"
22
+ end
23
+
24
+ it "should raise exception for missing source identifier" do
25
+ lambda{
26
+ @message = Message.new(nil)
27
+ }.should raise_error("Source not provided.")
28
+ end
29
+
30
+ it "should render SIF compliant instruct line" do
31
+ @message.content.should match(/<SIF_Message/)
32
+ @message.content.should match(/xmlns="#{Siffer.sif_xmlns}"/)
33
+ @message.content.should match(/version="#{Siffer.sif_version}"/)
34
+ @message.content.should match(/<\/SIF_Message>/)
35
+ end
36
+
37
+ it "should respond to 'to_str'" do
38
+ @message.should respond_to("to_str")
39
+ @message.to_str.should match(/SIF_Message/)
40
+ end
41
+
42
+ it "should respond to 'read'" do
43
+ @message.should respond_to("read")
44
+ @message.read.should match(/SIF_Message/)
45
+ end
46
+
47
+ it "should allow xmlns override" do
48
+ @message = Message.new("source", :xmlns => "bogus")
49
+ @message.xmlns.should == "bogus"
50
+ end
51
+
52
+ it "should allow version override" do
53
+ @message = Message.new("source", :version => '9.9')
54
+ @message.version.should == "9.9"
55
+ end
56
+
57
+ end
@@ -0,0 +1,86 @@
1
+ require File.join(File.dirname(__FILE__),"..","spec_helper")
2
+
3
+ include Siffer::Messages
4
+
5
+ describe Siffer::Messages::Register do
6
+
7
+ it "should reqiure a name of the Registering Agent" do
8
+ lambda {
9
+ reg = Register.new("source",nil)
10
+ }.should raise_error("Agent name required")
11
+ end
12
+
13
+ end
14
+
15
+ describe Siffer::Messages::Register, "defaults" do
16
+
17
+ before(:each) do
18
+ @reg = Register.new("source", "agent")
19
+ end
20
+
21
+ it "should default to Siffer.version version" do
22
+ @reg.version.should == Siffer.sif_version
23
+ end
24
+
25
+ it "should defaut to Pull mode" do
26
+ @reg.mode.should == 'Pull'
27
+ end
28
+
29
+ it "should default to 1024 max buffer" do
30
+ @reg.max_buffer.should == 1024
31
+ end
32
+
33
+ it "should default vendor to h3o(software)" do
34
+ @reg.vendor.should == Siffer.vendor
35
+ end
36
+
37
+ end
38
+
39
+ describe Siffer::Messages::Register, "overrides" do
40
+ it "should allow sif version override" do
41
+ reg = Register.new("source","agent",:version => '9.9')
42
+ reg.version.should == '9.9'
43
+ end
44
+
45
+ it "should allow max_buffer override" do
46
+ reg = Register.new("source", "agent", :max_buffer => 2048)
47
+ reg.max_buffer.should == 2048
48
+ end
49
+
50
+ it "should allow mode override" do
51
+ reg = Register.new("source", "agent", :mode => 'Push')
52
+ reg.mode.should == "Push"
53
+ end
54
+ end
55
+
56
+ describe Siffer::Messages::Register, "content" do
57
+
58
+ before(:each) do
59
+ @reg = Register.new("source", "agent")
60
+ end
61
+
62
+ it "should have max buffer size" do
63
+ @reg.content.should match(/SIF_MaxBufferSize>1024<\/SIF_MaxBufferSize/)
64
+ end
65
+
66
+ it "should have agent name" do
67
+ @reg.content.should match(/SIF_Name>agent<\/SIF_Name>/)
68
+ end
69
+
70
+ it "should parse name from body" do
71
+ Register.parse(@reg.content).name.should == "agent"
72
+ end
73
+
74
+ it "should parse SIF version from body" do
75
+ Register.parse(@reg.content).version.should == Siffer.sif_version
76
+ end
77
+
78
+ it "should parse max buffer size from body" do
79
+ Register.parse(@reg.content).max_buffer.should == 1024
80
+ end
81
+
82
+ it "should parse mode from body" do
83
+ Register.parse(@reg.content).mode.should == "Pull"
84
+ end
85
+
86
+ end
@@ -0,0 +1,58 @@
1
+ require File.join(File.dirname(__FILE__),"..","spec_helper")
2
+
3
+ describe Siffer::Messages::RequestBody do
4
+
5
+ before(:each) do
6
+ @xml = Siffer::Messages::Register.new("Clints Agent", "test server name")
7
+ @msg = Siffer::Messages::RequestBody.parse(@xml)
8
+ end
9
+
10
+ it "should require 'read'able input" do
11
+ lambda {
12
+ Siffer::Messages::RequestBody.parse([])
13
+ }.should raise_error("Unable to read Xml")
14
+ end
15
+
16
+ it "should allow StringIO input" do
17
+ lambda {
18
+ Siffer::Messages::RequestBody.parse(StringIO.new(@xml))
19
+ }.should_not raise_error
20
+ end
21
+
22
+ it "should allow string input" do
23
+ lambda {
24
+ Siffer::Messages::RequestBody.parse(@xml)
25
+ }.should_not raise_error
26
+ end
27
+
28
+ it "should parse message type" do
29
+ @msg.type.should == "Register"
30
+ end
31
+
32
+ it "should parse message type within SystemControl" do
33
+ ping = "<SIF_Message><SIF_SystemControl><SIF_Ping /></SIF_SystemControl></SIF_Message>"
34
+ @msg = Siffer::Messages::RequestBody.parse(ping)
35
+ @msg.type.should == "Ping"
36
+ end
37
+
38
+ it "should raise error when type not parsible" do
39
+ lambda {
40
+ Siffer::Messages::RequestBody.parse("<SIF_Message></SIF_Message>").type
41
+ }.should
42
+ raise_error("Failed to parse <SIF_Message></SIF_Message> for SIF Type")
43
+ end
44
+
45
+ it "should parse source id" do
46
+ @msg.source_id.should == @xml.source_id
47
+ end
48
+
49
+ it "should parse msg id" do
50
+ @msg.msg_id.should == @xml.msg_id
51
+ end
52
+
53
+ it "should drop SIF_ from element names" do
54
+ msg = Siffer::Messages::RequestBody.new("test")
55
+ msg.send("drop_sif","SIF_Test").should == "Test"
56
+ end
57
+
58
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__),"..","spec_helper")
2
+
3
+ describe Siffer::Messages::Status do
4
+ it "should return message for each status code" do
5
+ Siffer::Messages::Status::CODES.each do |key,value|
6
+ msg = Siffer::Messages::Status.send(value.downcase)
7
+ msg.should_not be_nil
8
+ msg.code.should == key
9
+ msg.description.should == value
10
+ msg.data.should be_nil
11
+ end
12
+ end
13
+
14
+ it "should have a SIF_Status element body" do
15
+ success = Siffer::Messages::Status.success
16
+ success.read.should match(/SIF_Status/)
17
+ success.read.should match(/SIF_Code>0<\/SIF_Code/)
18
+ success.read.should match(/SIF_Description>Success</)
19
+ end
20
+
21
+ it "should allow data to hold other SIF_Message(s)" do
22
+ data = Siffer::Messages::Status.success(Siffer::Messages::Message.new("source"))
23
+ data.read.should match(/SIF_Data><SIF_Message/)
24
+ end
25
+ end