rack-oauth2 0.2.3 → 0.3.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/Gemfile +1 -0
  2. data/README.rdoc +1 -0
  3. data/VERSION +1 -1
  4. data/lib/rack/oauth2.rb +1 -7
  5. data/lib/rack/oauth2/server.rb +0 -1
  6. data/lib/rack/oauth2/server/abstract.rb +2 -1
  7. data/lib/rack/oauth2/server/abstract/error.rb +55 -0
  8. data/lib/rack/oauth2/server/abstract/handler.rb +2 -3
  9. data/lib/rack/oauth2/server/abstract/request.rb +2 -3
  10. data/lib/rack/oauth2/server/abstract/response.rb +0 -5
  11. data/lib/rack/oauth2/server/authorize.rb +19 -14
  12. data/lib/rack/oauth2/server/authorize/code.rb +8 -19
  13. data/lib/rack/oauth2/server/authorize/error.rb +60 -0
  14. data/lib/rack/oauth2/server/authorize/token.rb +15 -24
  15. data/lib/rack/oauth2/server/resource.rb +1 -79
  16. data/lib/rack/oauth2/server/resource/bearer.rb +74 -0
  17. data/lib/rack/oauth2/server/resource/bearer/error.rb +80 -0
  18. data/lib/rack/oauth2/server/token.rb +12 -19
  19. data/lib/rack/oauth2/server/token/authorization_code.rb +4 -5
  20. data/lib/rack/oauth2/server/token/error.rb +54 -0
  21. data/lib/rack/oauth2/server/token/password.rb +0 -2
  22. data/lib/rack/oauth2/server/token/refresh_token.rb +1 -1
  23. data/lib/rack/oauth2/server/util.rb +29 -0
  24. data/rack-oauth2.gemspec +1 -1
  25. data/spec/rack/oauth2/server/abstract/error_spec.rb +51 -0
  26. data/spec/rack/oauth2/server/authorize/code_spec.rb +42 -28
  27. data/spec/rack/oauth2/server/authorize/error_spec.rb +103 -0
  28. data/spec/rack/oauth2/server/authorize/token_spec.rb +55 -26
  29. data/spec/rack/oauth2/server/authorize_spec.rb +24 -68
  30. data/spec/rack/oauth2/server/resource/bearer/error_spec.rb +118 -0
  31. data/spec/rack/oauth2/server/resource/bearer_spec.rb +117 -0
  32. data/spec/rack/oauth2/server/token/authorization_code_spec.rb +26 -109
  33. data/spec/rack/oauth2/server/token/error_spec.rb +77 -0
  34. data/spec/rack/oauth2/server/token/password_spec.rb +27 -47
  35. data/spec/rack/oauth2/server/token/refresh_token_spec.rb +22 -43
  36. data/spec/rack/oauth2/server/token_spec.rb +77 -116
  37. data/spec/rack/oauth2/server/util_spec.rb +75 -16
  38. data/spec/spec_helper.rb +0 -12
  39. metadata +25 -29
  40. data/lib/rack/oauth2/server/authorize/code_and_token.rb +0 -62
  41. data/lib/rack/oauth2/server/error.rb +0 -73
  42. data/lib/rack/oauth2/server/error/authorize.rb +0 -54
  43. data/lib/rack/oauth2/server/error/resource.rb +0 -50
  44. data/lib/rack/oauth2/server/error/token.rb +0 -59
  45. data/lib/rack/oauth2/server/token/assertion.rb +0 -29
  46. data/spec/rack/oauth2/server/authorize/code_and_token_spec.rb +0 -53
  47. data/spec/rack/oauth2/server/error/authorize_spec.rb +0 -102
  48. data/spec/rack/oauth2/server/error/resource_spec.rb +0 -69
  49. data/spec/rack/oauth2/server/error/token_spec.rb +0 -115
  50. data/spec/rack/oauth2/server/error_spec.rb +0 -107
  51. data/spec/rack/oauth2/server/resource_spec.rb +0 -141
  52. data/spec/rack/oauth2/server/token/assertion_spec.rb +0 -56
@@ -1,52 +1,66 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe Rack::OAuth2::Server::Authorize::Code do
4
+ let(:request) { Rack::MockRequest.new app }
5
+ let(:redirect_uri) { 'http://client.example.com/callback' }
6
+ let(:authorization_code) { 'authorization_code' }
7
+ let(:response) { request.get "/?response_type=code&client_id=client&redirect_uri=#{redirect_uri}" }
4
8
 
5
- context "when authorized" do
6
-
7
- before do
8
- @app = Rack::OAuth2::Server::Authorize.new(simple_app) do |request, response|
9
+ context 'when approved' do
10
+ subject { response }
11
+ let :app do
12
+ Rack::OAuth2::Server::Authorize.new do |request, response|
13
+ response.redirect_uri = redirect_uri
14
+ response.code = authorization_code
9
15
  response.approve!
10
- response.code = "authorization_code"
11
16
  end
12
- @request = Rack::MockRequest.new @app
13
17
  end
18
+ its(:status) { should == 302 }
19
+ its(:location) { should == "#{redirect_uri}?code=#{authorization_code}" }
14
20
 
15
- it "should redirect to redirect_uri with authorization code" do
16
- response = @request.get("/?response_type=code&client_id=client&redirect_uri=http://client.example.com/callback")
17
- response.status.should == 302
18
- response.location.should == "http://client.example.com/callback?code=authorization_code"
21
+ context 'when redirect_uri already includes query' do
22
+ let(:redirect_uri) { 'http://client.example.com/callback?k=v' }
23
+ its(:location) { should == "#{redirect_uri}&code=#{authorization_code}" }
19
24
  end
20
25
 
21
- context "when redirect_uri already includes query" do
22
- it "should keep original query" do
23
- response = @request.get("/?response_type=code&client_id=client&redirect_uri=http://client.example.com/callback?k=v")
24
- response.status.should == 302
25
- response.location.should == "http://client.example.com/callback?k=v&code=authorization_code"
26
+ context 'when redirect_uri is missing' do
27
+ let :app do
28
+ Rack::OAuth2::Server::Authorize.new do |request, response|
29
+ response.code = authorization_code
30
+ response.approve!
31
+ end
32
+ end
33
+ it do
34
+ expect { response }.should raise_error AttrRequired::AttrMissing
26
35
  end
27
36
  end
28
37
 
38
+ context 'when code is missing' do
39
+ let :app do
40
+ Rack::OAuth2::Server::Authorize.new do |request, response|
41
+ response.redirect_uri = redirect_uri
42
+ response.approve!
43
+ end
44
+ end
45
+ it do
46
+ expect { response }.should raise_error AttrRequired::AttrMissing
47
+ end
48
+ end
29
49
  end
30
50
 
31
- context "when denied" do
32
-
33
- before do
34
- @app = Rack::OAuth2::Server::Authorize.new(simple_app) do |request, response|
35
- request.access_denied! 'User rejected the requested access.'
51
+ context 'when denied' do
52
+ let :app do
53
+ Rack::OAuth2::Server::Authorize.new do |request, response|
54
+ request.access_denied!
36
55
  end
37
- @request = Rack::MockRequest.new @app
38
56
  end
39
-
40
- it "should redirect to redirect_uri with error message" do
41
- response = @request.get("/?response_type=code&client_id=client&redirect_uri=http://client.example.com/callback")
57
+ it 'should redirect with error in query' do
42
58
  response.status.should == 302
43
59
  error_message = {
44
60
  :error => :access_denied,
45
- :error_description => "User rejected the requested access."
61
+ :error_description => Rack::OAuth2::Server::Authorize::ErrorMethods::DEFAULT_DESCRIPTION[:access_denied]
46
62
  }
47
- response.location.should == "http://client.example.com/callback?#{error_message.to_query}"
63
+ response.location.should == "#{redirect_uri}?#{error_message.to_query}"
48
64
  end
49
-
50
65
  end
51
-
52
66
  end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Rack::OAuth2::Server::Authorize::BadRequest do
4
+ let(:klass) { Rack::OAuth2::Server::Authorize::BadRequest }
5
+ let(:error) { klass.new(:invalid_request) }
6
+ let(:redirect_uri) { 'http://client.example.com/callback' }
7
+
8
+ subject { error }
9
+ it { should be_a Rack::OAuth2::Server::Abstract::BadRequest }
10
+ its(:protocol_params) do
11
+ should == {
12
+ :error => :invalid_request,
13
+ :error_description => nil,
14
+ :error_uri => nil,
15
+ :state => nil
16
+ }
17
+ end
18
+
19
+ describe '#finish' do
20
+ context 'when redirect_uri is given' do
21
+ before { error.redirect_uri = redirect_uri }
22
+
23
+ context 'when protocol_params_location = :query' do
24
+ before { error.protocol_params_location = :query }
25
+ it 'should redirect with error in query' do
26
+ state, header, response = error.finish
27
+ state.should == 302
28
+ header["Location"].should == "#{redirect_uri}?error=invalid_request"
29
+ end
30
+ end
31
+
32
+ context 'when protocol_params_location = :fragment' do
33
+ before { error.protocol_params_location = :fragment }
34
+ it 'should redirect with error in fragment' do
35
+ state, header, response = error.finish
36
+ state.should == 302
37
+ header["Location"].should == "#{redirect_uri}#error=invalid_request"
38
+ end
39
+ end
40
+
41
+ context 'otherwise' do
42
+ before { error.protocol_params_location = :other }
43
+ it 'should redirect without error' do
44
+ state, header, response = error.finish
45
+ state.should == 302
46
+ header["Location"].should == redirect_uri
47
+ end
48
+ end
49
+ end
50
+
51
+ context 'otherwise' do
52
+ it 'should raise itself' do
53
+ expect { error.finish }.should raise_error(klass) { |e|
54
+ e.should == error
55
+ }
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ describe Rack::OAuth2::Server::Authorize::ErrorMethods do
62
+ let(:klass) { Rack::OAuth2::Server::Authorize::BadRequest }
63
+ let(:redirect_uri) { 'http://client.example.com/callback' }
64
+ let(:default_description) { Rack::OAuth2::Server::Authorize::ErrorMethods::DEFAULT_DESCRIPTION }
65
+ let(:env) { Rack::MockRequest.env_for("/authorize?client_id=client_id") }
66
+ let(:request) { Rack::OAuth2::Server::Authorize::Request.new env }
67
+ let(:request_for_code) { Rack::OAuth2::Server::Authorize::Code::Request.new env }
68
+ let(:request_for_token) { Rack::OAuth2::Server::Authorize::Token::Request.new env }
69
+
70
+ describe 'bad_request!' do
71
+ it do
72
+ expect { request.bad_request! }.should raise_error klass
73
+ end
74
+
75
+ context 'when response_type = :code' do
76
+ it 'should set protocol_params_location = :query' do
77
+ expect { request_for_code.bad_request! }.should raise_error(klass) { |e|
78
+ e.protocol_params_location.should == :query
79
+ }
80
+ end
81
+ end
82
+
83
+ context 'when response_type = :token' do
84
+ it 'should set protocol_params_location = :fragment' do
85
+ expect { request_for_token.bad_request! }.should raise_error(klass) { |e|
86
+ e.protocol_params_location.should == :fragment
87
+ }
88
+ end
89
+ end
90
+ end
91
+
92
+ Rack::OAuth2::Server::Authorize::ErrorMethods::DEFAULT_DESCRIPTION.keys.each do |error_code|
93
+ method = "#{error_code}!"
94
+ describe method do
95
+ it "should raise Rack::OAuth2::Server::Authorize::BadRequest with error = :#{error_code}" do
96
+ expect { request.send method }.should raise_error(klass) { |error|
97
+ error.error.should == error_code
98
+ error.description.should == default_description[error_code]
99
+ }
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,52 +1,81 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe Rack::OAuth2::Server::Authorize::Token do
4
+ let(:request) { Rack::MockRequest.new app }
5
+ let(:redirect_uri) { 'http://client.example.com/callback' }
6
+ let(:access_token) { 'access_token' }
7
+ let(:token_type) { 'bearer' }
8
+ let(:response) { request.get("/?response_type=token&client_id=client&redirect_uri=#{redirect_uri}") }
4
9
 
5
- context "when authorized" do
6
-
7
- before do
8
- @app = Rack::OAuth2::Server::Authorize.new do |request, response|
10
+ context "when approved" do
11
+ let :app do
12
+ Rack::OAuth2::Server::Authorize.new do |request, response|
13
+ response.redirect_uri = redirect_uri
14
+ response.access_token = access_token
15
+ response.token_type = token_type
9
16
  response.approve!
10
- response.access_token = "access_token"
11
17
  end
12
- @request = Rack::MockRequest.new @app
13
18
  end
14
19
 
15
- it "should redirect to redirect_uri with authorization code" do
16
- response = @request.get("/?response_type=token&client_id=client&redirect_uri=http://client.example.com/callback")
20
+ it 'should redirect with authorization code in fragment' do
17
21
  response.status.should == 302
18
- response.location.should == "http://client.example.com/callback#access_token=access_token"
22
+ response.location.should == "#{redirect_uri}#access_token=#{access_token}"
19
23
  end
20
24
 
21
- context "when redirect_uri already includes fragment" do
22
- it "should keep original fragment" do
23
- response = @request.get("/?response_type=token&client_id=client&redirect_uri=http://client.example.com/callback%23fragment")
24
- response.status.should == 302
25
- response.location.should == "http://client.example.com/callback#fragment&access_token=access_token"
25
+ context 'when redirect_uri is missing' do
26
+ let :app do
27
+ Rack::OAuth2::Server::Authorize.new do |request, response|
28
+ response.access_token = access_token
29
+ response.token_type = token_type
30
+ response.approve!
31
+ end
32
+ end
33
+ it do
34
+ expect { response }.should raise_error AttrRequired::AttrMissing
26
35
  end
27
36
  end
28
37
 
29
- end
38
+ context 'when access_token is missing' do
39
+ let :app do
40
+ Rack::OAuth2::Server::Authorize.new do |request, response|
41
+ response.redirect_uri = redirect_uri
42
+ response.token_type = token_type
43
+ response.approve!
44
+ end
45
+ end
46
+ it do
47
+ expect { response }.should raise_error AttrRequired::AttrMissing
48
+ end
49
+ end
30
50
 
31
- context "when denied" do
51
+ context 'when token_type is missing' do
52
+ let :app do
53
+ Rack::OAuth2::Server::Authorize.new do |request, response|
54
+ response.redirect_uri = redirect_uri
55
+ response.access_token = access_token
56
+ response.approve!
57
+ end
58
+ end
32
59
 
33
- before do
34
- @app = Rack::OAuth2::Server::Authorize.new do |request, response|
35
- request.access_denied! 'User rejected the requested access.'
60
+ it do
61
+ expect { response }.should raise_error AttrRequired::AttrMissing
36
62
  end
37
- @request = Rack::MockRequest.new @app
38
63
  end
64
+ end
39
65
 
40
- it "should redirect to redirect_uri with error message" do
41
- response = @request.get("/?response_type=token&client_id=client&redirect_uri=http://client.example.com/callback")
66
+ context 'when denied' do
67
+ let :app do
68
+ Rack::OAuth2::Server::Authorize.new do |request, response|
69
+ request.access_denied!
70
+ end
71
+ end
72
+ it 'should redirect with error in fragment' do
42
73
  response.status.should == 302
43
74
  error_message = {
44
75
  :error => :access_denied,
45
- :error_description => "User rejected the requested access."
76
+ :error_description => Rack::OAuth2::Server::Authorize::ErrorMethods::DEFAULT_DESCRIPTION[:access_denied]
46
77
  }
47
- response.location.should == "http://client.example.com/callback?#{error_message.to_query}"
78
+ response.location.should == "#{redirect_uri}##{error_message.to_query}"
48
79
  end
49
-
50
80
  end
51
-
52
81
  end
@@ -1,88 +1,44 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe Rack::OAuth2::Server::Authorize do
4
- it "should support realm" do
5
- app = Rack::OAuth2::Server::Authorize.new("server.example.com")
6
- app.realm.should == "server.example.com"
7
- end
8
- end
9
-
10
- describe Rack::OAuth2::Server::Authorize::Request do
4
+ let(:app) { Rack::OAuth2::Server::Authorize.new }
5
+ let(:request) { Rack::MockRequest.new app }
6
+ let(:redirect_uri) { 'http://client.example.com/callback' }
7
+ let(:bad_request) { Rack::OAuth2::Server::Authorize::BadRequest }
11
8
 
12
- before do
13
- @app = Rack::OAuth2::Server::Authorize.new(simple_app) do |request, response|
14
- response.code = "authorization_code"
15
- response.redirect_uri ||= "http://client.example.com/callback/pre-registered"
9
+ context 'when redirect_uri is missing' do
10
+ it do
11
+ expect { request.get '/' }.should raise_error bad_request
16
12
  end
17
- @request = Rack::MockRequest.new @app
18
13
  end
19
14
 
20
- context "when any required parameters are missing" do
21
- it "should return invalid_request error" do
22
- assert_error_response(:json, :invalid_request) do
23
- @request.get('/')
24
- end
25
- assert_error_response(:json, :invalid_request) do
26
- @request.get('/?response_type=code')
27
- end
28
- assert_error_response(:json, :invalid_request) do
29
- @request.get('/?client_id=client')
15
+ context 'when redirect_uri is given' do
16
+ context 'when client_id is missing' do
17
+ it do
18
+ expect { request.get "/?redirect_uri=#{redirect_uri}" }.should raise_error bad_request
30
19
  end
31
20
  end
32
- end
33
-
34
- context "when unsupported response_type is given" do
35
- it "should return unsupported_response_type error" do
36
- assert_error_response(:query, :unsupported_response_type) do
37
- @request.get('/?response_type=hello&client_id=client&redirect_uri=http://client.example.com/callback')
21
+ context 'when client_id is given' do
22
+ context 'when response_type is missing' do
23
+ it do
24
+ expect { request.get "/?client_id=client&redirect_uri=#{redirect_uri}" }.should raise_error bad_request
25
+ end
38
26
  end
39
27
  end
40
28
  end
41
29
 
42
- context "when all required parameters are valid" do
43
- it "should succeed" do
44
- response = @request.get('/?response_type=code&client_id=client')
45
- response.status.should == 200
30
+ context 'when unknown response_type is given' do
31
+ it do
32
+ expect { request.get "/?response_type=unknown&client_id=client&redirect_uri=#{redirect_uri}" }.should raise_error bad_request
46
33
  end
47
34
  end
48
35
 
49
- end
50
-
51
- describe Rack::OAuth2::Server::Authorize::Response do
52
-
53
- context "when required response params are missing" do
54
-
55
- before do
56
- @app = Rack::OAuth2::Server::Authorize.new(simple_app) do |request, response|
57
- response.approve!
58
- # code is missing
36
+ context 'when all required parameters are valid' do
37
+ [:code, :token].each do |request_type|
38
+ context "when response_type = :#{request_type}" do
39
+ subject { request.get "/?response_type=#{request_type}&client_id=client&redirect_uri=#{redirect_uri}" }
40
+ its(:status) { should == 200 }
59
41
  end
60
- @request = Rack::MockRequest.new @app
61
- end
62
-
63
- it "should raise an error" do
64
- lambda do
65
- @request.get("/?response_type=code&client_id=client&redirect_uri=http://client.example.com/callback")
66
- end.should raise_error(StandardError)
67
42
  end
68
-
69
- end
70
-
71
- context "when required response params are given" do
72
-
73
- before do
74
- @app = Rack::OAuth2::Server::Authorize.new(simple_app) do |request, response|
75
- response.approve!
76
- response.code = "authorization_code"
77
- end
78
- @request = Rack::MockRequest.new @app
79
- end
80
-
81
- it "should succeed" do
82
- response = @request.get("/?response_type=code&client_id=client&redirect_uri=http://client.example.com/callback")
83
- response.status.should == 302
84
- end
85
-
86
43
  end
87
-
88
44
  end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Rack::OAuth2::Server::Resource::Bearer::BadRequest do
4
+ let(:error) { Rack::OAuth2::Server::Resource::Bearer::BadRequest.new(:invalid_request) }
5
+
6
+ it { should be_a Rack::OAuth2::Server::Abstract::BadRequest }
7
+ describe '#finish' do
8
+ it 'should respond in JSON' do
9
+ status, header, response = error.finish
10
+ status.should == 400
11
+ header['Content-Type'].should == 'application/json'
12
+ response.body.should == ['{"error":"invalid_request"}']
13
+ end
14
+ end
15
+ end
16
+
17
+ describe Rack::OAuth2::Server::Resource::Bearer::Unauthorized do
18
+ let(:error) { Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new(:invalid_token) }
19
+
20
+ it { should be_a Rack::OAuth2::Server::Abstract::Unauthorized }
21
+ describe '#finish' do
22
+ it 'should respond in JSON' do
23
+ status, header, response = error.finish
24
+ status.should == 401
25
+ header['Content-Type'].should == 'application/json'
26
+ header['WWW-Authenticate'].should == 'Bearer error="invalid_token"'
27
+ response.body.should == ['{"error":"invalid_token"}']
28
+ end
29
+ end
30
+
31
+ context 'when error_code is not invalid_token' do
32
+ let(:error) { Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new(:something) }
33
+
34
+ it 'should have error_code in body but not in WWW-Authenticate header' do
35
+ status, header, response = error.finish
36
+ header['WWW-Authenticate'].should == 'Bearer'
37
+ response.body.first.should include '"error":"something"'
38
+ end
39
+ end
40
+ end
41
+
42
+ describe Rack::OAuth2::Server::Resource::Bearer::Forbidden do
43
+ let(:error) { Rack::OAuth2::Server::Resource::Bearer::Forbidden.new(:insufficient_scope) }
44
+
45
+ it { should be_a Rack::OAuth2::Server::Abstract::Forbidden }
46
+ describe '#finish' do
47
+ it 'should respond in JSON' do
48
+ status, header, response = error.finish
49
+ status.should == 403
50
+ header['Content-Type'].should == 'application/json'
51
+ response.body.should == ['{"error":"insufficient_scope"}']
52
+ end
53
+ end
54
+
55
+ context 'when scope option is given' do
56
+ let(:error) { Rack::OAuth2::Server::Resource::Bearer::Forbidden.new(:insufficient_scope, 'Desc', :scope => [:scope1, :scope2]) }
57
+
58
+ it 'should have blank WWW-Authenticate header' do
59
+ status, header, response = error.finish
60
+ response.body.first.should include '"scope":"scope1 scope2"'
61
+ end
62
+ end
63
+ end
64
+
65
+ describe Rack::OAuth2::Server::Resource::Bearer::ErrorMethods do
66
+ let(:bad_request) { Rack::OAuth2::Server::Resource::Bearer::BadRequest }
67
+ let(:unauthorized) { Rack::OAuth2::Server::Resource::Bearer::Unauthorized }
68
+ let(:forbidden) { Rack::OAuth2::Server::Resource::Bearer::Forbidden }
69
+ let(:redirect_uri) { 'http://client.example.com/callback' }
70
+ let(:default_description) { Rack::OAuth2::Server::Resource::Bearer::ErrorMethods::DEFAULT_DESCRIPTION }
71
+ let(:env) { Rack::MockRequest.env_for("/authorize?client_id=client_id") }
72
+ let(:request) { Rack::OAuth2::Server::Resource::Bearer::Request.new env }
73
+
74
+ describe 'bad_request!' do
75
+ it do
76
+ expect { request.bad_request! :invalid_request }.should raise_error bad_request
77
+ end
78
+ end
79
+
80
+ describe 'unauthorized!' do
81
+ it do
82
+ expect { request.unauthorized! :invalid_client }.should raise_error unauthorized
83
+ end
84
+ end
85
+
86
+ Rack::OAuth2::Server::Resource::Bearer::ErrorMethods::DEFAULT_DESCRIPTION.keys.each do |error_code|
87
+ method = "#{error_code}!"
88
+ case error_code
89
+ when :invalid_request
90
+ describe method do
91
+ it "should raise Rack::OAuth2::Server::Resource::Bearer::BadRequest with error = :#{error_code}" do
92
+ expect { request.send method }.should raise_error(bad_request) { |error|
93
+ error.error.should == error_code
94
+ error.description.should == default_description[error_code]
95
+ }
96
+ end
97
+ end
98
+ when :insufficient_scope
99
+ describe method do
100
+ it "should raise Rack::OAuth2::Server::Resource::Bearer::Forbidden with error = :#{error_code}" do
101
+ expect { request.send method }.should raise_error(forbidden) { |error|
102
+ error.error.should == error_code
103
+ error.description.should == default_description[error_code]
104
+ }
105
+ end
106
+ end
107
+ else
108
+ describe method do
109
+ it "should raise Rack::OAuth2::Server::Resource::Bearer::Unauthorized with error = :#{error_code}" do
110
+ expect { request.send method }.should raise_error(unauthorized) { |error|
111
+ error.error.should == error_code
112
+ error.description.should == default_description[error_code]
113
+ }
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end