Skip to content

Commit

Permalink
spec for revocation & change error for no token given
Browse files Browse the repository at this point in the history
  • Loading branch information
nov committed Jul 12, 2022
1 parent acaceb4 commit b5f55ef
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rack/oauth2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def revoke!(*args)
token_type_hint: :refresh_token
}
when options[:token].blank?
raise AttrRequired::AttrMissing, 'One of "token", "access_token" and "refresh_token" is required'
raise ArgumentError, 'One of "token", "access_token" and "refresh_token" is required'
end
params.merge! options

Expand Down
82 changes: 81 additions & 1 deletion spec/rack/oauth2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,86 @@
end
end

describe '#revoke!' do
context 'when access_token given' do
before do
mock_response(
:post,
'https://server.example.com/oauth2/revoke',
'blank',
status: 200,
body: {
token: 'access_token',
token_type_hint: 'access_token'
}
)
end
it do
client.revoke!(access_token: 'access_token').should == :success
end
end

context 'when refresh_token given' do
before do
mock_response(
:post,
'https://server.example.com/oauth2/revoke',
'blank',
status: 200,
body: {
token: 'refresh_token',
token_type_hint: 'refresh_token'
}
)
end

context 'as argument' do
it do
client.revoke!(refresh_token: 'refresh_token').should == :success
end
end

context 'as grant' do
it do
client.refresh_token = 'refresh_token'
client.revoke!
end
end
end

context 'when error response given' do
before do
mock_response(
:post,
'https://server.example.com/oauth2/revoke',
'errors/invalid_request.json',
status: 400
)
end

it do
expect do
client.revoke! access_token: 'access_token'
end.to raise_error Rack::OAuth2::Client::Error
end
end

context 'when no token given' do
it do
expect do
client.revoke!
end.to raise_error ArgumentError
end
end
end

context 'when no host info' do
let :client do
Rack::OAuth2::Client.new(
identifier: 'client_id',
secret: 'client_secret',
redirect_uri: 'https://client.example.com/callback'
redirect_uri: 'https://client.example.com/callback',
revocation_endpoint: '/oauth2/revoke'
)
end

Expand All @@ -468,5 +542,11 @@
expect { client.access_token! }.to raise_error 'No Host Info'
end
end

describe '#revoke!' do
it do
expect { client.revoke! access_token: 'access_token' }.to raise_error 'No Host Info'
end
end
end
end

0 comments on commit b5f55ef

Please sign in to comment.