Skip to content

Commit b5f55ef

Browse files
committed
spec for revocation & change error for no token given
1 parent acaceb4 commit b5f55ef

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

lib/rack/oauth2/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def revoke!(*args)
102102
token_type_hint: :refresh_token
103103
}
104104
when options[:token].blank?
105-
raise AttrRequired::AttrMissing, 'One of "token", "access_token" and "refresh_token" is required'
105+
raise ArgumentError, 'One of "token", "access_token" and "refresh_token" is required'
106106
end
107107
params.merge! options
108108

spec/rack/oauth2/client_spec.rb

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,86 @@
448448
end
449449
end
450450

451+
describe '#revoke!' do
452+
context 'when access_token given' do
453+
before do
454+
mock_response(
455+
:post,
456+
'https://server.example.com/oauth2/revoke',
457+
'blank',
458+
status: 200,
459+
body: {
460+
token: 'access_token',
461+
token_type_hint: 'access_token'
462+
}
463+
)
464+
end
465+
it do
466+
client.revoke!(access_token: 'access_token').should == :success
467+
end
468+
end
469+
470+
context 'when refresh_token given' do
471+
before do
472+
mock_response(
473+
:post,
474+
'https://server.example.com/oauth2/revoke',
475+
'blank',
476+
status: 200,
477+
body: {
478+
token: 'refresh_token',
479+
token_type_hint: 'refresh_token'
480+
}
481+
)
482+
end
483+
484+
context 'as argument' do
485+
it do
486+
client.revoke!(refresh_token: 'refresh_token').should == :success
487+
end
488+
end
489+
490+
context 'as grant' do
491+
it do
492+
client.refresh_token = 'refresh_token'
493+
client.revoke!
494+
end
495+
end
496+
end
497+
498+
context 'when error response given' do
499+
before do
500+
mock_response(
501+
:post,
502+
'https://server.example.com/oauth2/revoke',
503+
'errors/invalid_request.json',
504+
status: 400
505+
)
506+
end
507+
508+
it do
509+
expect do
510+
client.revoke! access_token: 'access_token'
511+
end.to raise_error Rack::OAuth2::Client::Error
512+
end
513+
end
514+
515+
context 'when no token given' do
516+
it do
517+
expect do
518+
client.revoke!
519+
end.to raise_error ArgumentError
520+
end
521+
end
522+
end
523+
451524
context 'when no host info' do
452525
let :client do
453526
Rack::OAuth2::Client.new(
454527
identifier: 'client_id',
455528
secret: 'client_secret',
456-
redirect_uri: 'https://client.example.com/callback'
529+
redirect_uri: 'https://client.example.com/callback',
530+
revocation_endpoint: '/oauth2/revoke'
457531
)
458532
end
459533

@@ -468,5 +542,11 @@
468542
expect { client.access_token! }.to raise_error 'No Host Info'
469543
end
470544
end
545+
546+
describe '#revoke!' do
547+
it do
548+
expect { client.revoke! access_token: 'access_token' }.to raise_error 'No Host Info'
549+
end
550+
end
471551
end
472552
end

0 commit comments

Comments
 (0)