nogara-wash_out 0.5.2

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 (59) hide show
  1. data/.gitignore +9 -0
  2. data/.travis.yml +3 -0
  3. data/Appraisals +7 -0
  4. data/CHANGELOG.md +79 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +118 -0
  7. data/LICENSE +22 -0
  8. data/README.md +181 -0
  9. data/Rakefile +14 -0
  10. data/app/helpers/wash_out_helper.rb +64 -0
  11. data/app/views/wash_with_soap/error.builder +10 -0
  12. data/app/views/wash_with_soap/response.builder +13 -0
  13. data/app/views/wash_with_soap/wsdl.builder +68 -0
  14. data/gemfiles/rails-3.0.11.gemfile +8 -0
  15. data/gemfiles/rails-3.0.11.gemfile.lock +130 -0
  16. data/gemfiles/rails-3.1.3.gemfile +8 -0
  17. data/gemfiles/rails-3.1.3.gemfile.lock +141 -0
  18. data/init.rb +1 -0
  19. data/lib/wash_out.rb +35 -0
  20. data/lib/wash_out/dispatcher.rb +206 -0
  21. data/lib/wash_out/engine.rb +30 -0
  22. data/lib/wash_out/model.rb +25 -0
  23. data/lib/wash_out/param.rb +176 -0
  24. data/lib/wash_out/router.rb +36 -0
  25. data/lib/wash_out/soap.rb +40 -0
  26. data/lib/wash_out/type.rb +28 -0
  27. data/lib/wash_out/version.rb +3 -0
  28. data/lib/wash_out/wsse.rb +79 -0
  29. data/spec/dummy/Rakefile +7 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  31. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/spec/dummy/config.ru +4 -0
  34. data/spec/dummy/config/application.rb +42 -0
  35. data/spec/dummy/config/boot.rb +10 -0
  36. data/spec/dummy/config/environment.rb +5 -0
  37. data/spec/dummy/config/environments/development.rb +23 -0
  38. data/spec/dummy/config/environments/test.rb +30 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/inflections.rb +10 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  42. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  43. data/spec/dummy/config/initializers/session_store.rb +8 -0
  44. data/spec/dummy/config/locales/en.yml +5 -0
  45. data/spec/dummy/config/routes.rb +58 -0
  46. data/spec/dummy/public/404.html +26 -0
  47. data/spec/dummy/public/422.html +26 -0
  48. data/spec/dummy/public/500.html +26 -0
  49. data/spec/dummy/public/favicon.ico +0 -0
  50. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  51. data/spec/dummy/script/rails +6 -0
  52. data/spec/spec_helper.rb +51 -0
  53. data/spec/support/httpi-rack.rb +46 -0
  54. data/spec/wash_out/dispatcher_spec.rb +65 -0
  55. data/spec/wash_out/param_spec.rb +26 -0
  56. data/spec/wash_out/type_spec.rb +23 -0
  57. data/spec/wash_out_spec.rb +686 -0
  58. data/wash_out.gemspec +21 -0
  59. metadata +183 -0
@@ -0,0 +1,36 @@
1
+ module WashOut
2
+ # This class is a Rack middleware used to route SOAP requests to a proper
3
+ # action of a given SOAP controller.
4
+ class Router
5
+ def initialize(controller_name)
6
+ @controller_name = "#{controller_name.to_s}_controller".camelize
7
+ end
8
+
9
+ def call(env)
10
+ controller = @controller_name.constantize
11
+
12
+ soap_action = env['HTTP_SOAPACTION']
13
+
14
+ if soap_action == '""'
15
+ soap_action = env["action_dispatch.request.request_parameters"]["Envelope"]["Body"].keys.first
16
+ env['wash_out.soap_action'] = soap_action
17
+ elsif soap_action
18
+ # RUBY18 1.8 does not have force_encoding.
19
+ soap_action.force_encoding('UTF-8') if soap_action.respond_to? :force_encoding
20
+
21
+ soap_action.gsub!(/^\"(.*)\"$/, '\1')
22
+
23
+ env['wash_out.soap_action'] = soap_action
24
+ end
25
+
26
+ action_spec = controller.soap_actions[soap_action]
27
+ if action_spec
28
+ action = action_spec[:to]
29
+ else
30
+ action = '_invalid_action'
31
+ end
32
+
33
+ controller.action(action).call(env)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ require 'active_support/concern'
2
+
3
+ module WashOut
4
+ module SOAP
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ attr_accessor :soap_actions
9
+
10
+ # Define a SOAP action +action+. The function has two required +options+:
11
+ # :args and :return. Each is a type +definition+ of format described in
12
+ # WashOut::Param#parse_def.
13
+ #
14
+ # An optional option :to can be passed to allow for names of SOAP actions
15
+ # which are not valid Ruby function names.
16
+ def soap_action(action, options={})
17
+ if action.is_a?(Symbol)
18
+ if WashOut::Engine.camelize_wsdl.to_s == 'lower'
19
+ options[:to] ||= action.to_s
20
+ action = action.to_s.camelize(:lower)
21
+ elsif WashOut::Engine.camelize_wsdl
22
+ options[:to] ||= action.to_s
23
+ action = action.to_s.camelize
24
+ end
25
+ end
26
+
27
+ self.soap_actions[action] = {
28
+ :in => WashOut::Param.parse_def(options[:args]),
29
+ :out => WashOut::Param.parse_def(options[:return]),
30
+ :to => options[:to] || action
31
+ }
32
+ end
33
+ end
34
+
35
+ included do
36
+ include WashOut::Dispatcher
37
+ self.soap_actions = {}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ module WashOut
2
+ class Type
3
+ def self.type_name(value)
4
+ @param_type_name = value
5
+ end
6
+
7
+ def self.map(value)
8
+ raise RuntimeError, "Wrong definition: #{value.inspect}" unless value.is_a?(Hash)
9
+ @param_map = value
10
+ end
11
+
12
+ def self.wash_out_param_map
13
+ @param_map
14
+ end
15
+
16
+ def self.wash_out_param_name
17
+ @param_type_name ||= name.underscore
18
+
19
+ if WashOut::Engine.camelize_wsdl.to_s == 'lower'
20
+ @param_type_name = @param_type_name.camelize(:lower)
21
+ elsif WashOut::Engine.camelize_wsdl
22
+ @param_type_name = @param_type_name.camelize
23
+ end
24
+
25
+ @param_type_name
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module WashOut
2
+ VERSION = "0.5.2"
3
+ end
@@ -0,0 +1,79 @@
1
+ module WashOut
2
+ class Wsse
3
+
4
+ def self.authenticate(token)
5
+ wsse = self.new(token)
6
+
7
+ unless wsse.eligible?
8
+ raise WashOut::Dispatcher::SOAPError, "Unauthorized"
9
+ end
10
+ end
11
+
12
+ def initialize(token)
13
+ if token.blank? && required?
14
+ raise WashOut::Dispatcher::SOAPError, "Missing required UsernameToken"
15
+ end
16
+ @username_token = token
17
+ end
18
+
19
+ def required?
20
+ !WashOut::Engine.wsse_username.blank?
21
+ end
22
+
23
+ def expected_user
24
+ WashOut::Engine.wsse_username
25
+ end
26
+
27
+ def expected_password
28
+ WashOut::Engine.wsse_password
29
+ end
30
+
31
+ def matches_expected_digest?(password)
32
+ nonce = @username_token.values_at(:nonce, :Nonce).compact.first
33
+ timestamp = @username_token.values_at(:created, :Created).compact.first
34
+
35
+ return false if nonce.nil? || timestamp.nil?
36
+
37
+ # Token should not be accepted if timestamp is older than 5 minutes ago
38
+ # http://www.oasis-open.org/committees/download.php/16782/wss-v1.1-spec-os-UsernameTokenProfile.pdf
39
+ offset_in_minutes = ((DateTime.now - DateTime.parse(timestamp))* 24 * 60).to_i
40
+ return false if offset_in_minutes >= 5
41
+
42
+ # There are a few different implementations of the digest calculation
43
+
44
+ flavors = Array.new
45
+
46
+ # Ruby / Savon
47
+ token = nonce + timestamp + expected_password
48
+ flavors << Base64.encode64(Digest::SHA1.hexdigest(token)).chomp!
49
+
50
+ # Java
51
+ token = Base64.decode64(nonce) + timestamp + expected_password
52
+ flavors << Base64.encode64(Digest::SHA1.digest(token)).chomp!
53
+
54
+ flavors.each do |f|
55
+ return true if f == password
56
+ end
57
+
58
+ return false
59
+ end
60
+
61
+ def eligible?
62
+ return true unless required?
63
+
64
+ user = @username_token.values_at(:username, :Username).compact.first
65
+ password = @username_token.values_at(:password, :Password).compact.first
66
+
67
+ if (expected_user == user && expected_password == password)
68
+ return true
69
+ end
70
+
71
+ if (expected_user == user && matches_expected_digest?(password))
72
+ return true
73
+ end
74
+
75
+ return false
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -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 Dummy::Application
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "rails/test_unit/railtie"
5
+
6
+ Bundler.require
7
+ require "wash_out"
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Custom directories with classes and modules you want to be autoloadable.
16
+ # config.autoload_paths += %W(#{config.root}/extras)
17
+
18
+ # Only load the plugins named here, in the order given (default is alphabetical).
19
+ # :all can be used as a placeholder for all plugins not explicitly named.
20
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
+
22
+ # Activate observers that should always be running.
23
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
+
25
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
+ # config.time_zone = 'Central Time (US & Canada)'
28
+
29
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
+ # config.i18n.default_locale = :de
32
+
33
+ # JavaScript files you want as :defaults (application.js is always included).
34
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
35
+
36
+ # Configure the default encoding used in templates for Ruby 1.9.
37
+ config.encoding = "utf-8"
38
+
39
+ # Configure sensitive parameters which will be filtered from the log file.
40
+ config.filter_parameters += [:password]
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,23 @@
1
+ Dummy::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_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Print deprecation notices to the Rails logger
18
+ config.active_support.deprecation = :log
19
+
20
+ # Only use best-standards-support built into browsers
21
+ config.action_dispatch.best_standards_support = :builtin
22
+ end
23
+
@@ -0,0 +1,30 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
24
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
25
+ # like if you have constraints or database-specific column types
26
+ # config.active_record.schema_format = :sql
27
+
28
+ # Print deprecation notices to the stderr
29
+ config.active_support.deprecation = :stderr
30
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'b8d5d5687c012c2ef1a7a6e8006172402c48a3dcccca67c076eaad81c4712ad236ca2717c3706df7b286468c749d223f22acb0d96c27bdf33bbdbb9684ad46e5'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,58 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get 'short'
20
+ # post 'toggle'
21
+ # end
22
+ #
23
+ # collection do
24
+ # get 'sold'
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get 'recent', :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id(.:format)))'
58
+ end