siffer 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/Rakefile +2 -2
  2. data/doc/rdoc/classes/Siffer.html +253 -368
  3. data/doc/rdoc/classes/Siffer/Agent.html +169 -288
  4. data/doc/rdoc/classes/Siffer/Container.html +158 -279
  5. data/doc/rdoc/classes/Siffer/Messages.html +79 -139
  6. data/doc/rdoc/classes/Siffer/Messages/Ack.html +109 -210
  7. data/doc/rdoc/classes/Siffer/Messages/Acl.html +78 -155
  8. data/doc/rdoc/classes/Siffer/Messages/Error.html +151 -242
  9. data/doc/rdoc/classes/Siffer/Messages/Message.html +227 -351
  10. data/doc/rdoc/classes/Siffer/Messages/Message/Header.html +102 -176
  11. data/doc/rdoc/classes/Siffer/Messages/Register.html +147 -250
  12. data/doc/rdoc/classes/Siffer/Messages/RequestBody.html +177 -292
  13. data/doc/rdoc/classes/Siffer/Messages/Status.html +149 -262
  14. data/doc/rdoc/classes/Siffer/Messaging.html +204 -323
  15. data/doc/rdoc/classes/Siffer/Protocol.html +246 -380
  16. data/doc/rdoc/classes/Siffer/Protocol/NonPostRequest.html +53 -110
  17. data/doc/rdoc/classes/Siffer/Protocol/UnknownPath.html +53 -110
  18. data/doc/rdoc/classes/Siffer/Registration.html +243 -383
  19. data/doc/rdoc/classes/Siffer/Request.html +97 -203
  20. data/doc/rdoc/classes/Siffer/RequestLogger.html +102 -204
  21. data/doc/rdoc/classes/Siffer/Response.html +85 -176
  22. data/doc/rdoc/classes/Siffer/Server.html +150 -236
  23. data/doc/rdoc/created.rid +1 -1
  24. data/doc/rdoc/files/LICENSE.html +75 -128
  25. data/doc/rdoc/files/README_rdoc.html +130 -183
  26. data/doc/rdoc/files/lib/siffer/agent_rb.html +49 -0
  27. data/doc/rdoc/files/lib/siffer/container_rb.html +57 -0
  28. data/doc/rdoc/files/lib/siffer/messages/ack_rb.html +49 -0
  29. data/doc/rdoc/files/lib/siffer/messages/acl_rb.html +49 -0
  30. data/doc/rdoc/files/lib/siffer/messages/error_rb.html +49 -0
  31. data/doc/rdoc/files/lib/siffer/messages/message_rb.html +49 -0
  32. data/doc/rdoc/files/lib/siffer/messages/register_rb.html +49 -0
  33. data/doc/rdoc/files/lib/siffer/messages/request_body_rb.html +49 -0
  34. data/doc/rdoc/files/lib/siffer/messages/status_rb.html +49 -0
  35. data/doc/rdoc/files/lib/siffer/messages_rb.html +63 -0
  36. data/doc/rdoc/files/lib/siffer/messaging_rb.html +49 -0
  37. data/doc/rdoc/files/lib/siffer/protocol_rb.html +49 -0
  38. data/doc/rdoc/files/lib/siffer/registration_rb.html +49 -0
  39. data/doc/rdoc/files/lib/siffer/request_logger_rb.html +49 -0
  40. data/doc/rdoc/files/lib/siffer/request_rb.html +49 -0
  41. data/doc/rdoc/files/lib/siffer/response_rb.html +49 -0
  42. data/doc/rdoc/files/lib/siffer/server_rb.html +49 -0
  43. data/doc/rdoc/files/lib/siffer_rb.html +62 -113
  44. data/doc/rdoc/fr_class_index.html +25 -47
  45. data/doc/rdoc/fr_file_index.html +39 -46
  46. data/doc/rdoc/fr_method_index.html +4539 -96
  47. data/doc/rdoc/index.html +14 -23
  48. data/doc/rdoc/rdoc-style.css +314 -203
  49. data/lib/siffer.rb +6 -6
  50. data/lib/{agent.rb → siffer/agent.rb} +5 -3
  51. data/lib/{container.rb → siffer/container.rb} +3 -5
  52. data/lib/siffer/messages.rb +7 -0
  53. data/lib/{messages → siffer/messages}/ack.rb +0 -0
  54. data/lib/{messages → siffer/messages}/acl.rb +0 -0
  55. data/lib/{messages → siffer/messages}/error.rb +0 -0
  56. data/lib/{messages → siffer/messages}/message.rb +0 -0
  57. data/lib/{messages → siffer/messages}/register.rb +0 -0
  58. data/lib/{messages → siffer/messages}/request_body.rb +0 -0
  59. data/lib/{messages → siffer/messages}/status.rb +0 -0
  60. data/lib/{messaging.rb → siffer/messaging.rb} +8 -5
  61. data/lib/{protocol.rb → siffer/protocol.rb} +37 -32
  62. data/lib/{registration.rb → siffer/registration.rb} +2 -2
  63. data/lib/siffer/request.rb +28 -0
  64. data/lib/{request_logger.rb → siffer/request_logger.rb} +8 -7
  65. data/lib/{response.rb → siffer/response.rb} +1 -1
  66. data/lib/{server.rb → siffer/server.rb} +5 -3
  67. data/spec/agent_spec.rb +6 -11
  68. data/spec/container_spec.rb +2 -2
  69. data/spec/default_agent +1 -1
  70. data/spec/messaging_spec.rb +3 -6
  71. data/spec/protocol_spec.rb +27 -26
  72. data/spec/registration_spec.rb +2 -2
  73. data/spec/request_logger_spec.rb +22 -9
  74. data/spec/request_spec.rb +15 -0
  75. data/spec/response_spec.rb +2 -2
  76. data/spec/server_spec.rb +0 -5
  77. data/spec/spec_helper.rb +9 -0
  78. metadata +40 -38
  79. data/doc/rdoc/files/lib/agent_rb.html +0 -101
  80. data/doc/rdoc/files/lib/container_rb.html +0 -108
  81. data/doc/rdoc/files/lib/messages/ack_rb.html +0 -101
  82. data/doc/rdoc/files/lib/messages/acl_rb.html +0 -101
  83. data/doc/rdoc/files/lib/messages/error_rb.html +0 -101
  84. data/doc/rdoc/files/lib/messages/message_rb.html +0 -101
  85. data/doc/rdoc/files/lib/messages/register_rb.html +0 -101
  86. data/doc/rdoc/files/lib/messages/request_body_rb.html +0 -101
  87. data/doc/rdoc/files/lib/messages/status_rb.html +0 -101
  88. data/doc/rdoc/files/lib/messages_rb.html +0 -114
  89. data/doc/rdoc/files/lib/messaging_rb.html +0 -101
  90. data/doc/rdoc/files/lib/protocol_rb.html +0 -101
  91. data/doc/rdoc/files/lib/registration_rb.html +0 -101
  92. data/doc/rdoc/files/lib/request_logger_rb.html +0 -101
  93. data/doc/rdoc/files/lib/request_rb.html +0 -101
  94. data/doc/rdoc/files/lib/response_rb.html +0 -101
  95. data/doc/rdoc/files/lib/server_rb.html +0 -101
  96. data/lib/messages.rb +0 -7
  97. data/lib/request.rb +0 -25
@@ -12,7 +12,7 @@ $: << File.expand_path(File.dirname(__FILE__))
12
12
  module Siffer
13
13
 
14
14
  VENDOR = "h3o(software)" unless defined?(Siffer::VENDOR)
15
- VERSION = [0,0,4] unless defined?(Siffer::VERSION)
15
+ VERSION = [0,0,5] unless defined?(Siffer::VERSION)
16
16
  SIF_VERSION = [2,2,0] unless defined?(Siffer::SIF_VERSION)
17
17
  SIF_XMLNS = "http://www.sifinfo.org/infrastructure/2.x" unless defined?(Siffer::SIF_XMLNS)
18
18
 
@@ -34,11 +34,11 @@ module Siffer
34
34
 
35
35
  end
36
36
 
37
- Siffer.autoload :Messages, "messages"
38
- Siffer.autoload :Protocol, "protocol"
39
- Siffer.autoload :Messaging, "messaging"
40
- Siffer.autoload :Registration, "registration"
37
+ Siffer.autoload :Messages, "siffer/messages"
38
+ Siffer.autoload :Protocol, "siffer/protocol"
39
+ Siffer.autoload :Messaging, "siffer/messaging"
40
+ Siffer.autoload :Registration, "siffer/registration"
41
41
 
42
42
  %w(server agent response request container request_logger).each do |component|
43
- require component
43
+ require "siffer/#{component}"
44
44
  end
@@ -7,8 +7,8 @@ module Siffer
7
7
  attr_reader :name, :host, :port, :admin, :server
8
8
 
9
9
  def initialize(options = {})
10
- raise "Server URL(s) required" unless options.include? "servers"
11
- @server = options["servers"]
10
+ raise "Zone Integration Server URL required" unless options.include? "server"
11
+ @server = options["server"]
12
12
  raise "Administration URL required" unless options.include? "admin"
13
13
  @admin = options["admin"]
14
14
  @name = options["name"] || "Default Agent"
@@ -19,7 +19,9 @@ module Siffer
19
19
 
20
20
  def call(env)
21
21
  with_each_request(env) do
22
-
22
+ #process_event
23
+ #process_request
24
+ #process_response
23
25
  end
24
26
  end
25
27
 
@@ -14,7 +14,8 @@ module Siffer
14
14
  Siffer::Agent.new(config["agent"]) :
15
15
  Siffer::Server.new(config["server"])
16
16
  @name = config[type]["name"]
17
- @host = config[type]["host"]
17
+ uri = URI.parse(config[type]["host"])
18
+ @host = uri.host.nil? ? uri.to_s : uri.host
18
19
  @port = config[type]["port"]
19
20
  @daemonize = options[:daemonize]
20
21
  @pid = options[:pid]
@@ -28,10 +29,7 @@ module Siffer
28
29
  def run
29
30
  daemonize
30
31
  server = best_available_server
31
- options = {
32
- :Host => host,
33
- :Port => port
34
- }
32
+ options = { :Host => host, :Port => port }
35
33
  component.wake_up if component.respond_to?("wake_up")
36
34
  app = component_wrapped_in_environment
37
35
  server.run app, options
@@ -0,0 +1,7 @@
1
+ require 'siffer/messages/error'
2
+ require 'siffer/messages/status'
3
+ require 'siffer/messages/acl'
4
+ require 'siffer/messages/request_body'
5
+ require 'siffer/messages/message'
6
+ require 'siffer/messages/ack'
7
+ require 'siffer/messages/register'
File without changes
File without changes
@@ -31,9 +31,9 @@ module Siffer
31
31
  @response = Response.new(Siffer::Protocol::HTTP_STATUS_CODES[406],
32
32
  406,
33
33
  {"Content-Type" => MIME_TYPES["htm"]})
34
- rescue MalformedXml; error_response(1,2);
35
- rescue MalformedSIFMessage; error_response(12,2);
36
- rescue VersionMismatch; error_response(12,3);
34
+ rescue MalformedXml; error_response(1,2,"There was no XML body to parse.");
35
+ rescue MalformedSIFMessage; error_response(12,2,"The XML was not a recognizable SIF Message.");
36
+ rescue VersionMismatch; error_response(12,3,"The SIF version did not match supported versions.");
37
37
  rescue XmlNsMismatch; error_response(1,4,"XMLNS not compatible with SIF")
38
38
  end
39
39
  end
@@ -48,7 +48,9 @@ module Siffer
48
48
  # BadContentType exception.
49
49
  def check_content_type
50
50
  content_type = @request.content_type
51
- unless [MIME_TYPES["xml"], MIME_TYPES["appxml"]].include? content_type
51
+ unless [MIME_TYPES["xml"],
52
+ MIME_TYPES["appxml"],
53
+ MIME_TYPES["appxmlencoded"]].include? content_type
52
54
  raise BadContentType
53
55
  end
54
56
  end
@@ -86,7 +88,8 @@ module Siffer
86
88
 
87
89
  # MIME Types used in Siffer
88
90
  MIME_TYPES = {
89
- "appxml" => "application/xml;charset=utf-8",
91
+ "appxmlencoded" => "application/xml;charset=utf-8",
92
+ "appxml" => "application/xml",
90
93
  "htm" => "text/html",
91
94
  "html" => "text/html",
92
95
  "xml" => "text/xml"
@@ -14,18 +14,22 @@ module Siffer
14
14
  # * Unknown PATH
15
15
  # * Non-POST request
16
16
  def request_failed_protocol?
17
- begin
18
- check_path_against_protocol
19
- rescue UnknownPath
20
- # TODO: Make a better Not Found response
21
- @response = Response.new(HTTP_STATUS_CODES[404],
22
- 404,
23
- {"Content-Type" => Siffer::Messaging::MIME_TYPES["htm"]})
24
- rescue NonPostRequest
25
- # TODO: Make a better Method Not Allowed response
26
- @response = Response.new(HTTP_STATUS_CODES[405],
27
- 405,
28
- {"Content-Type" => Siffer::Messaging::MIME_TYPES["htm"]})
17
+ if @request.get? and @request.path_info == ACCEPTABLE_PATHS[:root]
18
+ root_response
19
+ else
20
+ begin
21
+ check_path_against_protocol
22
+ rescue UnknownPath
23
+ # TODO: Make a better Not Found response
24
+ @response = Response.new(HTTP_STATUS_CODES[404],
25
+ 404,
26
+ {"Content-Type" => MIME_TYPES["htm"]})
27
+ rescue NonPostRequest
28
+ # TODO: Make a better Method Not Allowed response
29
+ @response = Response.new(HTTP_STATUS_CODES[405],
30
+ 405,
31
+ {"Content-Type" => MIME_TYPES["htm"]})
32
+ end
29
33
  end
30
34
  end
31
35
 
@@ -35,14 +39,14 @@ module Siffer
35
39
  unless ACCEPTABLE_PATHS.has_value? @request.path_info
36
40
  raise UnknownPath
37
41
  end
38
- unless @request.post?
42
+ unless @request.post?
39
43
  raise NonPostRequest
40
44
  end
41
45
  end
42
46
 
43
47
  # Returns the URI of the component (Server or Agent)
44
48
  def uri
45
- URI.parse("http://#{host}:#{port}").to_s
49
+ URI.parse("http://#{host.gsub(/(http|https):\/\//,"")}:#{port}").to_s
46
50
  end
47
51
 
48
52
  # Provides a context for each request. Creates the @request, @response and
@@ -80,21 +84,32 @@ module Siffer
80
84
  if @response.nil?
81
85
  err = <<"ERR"
82
86
  You are receiving this message because you failed to
83
- provide enough information to respond to. This is likely due
84
- to the message type missing (i.e. Register,Provide) or possibly
85
- not enough information to process effectively. Please check the
86
- message you are sending and resend after any corrections.
87
+ provide enough information to respond to. This message
88
+ went completely through the messaging stack and
89
+ failed to instigate a response.
90
+
91
+ Please check the message you are sending and resend after
92
+ any corrections.
87
93
  ERR
88
94
  !error_response(12,1,err)
89
95
  end
90
96
  end
97
+
98
+ def root_response
99
+ html = <<"HTML"
100
+ <html>
101
+ <body>
102
+ <h1>Siffer Endpoint</h1>
103
+ <p>You have reached a Siffer component.</p>
104
+ </body>
105
+ </html>
106
+ HTML
107
+ @response = Response.new(html,200,{"Content-Type" => MIME_TYPES["htm"]})
108
+ end
91
109
 
92
110
  # Paths that comply with the messaging protocol determined
93
111
  # by the SIF Specification. These are Siffer specific and not
94
- # spelled out in SIF Specification (rather implied). Each path
95
- # will generate it's own predicate method (i.e. #ping?) that can
96
- # be used to determine the requests path based on the content of the
97
- # message or the path-info of the request.
112
+ # spelled out in SIF Specification (rather implied).
98
113
  ACCEPTABLE_PATHS = {
99
114
  :root => "/",
100
115
  :ping => "/ping",
@@ -102,16 +117,6 @@ ERR
102
117
  :register => "/register"
103
118
  }
104
119
 
105
- ACCEPTABLE_PATHS.each do |name,path|
106
- define_method("#{name.to_s}?") do
107
- @request.message.type.downcase == name.to_s
108
- # The difference in these lines is the difference between allowing
109
- # any message to come through any PATH or forcing PATH and message
110
- # to match. What is better?
111
- # TODO: Decide on protocol validations !
112
- #@request.path_info == path || req_body.type.downcase == name.to_s
113
- end
114
- end
115
120
 
116
121
  # Every standard HTTP code mapped to the appropriate message.
117
122
  # Stolen from Mongrel.
@@ -23,7 +23,7 @@ module Siffer
23
23
  # source is already registered it passes through, otherwise raises
24
24
  # AgentNotRegistered exception.
25
25
  def check_for_registration
26
- unless register? or registered?(@request.message.source_id)
26
+ unless @request.register? or registered?(@request.message.source_id)
27
27
  raise AgentNotRegistered
28
28
  end
29
29
  end
@@ -36,7 +36,7 @@ module Siffer
36
36
  # If all validations pass the registration is stored by the ZIS and
37
37
  # the agent is added to the list of agents available to the zone.
38
38
  def register
39
- if register?
39
+ if @request.register?
40
40
  @registration = Register.parse(@request.body)
41
41
  validate_source_id
42
42
  validate_permission
@@ -0,0 +1,28 @@
1
+ module Siffer
2
+
3
+ # Request represents each message received by the Server or Agent in Siffer.
4
+ class Request < Rack::Request
5
+
6
+ # Provides access to the request message in Siffer::Messages::Message
7
+ # format.
8
+ def message
9
+ if body.is_a?(StringIO) && body.pos == body.length
10
+ body.rewind
11
+ end
12
+ Siffer::Messages::RequestBody.parse(body)
13
+ end
14
+ alias :original :message
15
+
16
+ Siffer::Protocol::ACCEPTABLE_PATHS.each do |name,path|
17
+ define_method("#{name.to_s}?") do
18
+ message.type.downcase == name.to_s
19
+ # The difference in these lines is the difference between allowing
20
+ # any message to come through any PATH or forcing PATH and message
21
+ # to match. What is better?
22
+ # TODO: Decide on protocol validations !
23
+ #@request.path_info == path || req_body.type.downcase == name.to_s
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -6,22 +6,23 @@ module Siffer
6
6
  end
7
7
 
8
8
  def call(env)
9
- @env = env
10
- # Maybe there is a better way to pick the body of the input
11
- # instead of reading it then stuffing it back in ??
12
9
  @msg = env["rack.input"].read
13
10
  log_request
14
- env["rack.input"] = StringIO.new(@msg)
11
+ env["rack.input"].rewind
15
12
  @app.call(env)
16
13
  end
17
14
 
18
15
  def log_request
19
16
  @now = Time.now
20
- message = Siffer::Messages::RequestBody.parse(@msg)
17
+ message = Siffer::Messages::RequestBody.parse(@msg).type rescue "Unknown"
18
+ host = Siffer::Messages::RequestBody.parse(@msg).source_id rescue "Unknown Source"
19
+ if host.nil? or host == ""
20
+ host = "Unknown Source"
21
+ end
21
22
  @log << %{%s request made by %s on %s at %s\n} %
22
23
  [
23
- message.type,
24
- @env["REMOTE_USER"],
24
+ message,
25
+ host,
25
26
  @now.strftime("%b/%d/%Y"),
26
27
  @now.strftime("%H:%M:%S")
27
28
  ]
@@ -3,7 +3,7 @@ module Siffer
3
3
  class Response < Rack::Response
4
4
 
5
5
  def initialize(body=[], status=200, header={}, &block)
6
- header["Content-Type"] ||= Siffer::Messaging::MIME_TYPES["appxml"]
6
+ header["Content-Type"] ||= Siffer::Messaging::MIME_TYPES["appxmlencoded"]
7
7
  super(body,status,header,&block)
8
8
  end
9
9
 
@@ -29,9 +29,11 @@ module Siffer
29
29
  def call(env)
30
30
  with_each_request(env) do
31
31
  process_registration
32
- # process_provision
33
- # process_subscription
34
- # process_event
32
+ # process_provision MAYBE SAME MODULE
33
+ # process_subscription MAYBE SAME MODULE
34
+ # process_event (server process not agent) REDIRECTS
35
+ # process_request (server process not agent) REDIRECTS
36
+ # process_response (server process not agent) REDIRECTS
35
37
  end
36
38
  end
37
39
 
@@ -3,7 +3,7 @@ require 'webrick'
3
3
 
4
4
  describe Siffer::Agent do
5
5
  it "should instantiate with default host, port, name" do
6
- agent = Siffer::Agent.new("servers" => 'none', "admin" => 'none')
6
+ agent = Siffer::Agent.new("server" => 'none', "admin" => 'none')
7
7
  agent.host.should == "localhost"
8
8
  agent.port.should == 8300
9
9
  agent.name.should == "Default Agent"
@@ -11,7 +11,7 @@ describe Siffer::Agent do
11
11
 
12
12
  it "should allow defaults to be overriden" do
13
13
  agent = Siffer::Agent.new("admin" => 'none',
14
- "servers" => 'none',
14
+ "server" => 'none',
15
15
  "name" => "name",
16
16
  "host" => "test",
17
17
  "port" => 222)
@@ -23,30 +23,25 @@ describe Siffer::Agent do
23
23
  it "should require a server url to register with" do
24
24
  lambda {
25
25
  agent = Siffer::Agent.new
26
- }.should raise_error("Server URL(s) required")
26
+ }.should raise_error("Zone Integration Server URL required")
27
27
  end
28
28
 
29
29
  it "should require an admin URL" do
30
30
  lambda {
31
- agent = Siffer::Agent.new("servers" => "none")
31
+ agent = Siffer::Agent.new("server" => "none")
32
32
  }.should raise_error("Administration URL required")
33
33
  end
34
34
 
35
- it "should respond to uri" do
36
- agent = Siffer::Agent.new("admin" => 'none', "servers" => 'none')
37
- agent.uri.should == "http://localhost:8300"
38
- end
39
-
40
35
  it "should register with server(s) on wake-up" do
41
36
  with_fake_server(Siffer::Server.new("admin" => "none")) do |url|
42
- agent = Siffer::Agent.new("admin" => 'none', "servers" => url)
37
+ agent = Siffer::Agent.new("admin" => 'none', "server" => url)
43
38
  agent.wake_up
44
39
  agent.should be_registered
45
40
  end
46
41
  end
47
42
 
48
43
  it "should be unregistered by default" do
49
- agent = Siffer::Agent.new("admin" => 'none', "servers" => 'none')
44
+ agent = Siffer::Agent.new("admin" => 'none', "server" => 'none')
50
45
  agent.should_not be_registered
51
46
  end
52
47
 
@@ -29,7 +29,7 @@ describe Siffer::Container, "options" do
29
29
  "host" => 'localhost',
30
30
  "port" => 8200,
31
31
  "admin" => 'http://localhost:3000/',
32
- "servers" => 'http://localhost:4001/'
32
+ "server" => 'http://localhost:4001/'
33
33
  }
34
34
  }
35
35
  }
@@ -88,7 +88,7 @@ describe Siffer::Container, "runtime" do
88
88
  "host" => 'localhost',
89
89
  "port" => 8210,
90
90
  "admin" => 'http://localhost:3000/',
91
- "servers" => 'http://localhost:4001/'
91
+ "server" => 'http://localhost:4001/'
92
92
  }
93
93
  }
94
94
  }
@@ -2,5 +2,5 @@ agent:
2
2
  name: 'Clints Agent'
3
3
  host: 'localhost'
4
4
  port: 4002
5
- servers: 'http://localhost:4001/'
5
+ server: 'http://localhost:4001/'
6
6
  admin: 'http://localhost:3000'
@@ -8,11 +8,8 @@ require File.join(File.dirname(__FILE__),"spec_helper")
8
8
  # Stage the component a little bit:
9
9
  # Agents require Servers
10
10
  # Both require central-admin
11
- component = component.new("admin" => 'none', "servers" => '')
12
- msg = Siffer::Messages::Message.new("source")
13
- msg.content do |xml|
14
- xml.SIF_BogusType
15
- end
11
+ component = component.new("admin" => 'none', "server" => '')
12
+ msg = Siffer::Messages::Message.new("source").content{|xml| xml.SIF_Bogus}
16
13
 
17
14
  describe component, "Messaging - response" do
18
15
  it "should always return Ack for proper SIF_Messages" do
@@ -25,7 +22,7 @@ require File.join(File.dirname(__FILE__),"spec_helper")
25
22
  describe component, "Messaging - content-type" do
26
23
  it "should always respond with application/xml" do
27
24
  for_every_path(:on => component, :input => msg) do |res|
28
- res.content_type.should == Siffer::Messaging::MIME_TYPES["appxml"]
25
+ res.content_type.should == Siffer::Messaging::MIME_TYPES["appxmlencoded"]
29
26
  end
30
27
  end
31
28
 
@@ -5,12 +5,8 @@ require File.join(File.dirname(__FILE__), "spec_helper")
5
5
  # Stage the component a little bit:
6
6
  # Agents require Servers
7
7
  # Both require central-admin
8
- component = component.new("admin" => 'none', "servers" => '')
9
- # setup messages to use for mock requests
10
- ping = "<SIF_Message><SIF_SystemControl><SIF_Ping /></SIF_SystemControl></SIF_Message>"
11
- status = "<SIF_Message><SIF_SystemControl><SIF_Status /></SIF_SystemControl></SIF_Message>"
12
- register = "<SIF_Message><SIF_Register /></SIF_Message>"
13
-
8
+ component = component.new("admin" => 'none', "server" => '')
9
+
14
10
  describe component, "Protocol - /unknown_path" do
15
11
  it "should return 404" do
16
12
  res = Rack::MockRequest.new(component).post("/bad_path")
@@ -18,32 +14,37 @@ require File.join(File.dirname(__FILE__), "spec_helper")
18
14
  end
19
15
  end
20
16
 
21
- describe component, "Protocol - Accepted Paths" do
17
+ describe component, "Protocol - Accepted Paths except Root URL" do
22
18
  it "should only allow POST method" do
23
19
  Siffer::Protocol::ACCEPTABLE_PATHS.each do |name,path|
24
- res = Rack::MockRequest.new(component).get(path)
25
- res.should be_client_error
26
- end
27
- end
28
-
29
- it "should be identified by predicate through body" do
30
- Siffer::Protocol::ACCEPTABLE_PATHS.each do |name,path|
31
- unless name == :root
32
- component.call({"rack.input" => eval(name.to_s)})
33
- component.should eval("be_#{name.to_s}")
20
+ if(path != "/")
21
+ res = Rack::MockRequest.new(component).get(path)
22
+ res.should be_client_error
34
23
  end
35
24
  end
36
25
  end
26
+ end
27
+
28
+ describe component, "Protocol - Root URL on GET" do
29
+ it "should display component info" do
30
+ res = Rack::MockRequest.new(component).get("/")
31
+ res.should be_ok
32
+ res.body.should match(/<h1>Siffer Endpoint<\/h1>/)
33
+ end
34
+ end
35
+
36
+ describe component, "Protocol - URI" do
37
37
 
38
- it "should be identified by predicate through path-info" do
39
- Siffer::Protocol::ACCEPTABLE_PATHS.each do |name,path|
40
- unless name == :root
41
- component.call({
42
- "rack.input" => "<SIF_Message><SIF_#{name.to_s} /></SIF_Message>",
43
- "PATH_INFO" => path})
44
- component.should eval("be_#{name.to_s}")
45
- end
46
- end
38
+ it "should respond to uri" do
39
+ component.uri.should == "http://localhost:8300"
40
+ end
41
+
42
+ it "should respond to full url in uri" do
43
+ component = component.class.new("admin" => "none",
44
+ "server" => "",
45
+ "host" => "http://localhost")
46
+ component.uri.should == "http://localhost:8300"
47
47
  end
48
48
  end
49
+
49
50
  end