Skip to content

Commit

Permalink
Fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Sep 26, 2018
1 parent 946bbbd commit fcc5e37
Show file tree
Hide file tree
Showing 55 changed files with 359 additions and 233 deletions.
4 changes: 2 additions & 2 deletions app/controllers/doorkeeper/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def set_application
end

def application_params
params.require(:doorkeeper_application).
permit(:name, :redirect_uri, :scopes, :confidential)
params.require(:doorkeeper_application)
.permit(:name, :redirect_uri, :scopes, :confidential)
end
end
end
2 changes: 1 addition & 1 deletion lib/doorkeeper/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def option(name, options = {})
value = if attribute_builder
attribute_builder.new(&block).build
else
block ? block : args.first
block || args.first
end

@config.instance_variable_set(:"@#{attribute}", value)
Expand Down
6 changes: 3 additions & 3 deletions lib/doorkeeper/models/access_grant_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def by_token(token)
def revoke_all_for(application_id, resource_owner, clock = Time)
where(application_id: application_id,
resource_owner_id: resource_owner.id,
revoked_at: nil).
update_all(revoked_at: clock.now.utc)
revoked_at: nil)
.update_all(revoked_at: clock.now.utc)
end

# Implements PKCE code_challenge encoding without base64 padding as described in the spec.
Expand Down Expand Up @@ -78,7 +78,7 @@ def revoke_all_for(application_id, resource_owner, clock = Time)
#
# urlsafe_encode64(bin)
# Returns the Base64-encoded version of bin. This method complies with
# Base 64 Encoding with URL and Filename Safe Alphabet in RFC 4648.
# "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC 4648.
# The alphabet uses '-' instead of '+' and '_' instead of '/'.

# @param code_verifier [#to_s] a one time use value (any object that responds to `#to_s`)
Expand Down
4 changes: 2 additions & 2 deletions lib/doorkeeper/models/access_token_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def by_refresh_token(refresh_token)
def revoke_all_for(application_id, resource_owner, clock = Time)
where(application_id: application_id,
resource_owner_id: resource_owner.id,
revoked_at: nil).
update_all(revoked_at: clock.now.utc)
revoked_at: nil)
.update_all(revoked_at: clock.now.utc)
end

# Looking for not revoked Access Token with a matching set of scopes
Expand Down
9 changes: 7 additions & 2 deletions lib/doorkeeper/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ def token_info_routes(mapping)
end

def application_routes(mapping)
routes.resources :doorkeeper_applications, controller: mapping[:controllers], as: :applications, path: 'applications'
routes.resources :doorkeeper_applications,
controller: mapping[:controllers],
as: :applications,
path: 'applications'
end

def authorized_applications_routes(mapping)
routes.resources :authorized_applications, only: %i[index destroy], controller: mapping[:controllers]
routes.resources :authorized_applications,
only: %i[index destroy],
controller: mapping[:controllers]
end
end
end
Expand Down
78 changes: 37 additions & 41 deletions spec/controllers/applications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ module Doorkeeper
it 'creates an application' do
expect do
post :create, params: {
doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}, format: :json
}
end.to change { Doorkeeper::Application.count }
doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}, format: :json
}
end.to(change { Doorkeeper::Application.count })

expect(response).to be_successful

Expand All @@ -31,11 +31,11 @@ module Doorkeeper
it 'returns validation errors on wrong create params' do
expect do
post :create, params: {
doorkeeper_application: {
name: 'Example'
}, format: :json
}
end.not_to change { Doorkeeper::Application.count }
doorkeeper_application: {
name: 'Example'
}, format: :json
}
end.not_to(change { Doorkeeper::Application.count })

expect(response).to have_http_status(422)

Expand Down Expand Up @@ -108,14 +108,13 @@ module Doorkeeper

it 'does not create application' do
expect do
post :create,
params: {
doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}
}
end.not_to change { Doorkeeper::Application.count }
post :create, params: {
doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}
}
end.not_to(change { Doorkeeper::Application.count })
end
end

Expand All @@ -139,41 +138,38 @@ module Doorkeeper

it 'creates application' do
expect do
post :create,
params: {
doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}
}
post :create, params: {
doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}
}
end.to change { Doorkeeper::Application.count }.by(1)

expect(response).to be_redirect
end

it 'does not allow mass assignment of uid or secret' do
application = FactoryBot.create(:application)
put :update,
params: {
id: application.id,
doorkeeper_application: {
uid: '1A2B3C4D',
secret: '1A2B3C4D'
}
}
put :update, params: {
id: application.id,
doorkeeper_application: {
uid: '1A2B3C4D',
secret: '1A2B3C4D'
}
}

expect(application.reload.uid).not_to eq '1A2B3C4D'
end

it 'updates application' do
application = FactoryBot.create(:application)
put :update,
params: {
id: application.id, doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}
}
put :update, params: {
id: application.id, doorkeeper_application: {
name: 'Example',
redirect_uri: 'https://example.com'
}
}

expect(application.reload.name).to eq 'Example'
end
Expand Down
89 changes: 71 additions & 18 deletions spec/controllers/authorizations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def translated_error_message(key)
end

it 'redirects to client redirect uri' do
expect(response.location).to match(%r{^#{client.redirect_uri}})
expect(response.location).to match(/^#{client.redirect_uri}/)
end

it 'includes access token in fragment' do
Expand Down Expand Up @@ -114,7 +114,13 @@ def translated_error_message(key)
describe 'POST #create with errors' do
before do
default_scopes_exist :public
post :create, params: { client_id: client.uid, response_type: 'token', scope: 'invalid', redirect_uri: client.redirect_uri }

post :create, params: {
client_id: client.uid,
response_type: 'token',
scope: 'invalid',
redirect_uri: client.redirect_uri
}
end

it 'redirects after authorization' do
Expand Down Expand Up @@ -146,7 +152,13 @@ def translated_error_message(key)
before do
allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
default_scopes_exist :public
post :create, params: { client_id: client.uid, response_type: 'token', scope: 'invalid', redirect_uri: client.redirect_uri }

post :create, params: {
client_id: client.uid,
response_type: 'token',
scope: 'invalid',
redirect_uri: client.redirect_uri
}
end

let(:response_json_body) { JSON.parse(response.body) }
Expand Down Expand Up @@ -182,7 +194,12 @@ def translated_error_message(key)
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)

access_token.save!
post :create, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }

post :create, params: {
client_id: client.uid,
response_type: 'token',
redirect_uri: client.redirect_uri
}
end

it 'returns the existing access token in a fragment' do
Expand All @@ -201,15 +218,21 @@ def translated_error_message(key)

describe 'when successful' do
after do
post :create, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
post :create, params: {
client_id: client.uid,
response_type: 'token',
redirect_uri: client.redirect_uri
}
end

it 'should call :before_successful_authorization callback' do
expect(Doorkeeper.configuration).to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
expect(Doorkeeper.configuration)
.to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
end

it 'should call :after_successful_authorization callback' do
expect(Doorkeeper.configuration).to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
expect(Doorkeeper.configuration)
.to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
end
end

Expand All @@ -233,13 +256,19 @@ def translated_error_message(key)
allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
true
end)

client.update_attribute :redirect_uri, 'urn:ietf:wg:oauth:2.0:oob'
get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }

get :new, params: {
client_id: client.uid,
response_type: 'token',
redirect_uri: client.redirect_uri
}
end

it 'should redirect immediately' do
expect(response).to be_redirect
expect(response.location).to match(/oauth\/token\/info\?access_token=/)
expect(response.location).to match(%r{/oauth/token/info\?access_token=})
end

it 'should not issue a grant' do
Expand All @@ -257,13 +286,20 @@ def translated_error_message(key)
allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
true
end)

client.update_attribute :redirect_uri, 'urn:ietf:wg:oauth:2.0:oob'
get :new, params: { client_id: client.uid, response_type: 'code', redirect_uri: client.redirect_uri }

get :new, params: {
client_id: client.uid,
response_type: 'code',
redirect_uri: client.redirect_uri
}
end

it 'should redirect immediately' do
expect(response).to be_redirect
expect(response.location).to match(/oauth\/authorize\/native\?code=#{Doorkeeper::AccessGrant.first.token}/)
expect(response.location)
.to match(%r{/oauth/authorize/native\?code=#{Doorkeeper::AccessGrant.first.token}})
end

it 'should issue a grant' do
Expand All @@ -280,12 +316,17 @@ def translated_error_message(key)
allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
true
end)
get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }

get :new, params: {
client_id: client.uid,
response_type: 'token',
redirect_uri: client.redirect_uri
}
end

it 'should redirect immediately' do
expect(response).to be_redirect
expect(response.location).to match(%r{^#{client.redirect_uri}})
expect(response.location).to match(/^#{client.redirect_uri}/)
end

it 'should issue a token' do
Expand All @@ -312,7 +353,12 @@ def translated_error_message(key)
describe 'GET #new in API mode' do
before do
allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }

get :new, params: {
client_id: client.uid,
response_type: 'token',
redirect_uri: client.redirect_uri
}
end

it 'should render success' do
Expand All @@ -337,7 +383,11 @@ def translated_error_message(key)
allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { true })
allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)

get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
get :new, params: {
client_id: client.uid,
response_type: 'token',
redirect_uri: client.redirect_uri
}
end

it 'should render success' do
Expand Down Expand Up @@ -405,7 +455,8 @@ def translated_error_message(key)
end

it 'includes error description in body' do
expect(response_json_body['error_description']).to eq(translated_error_message(:unsupported_response_type))
expect(response_json_body['error_description'])
.to eq(translated_error_message(:unsupported_response_type))
end

it 'does not issue any token' do
Expand All @@ -426,11 +477,13 @@ def translated_error_message(key)
end

it 'should call :before_successful_authorization callback' do
expect(Doorkeeper.configuration).to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
expect(Doorkeeper.configuration)
.to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
end

it 'should call :after_successful_authorization callback' do
expect(Doorkeeper.configuration).to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
expect(Doorkeeper.configuration)
.to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
end
end

Expand Down
3 changes: 1 addition & 2 deletions spec/controllers/protected_resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ def doorkeeper_unauthorized_render_options(error: nil)
module ControllerActions
remove_method :doorkeeper_unauthorized_render_options

def doorkeeper_unauthorized_render_options(error: nil)
end
def doorkeeper_unauthorized_render_options(error: nil); end
end
end

Expand Down
Loading

0 comments on commit fcc5e37

Please sign in to comment.