Skip to content

Commit

Permalink
Have strategy requests all invoke BaseRequest's callbacks (#1001)
Browse files Browse the repository at this point in the history
* Have BaseRequest subclasses invoke super on callbacks

This makes the BaseRequest#before_successful_response and BaseRequest#after_successful_response generally available. Some subclasses implement these callbacks, which then requires explicit per-strategy hooking vs one global one on BaseRequest, if desired by the developer.

* [Lint] Prefer double quotes for #it
  • Loading branch information
f3ndot authored and nbulaj committed Feb 11, 2018
1 parent 5cd1672 commit 4ad9458
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/doorkeeper/oauth/authorization_code_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def before_successful_response
grant.scopes,
server)
end
super
end

def validate_attributes
Expand Down
1 change: 1 addition & 0 deletions lib/doorkeeper/oauth/password_access_token_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(server, client, resource_owner, parameters = {})

def before_successful_response
find_or_create_access_token(client, resource_owner.id, scopes, server)
super
end

def validate_scopes
Expand Down
1 change: 1 addition & 0 deletions lib/doorkeeper/oauth/refresh_token_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def before_successful_response
refresh_token.revoke unless refresh_token_revoked_on_use?
create_access_token
end
super
end

def refresh_token_revoked_on_use?
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/oauth/authorization_code_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ module Doorkeeper::OAuth
end.to_not change { Doorkeeper::AccessToken.count }
end

it "calls BaseRequest callback methods" do
expect_any_instance_of(BaseRequest).to receive(:before_successful_response).once
expect_any_instance_of(BaseRequest).to receive(:after_successful_response).once
subject.authorize
end

context "when redirect_uri contains some query params" do
let(:redirect_uri) { client.redirect_uri + "?query=q" }

Expand Down
6 changes: 6 additions & 0 deletions spec/lib/oauth/password_access_token_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ module Doorkeeper::OAuth
end.to_not change { Doorkeeper::AccessToken.count }
end

it "calls BaseRequest callback methods" do
expect_any_instance_of(BaseRequest).to receive(:before_successful_response).once
expect_any_instance_of(BaseRequest).to receive(:after_successful_response).once
subject.authorize
end

describe 'with scopes' do
subject do
PasswordAccessTokenRequest.new(server, client, owner, scope: 'public')
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/oauth/refresh_token_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ module Doorkeeper::OAuth
expect { subject.authorize }.to change { refresh_token.revoked? }.from(false).to(true)
end

it "calls BaseRequest callback methods" do
expect_any_instance_of(BaseRequest).to receive(:before_successful_response).once
expect_any_instance_of(BaseRequest).to receive(:after_successful_response).once
subject.authorize
end

it 'requires the refresh token' do
subject.refresh_token = nil
subject.validate
Expand Down

0 comments on commit 4ad9458

Please sign in to comment.