Skip to content

Commit c219087

Browse files
authored
Update Sinatra to 4.2 and Rack to 3.2 (#4707)
* Rack 3 update: Replace :unprocessable_entity with :unprocessable_content * Rack::Test update: Rename response header -> headers * Rack 3 / Sinatra 4 upgrade: Rewind body before reading * Sinatra 4 expects a real IO-like object * Rack 3 update: Disable host authorization feature * Rack 3 update: Fix headers handling * Rack 3 update: Call rewind on request body * Update to Sinatra 4.2 and Rack 3.2 * Rack 3 update: Patch RspecApiDocumentation module * and add unit test to check rspec_api_documentation Gem version (will fail when Gem is updated)
1 parent 41f2057 commit c219087

34 files changed

+254
-202
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ gem 'redis'
3131
gem 'rubyzip', '>= 1.3.0'
3232
gem 'sequel', '~> 5.99'
3333
gem 'sequel_pg', require: 'sequel'
34-
gem 'sinatra', '~> 3.2'
34+
gem 'sinatra', '~> 4.2'
3535
gem 'sinatra-contrib'
3636
gem 'statsd-ruby', '~> 1.5.0'
3737
gem 'steno'
@@ -88,6 +88,7 @@ group :test do
8888
gem 'rubocop-sequel', '~> 0.4.1'
8989
gem 'timecop'
9090
gem 'webmock', '> 2.3.1'
91+
gem 'webrick', '~> 1.9.0'
9192
end
9293

9394
group :development do

Gemfile.lock

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,18 @@ GEM
369369
puma (7.1.0)
370370
nio4r (~> 2.0)
371371
racc (1.8.1)
372-
rack (2.2.21)
373-
rack-protection (3.2.0)
372+
rack (3.2.4)
373+
rack-protection (4.2.1)
374374
base64 (>= 0.1.0)
375-
rack (~> 2.2, >= 2.2.4)
376-
rack-session (1.0.2)
377-
rack (< 3)
375+
logger (>= 1.6.0)
376+
rack (>= 3.0.0, < 4)
377+
rack-session (2.1.1)
378+
base64 (>= 0.1.0)
379+
rack (>= 3.0.0)
378380
rack-test (2.2.0)
379381
rack (>= 1.3)
380-
rackup (1.0.1)
381-
rack (< 3)
382-
webrick
382+
rackup (2.3.1)
383+
rack (>= 3)
383384
rails-dom-testing (2.3.0)
384385
activesupport (>= 5.0.0)
385386
minitest
@@ -521,16 +522,18 @@ GEM
521522
json (>= 1.8, < 3)
522523
simplecov-html (~> 0.10.0)
523524
simplecov-html (0.10.2)
524-
sinatra (3.2.0)
525+
sinatra (4.2.1)
526+
logger (>= 1.6.0)
525527
mustermann (~> 3.0)
526-
rack (~> 2.2, >= 2.2.4)
527-
rack-protection (= 3.2.0)
528+
rack (>= 3.0.0, < 4)
529+
rack-protection (= 4.2.1)
530+
rack-session (>= 2.0.0, < 3)
528531
tilt (~> 2.0)
529-
sinatra-contrib (3.2.0)
532+
sinatra-contrib (4.2.1)
530533
multi_json (>= 0.0.2)
531534
mustermann (~> 3.0)
532-
rack-protection (= 3.2.0)
533-
sinatra (= 3.2.0)
535+
rack-protection (= 4.2.1)
536+
sinatra (= 4.2.1)
534537
tilt (~> 2.0)
535538
solargraph (0.57.0)
536539
backport (~> 1.2)
@@ -673,7 +676,7 @@ DEPENDENCIES
673676
rubyzip (>= 1.3.0)
674677
sequel (~> 5.99)
675678
sequel_pg
676-
sinatra (~> 3.2)
679+
sinatra (~> 4.2)
677680
sinatra-contrib
678681
solargraph
679682
spork!
@@ -686,6 +689,7 @@ DEPENDENCIES
686689
uri (~> 1.1)
687690
vmstat (~> 2.3)
688691
webmock (> 2.3.1)
692+
webrick (~> 1.9.0)
689693

690694
BUNDLED WITH
691695
2.4.19

app/controllers/internal/app_crashed_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def crashed(lrp_process_guid)
2626
private
2727

2828
def crashed_request
29-
payload = body.read
29+
request.body.rewind
30+
payload = request.body.read
3031
Oj.load(payload)
3132
rescue StandardError => e
3233
logger.error('diego.app_crashed.parse-error', payload: payload, error: e.to_s)

app/controllers/internal/app_readiness_changed_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def readiness_changed(process_guid)
2525
private
2626

2727
def readiness_request
28-
payload = body.read
28+
request.body.rewind
29+
payload = request.body.read
2930
Oj.load(payload)
3031
rescue StandardError => e
3132
logger.error('diego.app_readiness_changed.parse-error', payload: payload, error: e.to_s)

app/controllers/internal/app_rescheduling_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def rescheduling(process_guid)
2525
private
2626

2727
def rescheduling_request
28-
payload = body.read
28+
request.body.rewind
29+
payload = request.body.read
2930
Oj.load(payload)
3031
rescue StandardError => e
3132
logger.error('diego.app_rescheduling.parse-error', payload: payload, error: e.to_s)

app/controllers/internal/staging_completion_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def prometheus_updater
121121
attr_reader :stagers
122122

123123
def read_body
124-
payload = body.read
124+
request.body.rewind
125+
payload = request.body.read
125126
Oj.load(payload, symbol_keys: true)
126127
rescue StandardError => e
127128
logger.error('diego.staging.parse-error', payload: payload, error: e.to_s)

app/controllers/internal/task_completion_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def complete_task(task_guid, task_response)
2525
end
2626

2727
def read_body
28-
payload = body.read
28+
request.body.rewind
29+
payload = request.body.read
2930
Oj.load(payload, symbol_keys: true)
3031
rescue StandardError => e
3132
logger.error('diego.task.parse-error', payload: payload, error: e.to_s)

lib/cloud_controller/logs/steno_io.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,24 @@ def write(str)
88
@logger.log(@level, str)
99
end
1010

11+
def puts(*args)
12+
args.each { |a| write("#{a}\n") }
13+
nil
14+
end
15+
16+
def flush
17+
nil
18+
end
19+
20+
def close
21+
nil
22+
end
23+
1124
def sync
1225
true
1326
end
27+
28+
def to_s
29+
@logger.name
30+
end
1431
end

lib/sinatra/vcap.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def vcap_configure(opts={})
7070
set(:show_exceptions, false)
7171
set(:raise_errors, false)
7272
set(:dump_errors, false)
73+
set(:host_authorization, permitted_hosts: [])
7374
end
7475

7576
configure :development do

spec/request/packages_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@
11941194

11951195
expect(last_response.status).to eq(202)
11961196
expect(last_response.body).to eq('')
1197-
expect(last_response.header['Location']).to match(%r{jobs/[a-fA-F0-9-]+})
1197+
expect(last_response.headers['Location']).to match(%r{jobs/[a-fA-F0-9-]+})
11981198
execute_all_jobs(expected_successes: 2, expected_failures: 0)
11991199
get "/v3/packages/#{guid}", {}, user_header
12001200
expect(last_response.status).to eq(404)

0 commit comments

Comments
 (0)