jubilee 1.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +5 -0
  4. data/CHANGELOG +32 -0
  5. data/Gemfile +35 -0
  6. data/Gemfile.lock +244 -0
  7. data/Guardfile +24 -0
  8. data/KNOWN_ISSUES +6 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.md +147 -0
  11. data/ROADMAP +5 -0
  12. data/Rakefile +98 -0
  13. data/bin/jubilee +6 -0
  14. data/bin/jubilee_d +13 -0
  15. data/examples/chatapp/Gemfile +5 -0
  16. data/examples/chatapp/Gemfile.lock +27 -0
  17. data/examples/chatapp/README.md +17 -0
  18. data/examples/chatapp/app.rb +57 -0
  19. data/examples/chatapp/config.ru +3 -0
  20. data/examples/chatapp/public/assets/javascripts/application.js +67 -0
  21. data/examples/chatapp/public/assets/javascripts/jquery.js +5 -0
  22. data/examples/chatapp/public/assets/javascripts/sockjs-0.3.4.min.js +27 -0
  23. data/examples/chatapp/public/assets/javascripts/vertxbus.js +216 -0
  24. data/examples/chatapp/public/assets/stylesheets/application.css +29 -0
  25. data/examples/client/sockjs-0.3.4.min.js +27 -0
  26. data/examples/client/vertxbus.js +216 -0
  27. data/examples/jubilee.conf.rb +12 -0
  28. data/examples/jubilee/keystore.jks +0 -0
  29. data/examples/jubilee/server-keystore.jks +0 -0
  30. data/jars/hazelcast-2.6.3.jar +0 -0
  31. data/jars/jackson-annotations-2.2.2.jar +0 -0
  32. data/jars/jackson-core-2.2.2.jar +0 -0
  33. data/jars/jackson-databind-2.2.2.jar +0 -0
  34. data/jars/netty-all-4.0.13.Final.jar +0 -0
  35. data/jars/vertx-core-2.1M3-SNAPSHOT.jar +0 -0
  36. data/jars/vertx-hazelcast-2.1M3-SNAPSHOT.jar +0 -0
  37. data/java/src/jubilee/JubileeService.java +20 -0
  38. data/java/src/org/jruby/jubilee/Const.java +32 -0
  39. data/java/src/org/jruby/jubilee/RackApplication.java +103 -0
  40. data/java/src/org/jruby/jubilee/RackEnvironment.java +150 -0
  41. data/java/src/org/jruby/jubilee/RackEnvironmentHash.java +449 -0
  42. data/java/src/org/jruby/jubilee/RackInput.java +62 -0
  43. data/java/src/org/jruby/jubilee/RackResponse.java +11 -0
  44. data/java/src/org/jruby/jubilee/RubyHttpServerResponse.java +88 -0
  45. data/java/src/org/jruby/jubilee/RubyServer.java +171 -0
  46. data/java/src/org/jruby/jubilee/deploy/Starter.java +26 -0
  47. data/java/src/org/jruby/jubilee/impl/RubyIORackInput.java +201 -0
  48. data/java/src/org/jruby/jubilee/impl/RubyNullIO.java +107 -0
  49. data/java/src/org/jruby/jubilee/utils/RubyHelper.java +37 -0
  50. data/java/src/org/jruby/jubilee/vertx/JubileeVertx.java +38 -0
  51. data/jubilee.gemspec +201 -0
  52. data/lib/jubilee.rb +17 -0
  53. data/lib/jubilee/application.rb +13 -0
  54. data/lib/jubilee/cli.rb +127 -0
  55. data/lib/jubilee/configuration.rb +177 -0
  56. data/lib/jubilee/const.rb +40 -0
  57. data/lib/jubilee/jubilee.jar +0 -0
  58. data/lib/jubilee/response.rb +69 -0
  59. data/lib/jubilee/server.rb +12 -0
  60. data/lib/jubilee/version.rb +10 -0
  61. data/lib/rack/chunked.rb +38 -0
  62. data/lib/rack/handler/jubilee.rb +44 -0
  63. data/lib/vertx.rb +26 -0
  64. data/lib/vertx/README.md +7 -0
  65. data/lib/vertx/buffer.rb +251 -0
  66. data/lib/vertx/event_bus.rb +206 -0
  67. data/lib/vertx/shared_data.rb +214 -0
  68. data/spec/apps/rack/basic/config.ru +50 -0
  69. data/spec/apps/rails4/basic/.gitignore +16 -0
  70. data/spec/apps/rails4/basic/Gemfile +41 -0
  71. data/spec/apps/rails4/basic/Gemfile.lock +127 -0
  72. data/spec/apps/rails4/basic/README.rdoc +28 -0
  73. data/spec/apps/rails4/basic/Rakefile +6 -0
  74. data/spec/apps/rails4/basic/app/assets/images/.keep +0 -0
  75. data/spec/apps/rails4/basic/app/assets/images/rails.png +0 -0
  76. data/spec/apps/rails4/basic/app/assets/javascripts/application.js +12 -0
  77. data/spec/apps/rails4/basic/app/assets/stylesheets/application.css +13 -0
  78. data/spec/apps/rails4/basic/app/controllers/application_controller.rb +5 -0
  79. data/spec/apps/rails4/basic/app/controllers/concerns/.keep +0 -0
  80. data/spec/apps/rails4/basic/app/controllers/reloader_controller.rb +11 -0
  81. data/spec/apps/rails4/basic/app/controllers/reloader_controller.rb.erb +11 -0
  82. data/spec/apps/rails4/basic/app/controllers/root_controller.rb +14 -0
  83. data/spec/apps/rails4/basic/app/helpers/application_helper.rb +2 -0
  84. data/spec/apps/rails4/basic/app/mailers/.keep +0 -0
  85. data/spec/apps/rails4/basic/app/models/.keep +0 -0
  86. data/spec/apps/rails4/basic/app/models/concerns/.keep +0 -0
  87. data/spec/apps/rails4/basic/app/views/layouts/application.html.erb +14 -0
  88. data/spec/apps/rails4/basic/app/views/reloader/index.html.erb +1 -0
  89. data/spec/apps/rails4/basic/app/views/root/index.html.erb +8 -0
  90. data/spec/apps/rails4/basic/app/views/root/streaming.html.erb +6 -0
  91. data/spec/apps/rails4/basic/bin/bundle +3 -0
  92. data/spec/apps/rails4/basic/bin/rails +4 -0
  93. data/spec/apps/rails4/basic/bin/rake +4 -0
  94. data/spec/apps/rails4/basic/config.ru +4 -0
  95. data/spec/apps/rails4/basic/config/application.rb +23 -0
  96. data/spec/apps/rails4/basic/config/boot.rb +4 -0
  97. data/spec/apps/rails4/basic/config/database.yml +20 -0
  98. data/spec/apps/rails4/basic/config/environment.rb +5 -0
  99. data/spec/apps/rails4/basic/config/environments/development.rb +29 -0
  100. data/spec/apps/rails4/basic/config/environments/production.rb +80 -0
  101. data/spec/apps/rails4/basic/config/environments/test.rb +36 -0
  102. data/spec/apps/rails4/basic/config/initializers/backtrace_silencers.rb +7 -0
  103. data/spec/apps/rails4/basic/config/initializers/filter_parameter_logging.rb +4 -0
  104. data/spec/apps/rails4/basic/config/initializers/inflections.rb +16 -0
  105. data/spec/apps/rails4/basic/config/initializers/mime_types.rb +5 -0
  106. data/spec/apps/rails4/basic/config/initializers/secret_token.rb +12 -0
  107. data/spec/apps/rails4/basic/config/initializers/session_store.rb +2 -0
  108. data/spec/apps/rails4/basic/config/initializers/wrap_parameters.rb +14 -0
  109. data/spec/apps/rails4/basic/config/locales/en.yml +23 -0
  110. data/spec/apps/rails4/basic/config/routes.rb +5 -0
  111. data/spec/apps/rails4/basic/db/seeds.rb +7 -0
  112. data/spec/apps/rails4/basic/lib/assets/.keep +0 -0
  113. data/spec/apps/rails4/basic/lib/tasks/.keep +0 -0
  114. data/spec/apps/rails4/basic/public/404.html +58 -0
  115. data/spec/apps/rails4/basic/public/422.html +58 -0
  116. data/spec/apps/rails4/basic/public/500.html +57 -0
  117. data/spec/apps/rails4/basic/public/favicon.ico +0 -0
  118. data/spec/apps/rails4/basic/public/robots.txt +5 -0
  119. data/spec/apps/rails4/basic/public/some_page.html +7 -0
  120. data/spec/apps/rails4/basic/test/controllers/.keep +0 -0
  121. data/spec/apps/rails4/basic/test/fixtures/.keep +0 -0
  122. data/spec/apps/rails4/basic/test/helpers/.keep +0 -0
  123. data/spec/apps/rails4/basic/test/integration/.keep +0 -0
  124. data/spec/apps/rails4/basic/test/mailers/.keep +0 -0
  125. data/spec/apps/rails4/basic/test/models/.keep +0 -0
  126. data/spec/apps/rails4/basic/test/test_helper.rb +15 -0
  127. data/spec/apps/rails4/basic/vendor/assets/javascripts/.keep +0 -0
  128. data/spec/apps/rails4/basic/vendor/assets/stylesheets/.keep +0 -0
  129. data/spec/apps/sinatra/basic/Gemfile +4 -0
  130. data/spec/apps/sinatra/basic/Gemfile.lock +20 -0
  131. data/spec/apps/sinatra/basic/basic.rb +27 -0
  132. data/spec/apps/sinatra/basic/config.ru +7 -0
  133. data/spec/apps/sinatra/basic/public/some_page.html +7 -0
  134. data/spec/apps/sinatra/basic/views/index.erb +4 -0
  135. data/spec/apps/sinatra/basic/views/posted.haml +2 -0
  136. data/spec/apps/sinatra/basic/views/poster.haml +4 -0
  137. data/spec/apps/sinatra/basic/views/request_mapping.haml +4 -0
  138. data/spec/integration/basic_rack_spec.rb +89 -0
  139. data/spec/integration/basic_rails4_spec.rb +64 -0
  140. data/spec/integration/basic_sinatra_spec.rb +80 -0
  141. data/spec/spec_helper.rb +13 -0
  142. data/test/.ruby-version +1 -0
  143. data/test/config/app.rb +5 -0
  144. data/test/jubilee/test_cli.rb +11 -0
  145. data/test/jubilee/test_configuration.rb +31 -0
  146. data/test/jubilee/test_rack_server.rb +137 -0
  147. data/test/jubilee/test_response.rb +272 -0
  148. data/test/jubilee/test_server.rb +72 -0
  149. data/test/jubilee/test_upload.rb +301 -0
  150. data/test/sinatra_app/app.rb +31 -0
  151. data/test/sinatra_app/config.ru +6 -0
  152. data/test/sinatra_app/public/test.html +10 -0
  153. data/test/sinatra_app/unicorn.conf.rb +29 -0
  154. data/test/test_helper.rb +93 -0
  155. metadata +242 -0
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gem "sinatra"
4
+ gem "haml"
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ haml (4.0.4)
5
+ tilt
6
+ rack (1.5.2)
7
+ rack-protection (1.5.1)
8
+ rack
9
+ sinatra (1.4.4)
10
+ rack (~> 1.4)
11
+ rack-protection (~> 1.4)
12
+ tilt (~> 1.3, >= 1.3.4)
13
+ tilt (1.4.1)
14
+
15
+ PLATFORMS
16
+ java
17
+
18
+ DEPENDENCIES
19
+ haml
20
+ sinatra
@@ -0,0 +1,27 @@
1
+
2
+ require 'rubygems'
3
+ require 'sinatra'
4
+
5
+ disable :logging
6
+
7
+ options '/' do
8
+ response.headers['Access-Control-Allow-Origin'] = '*'
9
+ response.headers['Access-Control-Allow-Methods'] = 'POST'
10
+ end
11
+
12
+ get '/' do
13
+ headers 'Biscuit' => 'Gravy'
14
+ erb :index
15
+ end
16
+
17
+ get '/request-mapping' do
18
+ haml :request_mapping
19
+ end
20
+
21
+ get '/poster' do
22
+ haml :poster
23
+ end
24
+
25
+ post '/poster' do
26
+ haml :posted
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'haml'
4
+
5
+ require_relative './basic'
6
+
7
+ run Sinatra::Application
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <body>
3
+ <div class="default" id="success">
4
+ static page
5
+ </div>
6
+ </body>
7
+ </html>
@@ -0,0 +1,4 @@
1
+
2
+ <div class="sinatra-basic" id="success">
3
+ it worked with a view
4
+ </div>
@@ -0,0 +1,2 @@
1
+
2
+ #success= "you posted #{params[:field]}"
@@ -0,0 +1,4 @@
1
+
2
+ %form#success{:method=>'POST'}
3
+ %input{:type=>'text', :name=>'field', :value=>'nothing'}
4
+ %input#submit{:type=>'submit'}
@@ -0,0 +1,4 @@
1
+
2
+ #success
3
+ #scheme
4
+ = request.scheme
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ feature "basic rack at non-root context" do
4
+
5
+ before(:all) do
6
+ configurator = Jubilee::Configuration.new(chdir: "#{apps_dir}/rack/basic")
7
+ @server = Jubilee::Server.new(configurator.app, configurator.options)
8
+ @server.start
9
+ end
10
+
11
+ after(:all) do
12
+ @server.stop
13
+ end
14
+
15
+ it "should work for basic requests" do
16
+ visit "/basic-rack"
17
+ page.should have_content('it worked')
18
+ page.find("#success")[:class].strip.should == 'basic-rack'
19
+ page.find("#script_name").text.strip.should == ''
20
+ page.find("#path_info").text.strip.should == '/basic-rack'
21
+ page.find("#request_uri").text.strip.should == '/basic-rack'
22
+ end
23
+
24
+ it "should work for subcontext root with trailing slash" do
25
+ visit "/basic-rack/"
26
+ page.should have_content('it worked')
27
+ page.find("#success")[:class].strip.should == 'basic-rack'
28
+ page.find("#script_name").text.strip.should == ''
29
+ page.find("#path_info").text.strip.should == '/basic-rack/'
30
+ page.find("#request_uri").text.strip.should == '/basic-rack/'
31
+ end
32
+
33
+ it "should be running under the proper ruby version" do
34
+ visit "/basic-rack/"
35
+ page.find("#ruby-version").text.strip.should == RUBY_VERSION
36
+ end
37
+
38
+ it "should not have a vfs path for __FILE__" do
39
+ visit "/basic-rack/"
40
+ page.find("#path").text.strip.should_not match(/^vfs:/)
41
+ end
42
+
43
+ it "should not decode characters in URL" do
44
+ visit "/basic-rack/foo%23%2C"
45
+ page.find("#path_info").text.strip.should == '/basic-rack/foo%23%2C'
46
+ page.find("#request_uri").text.strip.should == '/basic-rack/foo%23%2C'
47
+ end
48
+
49
+ it "should contain correct request headers" do
50
+ uri = URI.parse("#{Capybara.app_host}/basic-rack/")
51
+ Net::HTTP.start(uri.host, uri.port) do |http|
52
+ accept = 'text/html;q=0.9,*/*;q=0.7'
53
+ response = http.get(uri.request_uri, {'Accept' => accept})
54
+ response.code.should == "200"
55
+ response.body.should include("<div id='accept_header'>#{accept}</div>")
56
+ end
57
+ end
58
+
59
+ it "should read post bodies via gets" do
60
+ uri = URI.parse("#{Capybara.app_host}/basic-rack/gets")
61
+ Net::HTTP.start(uri.host, uri.port) do |http|
62
+ request = Net::HTTP::Post.new(uri.request_uri)
63
+ request.form_data = {'field' => 'nothing'}
64
+ response = http.request(request)
65
+ response.body.should include("<div id='posted'>field=nothing</div>")
66
+ end
67
+ end
68
+
69
+ it "should read post bodies via read" do
70
+ uri = URI.parse("#{Capybara.app_host}/basic-rack/read")
71
+ Net::HTTP.start(uri.host, uri.port) do |http|
72
+ request = Net::HTTP::Post.new(uri.request_uri)
73
+ request.form_data = {'field' => 'nothing'}
74
+ response = http.request(request)
75
+ response.body.should include("<div id='posted'>field=nothing</div>")
76
+ end
77
+ end
78
+
79
+ it "should read post bodies via each" do
80
+ uri = URI.parse("#{Capybara.app_host}/basic-rack/each")
81
+ Net::HTTP.start(uri.host, uri.port) do |http|
82
+ request = Net::HTTP::Post.new(uri.request_uri)
83
+ request.form_data = {'field' => 'nothing'}
84
+ response = http.request(request)
85
+ response.body.should include("<div id='posted'>field=nothing</div>")
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'basic rails4 test' do
4
+
5
+ before(:all) do
6
+ configurator = Jubilee::Configuration.new(chdir: "#{apps_dir}/rails4/basic")
7
+ @server = Jubilee::Server.new(configurator.app, configurator.options)
8
+ @server.start
9
+ sleep 0.1
10
+ end
11
+
12
+ after(:all) do
13
+ @server.stop
14
+ end
15
+
16
+ it 'should do a basic get' do
17
+ visit '/'
18
+ page.should have_content('It works')
19
+ page.find('#success')[:class].should == 'basic-rails4'
20
+ end
21
+
22
+ context 'streaming' do
23
+ it "should work for small responses" do
24
+ verify_streaming("/root/streaming?count=0")
25
+ end
26
+
27
+ it "should work for large responses" do
28
+ verify_streaming("/root/streaming?count=500")
29
+ end
30
+
31
+ def verify_streaming(url)
32
+ uri = URI.parse("#{Capybara.app_host}#{url}")
33
+ Net::HTTP.get_response(uri) do |response|
34
+ response.should be_chunked
35
+ response.header['transfer-encoding'].should == 'chunked'
36
+ chunk_count, body = 0, ""
37
+ response.read_body do |chunk|
38
+ chunk_count += 1
39
+ body += chunk
40
+ end
41
+ body.should include('It works')
42
+ body.each_line do |line|
43
+ line.should_not match(/^\d+\s*$/)
44
+ end
45
+ chunk_count.should be > 1
46
+ end
47
+ end
48
+ end
49
+
50
+ it 'should return a static page beneath default public dir' do
51
+ visit "/some_page.html"
52
+ element = page.find('#success')
53
+ element.should_not be_nil
54
+ element.text.should == 'static page'
55
+ end
56
+
57
+ it "should support setting multiple cookies" do
58
+ visit "/root/multiple_cookies"
59
+ page.driver.cookies['foo1'].value.should == 'bar1'
60
+ page.driver.cookies['foo2'].value.should == 'bar2'
61
+ page.driver.cookies['foo3'].value.should == 'bar3'
62
+ end
63
+
64
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ feature "basic sinatra test" do
4
+
5
+ before(:all) do
6
+ configurator = Jubilee::Configuration.new(chdir: "#{apps_dir}/sinatra/basic")
7
+ @server = Jubilee::Server.new(configurator.app, configurator.options)
8
+ @server.start
9
+ end
10
+
11
+ after(:all) do
12
+ @server.stop
13
+ end
14
+
15
+ it "should work" do
16
+ visit ""
17
+ page.should have_content('it worked')
18
+ page.should have_selector('div.sinatra-basic')
19
+ find("#success").should have_content('it worked')
20
+ end
21
+
22
+ it "should return a valid request scheme" do
23
+ visit "/request-mapping"
24
+ find("#success #scheme").text.should eql("http")
25
+ end
26
+
27
+ it "should return a static page beneath default 'public' dir" do
28
+ visit "/some_page.html"
29
+ page.find('#success')[:class].should == 'default'
30
+ end
31
+
32
+ it "should return 304 for unmodified static assets" do
33
+ uri = URI.parse("#{Capybara.app_host}/some_page.html")
34
+ Net::HTTP.start(uri.host, uri.port) do |http|
35
+ request = Net::HTTP::Get.new(uri.request_uri)
36
+ request.add_field('If-Modified-Since', 'Sat, 31 Dec 2050 00:00:00 GMT')
37
+ response = http.request(request)
38
+ response.code.should == "304"
39
+ end
40
+ end
41
+
42
+ it "should post something" do
43
+ visit "/poster"
44
+ fill_in 'field', :with => 'something'
45
+ click_button 'submit'
46
+ find('#success').should have_content("you posted something")
47
+ end
48
+
49
+
50
+ it "should allow headers through" do
51
+ uri = URI.parse("#{Capybara.app_host}/")
52
+ response = Net::HTTP.get_response(uri)
53
+ response['Biscuit'].should == 'Gravy'
54
+ end
55
+
56
+ it "should allow OPTIONS requests" do
57
+ uri = URI.parse("#{Capybara.app_host}/")
58
+ Net::HTTP.start(uri.host, uri.port) do |http|
59
+ request = Net::HTTP::Options.new(uri.request_uri)
60
+ response = http.request(request)
61
+ response['access-control-allow-origin'].should == '*'
62
+ response['access-control-allow-methods'].should == 'POST'
63
+ end
64
+
65
+ end
66
+
67
+ it "should test Sir Postalot" do
68
+ uri = URI.parse("#{Capybara.app_host}/poster")
69
+ Net::HTTP.start(uri.host, uri.port) do |http|
70
+ 100.times do |i|
71
+ http.request(Net::HTTP::Get.new(uri.request_uri))
72
+ request = Net::HTTP::Post.new(uri.request_uri)
73
+ request.form_data = {'field' => 'nothing'}
74
+ response = http.request(request)
75
+ response.body.should include("<div id='success'>you posted nothing</div>")
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,13 @@
1
+ require 'jubilee'
2
+ require 'capybara/poltergeist'
3
+ require 'capybara/rspec'
4
+ require 'ostruct'
5
+ require 'net/http'
6
+
7
+ Capybara.app_host = "http://localhost:8080"
8
+ Capybara.run_server = false
9
+ Capybara.default_driver = :poltergeist
10
+
11
+ def apps_dir
12
+ File.expand_path("../apps", __FILE__)
13
+ end
@@ -0,0 +1 @@
1
+ jruby-1.7.4
@@ -0,0 +1,5 @@
1
+ class App
2
+ def call(env)
3
+ [200, {"Content-Type" => "text/plain"}, ["embeded app"]]
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+ require 'jubilee/cli'
3
+
4
+ class TestJubileeCLI < MiniTest::Unit::TestCase
5
+ def test_parse_options
6
+ cli = Jubilee::CLI.new(["app.rb"])
7
+ cli.parse_options
8
+ assert_equal "app.rb", cli.options[:rackup]
9
+ assert_equal 8080, cli.options[:Port]
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+ require 'jubilee/configuration'
3
+
4
+ class TestConfig < MiniTest::Unit::TestCase
5
+
6
+ def setup
7
+ end
8
+
9
+ def test_load
10
+ @config = Jubilee::Configuration.new({rackup: "config/app.rb"})
11
+ resp = [200, {"Content-Type" => "text/plain"}, ["embeded app"]]
12
+ assert_equal resp, @config.app.call({})
13
+ end
14
+
15
+ def test_config_invalid
16
+ tmp = Tempfile.new("jubilee_config")
17
+ tmp.syswrite(%q(abcd "helloword"))
18
+ assert_raises(NoMethodError) do
19
+ Jubilee::Configuration.new(config_file: tmp.path)
20
+ end
21
+ end
22
+
23
+ def test_config_non_exist
24
+ tmp = Tempfile.new("jubilee_config")
25
+ path = tmp.path
26
+ tmp.close!
27
+ assert_raises(Errno::ENOENT) do
28
+ Jubilee::Configuration.new(config_file: path)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,137 @@
1
+ require 'test_helper'
2
+ require 'rack/lint'
3
+ require 'rack/commonlogger'
4
+
5
+ class TestRackServer < MiniTest::Unit::TestCase
6
+ include Helpers
7
+
8
+ class ErrorChecker
9
+ def initialize(app)
10
+ @app = app
11
+ @exception = nil
12
+ @env = nil
13
+ end
14
+
15
+ attr_reader :exception, :env
16
+
17
+ def call(env)
18
+ begin
19
+ @env = env
20
+ return @app.call(env)
21
+ rescue Exception => e
22
+ @exception = e
23
+
24
+ [
25
+ 500,
26
+ { "X-Exception" => e.message, "X-Exception-Class" => e.class.to_s },
27
+ ["Error detected"]
28
+ ]
29
+ end
30
+ end
31
+ end
32
+
33
+ class ServerLint < Rack::Lint
34
+ def call(env)
35
+ assert("No env given") { env }
36
+ check_env env
37
+
38
+ @app.call(env)
39
+ end
40
+ end
41
+
42
+ def setup
43
+ @valid_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\n\r\n"
44
+
45
+ @simple = lambda { |env| [200, { "X-Header" => "Works" }, ["Hello"]] }
46
+ @checker = ErrorChecker.new ServerLint.new(@simple)
47
+ @host = "localhost"
48
+ @port = 8080
49
+ end
50
+
51
+ def teardown
52
+ @server.stop
53
+ sleep 0.1
54
+ end
55
+
56
+ def test_lint
57
+ @server = Jubilee::Server.new @checker
58
+
59
+ @server.start
60
+
61
+ hit(['http://127.0.0.1:8080/test'])
62
+
63
+ if exc = @checker.exception
64
+ raise exc
65
+ end
66
+ end
67
+
68
+ def test_large_post_body
69
+ @checker = ErrorChecker.new ServerLint.new(@simple)
70
+ @server = Jubilee::Server.new @checker
71
+
72
+ @server.start
73
+ sleep 0.1
74
+
75
+ big = "x" * (1024 * 16)
76
+
77
+ Net::HTTP.post_form URI.parse('http://127.0.0.1:8080/test'),
78
+ { "big" => big }
79
+
80
+ if exc = @checker.exception
81
+ raise exc
82
+ end
83
+ end
84
+
85
+ def test_path_info
86
+ input = nil
87
+ @server = Jubilee::Server.new (lambda { |env| input = env; @simple.call(env) })
88
+ @server.start
89
+
90
+ hit(['http://127.0.0.1:8080/test/a/b/c'])
91
+
92
+ assert_equal "/test/a/b/c", input['PATH_INFO']
93
+ end
94
+
95
+ def test_request_method
96
+ input = nil
97
+ @server = Jubilee::Server.new(Rack::MethodOverride.new(lambda { |env| input = env; @simple.call(env) }))
98
+ @server.start
99
+ sleep 0.1
100
+
101
+ POST('/test/a/b/c', {"_method" => "delete", "user" => 1})
102
+ assert_equal "DELETE", input['REQUEST_METHOD']
103
+
104
+ # it should not memorize env
105
+ POST('/test/a/b/c', {"foo" => "bar"})
106
+ assert_equal "POST", input['REQUEST_METHOD']
107
+
108
+ end
109
+
110
+ def test_query_string
111
+ input = nil
112
+ @server = Jubilee::Server.new (lambda { |env| input = env; @simple.call(env) })
113
+ @server.start
114
+
115
+ hit(['http://127.0.0.1:8080/test/a/b/c?foo=bar'])
116
+
117
+ assert_equal "foo=bar", input['QUERY_STRING']
118
+ end
119
+
120
+ def test_post_data
121
+ require 'rack/request'
122
+ input = nil
123
+ @server = Jubilee::Server.new (lambda { |env| input = env; @simple.call(env) })
124
+ @server.start
125
+ sleep 0.1
126
+
127
+ req = Net::HTTP::Post::Multipart.new("/", "foo" => "bar")
128
+ resp = Net::HTTP.start('localhost', 8080) do |http|
129
+ http.request req
130
+ end
131
+
132
+ #Net::HTTP.post_form URI.parse('http://127.0.0.1:8080/test'), { "foo" => "bar" }
133
+
134
+ request = Rack::Request.new input
135
+ assert_equal "bar", request.params["foo"]
136
+ end
137
+ end