Skip to content

Commit

Permalink
Merge pull request #939 from maclover7/jm-authorizations-cleanup
Browse files Browse the repository at this point in the history
Change to "query params" rather than "fragments"
  • Loading branch information
maclover7 committed Feb 12, 2017
2 parents f37f114 + 3ffc3ec commit 6aee782
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions spec/controllers/authorizations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@
describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
include AuthorizationRequestHelper

def fragments(param)
fragment = URI.parse(response.location).fragment
Rack::Utils.parse_query(fragment)[param]
if Rails::VERSION::MAJOR == 5
class ActionDispatch::TestResponse
def query_params
@_query_params ||= begin
fragment = URI.parse(location).fragment
Rack::Utils.parse_query(fragment)
end
end
end
else
class ActionController::TestResponse
def query_params
@_query_params ||= begin
fragment = URI.parse(location).fragment
Rack::Utils.parse_query(fragment)
end
end
end
end

def translated_error_message(key)
Expand Down Expand Up @@ -35,15 +50,15 @@ def translated_error_message(key)
end

it 'includes access token in fragment' do
expect(fragments('access_token')).to eq(Doorkeeper::AccessToken.first.token)
expect(response.query_params['access_token']).to eq(Doorkeeper::AccessToken.first.token)
end

it 'includes token type in fragment' do
expect(fragments('token_type')).to eq('bearer')
expect(response.query_params['token_type']).to eq('bearer')
end

it 'includes token expiration in fragment' do
expect(fragments('expires_in').to_i).to eq(2.hours.to_i)
expect(response.query_params['expires_in'].to_i).to eq(2.hours.to_i)
end

it 'issues the token for the current client' do
Expand All @@ -70,15 +85,15 @@ def translated_error_message(key)
end

it 'does not include access token in fragment' do
expect(fragments('access_token')).to be_nil
expect(response.query_params['access_token']).to be_nil
end

it 'includes error in fragment' do
expect(fragments('error')).to eq('invalid_scope')
expect(response.query_params['error']).to eq('invalid_scope')
end

it 'includes error description in fragment' do
expect(fragments('error_description')).to eq(translated_error_message(:invalid_scope))
expect(response.query_params['error_description']).to eq(translated_error_message(:invalid_scope))
end

it 'does not issue any access token' do
Expand All @@ -95,7 +110,7 @@ def translated_error_message(key)
end

it 'returns the existing access token in a fragment' do
expect(fragments('access_token')).to eq(access_token.token)
expect(response.query_params['access_token']).to eq(access_token.token)
end

it 'does not creates a new access token' do
Expand Down Expand Up @@ -169,11 +184,11 @@ def translated_error_message(key)
end

it 'includes token type in fragment' do
expect(fragments('token_type')).to eq('bearer')
expect(response.query_params['token_type']).to eq('bearer')
end

it 'includes token expiration in fragment' do
expect(fragments('expires_in').to_i).to eq(2.hours.to_i)
expect(response.query_params['expires_in'].to_i).to eq(2.hours.to_i)
end

it 'issues the token for the current client' do
Expand Down

0 comments on commit 6aee782

Please sign in to comment.