From 0d9b82700247307f27cf28e9f2470c789214a256 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Fri, 30 Aug 2024 09:12:50 -0400 Subject: [PATCH] Remove cookies header from rack_response that was added in v6 release (#182) * remove cookies from rack_response * write tests for rack_response to ensure correct keys are present * use github action rubygems/release-gem --- .github/workflows/release.yml | 26 ++++++++++++++++++++++++++ CHANGELOG.md | 4 ++++ Gemfile.lock | 2 +- lib/lamby/handler.rb | 1 - lib/lamby/version.rb | 2 +- test/handler_test.rb | 24 ++++++++++++++++++++++++ test/proxy_server_test.rb | 4 ++-- 7 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ca51938 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Release Gem +on: + workflow_dispatch: + branches: + - master + +jobs: + push: + name: Push gem to RubyGems.org + runs-on: ubuntu-latest + + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag + + steps: + # Set up + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ruby + + # Release + - uses: rubygems/release-gem@v1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e6be18..adf4373 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ See this http://keepachangelog.com link for information on how we want this docu ## v6.0.0 +- Remove "cookies" header from rack response to conform to Lambda proxy integration requirements. + +## v6.0.0 + ### Changed - ⚠️ Breaking Changes ⚠️ diff --git a/Gemfile.lock b/Gemfile.lock index 2c4f5ef..cb74820 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lamby (6.0.0) + lamby (6.0.1) lambda-console-ruby rack (>= 3.0.0) diff --git a/lib/lamby/handler.rb b/lib/lamby/handler.rb index 71ea7e7..41793cf 100644 --- a/lib/lamby/handler.rb +++ b/lib/lamby/handler.rb @@ -81,7 +81,6 @@ def rack_option def rack_response { statusCode: status, headers: stringify_values!(headers), - cookies: @set_cookies, body: body }.merge(rack.response(self)) end diff --git a/lib/lamby/version.rb b/lib/lamby/version.rb index ee8d39f..8bf3ad1 100644 --- a/lib/lamby/version.rb +++ b/lib/lamby/version.rb @@ -1,3 +1,3 @@ module Lamby - VERSION = '6.0.0' + VERSION = '6.0.1' end diff --git a/test/handler_test.rb b/test/handler_test.rb index 76942aa..17e861f 100644 --- a/test/handler_test.rb +++ b/test/handler_test.rb @@ -5,7 +5,19 @@ class HandlerTest < LambySpec let(:app) { Rack::Builder.new { run Rails.application }.to_app } let(:context) { TestHelpers::LambdaContext.new } + describe 'http-v2' do + it 'returns the correct rack response' do + event = TestHelpers::Events::HttpV2.create + handler = Lamby::Handler.new(app, event, context, rack: :http) + handler.call + response = handler.send(:rack_response) + + expect(response[:statusCode]).must_equal 200 + expect(response[:headers]['Content-Type']).must_equal 'text/html; charset=utf-8' + expect(response[:body]).must_match %r{

Hello Lamby

} + expect(response.keys).must_equal [:statusCode, :headers, :body] + end it 'get' do event = TestHelpers::Events::HttpV2.create @@ -101,6 +113,18 @@ class HandlerTest < LambySpec describe 'http-v1' do + it 'returns the correct rack response' do + event = TestHelpers::Events::HttpV1.create + handler = Lamby::Handler.new(app, event, context, rack: :http) + handler.call + response = handler.send(:rack_response) + + expect(response[:statusCode]).must_equal 200 + expect(response[:headers]['Content-Type']).must_equal 'text/html; charset=utf-8' + expect(response[:body]).must_match %r{

Hello Lamby

} + expect(response.keys).must_equal [:statusCode, :headers, :body] + end + it 'get' do event = TestHelpers::Events::HttpV1.create result = Lamby.handler app, event, context, rack: :http diff --git a/test/proxy_server_test.rb b/test/proxy_server_test.rb index a88960a..abca7f2 100644 --- a/test/proxy_server_test.rb +++ b/test/proxy_server_test.rb @@ -19,7 +19,7 @@ class ProxyServerTest < LambySpec 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", "content-length"=>"755"}) + expect(response.headers).must_equal({"content-type"=>"application/json", "content-length"=>"740"}) response_body = JSON.parse(response.body) expect(response_body['statusCode']).must_equal 200 expect(response_body['headers']).must_be_kind_of Hash @@ -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", "content-length"=>"58"}) + expect(response.headers).must_equal({"content-type"=>"application/json", "content-length"=>"43"}) response_body = JSON.parse(response.body) expect(response_body['statusCode']).must_equal 200 expect(response_body['headers']).must_equal({})