Skip to content

Commit

Permalink
follow rack changes
Browse files Browse the repository at this point in the history
now Rack::Response#finish returns an Array of body strings.
  • Loading branch information
nov committed Mar 25, 2020
1 parent 40c9a99 commit 0fe3f6c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/rack/oauth2/server/rails/response_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Rails
module ResponseExt
def redirect?
ensure_finish do
@response.redirect?
super
end
end

Expand All @@ -17,7 +17,7 @@ def location

def json
ensure_finish do
@response.body
@body
end
end

Expand All @@ -39,7 +39,7 @@ def finished?
end

def ensure_finish
@status, @header, @response = finish unless finished?
@status, @header, @body = finish unless finished?
yield
end
end
Expand Down
2 changes: 1 addition & 1 deletion rack-oauth2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.add_runtime_dependency 'rack'
s.add_runtime_dependency 'rack', '>= 2.1.0'
s.add_runtime_dependency 'httpclient'
s.add_runtime_dependency 'activesupport'
s.add_runtime_dependency 'attr_required'
Expand Down
14 changes: 7 additions & 7 deletions spec/rack/oauth2/server/resource/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
status, header, response = error.finish
status.should == 400
header['Content-Type'].should == 'application/json'
response.body.should == ['{"error":"invalid_request"}']
response.should == ['{"error":"invalid_request"}']
end
end
end
Expand Down Expand Up @@ -44,7 +44,7 @@ def scheme
status.should == 401
header['Content-Type'].should == 'application/json'
header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\", error=\"invalid_token\""
response.body.should == ['{"error":"invalid_token"}']
response.should == ['{"error":"invalid_token"}']
end

context 'when error_code is not invalid_token' do
Expand All @@ -53,7 +53,7 @@ def scheme
it 'should have error_code in body but not in WWW-Authenticate header' do
status, header, response = error_with_scheme.finish
header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\""
response.body.first.should include '"error":"something"'
response.first.should include '"error":"something"'
end
end

Expand All @@ -63,7 +63,7 @@ def scheme
it 'should have error_code in body but not in WWW-Authenticate header' do
status, header, response = error_with_scheme.finish
header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\""
response.body.first.should == '{"error":"unauthorized"}'
response.first.should == '{"error":"unauthorized"}'
end
end

Expand All @@ -74,7 +74,7 @@ def scheme
it 'should use given realm' do
status, header, response = error_with_scheme.finish
header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\""
response.body.first.should include '"error":"something"'
response.first.should include '"error":"something"'
end
end
end
Expand All @@ -91,7 +91,7 @@ def scheme
status, header, response = error.finish
status.should == 403
header['Content-Type'].should == 'application/json'
response.body.should == ['{"error":"insufficient_scope"}']
response.should == ['{"error":"insufficient_scope"}']
end
end

Expand All @@ -100,7 +100,7 @@ def scheme

it 'should have blank WWW-Authenticate header' do
status, header, response = error.finish
response.body.first.should include '"scope":"scope1 scope2"'
response.first.should include '"scope":"scope1 scope2"'
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/rack/oauth2/server/token/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
status, header, response = error.finish
status.should == 400
header['Content-Type'].should == 'application/json'
response.body.should == ['{"error":"invalid_request"}']
response.should == ['{"error":"invalid_request"}']
end
end
end
Expand All @@ -26,7 +26,7 @@
status.should == 401
header['Content-Type'].should == 'application/json'
header['WWW-Authenticate'].should == 'Basic realm="OAuth2 Token Endpoint"'
response.body.should == ['{"error":"invalid_request"}']
response.should == ['{"error":"invalid_request"}']
end
end
end
Expand Down Expand Up @@ -74,4 +74,4 @@
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/rack/oauth2/server/token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
it 'should fail with unsupported_grant_type' do
status, header, response = app.call(env)
status.should == 400
response.body.first.should include '"error":"invalid_request"'
response.first.should include '"error":"invalid_request"'
end
end

Expand Down

0 comments on commit 0fe3f6c

Please sign in to comment.