diff --git a/CHANGELOG.md b/CHANGELOG.md index af2b5e3..2e6be18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ See this http://keepachangelog.com link for information on how we want this documented formatted. +## v6.0.0 + +### Changed + +- ⚠️ Breaking Changes ⚠️ +- Remove Rack v2 support. +- Added Rack v3 support. + ## v5.2.1 - Rack 3.X compatibility, by removing uninitialized constants. diff --git a/Gemfile b/Gemfile index eba2800..e575e2e 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,9 @@ source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } gemspec -gem 'rails' +gem 'rails', '7.1.3.4' +gem 'mocha', '~> 2.4' +gem 'rack', "~> 3.1", ">= 3.1.7" group :test do gem 'lambdakiq' diff --git a/Gemfile.lock b/Gemfile.lock index 4a85ddd..679b813 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,101 +3,118 @@ PATH specs: lamby (5.2.1) lambda-console-ruby - rack + rack (>= 3.0.0) GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) + actioncable (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4.3) - actionpack (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activesupport (= 7.0.4.3) + actionmailer (7.1.3.4) + actionpack (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activesupport (= 7.1.3.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.4.3) - actionview (= 7.0.4.3) - activesupport (= 7.0.4.3) - rack (~> 2.0, >= 2.2.0) + rails-dom-testing (~> 2.2) + actionpack (7.1.3.4) + actionview (= 7.1.3.4) + activesupport (= 7.1.3.4) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4.3) - actionpack (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.4) + actionpack (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4.3) - activesupport (= 7.0.4.3) + actionview (7.1.3.4) + activesupport (= 7.1.3.4) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4.3) - activesupport (= 7.0.4.3) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.4) + activesupport (= 7.1.3.4) globalid (>= 0.3.6) - activemodel (7.0.4.3) - activesupport (= 7.0.4.3) - activerecord (7.0.4.3) - activemodel (= 7.0.4.3) - activesupport (= 7.0.4.3) - activestorage (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activesupport (= 7.0.4.3) + activemodel (7.1.3.4) + activesupport (= 7.1.3.4) + activerecord (7.1.3.4) + activemodel (= 7.1.3.4) + activesupport (= 7.1.3.4) + timeout (>= 0.4.0) + activestorage (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activesupport (= 7.1.3.4) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.4.3) + activesupport (7.1.3.4) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - aws-eventstream (1.2.0) - aws-partitions (1.752.0) - aws-sdk-core (3.171.0) - aws-eventstream (~> 1, >= 1.0.2) + aws-eventstream (1.3.0) + aws-partitions (1.956.0) + aws-sdk-core (3.201.1) + aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) - aws-sigv4 (~> 1.5) + aws-sigv4 (~> 1.8) jmespath (~> 1, >= 1.6.1) - aws-sdk-sqs (1.53.0) - aws-sdk-core (~> 3, >= 3.165.0) - aws-sigv4 (~> 1.1) + aws-sdk-sqs (1.80.0) + aws-sdk-core (~> 3, >= 3.201.0) + aws-sigv4 (~> 1.5) aws-sdk-ssm (1.150.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) - aws-sigv4 (1.5.2) + aws-sigv4 (1.8.0) aws-eventstream (~> 1, >= 1.0.2) - builder (3.2.4) + base64 (0.2.0) + bigdecimal (3.1.8) + builder (3.3.0) coderay (1.1.3) - concurrent-ruby (1.2.2) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) - erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) - i18n (1.12.0) + date (3.3.4) + drb (2.2.1) + erubi (1.13.0) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) jmespath (1.6.2) lambda-console-ruby (1.0.0) lambdakiq (2.2.0) @@ -105,81 +122,97 @@ GEM aws-sdk-sqs concurrent-ruby railties - loofah (2.20.0) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.18.0) + mini_mime (1.1.5) + minitest (5.24.1) minitest-focus (1.3.1) minitest (>= 4, < 6) - mocha (2.0.2) + mocha (2.4.0) ruby2_keywords (>= 0.0.5) - net-imap (0.3.4) + mutex_m (0.2.0) + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.5.0) net-protocol - nio4r (2.5.9) - nokogiri (1.14.3-aarch64-linux) + nio4r (2.7.3) + nokogiri (1.16.6-aarch64-linux) racc (~> 1.4) - nokogiri (1.14.3-arm64-darwin) + nokogiri (1.16.6-arm64-darwin) racc (~> 1.4) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - racc (1.6.2) - rack (2.2.6.4) + psych (5.1.2) + stringio + racc (1.8.0) + rack (3.1.7) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.4.3) - actioncable (= 7.0.4.3) - actionmailbox (= 7.0.4.3) - actionmailer (= 7.0.4.3) - actionpack (= 7.0.4.3) - actiontext (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activemodel (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.4) + actioncable (= 7.1.3.4) + actionmailbox (= 7.1.3.4) + actionmailer (= 7.1.3.4) + actionpack (= 7.1.3.4) + actiontext (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activemodel (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) bundler (>= 1.15.0) - railties (= 7.0.4.3) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + railties (= 7.1.3.4) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - railties (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) - method_source + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rake (13.0.6) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + reline (0.5.9) + io-console (~> 0.5) ruby2_keywords (0.0.5) - thor (1.2.1) + stringio (3.1.1) + thor (1.3.1) timecop (0.9.6) - timeout (0.3.2) + timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) webrick (1.8.1) - websocket-driver (0.7.5) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.7) + zeitwerk (2.6.16) PLATFORMS aarch64-linux @@ -194,9 +227,10 @@ DEPENDENCIES lamby! minitest minitest-focus - mocha + mocha (~> 2.4) pry - rails + rack (~> 3.1, >= 3.1.7) + rails (= 7.1.3.4) rake timecop webrick diff --git a/bin/setup b/bin/setup index d37a278..65421bf 100755 --- a/bin/setup +++ b/bin/setup @@ -3,4 +3,4 @@ set -e echo '== Installing dependencies ==' bundle config set --local path 'vendor/bundle' -bundle install +bundle install \ No newline at end of file diff --git a/bin/test b/bin/test index e97de58..cc9e057 100755 --- a/bin/test +++ b/bin/test @@ -5,4 +5,4 @@ export RAILS_ENV="test" bundle exec rake test LAMBY_TEST_DYNAMIC_HANDLER=1 bundle exec rake test -LAMBY_RACK_DEFLATE_ENABLED=1 bundle exec rake test_deflate +LAMBY_RACK_DEFLATE_ENABLED=1 bundle exec rake test_deflate \ No newline at end of file diff --git a/lamby.gemspec b/lamby.gemspec index 77ac617..90a8185 100644 --- a/lamby.gemspec +++ b/lamby.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency 'rack' + spec.add_dependency 'rack', '>= 3.0.0' spec.add_dependency 'lambda-console-ruby' spec.add_development_dependency 'aws-sdk-ssm' spec.add_development_dependency 'bundler' diff --git a/lib/lamby/handler.rb b/lib/lamby/handler.rb index 60ac46e..71ea7e7 100644 --- a/lib/lamby/handler.rb +++ b/lib/lamby/handler.rb @@ -31,14 +31,15 @@ def headers def set_cookies return @set_cookies if defined?(@set_cookies) - @set_cookies = if @headers && @headers['Set-Cookie'] - @headers.delete('Set-Cookie').split("\n") + set_cookie = @headers.delete("Set-Cookie") || @headers.delete("set-cookie") + @set_cookies = if @headers && set_cookie + Array(set_cookie).flat_map { |cookie| cookie.split("\n").map(&:strip) } end end def body @rbody ||= ''.tap do |rbody| - @body.each { |part| rbody << part if part } + @body.each { |part| rbody << part.to_s if part } @body.close if @body.respond_to? :close end end @@ -50,6 +51,7 @@ def call def base64_encodeable?(hdrs = @headers) hdrs && ( + hdrs['content-transfer-encoding'] == 'binary' || hdrs['Content-Transfer-Encoding'] == 'binary' || content_encoding_compressed?(hdrs) || hdrs['X-Lamby-Base64'] == '1' @@ -78,10 +80,18 @@ def rack_option def rack_response { statusCode: status, - headers: headers, + headers: stringify_values!(headers), + cookies: @set_cookies, body: body }.merge(rack.response(self)) end + def stringify_values!(headers) + headers.each do |k, v| + headers[k] = v.to_s + end + headers + end + def call_app if Debug.on?(@event) Debug.call @event, @context, rack.env @@ -103,7 +113,7 @@ def call_app end def content_encoding_compressed?(hdrs) - content_encoding_header = hdrs['Content-Encoding'] || '' + content_encoding_header = hdrs['Content-Encoding'] || hdrs['content-encoding'] || '' content_encoding_header.split(', ').any? { |h| ['br', 'gzip'].include?(h) } end diff --git a/lib/lamby/rack_alb.rb b/lib/lamby/rack_alb.rb index 2511ec0..14260ba 100644 --- a/lib/lamby/rack_alb.rb +++ b/lib/lamby/rack_alb.rb @@ -36,6 +36,7 @@ def response(handler) private def env_base + rack_version = defined?(::Rack::VERSION) ? ::Rack::VERSION : ::Rack.release { ::Rack::REQUEST_METHOD => event['httpMethod'], ::Rack::SCRIPT_NAME => '', ::Rack::PATH_INFO => event['path'] || '', @@ -43,7 +44,7 @@ def env_base ::Rack::SERVER_NAME => headers['host'], ::Rack::SERVER_PORT => headers['x-forwarded-port'], ::Rack::SERVER_PROTOCOL => 'HTTP/1.1', - ::Rack::RACK_VERSION => ::Rack::VERSION, + ::Rack::RACK_VERSION => rack_version, ::Rack::RACK_URL_SCHEME => headers['x-forwarded-proto'], ::Rack::RACK_INPUT => StringIO.new(body || ''), ::Rack::RACK_ERRORS => $stderr, diff --git a/lib/lamby/rack_http.rb b/lib/lamby/rack_http.rb index 2c803b3..d95d721 100644 --- a/lib/lamby/rack_http.rb +++ b/lib/lamby/rack_http.rb @@ -31,6 +31,7 @@ def response(handler) private def env_base + rack_version = defined?(::Rack::VERSION) ? ::Rack::VERSION : ::Rack.release { ::Rack::REQUEST_METHOD => request_method, ::Rack::SCRIPT_NAME => '', ::Rack::PATH_INFO => path_info, @@ -38,7 +39,7 @@ def env_base ::Rack::SERVER_NAME => server_name, ::Rack::SERVER_PORT => server_port, ::Rack::SERVER_PROTOCOL => server_protocol, - ::Rack::RACK_VERSION => ::Rack::VERSION, + ::Rack::RACK_VERSION => rack_version, ::Rack::RACK_URL_SCHEME => 'https', ::Rack::RACK_INPUT => StringIO.new(body || ''), ::Rack::RACK_ERRORS => $stderr, diff --git a/lib/lamby/rack_rest.rb b/lib/lamby/rack_rest.rb index da13481..015a7c2 100644 --- a/lib/lamby/rack_rest.rb +++ b/lib/lamby/rack_rest.rb @@ -25,6 +25,7 @@ def response(handler) private def env_base + rack_version = defined?(::Rack::VERSION) ? ::Rack::VERSION : ::Rack.release { ::Rack::REQUEST_METHOD => event['httpMethod'], ::Rack::SCRIPT_NAME => '', ::Rack::PATH_INFO => event['path'] || '', @@ -32,7 +33,7 @@ def env_base ::Rack::SERVER_NAME => headers['Host'], ::Rack::SERVER_PORT => headers['X-Forwarded-Port'], ::Rack::SERVER_PROTOCOL => event.dig('requestContext', 'protocol') || 'HTTP/1.1', - ::Rack::RACK_VERSION => ::Rack::VERSION, + ::Rack::RACK_VERSION => rack_version, ::Rack::RACK_URL_SCHEME => 'https', ::Rack::RACK_INPUT => StringIO.new(body || ''), ::Rack::RACK_ERRORS => $stderr, diff --git a/lib/lamby/version.rb b/lib/lamby/version.rb index b67f254..ee8d39f 100644 --- a/lib/lamby/version.rb +++ b/lib/lamby/version.rb @@ -1,3 +1,3 @@ module Lamby - VERSION = '5.2.1' + VERSION = '6.0.0' end diff --git a/test/dummy_app/init.rb b/test/dummy_app/init.rb index 2bc2a70..6db37c6 100644 --- a/test/dummy_app/init.rb +++ b/test/dummy_app/init.rb @@ -27,7 +27,7 @@ class Application < ::Rails::Application } # Mimic production environment. config.consider_all_requests_local = false - config.action_dispatch.show_exceptions = true + config.action_dispatch.show_exceptions = :all # Mimic test environment. config.action_controller.perform_caching = false config.action_controller.allow_forgery_protection = false diff --git a/test/handler_test.rb b/test/handler_test.rb index 4f8bf30..76942aa 100644 --- a/test/handler_test.rb +++ b/test/handler_test.rb @@ -45,7 +45,7 @@ class HandlerTest < LambySpec result = Lamby.handler app, event, context, rack: :http expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image) - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' expect(result[:isBase64Encoded]).must_equal true # Public file server. event = TestHelpers::Events::HttpV2.create( @@ -55,7 +55,7 @@ class HandlerTest < LambySpec result = Lamby.handler app, event, context, rack: :http expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image_public), 'not' - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' expect(result[:headers]['Cache-Control']).must_equal 'public, max-age=2592000' expect(result[:headers]['X-Lamby-Base64']).must_equal '1' expect(result[:isBase64Encoded]).must_equal true @@ -65,7 +65,6 @@ class HandlerTest < LambySpec event = TestHelpers::Events::HttpV2Post.create result = Lamby.handler app, event, context, rack: :http expect(result[:statusCode]).must_equal 302 - expect(result[:body]).must_match %r{https://myawesomelambda.example.com} expect(result[:headers]['Location']).must_equal 'https://myawesomelambda.example.com/' # Check logged in state via GET. event = TestHelpers::Events::HttpV2.create( @@ -141,7 +140,7 @@ class HandlerTest < LambySpec result = Lamby.handler app, event, context, rack: :http expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image) - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' # Public file server. event = TestHelpers::Events::HttpV1.create( 'path' => '/production/1-public.png', @@ -150,7 +149,7 @@ class HandlerTest < LambySpec result = Lamby.handler app, event, context, rack: :http expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image_public), 'not' - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' expect(result[:headers]['Cache-Control']).must_equal 'public, max-age=2592000' expect(result[:headers]['X-Lamby-Base64']).must_equal '1' expect(result[:isBase64Encoded]).must_equal true @@ -160,7 +159,6 @@ class HandlerTest < LambySpec event = TestHelpers::Events::HttpV1Post.create result = Lamby.handler app, event, context, rack: :http expect(result[:statusCode]).must_equal 302 - expect(result[:body]).must_match %r{https://myawesomelambda.example.com} expect(result[:headers]['Location']).must_equal 'https://myawesomelambda.example.com/' # Check logged in state via GET. event = TestHelpers::Events::HttpV1.create( @@ -225,7 +223,7 @@ class HandlerTest < LambySpec result = Lamby.handler app, event, context, rack: :rest expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image) - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' # Public file server. event = TestHelpers::Events::Rest.create( 'path' => '/1-public.png', @@ -234,7 +232,7 @@ class HandlerTest < LambySpec result = Lamby.handler app, event, context, rack: :rest expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image_public), 'not' - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' expect(result[:headers]['Cache-Control']).must_equal 'public, max-age=2592000' expect(result[:headers]['X-Lamby-Base64']).must_equal '1' expect(result[:isBase64Encoded]).must_equal true @@ -244,7 +242,6 @@ class HandlerTest < LambySpec event = TestHelpers::Events::RestPost.create result = Lamby.handler app, event, context, rack: :rest expect(result[:statusCode]).must_equal 302 - expect(result[:body]).must_match %r{https://myawesomelambda.example.com} expect(result[:headers]['Location']).must_equal 'https://myawesomelambda.example.com/' # Check logged in state via GET. event = TestHelpers::Events::Rest.create( @@ -303,12 +300,12 @@ class HandlerTest < LambySpec result = Lamby.handler app, event, context, rack: :alb expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image) - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' event = TestHelpers::Events::Alb.create 'path' => '/1-public.png' result = Lamby.handler app, event, context, rack: :alb expect(result[:statusCode]).must_equal 200 expect(result[:body]).must_equal encode64(dummy_app_image_public), 'not' - expect(result[:headers]['Content-Type']).must_equal 'image/png' + expect(result[:headers]['content-type']).must_equal 'image/png' expect(result[:headers]['Cache-Control']).must_equal 'public, max-age=2592000' expect(result[:headers]['X-Lamby-Base64']).must_equal '1' expect(result[:isBase64Encoded]).must_equal true diff --git a/test/proxy_server_test.rb b/test/proxy_server_test.rb index 1db2dd5..a88960a 100644 --- a/test/proxy_server_test.rb +++ b/test/proxy_server_test.rb @@ -12,14 +12,14 @@ class ProxyServerTest < LambySpec it 'should return a 405 helpful message on GET' do response = get '/' expect(response.status).must_equal 405 - expect(response.headers).must_equal({"Content-Type" => "text/html"}) + expect(response.headers).must_equal({"content-type"=>"text/html", "content-length"=>"233"}) expect(response.body).must_include 'Method Not Allowed' end it 'should call Lamby.cmd on POST and include full response as JSON' do response = post '/', json, 'CONTENT_TYPE' => 'application/json' expect(response.status).must_equal 200 - expect(response.headers).must_equal({"Content-Type" => "application/json"}) + expect(response.headers).must_equal({"content-type"=>"application/json", "content-length"=>"755"}) response_body = JSON.parse(response.body) expect(response_body['statusCode']).must_equal 200 expect(response_body['headers']).must_be_kind_of Hash @@ -30,7 +30,7 @@ class ProxyServerTest < LambySpec Lamby.stubs(:cmd).returns({statusCode: 200}) response = post '/', json, 'CONTENT_TYPE' => 'application/json' expect(response.status).must_equal 200 - expect(response.headers).must_equal({"Content-Type" => "application/json"}) + expect(response.headers).must_equal({"content-type"=>"application/json", "content-length"=>"18"}) response_body = JSON.parse(response.body) expect(response_body['statusCode']).must_equal 200 expect(response_body['headers']).must_be_nil @@ -42,7 +42,7 @@ class ProxyServerTest < LambySpec Lamby.config.rack_app = rack_app response = post '/', json, 'CONTENT_TYPE' => 'application/json' expect(response.status).must_equal 200 - expect(response.headers).must_equal({"Content-Type" => "application/json"}) + expect(response.headers).must_equal({"content-type"=>"application/json", "content-length"=>"58"}) response_body = JSON.parse(response.body) expect(response_body['statusCode']).must_equal 200 expect(response_body['headers']).must_equal({}) diff --git a/test/test_helper/events/http_v1.rb b/test/test_helper/events/http_v1.rb index 7747703..dfe6728 100644 --- a/test/test_helper/events/http_v1.rb +++ b/test/test_helper/events/http_v1.rb @@ -1,15 +1,156 @@ module TestHelpers module Events class HttpV1 < Base - # Via Custom Domain Name integration. # - self.event = {"version"=>"1.0", "resource"=>"$default", "path"=>"/", "httpMethod"=>"GET", "headers"=>{"Content-Length"=>"0", "Host"=>"myawesomelambda.example.com", "User-Agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", "X-Amzn-Trace-Id"=>"Root=1-5e7fe714-fee6909429159440eb352c40", "X-Forwarded-For"=>"72.218.219.201", "X-Forwarded-Port"=>"443", "X-Forwarded-Proto"=>"https", "accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-encoding"=>"gzip, deflate, br", "accept-language"=>"en-us", "cookie"=>"signal1=test; signal2=control"}, "multiValueHeaders"=>{"Content-Length"=>["0"], "Host"=>["myawesomelambda.example.com"], "User-Agent"=>["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"], "X-Amzn-Trace-Id"=>["Root=1-5e7fe714-fee6909429159440eb352c40"], "X-Forwarded-For"=>["72.218.219.201"], "X-Forwarded-Port"=>["443"], "X-Forwarded-Proto"=>["https"], "accept"=>["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "accept-encoding"=>["gzip, deflate, br"], "accept-language"=>["en-us"]}, "queryStringParameters"=>{"colors[]"=>"red"}, "multiValueQueryStringParameters"=>{"colors[]"=>["blue", "red"]}, "requestContext"=>{"accountId"=>nil, "apiId"=>"n12pmpajak", "domainName"=>"myawesomelambda.example.com", "domainPrefix"=>"myawesomelambda", "extendedRequestId"=>"KSCL-irBIAMEJIA=", "httpMethod"=>"GET", "identity"=>{"accessKey"=>nil, "accountId"=>nil, "caller"=>nil, "cognitoAuthenticationProvider"=>nil, "cognitoAuthenticationType"=>nil, "cognitoIdentityId"=>nil, "cognitoIdentityPoolId"=>nil, "principalOrgId"=>nil, "sourceIp"=>"72.218.219.201", "user"=>nil, "userAgent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", "userArn"=>nil}, "path"=>"/production/", "protocol"=>"HTTP/1.1", "requestId"=>"KSCL-irBIAMEJIA=", "requestTime"=>"01/Apr/2020:00:44:22 +0000", "requestTimeEpoch"=>1585701862143, "resourceId"=>"$default", "resourcePath"=>"$default", "stage"=>"production"}, "pathParameters"=>nil, "stageVariables"=>nil, "body"=>nil, "isBase64Encoded"=>false}.freeze + self.event = { + "version" => "1.0", + "resource" => "$default", + "path" => "/", + "httpMethod" => "GET", + "headers" => { + "Content-Length" => "0", + "Host" => "myawesomelambda.example.com", + "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", + "X-Amzn-Trace-Id" => "Root=1-5e7fe714-fee6909429159440eb352c40", + "X-Forwarded-For" => "72.218.219.201", + "X-Forwarded-Port" => "443", + "X-Forwarded-Proto" => "https", + "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "accept-encoding" => "gzip, deflate, br", + "accept-language" => "en-us", + "cookie" => "signal1=test; signal2=control" + }, + "multiValueHeaders" => { + "Content-Length" => ["0"], + "Host" => ["myawesomelambda.example.com"], + "User-Agent" => ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"], + "X-Amzn-Trace-Id" => ["Root=1-5e7fe714-fee6909429159440eb352c40"], + "X-Forwarded-For" => ["72.218.219.201"], + "X-Forwarded-Port" => ["443"], + "X-Forwarded-Proto" => ["https"], + "accept" => ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], + "accept-encoding" => ["gzip, deflate, br"], + "accept-language" => ["en-us"] + }, + "queryStringParameters" => { + "colors[]" => "red" + }, + "multiValueQueryStringParameters" => { + "colors[]" => ["blue", "red"] + }, + "requestContext" => { + "accountId" => nil, + "apiId" => "n12pmpajak", + "domainName" => "myawesomelambda.example.com", + "domainPrefix" => "myawesomelambda", + "extendedRequestId" => "KSCL-irBIAMEJIA=", + "httpMethod" => "GET", + "identity" => { + "accessKey" => nil, + "accountId" => nil, + "caller" => nil, + "cognitoAuthenticationProvider" => nil, + "cognitoAuthenticationType" => nil, + "cognitoIdentityId" => nil, + "cognitoIdentityPoolId" => nil, + "principalOrgId" => nil, + "sourceIp" => "72.218.219.201", + "user" => nil, + "userAgent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", + "userArn" => nil + }, + "path" => "/production/", + "protocol" => "HTTP/1.1", + "requestId" => "KSCL-irBIAMEJIA=", + "requestTime" => "01/Apr/2020:00:44:22 +0000", + "requestTimeEpoch" => 1585701862143, + "resourceId" => "$default", + "resourcePath" => "$default", + "stage" => "production" + }, + "pathParameters" => nil, + "stageVariables" => nil, + "body" => nil, + "isBase64Encoded" => false + }.freeze # Via CloudFront directly to API Gateway w/Origin Path. # - # {"version"=>"1.0", "resource"=>"$default", "path"=>"/production/", "httpMethod"=>"GET", "headers"=>{"Content-Length"=>"0", "Host"=>"n12pmpajak.execute-api.us-east-1.amazonaws.com", "User-Agent"=>"Amazon CloudFront", "X-Amz-Cf-Id"=>"XPTzwjMoVu5Vlp6QLBl_f1NNa2IXRpF_LAFJ9isoq_Pb4MUarItT0w==", "X-Amzn-Trace-Id"=>"Root=1-5e83cbd2-bfd143859e9214f4860e2779", "X-Forwarded-For"=>"72.218.219.201, 3.231.2.50", "X-Forwarded-Host"=>"myawesomelambda.example.com", "X-Forwarded-Port"=>"443", "X-Forwarded-Proto"=>"https", "accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-encoding"=>"gzip", "via"=>"2.0 613faec4b883bfe2ebdd8a74d5006f4c.cloudfront.net (CloudFront)"}, "multiValueHeaders"=>{"Content-Length"=>["0"], "Host"=>["n12pmpajak.execute-api.us-east-1.amazonaws.com"], "User-Agent"=>["Amazon CloudFront"], "X-Amz-Cf-Id"=>["XPTzwjMoVu5Vlp6QLBl_f1NNa2IXRpF_LAFJ9isoq_Pb4MUarItT0w=="], "X-Amzn-Trace-Id"=>["Root=1-5e83cbd2-bfd143859e9214f4860e2779"], "X-Forwarded-For"=>["72.218.219.201, 3.231.2.50"], "X-Forwarded-Host"=>["myawesomelambda.example.com"], "X-Forwarded-Port"=>["443"], "X-Forwarded-Proto"=>["https"], "accept"=>["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "accept-encoding"=>["gzip"], "via"=>["2.0 613faec4b883bfe2ebdd8a74d5006f4c.cloudfront.net (CloudFront)"]}, "queryStringParameters"=>{"colors[]"=>"red"}, "multiValueQueryStringParameters"=>{"colors[]"=>["blue", "red"]}, "requestContext"=>{"accountId"=>nil, "apiId"=>"n12pmpajak", "domainName"=>"n12pmpajak.execute-api.us-east-1.amazonaws.com", "domainPrefix"=>"n12pmpajak", "extendedRequestId"=>"KRzI1i2uoAMEPCA=", "httpMethod"=>"GET", "identity"=>{"accessKey"=>nil, "accountId"=>nil, "caller"=>nil, "cognitoAuthenticationProvider"=>nil, "cognitoAuthenticationType"=>nil, "cognitoIdentityId"=>nil, "cognitoIdentityPoolId"=>nil, "principalOrgId"=>nil, "sourceIp"=>" 3.231.2.50", "user"=>nil, "userAgent"=>"Amazon CloudFront", "userArn"=>nil}, "path"=>"/production/", "protocol"=>"HTTP/1.1", "requestId"=>"KRzI1i2uoAMEPCA=", "requestTime"=>"31/Mar/2020:23:01:38 +0000", "requestTimeEpoch"=>1585695698070, "resourceId"=>"$default", "resourcePath"=>"$default", "stage"=>"production"}, "pathParameters"=>nil, "stageVariables"=>nil, "body"=>nil, "isBase64Encoded"=>false} - + # self.event = { + # "version" => "1.0", + # "resource" => "$default", + # "path" => "/production/", + # "httpMethod" => "GET", + # "headers" => { + # "Content-Length" => "0", + # "Host" => "n12pmpajak.execute-api.us-east-1.amazonaws.com", + # "User-Agent" => "Amazon CloudFront", + # "X-Amz-Cf-Id" => "XPTzwjMoVu5Vlp6QLBl_f1NNa2IXRpF_LAFJ9isoq_Pb4MUarItT0w==", + # "X-Amzn-Trace-Id" => "Root=1-5e83cbd2-bfd143859e9214f4860e2779", + # "X-Forwarded-For" => "72.218.219.201, 3.231.2.50", + # "X-Forwarded-Host" => "myawesomelambda.example.com", + # "X-Forwarded-Port" => "443", + # "X-Forwarded-Proto" => "https", + # "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + # "accept-encoding" => "gzip", + # "via" => "2.0 613faec4b883bfe2ebdd8a74d5006f4c.cloudfront.net (CloudFront)" + # }, + # "multiValueHeaders" => { + # "Content-Length" => ["0"], + # "Host" => ["n12pmpajak.execute-api.us-east-1.amazonaws.com"], + # "User-Agent" => ["Amazon CloudFront"], + # "X-Amz-Cf-Id" => ["XPTzwjMoVu5Vlp6QLBl_f1NNa2IXRpF_LAFJ9isoq_Pb4MUarItT0w=="], + # "X-Amzn-Trace-Id" => ["Root=1-5e83cbd2-bfd143859e9214f4860e2779"], + # "X-Forwarded-For" => ["72.218.219.201, 3.231.2.50"], + # "X-Forwarded-Host" => ["myawesomelambda.example.com"], + # "X-Forwarded-Port" => ["443"], + # "X-Forwarded-Proto" => ["https"], + # "accept" => ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], + # "accept-encoding" => ["gzip"], + # "via" => ["2.0 613faec4b883bfe2ebdd8a74d5006f4c.cloudfront.net (CloudFront)"] + # }, + # "queryStringParameters" => { + # "colors[]" => "red" + # }, + # "multiValueQueryStringParameters" => { + # "colors[]" => ["blue", "red"] + # }, + # "requestContext" => { + # "accountId" => nil, + # "apiId" => "n12pmpajak", + # "domainName" => "n12pmpajak.execute-api.us-east-1.amazonaws.com", + # "domainPrefix" => "n12pmpajak", + # "extendedRequestId" => "KRzI1i2uoAMEPCA=", + # "httpMethod" => "GET", + # "identity" => { + # "accessKey" => nil, + # "accountId" => nil, + # "caller" => nil, + # "cognitoAuthenticationProvider" => nil, + # "cognitoAuthenticationType" => nil, + # "cognitoIdentityId" => nil, + # "cognitoIdentityPoolId" => nil, + # "principalOrgId" => nil, + # "sourceIp" => "3.231.2.50", + # "user" => nil, + # "userAgent" => "Amazon CloudFront", + # "userArn" => nil + # }, + # "path" => "/production/", + # "protocol" => "HTTP/1.1", + # "requestId" => "KRzI1i2uoAMEPCA=", + # "requestTime" => "31/Mar/2020:23:01:38 +0000", + # "requestTimeEpoch" => 1585695698070, + # "resourceId" => "$default", + # "resourcePath" => "$default", + # "stage" => "production" + # }, + # "pathParameters" => nil, + # "stageVariables" => nil, + # "body" => nil, + # "isBase64Encoded" => false + # }.freeze end end -end +end \ No newline at end of file diff --git a/test/test_helper/events/http_v1_post.rb b/test/test_helper/events/http_v1_post.rb index 5f95d20..26302fb 100644 --- a/test/test_helper/events/http_v1_post.rb +++ b/test/test_helper/events/http_v1_post.rb @@ -1,11 +1,82 @@ module TestHelpers module Events class HttpV1Post < Base - # Via Custom Domain Name integration. # - self.event = {"version"=>"1.0", "resource"=>"$default", "path"=>"/login", "httpMethod"=>"POST", "headers"=>{"Content-Length"=>"144", "Content-Type"=>"application/x-www-form-urlencoded", "Host"=>"myawesomelambda.example.com", "User-Agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", "X-Amzn-Trace-Id"=>"Root=1-5e83e682-ab153f7a267a9a904369faa6", "X-Forwarded-For"=>"72.218.219.201", "X-Forwarded-Port"=>"443", "X-Forwarded-Proto"=>"https", "accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-encoding"=>"gzip, deflate, br", "accept-language"=>"en-us", "cookie"=>"signal1=test; signal2=control", "origin"=>"https://myawesomelambda.example.com", "referer"=>"https://myawesomelambda.example.com/?colors[]=blue&colors[]=red"}, "multiValueHeaders"=>{"Content-Length"=>["144"], "Content-Type"=>["application/x-www-form-urlencoded"], "Host"=>["myawesomelambda.example.com"], "User-Agent"=>["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"], "X-Amzn-Trace-Id"=>["Root=1-5e83e682-ab153f7a267a9a904369faa6"], "X-Forwarded-For"=>["72.218.219.201"], "X-Forwarded-Port"=>["443"], "X-Forwarded-Proto"=>["https"], "accept"=>["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "accept-encoding"=>["gzip, deflate, br"], "accept-language"=>["en-us"], "cookie"=>["signal1=test; signal2=control"], "origin"=>["https://myawesomelambda.example.com"], "referer"=>["https://myawesomelambda.example.com/?colors[]=blue&colors[]=red"]}, "queryStringParameters"=>nil, "multiValueQueryStringParameters"=>nil, "requestContext"=>{"accountId"=>nil, "apiId"=>"n12pmpajak", "domainName"=>"myawesomelambda.example.com", "domainPrefix"=>"myawesomelambda", "extendedRequestId"=>"KSD0ZgV2oAMESNg=", "httpMethod"=>"POST", "identity"=>{"accessKey"=>nil, "accountId"=>nil, "caller"=>nil, "cognitoAuthenticationProvider"=>nil, "cognitoAuthenticationType"=>nil, "cognitoIdentityId"=>nil, "cognitoIdentityPoolId"=>nil, "principalOrgId"=>nil, "sourceIp"=>"72.218.219.201", "user"=>nil, "userAgent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", "userArn"=>nil}, "path"=>"/production/login", "protocol"=>"HTTP/1.1", "requestId"=>"KSD0ZgV2oAMESNg=", "requestTime"=>"01/Apr/2020:00:55:30 +0000", "requestTimeEpoch"=>1585702530405, "resourceId"=>"$default", "resourcePath"=>"$default", "stage"=>"production"}, "pathParameters"=>nil, "stageVariables"=>nil, "body"=>"YXV0aGVudGljaXR5X3Rva2VuPVBNbThhY1FCZkZsVTBtbVltbTdOZnhmNktxJTJGWDRlVHRuMXIwYngzWWlJemFjeTRlUURVbk13MHJFUG5GNXVZbk9MRm5QbnlCcXQxVFlzemRMSDBtOUElM0QlM0QmcGFzc3dvcmQ9cGFzc3dvcmQmY29tbWl0PUxvZ2lu", "isBase64Encoded"=>true}.freeze - + self.event = { + "version" => "1.0", + "resource" => "$default", + "path" => "/login", + "httpMethod" => "POST", + "headers" => { + "content-length" => "144", + "content-type" => "application/x-www-form-urlencoded", + "host" => "myawesomelambda.example.com", + "user-agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", + "x-amzn-trace-id" => "Root=1-5e83e682-ab153f7a267a9a904369faa6", + "x-forwarded-for" => "72.218.219.201", + "x-forwarded-port" => "443", + "x-forwarded-proto" => "https", + "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "accept-encoding" => "gzip, deflate, br", + "accept-language" => "en-us", + "cookie" => "signal1=test; signal2=control", + "origin" => "https://myawesomelambda.example.com", + "referer" => "https://myawesomelambda.example.com/?colors[]=blue&colors[]=red" + }, + "multiValueHeaders" => { + "content-length" => ["144"], + "content-type" => ["application/x-www-form-urlencoded"], + "host" => ["myawesomelambda.example.com"], + "user-agent" => ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"], + "x-amzn-trace-id" => ["Root=1-5e83e682-ab153f7a267a9a904369faa6"], + "x-forwarded-for" => ["72.218.219.201"], + "x-forwarded-port" => ["443"], + "x-forwarded-proto" => ["https"], + "accept" => ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], + "accept-encoding" => ["gzip, deflate, br"], + "accept-language" => ["en-us"], + "cookie" => ["signal1=test; signal2=control"], + "origin" => ["https://myawesomelambda.example.com"], + "referer" => ["https://myawesomelambda.example.com/?colors[]=blue&colors[]=red"] + }, + "queryStringParameters" => nil, + "multiValueQueryStringParameters" => nil, + "requestContext" => { + "accountId" => nil, + "apiId" => "n12pmpajak", + "domainName" => "myawesomelambda.example.com", + "domainPrefix" => "myawesomelambda", + "extendedRequestId" => "KSD0ZgV2oAMESNg=", + "httpMethod" => "POST", + "identity" => { + "accessKey" => nil, + "accountId" => nil, + "caller" => nil, + "cognitoAuthenticationProvider" => nil, + "cognitoAuthenticationType" => nil, + "cognitoIdentityId" => nil, + "cognitoIdentityPoolId" => nil, + "principalOrgId" => nil, + "sourceIp" => "72.218.219.201", + "user" => nil, + "userAgent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", + "userArn" => nil + }, + "path" => "/production/login", + "protocol" => "HTTP/1.1", + "requestId" => "KSD0ZgV2oAMESNg=", + "requestTime" => "01/Apr/2020:00:55:30 +0000", + "requestTimeEpoch" => 1585702530405, + "resourceId" => "$default", + "resourcePath" => "$default", + "stage" => "production" + }, + "pathParameters" => nil, + "stageVariables" => nil, + "body" => "YXV0aGVudGljaXR5X3Rva2VuPVBNbThhY1FCZkZsVTBtbVltbTdOZnhmNktxJTJGWDRlVHRuMXIwYngzWWlJemFjeTRlUURVbk13MHJFUG5GNXVZbk9MRm5QbnlCcXQxVFlzemRMSDBtOUElM0QlM0QmcGFzc3dvcmQ9cGFzc3dvcmQmY29tbWl0PUxvZ2lu", + "isBase64Encoded" => true + }.freeze end end -end +end \ No newline at end of file diff --git a/test/test_helper/events/http_v2.rb b/test/test_helper/events/http_v2.rb index 31283f6..18efcfc 100644 --- a/test/test_helper/events/http_v2.rb +++ b/test/test_helper/events/http_v2.rb @@ -4,7 +4,44 @@ class HttpV2 < Base # Via Custom Domain Name integration. # - self.event = {"version"=>"2.0", "routeKey"=>"$default", "rawPath"=>"/production/", "rawQueryString"=>"colors[]=blue&colors[]=red", "cookies"=>["signal1=test", "signal2=control"], "headers"=>{"accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-encoding"=>"gzip, deflate, br", "accept-language"=>"en-us", "content-length"=>"0", "host"=>"myawesomelambda.example.com", "user-agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", "x-amzn-trace-id"=>"Root=1-5e7fe714-fee6909429159440eb352c40", "x-forwarded-for"=>"72.218.219.201", "x-forwarded-port"=>"443", "x-forwarded-proto"=>"https"}, "requestContext"=>{"accountId"=>nil, "apiId"=>"n12pmpajak", "domainName"=>"myawesomelambda.example.com", "domainPrefix"=>"myawesomelambda", "http"=>{"method"=>"GET", "path"=>"/production/", "protocol"=>"HTTP/1.1", "sourceIp"=>"72.218.219.201", "userAgent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"}, "requestId"=>"KSP7Mj94IAMEMFQ=", "routeKey"=>"$default", "stage"=>"production", "time"=>"01/Apr/2020:02:18:09 +0000", "timeEpoch"=>1585707489142}, "isBase64Encoded"=>false}.freeze + self.event = { + "version" => "2.0", + "routeKey" => "$default", + "rawPath" => "/production/", + "rawQueryString" => "colors[]=blue&colors[]=red", + "cookies" => ["signal1=test", "signal2=control"], + "headers" => { + "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "accept-encoding" => "gzip, deflate, br", + "accept-language" => "en-us", + "content-length" => "0", + "host" => "myawesomelambda.example.com", + "user-agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", + "x-amzn-trace-id" => "Root=1-5e7fe714-fee6909429159440eb352c40", + "x-forwarded-for" => "72.218.219.201", + "x-forwarded-port" => "443", + "x-forwarded-proto" => "https" + }, + "requestContext" => { + "accountId" => nil, + "apiId" => "n12pmpajak", + "domainName" => "myawesomelambda.example.com", + "domainPrefix" => "myawesomelambda", + "http" => { + "method" => "GET", + "path" => "/production/", + "protocol" => "HTTP/1.1", + "sourceIp" => "72.218.219.201", + "userAgent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15" + }, + "requestId" => "KSP7Mj94IAMEMFQ=", + "routeKey" => "$default", + "stage" => "production", + "time" => "01/Apr/2020:02:18:09 +0000", + "timeEpoch" => 1585707489142 + }, + "isBase64Encoded" => false + }.freeze # Via CloudFront directly to API Gateway w/Origin Path. # diff --git a/test/test_helper/events/http_v2_post.rb b/test/test_helper/events/http_v2_post.rb index 9c64355..d87a014 100644 --- a/test/test_helper/events/http_v2_post.rb +++ b/test/test_helper/events/http_v2_post.rb @@ -1,11 +1,50 @@ module TestHelpers module Events class HttpV2Post < Base - # Via Custom Domain Name integration. # - self.event = {"version"=>"2.0", "routeKey"=>"$default", "rawPath"=>"/production/login", "rawQueryString"=>"", "cookies"=>["signal1=test", "signal2=control"], "headers"=>{"accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-encoding"=>"gzip, deflate, br", "accept-language"=>"en-us", "content-length"=>"146", "content-type"=>"application/x-www-form-urlencoded", "host"=>"myawesomelambda.example.com", "origin"=>"https://myawesomelambda.example.com", "referer"=>"https://myawesomelambda.example.com/?colors[]=blue&colors[]=red", "user-agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", "x-amzn-trace-id"=>"Root=1-5e852ca4-3a8dd0c91bfb6e85f0dc55ba", "x-forwarded-for"=>"72.218.219.201", "x-forwarded-port"=>"443", "x-forwarded-proto"=>"https"}, "requestContext"=>{"accountId"=>nil, "apiId"=>"n12pmpajak", "domainName"=>"myawesomelambda.example.com", "domainPrefix"=>"myawesomelambda", "http"=>{"method"=>"POST", "path"=>"/production/login", "protocol"=>"HTTP/1.1", "sourceIp"=>"72.218.219.201", "userAgent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"}, "requestId"=>"KVPpsgCooAMEMBQ=", "routeKey"=>"$default", "stage"=>"production", "time"=>"02/Apr/2020:00:07:00 +0000", "timeEpoch"=>1585786020373}, "body"=>"YXV0aGVudGljaXR5X3Rva2VuPThHR3ZFTTYlMkZiandERzNYQTNjaklaQk5Vc1RudWdTNXBjNEd1ZHlwNVpuZWNvcFFSNTYwcEt2bmJOcmhMYTRpVWpGT0NZT214JTJGeUV5SXBKcHNkM3NHQSUzRCUzRCZwYXNzd29yZD1wYXNzd29yZCZjb21taXQ9TG9naW4=", "isBase64Encoded"=>true} - + self.event = { + "version" => "2.0", + "routeKey" => "$default", + "rawPath" => "/production/login", + "rawQueryString" => "", + "cookies" => ["signal1=test", "signal2=control"], + "headers" => { + "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "accept-encoding" => "gzip, deflate, br", + "accept-language" => "en-us", + "content-length" => "146", + "content-type" => "application/x-www-form-urlencoded", + "host" => "myawesomelambda.example.com", + "origin" => "https://myawesomelambda.example.com", + "referer" => "https://myawesomelambda.example.com/?colors[]=blue&colors[]=red", + "user-agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15", + "x-amzn-trace-id" => "Root=1-5e852ca4-3a8dd0c91bfb6e85f0dc55ba", + "x-forwarded-for" => "72.218.219.201", + "x-forwarded-port" => "443", + "x-forwarded-proto" => "https" + }, + "requestContext" => { + "accountId" => nil, + "apiId" => "n12pmpajak", + "domainName" => "myawesomelambda.example.com", + "domainPrefix" => "myawesomelambda", + "http" => { + "method" => "POST", + "path" => "/production/login", + "protocol" => "HTTP/1.1", + "sourceIp" => "72.218.219.201", + "userAgent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15" + }, + "requestId" => "KVPpsgCooAMEMBQ=", + "routeKey" => "$default", + "stage" => "production", + "time" => "02/Apr/2020:00:07:00 +0000", + "timeEpoch" => 1585786020373 + }, + "body" => "YXV0aGVudGljaXR5X3Rva2VuPThHR3ZFTTYlMkZiandERzNYQTNjaklaQk5Vc1RudWdTNXBjNEd1ZHlwNVpuZWNvcFFSNTYwcEt2bmJOcmhMYTRpVWpGT0NZT214JTJGeUV5SXBKcHNkM3NHQSUzRCUzRCZwYXNzd29yZD1wYXNzd29yZCZjb21taXQ9TG9naW4=", + "isBase64Encoded" => true + } end end -end +end \ No newline at end of file diff --git a/test/test_helper/events/rest.rb b/test/test_helper/events/rest.rb index 0dd6fb2..1ea4b10 100644 --- a/test/test_helper/events/rest.rb +++ b/test/test_helper/events/rest.rb @@ -1,9 +1,77 @@ module TestHelpers module Events class Rest < Base - - self.event = {"resource"=>"/", "path"=>"/", "httpMethod"=>"GET", "headers"=>{"Accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding"=>"gzip", "Cookie"=>"signal1=test; signal2=control", "Host"=>"4o8v9z4feh.execute-api.us-east-1.amazonaws.com", "origin"=>"https://myawesomelambda.example.com", "User-Agent"=>"Amazon CloudFront", "Via"=>"2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)", "X-Amz-Cf-Id"=>"kXZzJ72NOsZSsPu-JzNUGyFei1G0r9uzoup3yHrwk4J5qGLKrdUrRA==", "X-Amzn-Trace-Id"=>"Root=1-5e7fe714-fee6909429159440eb352c40", "X-Forwarded-For"=>"72.218.219.201, 34.195.252.119", "X-Forwarded-Host"=>"myawesomelambda.example.com", "X-Forwarded-Port"=>"443", "X-Forwarded-Proto"=>"https"}, "multiValueHeaders"=>{"Accept"=>["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Encoding"=>["gzip"], "Cookie"=>["signal1=test; signal2=control"], "Host"=>["4o8v9z4feh.execute-api.us-east-1.amazonaws.com"], "origin"=>["https://myawesomelambda.example.com"], "User-Agent"=>["Amazon CloudFront"], "Via"=>["2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)"], "X-Amz-Cf-Id"=>["kXZzJ72NOsZSsPu-JzNUGyFei1G0r9uzoup3yHrwk4J5qGLKrdUrRA=="], "X-Amzn-Trace-Id"=>["Root=1-5e7fe714-fee6909429159440eb352c40"], "X-Forwarded-For"=>["72.218.219.201, 34.195.252.119"], "X-Forwarded-Host"=>["myawesomelambda.example.com"], "X-Forwarded-Port"=>["443"], "X-Forwarded-Proto"=>["https"]}, "queryStringParameters"=>{"colors[]"=>"red"}, "multiValueQueryStringParameters"=>{"colors[]"=>["blue", "red"]}, "pathParameters"=>nil, "stageVariables"=>nil, "requestContext"=>{"resourceId"=>"77ce0rz741", "resourcePath"=>"/", "httpMethod"=>"GET", "extendedRequestId"=>"KIELPF7PoAMFePQ=", "requestTime"=>"29/Mar/2020:00:08:52 +0000", "path"=>"/production/", "accountId"=>nil, "protocol"=>"HTTP/1.1", "stage"=>"production", "domainPrefix"=>"4o8v9z4feh", "requestTimeEpoch"=>1585440532675, "requestId"=>"e5c78607-6a25-4f15-bb87-aca7d4522093", "identity"=>{"cognitoIdentityPoolId"=>nil, "accountId"=>nil, "cognitoIdentityId"=>nil, "caller"=>nil, "sourceIp"=>"72.218.219.201", "principalOrgId"=>nil, "accessKey"=>nil, "cognitoAuthenticationType"=>nil, "cognitoAuthenticationProvider"=>nil, "userArn"=>nil, "userAgent"=>"Amazon CloudFront", "user"=>nil}, "domainName"=>"4o8v9z4feh.execute-api.us-east-1.amazonaws.com", "apiId"=>"4o8v9z4feh"}, "body"=>nil, "isBase64Encoded"=>false}.freeze - + self.event = { + "resource" => "/", + "path" => "/", + "httpMethod" => "GET", + "headers" => { + "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "Accept-Encoding" => "gzip", + "Cookie" => "signal1=test; signal2=control", + "Host" => "4o8v9z4feh.execute-api.us-east-1.amazonaws.com", + "origin" => "https://myawesomelambda.example.com", + "User-Agent" => "Amazon CloudFront", + "Via" => "2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)", + "X-Amz-Cf-Id" => "kXZzJ72NOsZSsPu-JzNUGyFei1G0r9uzoup3yHrwk4J5qGLKrdUrRA==", + "X-Amzn-Trace-Id" => "Root=1-5e7fe714-fee6909429159440eb352c40", + "X-Forwarded-For" => "72.218.219.201, 34.195.252.119", + "X-Forwarded-Host" => "myawesomelambda.example.com", + "X-Forwarded-Port" => "443", + "X-Forwarded-Proto" => "https" + }, + "multiValueHeaders" => { + "Accept" => ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], + "Accept-Encoding" => ["gzip"], + "Cookie" => ["signal1=test; signal2=control"], + "Host" => ["4o8v9z4feh.execute-api.us-east-1.amazonaws.com"], + "origin" => ["https://myawesomelambda.example.com"], + "User-Agent" => ["Amazon CloudFront"], + "Via" => ["2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)"], + "X-Amz-Cf-Id" => ["kXZzJ72NOsZSsPu-JzNUGyFei1G0r9uzoup3yHrwk4J5qGLKrdUrRA=="], + "X-Amzn-Trace-Id" => ["Root=1-5e7fe714-fee6909429159440eb352c40"], + "X-Forwarded-For" => ["72.218.219.201, 34.195.252.119"], + "X-Forwarded-Host" => ["myawesomelambda.example.com"], + "X-Forwarded-Port" => ["443"], + "X-Forwarded-Proto" => ["https"] + }, + "queryStringParameters" => { "colors[]" => "red" }, + "multiValueQueryStringParameters" => { "colors[]" => ["blue", "red"] }, + "pathParameters" => nil, + "stageVariables" => nil, + "requestContext" => { + "resourceId" => "77ce0rz741", + "resourcePath" => "/", + "httpMethod" => "GET", + "extendedRequestId" => "KIELPF7PoAMFePQ=", + "requestTime" => "29/Mar/2020:00:08:52 +0000", + "path" => "/production/", + "accountId" => nil, + "protocol" => "HTTP/1.1", + "stage" => "production", + "domainPrefix" => "4o8v9z4feh", + "requestTimeEpoch" => 1585440532675, + "requestId" => "e5c78607-6a25-4f15-bb87-aca7d4522093", + "identity" => { + "cognitoIdentityPoolId" => nil, + "accountId" => nil, + "cognitoIdentityId" => nil, + "caller" => nil, + "sourceIp" => "72.218.219.201", + "principalOrgId" => nil, + "accessKey" => nil, + "cognitoAuthenticationType" => nil, + "cognitoAuthenticationProvider" => nil, + "userArn" => nil, + "userAgent" => "Amazon CloudFront", + "user" => nil + }, + "domainName" => "4o8v9z4feh.execute-api.us-east-1.amazonaws.com", + "apiId" => "4o8v9z4feh" + }, + "body" => nil, + "isBase64Encoded" => false + }.freeze end end -end +end \ No newline at end of file diff --git a/test/test_helper/events/rest_post.rb b/test/test_helper/events/rest_post.rb index 336d4a3..8e88014 100644 --- a/test/test_helper/events/rest_post.rb +++ b/test/test_helper/events/rest_post.rb @@ -2,8 +2,80 @@ module TestHelpers module Events class RestPost < Base - self.event = {"resource"=>"/{resource+}", "path"=>"/login", "httpMethod"=>"POST", "headers"=>{"Accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding"=>"gzip, deflate, br", "content-type"=>"application/x-www-form-urlencoded", "Cookie"=>"signal1=test; signal2=control", "Host"=>"4o8v9z4feh.execute-api.us-east-1.amazonaws.com", "origin"=>"https://myawesomelambda.example.com", "User-Agent"=>"Amazon CloudFront", "Via"=>"2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)", "X-Amz-Cf-Id"=>"HlVPz9T-9eYwLqzFi21O7EU7b_dvHEzqlgs4YLetEq036kBnyNv6_Q==", "X-Amzn-Trace-Id"=>"Root=1-5e7fe714-d306a3db0536f45b4197aa52", "X-Forwarded-For"=>"72.218.219.201, 70.132.33.68", "X-Forwarded-Host"=>"myawesomelambda.example.com", "X-Forwarded-Port"=>"443", "X-Forwarded-Proto"=>"https"}, "multiValueHeaders"=>{"Accept"=>["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Encoding"=>["gzip, deflate, br"], "content-type"=>["application/x-www-form-urlencoded"], "Cookie"=>["signal1=test; signal2=control"], "Host"=>["4o8v9z4feh.execute-api.us-east-1.amazonaws.com"], "origin"=>["https://myawesomelambda.example.com"], "User-Agent"=>["Amazon CloudFront"], "Via"=>["2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)"], "X-Amz-Cf-Id"=>["HlVPz9T-9eYwLqzFi21O7EU7b_dvHEzqlgs4YLetEq036kBnyNv6_Q=="], "X-Amzn-Trace-Id"=>["Root=1-5e7fe714-d306a3db0536f45b4197aa52"], "X-Forwarded-For"=>["72.218.219.201, 70.132.33.68"], "X-Forwarded-Host"=>["myawesomelambda.example.com"], "X-Forwarded-Port"=>["443"], "X-Forwarded-Proto"=>["https"]}, "queryStringParameters"=>nil, "multiValueQueryStringParameters"=>nil, "pathParameters"=>{"resource"=>"login"}, "stageVariables"=>nil, "requestContext"=>{"resourceId"=>"s2mq69", "resourcePath"=>"/{resource+}", "httpMethod"=>"POST", "extendedRequestId"=>"KIELOHygoAMFXxA=", "requestTime"=>"29/Mar/2020:00:08:52 +0000", "path"=>"/production/login", "accountId"=>nil, "protocol"=>"HTTP/1.1", "stage"=>"production", "domainPrefix"=>"4o8v9z4feh", "requestTimeEpoch"=>1585440532566, "requestId"=>"552c9b8d-23fa-42de-9f89-9b56af1e6770", "identity"=>{"cognitoIdentityPoolId"=>nil, "accountId"=>nil, "cognitoIdentityId"=>nil, "caller"=>nil, "sourceIp"=>"72.218.219.201", "principalOrgId"=>nil, "accessKey"=>nil, "cognitoAuthenticationType"=>nil, "cognitoAuthenticationProvider"=>nil, "userArn"=>nil, "userAgent"=>"Amazon CloudFront", "user"=>nil}, "domainName"=>"4o8v9z4feh.execute-api.us-east-1.amazonaws.com", "apiId"=>"4o8v9z4feh"}, "body"=>"YXV0aGVudGljaXR5X3Rva2VuPXRObXZ0T2xlaHY0YU1GUlFlZTg4c2MxcTViZ3lJaGxqM3pscVJPelg5bWtyYnZwOVZrOUdoUlh4NG9sNFl4dW9jbDRJR2ZOOTk1ckh3SXhDSXhpVWZnJTNEJTNEJnBhc3N3b3JkPXBhc3N3b3JkJmNvbW1pdD1Mb2dpbg==", "isBase64Encoded"=>true}.freeze + self.event = { + "resource" => "/{resource+}", + "path" => "/login", + "httpMethod" => "POST", + "headers" => { + "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "Accept-Encoding" => "gzip, deflate, br", + "content-type" => "application/x-www-form-urlencoded", + "Cookie" => "signal1=test; signal2=control", + "Host" => "4o8v9z4feh.execute-api.us-east-1.amazonaws.com", + "origin" => "https://myawesomelambda.example.com", + "User-Agent" => "Amazon CloudFront", + "Via" => "2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)", + "X-Amz-Cf-Id" => "HlVPz9T-9eYwLqzFi21O7EU7b_dvHEzqlgs4YLetEq036kBnyNv6_Q==", + "X-Amzn-Trace-Id" => "Root=1-5e7fe714-d306a3db0536f45b4197aa52", + "X-Forwarded-For" => "72.218.219.201, 70.132.33.68", + "X-Forwarded-Host" => "myawesomelambda.example.com", + "X-Forwarded-Port" => "443", + "X-Forwarded-Proto" => "https" + }, + "multiValueHeaders" => { + "Accept" => ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], + "Accept-Encoding" => ["gzip, deflate, br"], + "content-type" => ["application/x-www-form-urlencoded"], + "Cookie" => ["signal1=test; signal2=control"], + "Host" => ["4o8v9z4feh.execute-api.us-east-1.amazonaws.com"], + "origin" => ["https://myawesomelambda.example.com"], + "User-Agent" => ["Amazon CloudFront"], + "Via" => ["2.0 7f7e359e1c06a914d3d305785359b84d.cloudfront.net (CloudFront)"], + "X-Amz-Cf-Id" => ["HlVPz9T-9eYwLqzFi21O7EU7b_dvHEzqlgs4YLetEq036kBnyNv6_Q=="], + "X-Amzn-Trace-Id" => ["Root=1-5e7fe714-d306a3db0536f45b4197aa52"], + "X-Forwarded-For" => ["72.218.219.201, 70.132.33.68"], + "X-Forwarded-Host" => ["myawesomelambda.example.com"], + "X-Forwarded-Port" => ["443"], + "X-Forwarded-Proto" => ["https"] + }, + "queryStringParameters" => nil, + "multiValueQueryStringParameters" => nil, + "pathParameters" => { "resource" => "login" }, + "stageVariables" => nil, + "requestContext" => { + "resourceId" => "s2mq69", + "resourcePath" => "/{resource+}", + "httpMethod" => "POST", + "extendedRequestId" => "KIELOHygoAMFXxA=", + "requestTime" => "29/Mar/2020:00:08:52 +0000", + "path" => "/production/login", + "accountId" => nil, + "protocol" => "HTTP/1.1", + "stage" => "production", + "domainPrefix" => "4o8v9z4feh", + "requestTimeEpoch" => 1585440532566, + "requestId" => "552c9b8d-23fa-42de-9f89-9b56af1e6770", + "identity" => { + "cognitoIdentityPoolId" => nil, + "accountId" => nil, + "cognitoIdentityId" => nil, + "caller" => nil, + "sourceIp" => "72.218.219.201", + "principalOrgId" => nil, + "accessKey" => nil, + "cognitoAuthenticationType" => nil, + "cognitoAuthenticationProvider" => nil, + "userArn" => nil, + "userAgent" => "Amazon CloudFront", + "user" => nil + }, + "domainName" => "4o8v9z4feh.execute-api.us-east-1.amazonaws.com", + "apiId" => "4o8v9z4feh" + }, + "body" => "YXV0aGVudGljaXR5X3Rva2VuPXRObXZ0T2xlaHY0YU1GUlFlZTg4c2MxcTViZ3lJaGxqM3pscVJPelg5bWtyYnZwOVZrOUdoUlh4NG9sNFl4dW9jbDRJR2ZOOTk1ckh3SXhDSXhpVWZnJTNEJTNEJnBhc3N3b3JkPXBhc3N3b3JkJmNvbW1pdD1Mb2dpbg==", + "isBase64Encoded" => true + }.freeze end end -end +end \ No newline at end of file diff --git a/vendor/.keep b/vendor/.keep deleted file mode 100644 index e69de29..0000000