jetpack 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +2 -1
  2. data/LICENSE +14 -0
  3. data/README.markdown +35 -6
  4. data/Rakefile +14 -3
  5. data/bin/jetpack +39 -6
  6. data/bin_files/launch.erb +16 -0
  7. data/gems/bundler-1.1.0.gem +0 -0
  8. data/jetpack.gemspec +3 -3
  9. data/jetty_files/etc/fake.crt +31 -0
  10. data/jetty_files/etc/fake.jceks +0 -0
  11. data/jetty_files/etc/fake.key +51 -0
  12. data/jetty_files/etc/fake.pem +89 -0
  13. data/jetty_files/etc/jetty.xml.erb +53 -25
  14. data/jetty_files/jetty-init.erb +4 -0
  15. data/lib/jetpack/settings.rb +24 -10
  16. data/script/ci +1 -1
  17. data/spec/bundler_spec.rb +1 -1
  18. data/spec/filter_spec.rb +59 -0
  19. data/spec/rack_spec.rb +40 -0
  20. data/spec/sample_projects/has_gems_via_bundler/config/jetpack.yml +1 -1
  21. data/spec/sample_projects/has_gems_via_bundler_19/config/jetpack.yml +1 -1
  22. data/spec/sample_projects/has_gems_via_bundler_bad_gemfile_lock/config/jetpack.yml +1 -1
  23. data/spec/sample_projects/no_dependencies/config/jetpack.yml +1 -1
  24. data/spec/sample_projects/rack_19/Gemfile +3 -0
  25. data/spec/sample_projects/rack_19/Gemfile.lock +11 -0
  26. data/spec/sample_projects/rack_19/config.ru +8 -0
  27. data/spec/sample_projects/rack_19/config/jetpack.yml +9 -0
  28. data/spec/sample_projects/webapp/config/jetpack.yml +8 -5
  29. data/spec/sample_projects/webapp_filters/Gemfile +3 -0
  30. data/spec/sample_projects/webapp_filters/Gemfile.lock +88 -0
  31. data/spec/sample_projects/webapp_filters/app/controllers/application_controller.rb +5 -0
  32. data/spec/sample_projects/webapp_filters/config.ru +4 -0
  33. data/spec/sample_projects/webapp_filters/config/application.rb +46 -0
  34. data/spec/sample_projects/webapp_filters/config/boot.rb +6 -0
  35. data/spec/sample_projects/webapp_filters/config/environment.rb +5 -0
  36. data/spec/sample_projects/webapp_filters/config/environments/development.rb +25 -0
  37. data/spec/sample_projects/webapp_filters/config/environments/test.rb +35 -0
  38. data/spec/sample_projects/webapp_filters/config/initializers/secret_token.rb +7 -0
  39. data/spec/sample_projects/webapp_filters/config/jetpack.yml +10 -0
  40. data/spec/sample_projects/webapp_filters/config/jetpack_files/vendor/jetty/etc/custom-project-specific-jetty.xml +5 -0
  41. data/spec/sample_projects/webapp_filters/config/jetpack_files/vendor/jetty/etc/template-from-project-jetty.xml.erb +9 -0
  42. data/spec/sample_projects/webapp_filters/config/routes.rb +60 -0
  43. data/spec/sample_projects/webapp_filters/public/index.html +239 -0
  44. data/spec/sample_projects/webapp_filters/script/rails +6 -0
  45. data/spec/spec_helper.rb +0 -7
  46. data/spec/web_spec.rb +25 -9
  47. data/src/java/jetpack/filter/IgnoreUnknownHttpMethodsFilter.java +43 -0
  48. data/src/java/jetpack/filter/ValidUrlFilter.java +62 -0
  49. data/web_inf_files/web.xml.erb +46 -4
  50. metadata +110 -32
  51. data/gems/bundler-1.0.18.gem +0 -0
  52. data/gems/bundler-1.1.rc.gem +0 -0
@@ -14,6 +14,10 @@ JETTY_LOGS=$WEB_ROOT/log
14
14
  # Avoid unnecessary su call if we're already the app user
15
15
  test `whoami` != <%=@settings.app_user%> && JETTY_USER=<%=@settings.app_user%>
16
16
 
17
+ <% if @settings.environment %>
18
+ source <%=@settings.environment%>
19
+ <% end %>
20
+
17
21
  # Startup script for jetty under *nix systems (it works under NT/cygwin too).
18
22
 
19
23
  # To get the service to restart correctly on reboot, uncomment below (3 lines):
@@ -12,17 +12,23 @@ module Jetpack
12
12
  end
13
13
 
14
14
  def initialize(project_dir, user_defined_options)
15
- contents = {}
16
- contents["app_root"] = user_defined_options["app_root"] || File.expand_path(project_dir)
17
- contents["app_user"] = user_defined_options["app_user"] || Etc.getpwuid(File.stat(contents["app_root"]).uid).name
18
- contents["java_options"] = user_defined_options["java_options"] || "-Xmx2048m"
19
- contents["https_port"] = user_defined_options["https_port"] || "4443"
20
- contents["http_port"] = user_defined_options["http_port"] || "4080"
21
- contents["jruby_rack"] = user_defined_options["jruby-rack"] if user_defined_options.key?("jruby-rack")
22
- contents["jetty"] = user_defined_options["jetty"] if user_defined_options.key?("jetty")
23
- contents["jruby"] = user_defined_options["jruby"] if user_defined_options.key?("jruby")
15
+ contents = {}
16
+ contents["app_root"] = user_defined_options["app_root"] || File.expand_path(project_dir)
17
+ contents["app_user"] = user_defined_options["app_user"] || Etc.getpwuid(File.stat(contents["app_root"]).uid).name
18
+ contents["java_options"] = user_defined_options["java_options"] || "-Xmx2048m"
19
+ contents["https_port"] = user_defined_options["https_port"] if user_defined_options.key?("https_port")
20
+ contents["http_port"] = user_defined_options["http_port"] if user_defined_options.key?("http_port")
21
+ contents["jruby_rack"] = user_defined_options["jruby-rack"] if user_defined_options.key?("jruby-rack")
22
+ contents["jetty"] = user_defined_options["jetty"] if user_defined_options.key?("jetty")
23
+ contents["jetty_filters"] = user_defined_options["jetty_filters"] if user_defined_options.key?("jetty_filters")
24
+ contents["jruby"] = user_defined_options["jruby"] if user_defined_options.key?("jruby")
24
25
  contents["max_concurrent_connections"] = user_defined_options["max_concurrent_connections"] || 20
25
- contents["ruby_version"] = user_defined_options["ruby_version"] || "1.8"
26
+ contents["ruby_version"] = user_defined_options["ruby_version"] || "1.8"
27
+ contents["app_type"] = user_defined_options["app_type"] || "rails"
28
+ contents["environment"] = user_defined_options["environment"] || nil
29
+ contents["keystore_type"] = user_defined_options["keystore_type"] || "PKCS12"
30
+ contents["keystore"] = user_defined_options["keystore"] || nil
31
+ contents["keystore_password"] = user_defined_options["keystore_password"] || nil
26
32
 
27
33
  @keys = contents.keys.sort
28
34
 
@@ -37,6 +43,14 @@ module Jetpack
37
43
  respond_to?(:jetty)
38
44
  end
39
45
 
46
+ def jetty_filters?
47
+ respond_to?(:jetty_filters)
48
+ end
49
+
50
+ def rails?
51
+ app_type == 'rails'
52
+ end
53
+
40
54
  def jetty_pid_path
41
55
  File.join(app_root, "/vendor/jetty/run/jetty.pid")
42
56
  end
data/script/ci CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- bundler_version="1.0.18"
3
+ bundler_version="1.1.0"
4
4
  rspec_version="2.6.0"
5
5
 
6
6
  source "$HOME/.rvm/scripts/rvm"
@@ -36,7 +36,7 @@ describe "jetpack - bundler and gems" do
36
36
  it "can be used from a script fed to jruby." do
37
37
  rake_result = x(%{spec/sample_projects/has_gems_via_bundler/bin/ruby -e 'require \\"rubygems\\"; require \\"bundler\\"; puts Bundler::VERSION'})
38
38
  rake_result[:stderr].should == ""
39
- rake_result[:stdout].should include("1.1.rc")
39
+ rake_result[:stdout].should include("1.1.0")
40
40
  rake_result[:exitstatus].should == 0
41
41
  end
42
42
  end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+ require "yaml"
3
+
4
+ describe "jetpack - filters" do
5
+ before(:all) do
6
+ reset
7
+ @result = x!("bin/jetpack spec/sample_projects/webapp_filters")
8
+ end
9
+
10
+ after(:all) do
11
+ reset
12
+ end
13
+
14
+ it "runs" do
15
+ pid_to_kill = run_app
16
+ begin
17
+ x!("curl https://localhost:11443/hello --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
18
+
19
+ x!("curl https://localhost:11443/hello?foo=bar --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
20
+
21
+ x!("curl --head --request DEBUG https://localhost:11443/ --insecure")[:stdout].split("\n").first.strip.should == "HTTP/1.1 405 Method Not Allowed"
22
+
23
+ x!("curl --head 'https://localhost:11443/<script>xss</script>.aspx' --insecure")[:stdout].split("\n").first.strip.should == "HTTP/1.1 400 Bad Request"
24
+
25
+ x!("curl --head 'https://localhost:11443/?foo=<script>xss</script>.aspx' --insecure")[:stdout].split("\n").first.strip.should == "HTTP/1.1 400 Bad Request"
26
+
27
+ x!("curl http://localhost:11080/hello")[:stdout].split("<br/>").first.strip.should == "Hello World"
28
+
29
+ x!("curl http://localhost:11080/hello?foo=bar")[:stdout].split("<br/>").first.strip.should == "Hello World"
30
+
31
+ x!("curl http://#{Socket.gethostname}:11080/hello")[:stdout].split("<br/>").first.strip.should == "Hello World"
32
+
33
+ x!("curl http://127.0.0.1:11080/hello")[:stdout].split("<br/>").first.strip.should == "Hello World"
34
+
35
+ x!("curl --head --request DEBUG http://localhost:11080/")[:stdout].split("\n").first.strip.should == "HTTP/1.1 405 Method Not Allowed"
36
+
37
+ x!("curl --head 'http://localhost:11080/<script>xss</script>.aspx'")[:stdout].split("\n").first.strip.should == "HTTP/1.1 400 Bad Request"
38
+
39
+ x!("curl --head 'http://localhost:11080/?foo=<script>xss</script>.aspx'")[:stdout].split("\n").first.strip.should == "HTTP/1.1 400 Bad Request"
40
+
41
+ ensure
42
+ system("kill -9 #{pid_to_kill}")
43
+ end
44
+ end
45
+
46
+ def run_app
47
+ jetty_pid = Process.spawn({'RAILS_ENV' => 'development'}, 'java', '-jar', 'start.jar', {:chdir => "spec/sample_projects/webapp_filters/vendor/jetty"})
48
+ start_time = Time.now
49
+ loop do
50
+ begin
51
+ TCPSocket.open("localhost", 11443)
52
+ return jetty_pid
53
+ rescue Errno::ECONNREFUSED
54
+ raise "it's taking too long to start the server, something might be wrong" if Time.now - start_time > 60
55
+ sleep 0.1
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require "yaml"
3
+
4
+ describe "jetpack - web start for rack app" do
5
+ before(:all) do
6
+ reset
7
+ @result = x!("bin/jetpack spec/sample_projects/rack_19")
8
+ end
9
+
10
+ after(:all) do
11
+ reset
12
+ end
13
+
14
+ it "runs" do
15
+ pid_to_kill = run_app("spec/sample_projects/rack_19")
16
+ begin
17
+ #HTTP 4443 - intended to be proxied to from something listening on 443
18
+ x!("curl https://localhost:10443/hello --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
19
+
20
+ #HTTP 9080 - intended for internal health checking
21
+ x!("curl http://localhost:10080/hello --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
22
+ ensure
23
+ system("kill -9 #{pid_to_kill}")
24
+ end
25
+ end
26
+
27
+ def run_app(app)
28
+ jetty_pid = Process.spawn({'RAILS_ENV' => 'development'}, 'java', '-jar', 'start.jar', {:chdir => "#{app}/vendor/jetty"})
29
+ start_time = Time.now
30
+ loop do
31
+ begin
32
+ TCPSocket.open("localhost", 10443)
33
+ return jetty_pid
34
+ rescue Errno::ECONNREFUSED
35
+ raise "it's taking too long to start the server, something might be wrong" if Time.now - start_time > 60
36
+ sleep 0.1
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1 +1 @@
1
- jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
1
+ jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.7.jar"
@@ -1,2 +1,2 @@
1
- jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
1
+ jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.7.jar"
2
2
  ruby_version: 1.9
@@ -1 +1 @@
1
- jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
1
+ jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.7.jar"
@@ -1 +1 @@
1
- jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
1
+ jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.7.jar"
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem 'rack'
@@ -0,0 +1,11 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ rack (1.4.1)
5
+
6
+ PLATFORMS
7
+ java
8
+ ruby
9
+
10
+ DEPENDENCIES
11
+ rack
@@ -0,0 +1,8 @@
1
+ hash_in_19_syntax = {
2
+ a: 1
3
+ }
4
+
5
+ run Proc.new {|env| [200,
6
+ {"Content-Type" => "application/json"},
7
+ ["Hello World"]
8
+ ]}
@@ -0,0 +1,9 @@
1
+ jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.7.jar"
2
+ jetty: "file://<%= File.expand_path('spec/local_mirror') %>/jetty-hightide-8.1.3.v20120416.zip"
3
+ jruby-rack: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-rack-1.1.5.jar"
4
+ http_port: 10080
5
+ https_port: 10443
6
+ ruby_version: 1.9
7
+ app_type: rack
8
+ keystore: "etc/fake.p12"
9
+ keystore_password: "foobar"
@@ -1,6 +1,9 @@
1
- jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
2
- jetty: "file://<%= File.expand_path('spec/local_mirror') %>/jetty-hightide-7.4.5.v20110725.zip"
3
- jruby-rack: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-rack-1.0.10.jar"
4
- http_port: 10080
5
- https_port: 10443
1
+ jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.7.jar"
2
+ jetty: "file://<%= File.expand_path('spec/local_mirror') %>/jetty-hightide-8.1.3.v20120416.zip"
3
+ jruby-rack: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-rack-1.1.5.jar"
4
+ http_port: 9080
5
+ https_port: 9443
6
6
  max_concurrent_connections: 15
7
+ java_options: -Xmx256M
8
+ keystore: "etc/fake.p12"
9
+ keystore_password: "foobar"
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem "rails"
@@ -0,0 +1,88 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.1.0)
5
+ actionpack (= 3.1.0)
6
+ mail (~> 2.3.0)
7
+ actionpack (3.1.0)
8
+ activemodel (= 3.1.0)
9
+ activesupport (= 3.1.0)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6)
13
+ rack (~> 1.3.2)
14
+ rack-cache (~> 1.0.3)
15
+ rack-mount (~> 0.8.2)
16
+ rack-test (~> 0.6.1)
17
+ sprockets (~> 2.0.0)
18
+ activemodel (3.1.0)
19
+ activesupport (= 3.1.0)
20
+ bcrypt-ruby (~> 3.0.0)
21
+ builder (~> 3.0.0)
22
+ i18n (~> 0.6)
23
+ activerecord (3.1.0)
24
+ activemodel (= 3.1.0)
25
+ activesupport (= 3.1.0)
26
+ arel (~> 2.2.1)
27
+ tzinfo (~> 0.3.29)
28
+ activeresource (3.1.0)
29
+ activemodel (= 3.1.0)
30
+ activesupport (= 3.1.0)
31
+ activesupport (3.1.0)
32
+ multi_json (~> 1.0)
33
+ arel (2.2.1)
34
+ bcrypt-ruby (3.0.1)
35
+ builder (3.0.0)
36
+ erubis (2.7.0)
37
+ hike (1.2.1)
38
+ i18n (0.6.0)
39
+ mail (2.3.0)
40
+ i18n (>= 0.4.0)
41
+ mime-types (~> 1.16)
42
+ treetop (~> 1.4.8)
43
+ mime-types (1.16)
44
+ multi_json (1.0.3)
45
+ polyglot (0.3.2)
46
+ rack (1.3.4)
47
+ rack-cache (1.0.3)
48
+ rack (>= 0.4)
49
+ rack-mount (0.8.3)
50
+ rack (>= 1.0.0)
51
+ rack-ssl (1.3.2)
52
+ rack
53
+ rack-test (0.6.1)
54
+ rack (>= 1.0)
55
+ rails (3.1.0)
56
+ actionmailer (= 3.1.0)
57
+ actionpack (= 3.1.0)
58
+ activerecord (= 3.1.0)
59
+ activeresource (= 3.1.0)
60
+ activesupport (= 3.1.0)
61
+ bundler (~> 1.0)
62
+ railties (= 3.1.0)
63
+ railties (3.1.0)
64
+ actionpack (= 3.1.0)
65
+ activesupport (= 3.1.0)
66
+ rack-ssl (~> 1.3.2)
67
+ rake (>= 0.8.7)
68
+ rdoc (~> 3.4)
69
+ thor (~> 0.14.6)
70
+ rake (0.9.2)
71
+ rdoc (3.9.4)
72
+ sprockets (2.0.1)
73
+ hike (~> 1.2)
74
+ rack (~> 1.0)
75
+ tilt (~> 1.1, != 1.3.0)
76
+ thor (0.14.6)
77
+ tilt (1.3.3)
78
+ treetop (1.4.10)
79
+ polyglot
80
+ polyglot (>= 0.3.1)
81
+ tzinfo (0.3.30)
82
+
83
+ PLATFORMS
84
+ java
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ rails
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ def hello
3
+ render :text => "Hello World<br/>LOAD_PATH:#{$LOAD_PATH}<br/>Gem.path:#{Gem.path}"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Foo::Application
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # require “active_record/railtie”
4
+ require "action_controller/railtie"
5
+ require "action_mailer/railtie"
6
+ require "active_resource/railtie"
7
+ require "rails/test_unit/railtie"
8
+
9
+ # If you have a Gemfile, require the gems listed there, including any gems
10
+ # you've limited to :test, :development, or :production.
11
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
12
+
13
+ module Foo
14
+ class Application < Rails::Application
15
+ # Settings in config/environments/* take precedence over those specified here.
16
+ # Application configuration should go into files in config/initializers
17
+ # -- all .rb files in that directory are automatically loaded.
18
+
19
+ # Custom directories with classes and modules you want to be autoloadable.
20
+ # config.autoload_paths += %W(#{config.root}/extras)
21
+
22
+ # Only load the plugins named here, in the order given (default is alphabetical).
23
+ # :all can be used as a placeholder for all plugins not explicitly named.
24
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
25
+
26
+ # Activate observers that should always be running.
27
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
28
+
29
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
30
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
31
+ # config.time_zone = 'Central Time (US & Canada)'
32
+
33
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
34
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
35
+ # config.i18n.default_locale = :de
36
+
37
+ # JavaScript files you want as :defaults (application.js is always included).
38
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
39
+
40
+ # Configure the default encoding used in templates for Ruby 1.9.
41
+ config.encoding = "utf-8"
42
+
43
+ # Configure sensitive parameters which will be filtered from the log file.
44
+ config.filter_parameters += [:password]
45
+ end
46
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Foo::Application.initialize!
@@ -0,0 +1,25 @@
1
+ Foo::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = true
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+ end
25
+