doorkeeper 1.1.0 → 1.2.0
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.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +14 -2
- data/README.md +93 -42
- data/app/controllers/doorkeeper/application_controller.rb +1 -1
- data/app/controllers/doorkeeper/applications_controller.rb +4 -4
- data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +3 -3
- data/app/controllers/doorkeeper/tokens_controller.rb +29 -2
- data/app/helpers/doorkeeper/form_errors_helper.rb +2 -2
- data/app/validators/redirect_uri_validator.rb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +3 -3
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +5 -5
- data/doorkeeper.gemspec +1 -1
- data/lib/doorkeeper.rb +31 -31
- data/lib/doorkeeper/config.rb +66 -37
- data/lib/doorkeeper/doorkeeper_for.rb +6 -3
- data/lib/doorkeeper/engine.rb +2 -2
- data/lib/doorkeeper/helpers/controller.rb +9 -9
- data/lib/doorkeeper/helpers/filter.rb +1 -1
- data/lib/doorkeeper/models/access_grant.rb +5 -5
- data/lib/doorkeeper/models/access_token.rb +22 -18
- data/lib/doorkeeper/models/active_record/access_token.rb +8 -8
- data/lib/doorkeeper/models/active_record/application.rb +5 -5
- data/lib/doorkeeper/models/application.rb +8 -9
- data/lib/doorkeeper/models/expirable.rb +1 -1
- data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +2 -2
- data/lib/doorkeeper/models/mongo_mapper/access_token.rb +11 -11
- data/lib/doorkeeper/models/mongo_mapper/application.rb +4 -4
- data/lib/doorkeeper/models/mongoid/version.rb +2 -2
- data/lib/doorkeeper/models/mongoid2/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid2/access_token.rb +14 -14
- data/lib/doorkeeper/models/mongoid2/application.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +13 -13
- data/lib/doorkeeper/models/mongoid3_4/application.rb +6 -6
- data/lib/doorkeeper/models/ownership.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +7 -7
- data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -19
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -4
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -4
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +2 -2
- data/lib/doorkeeper/oauth/client_credentials_request.rb +11 -15
- data/lib/doorkeeper/oauth/code_request.rb +5 -4
- data/lib/doorkeeper/oauth/code_response.rb +8 -7
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +10 -10
- data/lib/doorkeeper/oauth/password_access_token_request.rb +57 -54
- data/lib/doorkeeper/oauth/pre_authorization.rb +7 -7
- data/lib/doorkeeper/oauth/refresh_token_request.rb +27 -24
- data/lib/doorkeeper/oauth/scopes.rb +3 -3
- data/lib/doorkeeper/oauth/token.rb +27 -1
- data/lib/doorkeeper/oauth/token_request.rb +14 -4
- data/lib/doorkeeper/rails/routes.rb +31 -22
- data/lib/doorkeeper/rails/routes/mapping.rb +11 -12
- data/lib/doorkeeper/request.rb +5 -5
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/install_generator.rb +5 -5
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +2 -2
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +2 -2
- data/lib/generators/doorkeeper/templates/initializer.rb +16 -3
- data/lib/generators/doorkeeper/templates/migration.rb +16 -17
- data/lib/generators/doorkeeper/views_generator.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +7 -7
- data/spec/controllers/authorizations_controller_spec.rb +48 -48
- data/spec/controllers/protected_resources_controller_spec.rb +108 -107
- data/spec/controllers/token_info_controller_spec.rb +11 -11
- data/spec/controllers/tokens_controller_spec.rb +8 -8
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -2
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +3 -3
- data/spec/dummy/app/controllers/home_controller.rb +5 -5
- data/spec/dummy/app/controllers/metal_controller.rb +1 -1
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/models/user.rb +3 -3
- data/spec/dummy/config/application.rb +8 -9
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -5
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/routes.rb +27 -27
- data/spec/dummy/db/migrate/20130902165751_create_doorkeeper_tables.rb +16 -17
- data/spec/dummy/db/migrate/20130902175349_add_owner_to_application.rb +3 -3
- data/spec/dummy/db/schema.rb +39 -39
- data/spec/factories/access_grant.rb +3 -3
- data/spec/factories/access_token.rb +1 -1
- data/spec/factories/application.rb +3 -3
- data/spec/generators/application_owner_generator_spec.rb +6 -7
- data/spec/generators/install_generator_spec.rb +9 -9
- data/spec/generators/migration_generator_spec.rb +4 -4
- data/spec/lib/config_spec.rb +136 -44
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/revocable_spec.rb +4 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +4 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +4 -4
- data/spec/lib/oauth/client/methods_spec.rb +10 -10
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +9 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials_request_spec.rb +6 -6
- data/spec/lib/oauth/client_spec.rb +4 -4
- data/spec/lib/oauth/code_request_spec.rb +10 -9
- data/spec/lib/oauth/error_response_spec.rb +8 -8
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +17 -17
- data/spec/lib/oauth/helpers/unique_token_spec.rb +7 -7
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +33 -33
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +13 -13
- data/spec/lib/oauth/pre_authorization_spec.rb +47 -7
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -21
- data/spec/lib/oauth/scopes_spec.rb +32 -32
- data/spec/lib/oauth/token_request_spec.rb +10 -9
- data/spec/lib/oauth/token_response_spec.rb +13 -15
- data/spec/lib/oauth/token_spec.rb +24 -10
- data/spec/lib/server_spec.rb +24 -2
- data/spec/models/doorkeeper/access_grant_spec.rb +8 -8
- data/spec/models/doorkeeper/access_token_spec.rb +79 -33
- data/spec/models/doorkeeper/application_spec.rb +29 -29
- data/spec/requests/applications/applications_request_spec.rb +15 -15
- data/spec/requests/applications/authorized_applications_spec.rb +7 -7
- data/spec/requests/endpoints/authorization_spec.rb +19 -12
- data/spec/requests/endpoints/token_spec.rb +26 -8
- data/spec/requests/flows/authorization_code_errors_spec.rb +17 -17
- data/spec/requests/flows/authorization_code_spec.rb +28 -28
- data/spec/requests/flows/client_credentials_spec.rb +3 -3
- data/spec/requests/flows/implicit_grant_errors_spec.rb +5 -5
- data/spec/requests/flows/implicit_grant_spec.rb +2 -2
- data/spec/requests/flows/password_spec.rb +32 -32
- data/spec/requests/flows/refresh_token_spec.rb +23 -23
- data/spec/requests/flows/revoke_token_spec.rb +165 -0
- data/spec/requests/flows/skip_authorization_spec.rb +10 -10
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +5 -5
- data/spec/routing/custom_controller_routes_spec.rb +4 -0
- data/spec/routing/default_routes_spec.rb +5 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_integration.rb +8 -10
- data/spec/support/helpers/access_token_request_helper.rb +3 -3
- data/spec/support/helpers/authorization_request_helper.rb +3 -3
- data/spec/support/helpers/config_helper.rb +1 -1
- data/spec/support/helpers/model_helper.rb +2 -2
- data/spec/support/helpers/request_spec_helper.rb +3 -3
- data/spec/support/helpers/url_helper.rb +25 -21
- data/spec/support/orm/active_record.rb +4 -4
- data/spec/support/orm/mongo_mapper.rb +2 -3
- data/spec/support/orm/mongoid.rb +5 -6
- data/spec/support/shared/controllers_shared_context.rb +15 -15
- data/spec/support/shared/models_shared_examples.rb +13 -13
- data/spec/validators/redirect_uri_validator_spec.rb +9 -9
- metadata +5 -4
@@ -3,14 +3,14 @@ require 'spec_helper_integration'
|
|
3
3
|
feature 'Private API' do
|
4
4
|
background do
|
5
5
|
@client = FactoryGirl.create(:application)
|
6
|
-
@resource = User.create!(:
|
6
|
+
@resource = User.create!(name: 'Joe', password: 'sekret')
|
7
7
|
@token = client_is_authorized(@client, @resource)
|
8
8
|
end
|
9
9
|
|
10
10
|
scenario 'client requests protected resource with valid token' do
|
11
11
|
with_access_token_header @token.token
|
12
12
|
visit '/full_protected_resources'
|
13
|
-
expect(page.body).to have_content(
|
13
|
+
expect(page.body).to have_content('index')
|
14
14
|
end
|
15
15
|
|
16
16
|
scenario 'client requests protected resource with disabled header authentication' do
|
@@ -21,7 +21,7 @@ feature 'Private API' do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
scenario 'client attempts to request protected resource with invalid token' do
|
24
|
-
with_access_token_header
|
24
|
+
with_access_token_header 'invalid'
|
25
25
|
visit '/full_protected_resources'
|
26
26
|
response_status_should_be 401
|
27
27
|
end
|
@@ -37,7 +37,7 @@ feature 'Private API' do
|
|
37
37
|
@token.update_column :expires_in, nil # never expires
|
38
38
|
with_access_token_header @token.token
|
39
39
|
visit '/full_protected_resources'
|
40
|
-
expect(page.body).to have_content(
|
40
|
+
expect(page.body).to have_content('index')
|
41
41
|
end
|
42
42
|
|
43
43
|
scenario 'access token with no scopes' do
|
@@ -53,6 +53,6 @@ feature 'Private API' do
|
|
53
53
|
@token.update_column :scopes, 'admin'
|
54
54
|
with_access_token_header @token.token
|
55
55
|
visit '/full_protected_resources/1.json'
|
56
|
-
expect(page.body).to have_content(
|
56
|
+
expect(page.body).to have_content('show')
|
57
57
|
end
|
58
58
|
end
|
@@ -41,6 +41,10 @@ describe 'Custom controller for routes' do
|
|
41
41
|
expect(post('/space/oauth/token')).to route_to('custom_authorizations#create')
|
42
42
|
end
|
43
43
|
|
44
|
+
it 'POST /space/oauth/revoke routes to tokens controller' do
|
45
|
+
post('/space/oauth/revoke').should route_to('custom_authorizations#revoke')
|
46
|
+
end
|
47
|
+
|
44
48
|
it 'GET /space/oauth/applications routes to applications controller' do
|
45
49
|
expect(get('/space/oauth/applications')).to route_to('custom_authorizations#index')
|
46
50
|
end
|
@@ -17,6 +17,10 @@ describe 'Default routes' do
|
|
17
17
|
expect(post('/oauth/token')).to route_to('doorkeeper/tokens#create')
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'POST /oauth/revoke routes to tokens controller' do
|
21
|
+
post('/oauth/revoke').should route_to('doorkeeper/tokens#revoke')
|
22
|
+
end
|
23
|
+
|
20
24
|
it 'GET /oauth/applications routes to applications controller' do
|
21
25
|
expect(get('/oauth/applications')).to route_to('doorkeeper/applications#index')
|
22
26
|
end
|
@@ -26,7 +30,7 @@ describe 'Default routes' do
|
|
26
30
|
end
|
27
31
|
|
28
32
|
it 'GET /oauth/token/info route to authorzed tokeninfo controller' do
|
29
|
-
expect(get('/oauth/token/info')).to route_to('doorkeeper/token_info#show')
|
33
|
+
expect(get('/oauth/token/info')).to route_to('doorkeeper/token_info#show')
|
30
34
|
end
|
31
35
|
|
32
36
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__),
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__),
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../app'))
|
@@ -1,9 +1,9 @@
|
|
1
|
-
ENV[
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
2
|
DOORKEEPER_ORM = (ENV['orm'] || :active_record).to_sym
|
3
3
|
TABLE_NAME_PREFIX = ENV['table_name_prefix'] || nil
|
4
4
|
TABLE_NAME_SUFFIX = ENV['table_name_suffix'] || nil
|
5
5
|
|
6
|
-
|
6
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
7
7
|
|
8
8
|
require 'dummy/config/environment'
|
9
9
|
require 'rspec/rails'
|
@@ -12,13 +12,13 @@ require 'generator_spec/test_case'
|
|
12
12
|
require 'timecop'
|
13
13
|
require 'database_cleaner'
|
14
14
|
|
15
|
-
|
15
|
+
Rails.logger.info "====> Doorkeeper.orm = #{Doorkeeper.configuration.orm.inspect}"
|
16
16
|
if Doorkeeper.configuration.orm == :active_record
|
17
|
-
|
18
|
-
|
17
|
+
Rails.logger.info "======> active_record.table_name_prefix = #{Rails.configuration.active_record.table_name_prefix.inspect}"
|
18
|
+
Rails.logger.info "======> active_record.table_name_suffix = #{Rails.configuration.active_record.table_name_suffix.inspect}"
|
19
19
|
end
|
20
|
-
|
21
|
-
|
20
|
+
Rails.logger.info "====> Rails version: #{Rails.version}"
|
21
|
+
Rails.logger.info "====> Ruby version: #{RUBY_VERSION}"
|
22
22
|
|
23
23
|
require "support/orm/#{Doorkeeper.configuration.orm_name}"
|
24
24
|
|
@@ -33,9 +33,7 @@ RSpec.configure do |config|
|
|
33
33
|
|
34
34
|
config.before do
|
35
35
|
DatabaseCleaner.start
|
36
|
-
Doorkeeper.configure {
|
37
|
-
orm DOORKEEPER_ORM
|
38
|
-
}
|
36
|
+
Doorkeeper.configure { orm DOORKEEPER_ORM }
|
39
37
|
end
|
40
38
|
|
41
39
|
config.after do
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module AccessTokenRequestHelper
|
2
2
|
def client_is_authorized(client, resource_owner, access_token_attributes = {})
|
3
3
|
attributes = {
|
4
|
-
:
|
5
|
-
:
|
4
|
+
application: client,
|
5
|
+
resource_owner_id: resource_owner.id
|
6
6
|
}.merge(access_token_attributes)
|
7
7
|
FactoryGirl.create(:access_token, attributes)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
RSpec.configuration.send :include, AccessTokenRequestHelper, :
|
11
|
+
RSpec.configuration.send :include, AccessTokenRequestHelper, type: :request
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module AuthorizationRequestHelper
|
2
2
|
def resource_owner_is_authenticated(resource_owner = nil)
|
3
|
-
resource_owner ||= User.create!(:
|
3
|
+
resource_owner ||= User.create!(name: 'Joe', password: 'sekret')
|
4
4
|
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { resource_owner })
|
5
5
|
end
|
6
6
|
|
7
7
|
def resource_owner_is_not_authenticated
|
8
|
-
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { redirect_to(
|
8
|
+
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { redirect_to('/sign_in') })
|
9
9
|
end
|
10
10
|
|
11
11
|
def default_scopes_exist(*scopes)
|
@@ -29,4 +29,4 @@ module AuthorizationRequestHelper
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
RSpec.configuration.send :include, AuthorizationRequestHelper, :
|
32
|
+
RSpec.configuration.send :include, AuthorizationRequestHelper, type: :request
|
@@ -4,7 +4,7 @@ module ModelHelper
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def create_resource_owner
|
7
|
-
@resource_owner = User.create!(:
|
7
|
+
@resource_owner = User.create!(name: 'Joe', password: 'sekret')
|
8
8
|
end
|
9
9
|
|
10
10
|
def authorization_code_exists(options = {})
|
@@ -42,4 +42,4 @@ module ModelHelper
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
RSpec.configuration.send :include, ModelHelper, :
|
45
|
+
RSpec.configuration.send :include, ModelHelper, type: :request
|
@@ -57,7 +57,7 @@ module RequestSpecHelper
|
|
57
57
|
|
58
58
|
def sign_in
|
59
59
|
visit '/'
|
60
|
-
click_on
|
60
|
+
click_on 'Sign in'
|
61
61
|
end
|
62
62
|
|
63
63
|
def i_should_see_translated_error_message(key)
|
@@ -65,7 +65,7 @@ module RequestSpecHelper
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def translated_error_message(key)
|
68
|
-
I18n.translate key, :
|
68
|
+
I18n.translate key, scope: [:doorkeeper, :errors, :messages]
|
69
69
|
end
|
70
70
|
|
71
71
|
def response_status_should_be(status)
|
@@ -73,4 +73,4 @@ module RequestSpecHelper
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
RSpec.configuration.send :include, RequestSpecHelper, :
|
76
|
+
RSpec.configuration.send :include, RequestSpecHelper, type: :request
|
@@ -1,51 +1,55 @@
|
|
1
1
|
module UrlHelper
|
2
2
|
def token_endpoint_url(options = {})
|
3
3
|
parameters = {
|
4
|
-
:
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
4
|
+
code: options[:code],
|
5
|
+
client_id: options[:client_id] || (options[:client] ? options[:client].uid : nil),
|
6
|
+
client_secret: options[:client_secret] || (options[:client] ? options[:client].secret : nil),
|
7
|
+
redirect_uri: options[:redirect_uri] || (options[:client] ? options[:client].redirect_uri : nil),
|
8
|
+
grant_type: options[:grant_type] || 'authorization_code'
|
9
9
|
}
|
10
10
|
"/oauth/token?#{build_query(parameters)}"
|
11
11
|
end
|
12
12
|
|
13
13
|
def password_token_endpoint_url(options = {})
|
14
14
|
parameters = {
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
15
|
+
code: options[:code],
|
16
|
+
client_id: options[:client_id] || (options[:client] ? options[:client].uid : nil),
|
17
|
+
client_secret: options[:client_secret] || (options[:client] ? options[:client].secret : nil),
|
18
|
+
username: options[:resource_owner_username] || (options[:resource_owner] ? options[:resource_owner].name : nil),
|
19
|
+
password: options[:resource_owner_password] || (options[:resource_owner] ? options[:resource_owner].password : nil),
|
20
|
+
grant_type: 'password'
|
21
21
|
}
|
22
22
|
"/oauth/token?#{build_query(parameters)}"
|
23
23
|
end
|
24
24
|
|
25
25
|
def authorization_endpoint_url(options = {})
|
26
26
|
parameters = {
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
27
|
+
client_id: options[:client_id] || options[:client].uid,
|
28
|
+
redirect_uri: options[:redirect_uri] || options[:client].redirect_uri,
|
29
|
+
response_type: options[:response_type] || 'code',
|
30
|
+
scope: options[:scope],
|
31
|
+
state: options[:state]
|
32
32
|
}.reject { |k, v| v.blank? }
|
33
33
|
"/oauth/authorize?#{build_query(parameters)}"
|
34
34
|
end
|
35
35
|
|
36
36
|
def refresh_token_endpoint_url(options = {})
|
37
37
|
parameters = {
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
38
|
+
refresh_token: options[:refresh_token],
|
39
|
+
client_id: options[:client_id] || options[:client].uid,
|
40
|
+
client_secret: options[:client_secret] || options[:client].secret,
|
41
|
+
grant_type: options[:grant_type] || 'refresh_token'
|
42
42
|
}
|
43
43
|
"/oauth/token?#{build_query(parameters)}"
|
44
44
|
end
|
45
45
|
|
46
|
+
def revocation_token_endpoint_url
|
47
|
+
'/oauth/revoke'
|
48
|
+
end
|
49
|
+
|
46
50
|
def build_query(hash)
|
47
51
|
Rack::Utils.build_query(hash)
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
|
-
RSpec.configuration.send :include, UrlHelper, :
|
55
|
+
RSpec.configuration.send :include, UrlHelper, type: :request
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# load schema to in memory sqlite
|
2
2
|
ActiveRecord::Migration.verbose = false
|
3
|
-
load Rails.root +
|
3
|
+
load Rails.root + 'db/schema.rb'
|
4
4
|
|
5
5
|
module Doorkeeper
|
6
6
|
module OrmHelper
|
7
|
-
|
8
|
-
mock_model 'User', :
|
9
|
-
|
7
|
+
def mock_application_owner
|
8
|
+
mock_model 'User', id: 1234
|
9
|
+
end
|
10
10
|
end
|
11
11
|
end
|
@@ -13,9 +13,8 @@ module Doorkeeper
|
|
13
13
|
class PlaceholderApplicationOwner
|
14
14
|
include MongoMapper::Document
|
15
15
|
|
16
|
-
set_collection_name
|
17
|
-
many :applications, :
|
18
|
-
|
16
|
+
set_collection_name 'placeholder_application_owners'
|
17
|
+
many :applications, class: Doorkeeper::Application
|
19
18
|
end
|
20
19
|
|
21
20
|
module OrmHelper
|
data/spec/support/orm/mongoid.rb
CHANGED
@@ -13,19 +13,18 @@ module Doorkeeper
|
|
13
13
|
class PlaceholderApplicationOwner
|
14
14
|
include Mongoid::Document
|
15
15
|
|
16
|
-
if ::Mongoid::VERSION >=
|
17
|
-
self.store_in :
|
16
|
+
if ::Mongoid::VERSION >= '3'
|
17
|
+
self.store_in collection: :placeholder_application_owners
|
18
18
|
else
|
19
19
|
self.store_in :placeholder_application_owners
|
20
20
|
end
|
21
21
|
|
22
22
|
has_many :applications
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
module OrmHelper
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def mock_application_owner
|
27
|
+
PlaceholderApplicationOwner.new
|
28
|
+
end
|
30
29
|
end
|
31
30
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
shared_context
|
1
|
+
shared_context 'valid token', token: :valid do
|
2
2
|
let :token_string do
|
3
|
-
|
3
|
+
'1A2B3C4D'
|
4
4
|
end
|
5
5
|
|
6
6
|
let :token do
|
7
|
-
double(Doorkeeper::AccessToken,
|
7
|
+
double(Doorkeeper::AccessToken, accessible?: true)
|
8
8
|
end
|
9
9
|
|
10
10
|
before :each do
|
@@ -12,13 +12,13 @@ shared_context "valid token", :token => :valid do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
shared_context
|
15
|
+
shared_context 'invalid token', token: :invalid do
|
16
16
|
let :token_string do
|
17
|
-
|
17
|
+
'1A2B3C4D'
|
18
18
|
end
|
19
19
|
|
20
20
|
let :token do
|
21
|
-
double(Doorkeeper::AccessToken,
|
21
|
+
double(Doorkeeper::AccessToken, accessible?: false, revoked?: false, expired?: false)
|
22
22
|
end
|
23
23
|
|
24
24
|
before :each do
|
@@ -26,22 +26,22 @@ shared_context "invalid token", :token => :invalid do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
shared_context
|
29
|
+
shared_context 'authenticated resource owner' do
|
30
30
|
before do
|
31
|
-
user = double(:resource, :
|
32
|
-
allow(Doorkeeper.configuration).to receive(:authenticate_resource_owner) { proc
|
31
|
+
user = double(:resource, id: 1)
|
32
|
+
allow(Doorkeeper.configuration).to receive(:authenticate_resource_owner) { proc { user } }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
shared_context
|
36
|
+
shared_context 'not authenticated resource owner' do
|
37
37
|
before do
|
38
|
-
allow(Doorkeeper.configuration).to receive(:authenticate_resource_owner) { proc
|
38
|
+
allow(Doorkeeper.configuration).to receive(:authenticate_resource_owner) { proc { redirect_to '/' } }
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
shared_context
|
42
|
+
shared_context 'valid authorization request' do
|
43
43
|
let :authorization do
|
44
|
-
double(:authorization,
|
44
|
+
double(:authorization, valid?: true, authorize: true, success_redirect_uri: 'http://something.com/cb?code=token')
|
45
45
|
end
|
46
46
|
|
47
47
|
before do
|
@@ -49,9 +49,9 @@ shared_context "valid authorization request" do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
shared_context
|
52
|
+
shared_context 'invalid authorization request' do
|
53
53
|
let :authorization do
|
54
|
-
double(:authorization,
|
54
|
+
double(:authorization, valid?: false, authorize: false, redirect_on_error?: false)
|
55
55
|
end
|
56
56
|
|
57
57
|
before do
|
@@ -1,35 +1,35 @@
|
|
1
|
-
shared_examples
|
1
|
+
shared_examples 'an accessible token' do
|
2
2
|
describe :accessible? do
|
3
|
-
it
|
3
|
+
it 'is accessible if token is not expired' do
|
4
4
|
allow(subject).to receive(:expired?).and_return(false)
|
5
5
|
should be_accessible
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'is not accessible if token is expired' do
|
9
9
|
allow(subject).to receive(:expired?).and_return(true)
|
10
10
|
should_not be_accessible
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
shared_examples
|
15
|
+
shared_examples 'a revocable token' do
|
16
16
|
describe :accessible? do
|
17
17
|
before { subject.save! }
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'is accessible if token is not revoked' do
|
20
20
|
expect(subject).to be_accessible
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'is not accessible if token is revoked' do
|
24
24
|
subject.revoke
|
25
25
|
expect(subject).not_to be_accessible
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
shared_examples
|
30
|
+
shared_examples 'an unique token' do
|
31
31
|
describe :token do
|
32
|
-
it
|
32
|
+
it 'is unique' do
|
33
33
|
tokens = []
|
34
34
|
3.times do
|
35
35
|
token = FactoryGirl.create(factory_name).token
|
@@ -37,11 +37,11 @@ shared_examples "an unique token" do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'is generated before validation' do
|
41
41
|
expect { subject.valid? }.to change { subject.token }.from(nil)
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'is not valid if token exists' do
|
45
45
|
token1 = FactoryGirl.create factory_name
|
46
46
|
token2 = FactoryGirl.create factory_name
|
47
47
|
token2.token = token1.token
|
@@ -52,9 +52,9 @@ shared_examples "an unique token" do
|
|
52
52
|
token1 = FactoryGirl.create factory_name
|
53
53
|
token2 = FactoryGirl.create factory_name
|
54
54
|
token2.token = token1.token
|
55
|
-
expect
|
56
|
-
token2.save!(:
|
57
|
-
|
55
|
+
expect do
|
56
|
+
token2.save!(validate: false)
|
57
|
+
end.to raise_error
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|