doorkeeper 4.4.3 → 5.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/Appraisals +2 -2
- data/Gemfile +1 -1
- data/NEWS.md +36 -17
- data/README.md +85 -3
- data/Rakefile +6 -0
- data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +4 -3
- data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
- data/app/controllers/doorkeeper/applications_controller.rb +42 -22
- data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +15 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +12 -15
- data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
- data/app/validators/redirect_uri_validator.rb +3 -2
- data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
- data/app/views/doorkeeper/applications/_form.html.erb +25 -24
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +17 -7
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +6 -6
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
- data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
- data/config/locales/en.yml +9 -1
- data/doorkeeper.gemspec +0 -2
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/lib/doorkeeper/config.rb +58 -35
- data/lib/doorkeeper/engine.rb +4 -0
- data/lib/doorkeeper/errors.rb +2 -5
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +7 -2
- data/lib/doorkeeper/models/access_grant_mixin.rb +56 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +38 -21
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
- data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +23 -6
- data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
- data/lib/doorkeeper/oauth/base_request.rb +18 -8
- data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -1
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -2
- data/lib/doorkeeper/oauth/error_response.rb +11 -3
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +41 -11
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
- data/lib/doorkeeper/oauth/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/token.rb +5 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
- data/lib/doorkeeper/oauth/token_response.rb +4 -2
- data/lib/doorkeeper/oauth.rb +13 -0
- data/lib/doorkeeper/orm/active_record/application.rb +13 -16
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
- data/lib/doorkeeper/orm/active_record.rb +2 -0
- data/lib/doorkeeper/rails/helpers.rb +2 -4
- data/lib/doorkeeper/rails/routes.rb +14 -6
- data/lib/doorkeeper/rake/db.rake +40 -0
- data/lib/doorkeeper/rake/setup.rake +6 -0
- data/lib/doorkeeper/rake.rb +14 -0
- data/lib/doorkeeper/request.rb +28 -28
- data/lib/doorkeeper/version.rb +5 -25
- data/lib/doorkeeper.rb +4 -17
- data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
- data/lib/generators/doorkeeper/install_generator.rb +17 -9
- data/lib/generators/doorkeeper/migration_generator.rb +23 -18
- data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
- data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +60 -9
- data/lib/generators/doorkeeper/views_generator.rb +3 -1
- data/spec/controllers/application_metal_controller_spec.rb +50 -0
- data/spec/controllers/applications_controller_spec.rb +126 -13
- data/spec/controllers/authorizations_controller_spec.rb +252 -49
- data/spec/controllers/protected_resources_controller_spec.rb +16 -16
- data/spec/controllers/token_info_controller_spec.rb +4 -12
- data/spec/controllers/tokens_controller_spec.rb +19 -73
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/config/environments/test.rb +4 -5
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -4
- data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
- data/spec/dummy/db/schema.rb +36 -36
- data/spec/generators/application_owner_generator_spec.rb +1 -1
- data/spec/generators/confidential_applications_generator_spec.rb +45 -0
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/migration_generator_spec.rb +1 -1
- data/spec/generators/pkce_generator_spec.rb +43 -0
- data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
- data/spec/generators/views_generator_spec.rb +1 -1
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +51 -31
- data/spec/lib/doorkeeper_spec.rb +1 -126
- data/spec/lib/models/expirable_spec.rb +0 -3
- data/spec/lib/models/revocable_spec.rb +0 -2
- data/spec/lib/models/scopes_spec.rb +0 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +9 -2
- data/spec/lib/oauth/base_request_spec.rb +16 -2
- data/spec/lib/oauth/base_response_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +1 -3
- data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
- data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
- data/spec/lib/oauth/client_spec.rb +0 -3
- data/spec/lib/oauth/code_request_spec.rb +4 -2
- data/spec/lib/oauth/error_response_spec.rb +0 -3
- data/spec/lib/oauth/error_spec.rb +0 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -7
- data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
- data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
- data/spec/lib/oauth/scopes_spec.rb +0 -3
- data/spec/lib/oauth/token_request_spec.rb +4 -5
- data/spec/lib/oauth/token_response_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +37 -14
- data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
- data/spec/lib/request/strategy_spec.rb +0 -1
- data/spec/lib/server_spec.rb +1 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +1 -1
- data/spec/models/doorkeeper/access_token_spec.rb +50 -16
- data/spec/models/doorkeeper/application_spec.rb +1 -47
- data/spec/requests/applications/applications_request_spec.rb +89 -1
- data/spec/requests/applications/authorized_applications_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +7 -5
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_spec.rb +198 -2
- data/spec/requests/flows/client_credentials_spec.rb +46 -6
- data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
- data/spec/requests/flows/implicit_grant_spec.rb +38 -11
- data/spec/requests/flows/password_spec.rb +56 -2
- data/spec/requests/flows/refresh_token_spec.rb +2 -2
- data/spec/requests/flows/revoke_token_spec.rb +11 -11
- data/spec/requests/flows/skip_authorization_spec.rb +16 -11
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +1 -1
- data/spec/routing/custom_controller_routes_spec.rb +59 -7
- data/spec/routing/default_routes_spec.rb +2 -2
- data/spec/routing/scoped_routes_spec.rb +16 -2
- data/spec/spec_helper.rb +54 -3
- data/spec/spec_helper_integration.rb +2 -74
- data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
- data/spec/support/doorkeeper_rspec.rb +19 -0
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/request_spec_helper.rb +2 -2
- data/spec/support/helpers/url_helper.rb +7 -3
- data/spec/support/http_method_shim.rb +12 -16
- data/spec/validators/redirect_uri_validator_spec.rb +7 -1
- data/spec/version/version_spec.rb +3 -3
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
- metadata +33 -31
- data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
- data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
- data/spec/controllers/application_metal_controller.rb +0 -10
@@ -4,56 +4,89 @@ Doorkeeper.configure do
|
|
4
4
|
|
5
5
|
# This block will be called to check whether the resource owner is authenticated or not.
|
6
6
|
resource_owner_authenticator do
|
7
|
-
|
7
|
+
raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
|
8
8
|
# Put your resource owner authentication logic here.
|
9
9
|
# Example implementation:
|
10
10
|
# User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
|
11
11
|
end
|
12
12
|
|
13
|
-
# If you want to restrict access to the web interface for adding oauth authorized applications,
|
13
|
+
# If you want to restrict access to the web interface for adding oauth authorized applications,
|
14
|
+
# you need to declare the block below.
|
15
|
+
#
|
14
16
|
# admin_authenticator do
|
15
17
|
# # Put your admin authentication logic here.
|
16
18
|
# # Example implementation:
|
17
19
|
# Admin.find_by_id(session[:admin_id]) || redirect_to(new_admin_session_url)
|
18
20
|
# end
|
19
21
|
|
22
|
+
# If you are planning to use Doorkeeper in Rails 5 API-only application, then you might
|
23
|
+
# want to use API mode that will skip all the views management and change the way how
|
24
|
+
# Doorkeeper responds to a requests.
|
25
|
+
#
|
26
|
+
# api_only
|
27
|
+
|
28
|
+
# Enforce token request content type to application/x-www-form-urlencoded.
|
29
|
+
# It is not enabled by default to not break prior versions of the gem.
|
30
|
+
#
|
31
|
+
# enforce_content_type
|
32
|
+
|
20
33
|
# Authorization Code expiration time (default 10 minutes).
|
34
|
+
#
|
21
35
|
# authorization_code_expires_in 10.minutes
|
22
36
|
|
23
37
|
# Access token expiration time (default 2 hours).
|
24
38
|
# If you want to disable expiration, set this to nil.
|
39
|
+
#
|
25
40
|
# access_token_expires_in 2.hours
|
26
41
|
|
27
|
-
# Assign
|
28
|
-
#
|
29
|
-
#
|
42
|
+
# Assign custom TTL for access tokens. Will be used instead of access_token_expires_in
|
43
|
+
# option if defined. `context` has the following properties available
|
44
|
+
#
|
45
|
+
# `client` - the OAuth client application (see Doorkeeper::OAuth::Client)
|
46
|
+
# `grant_type` - the grant type of the request (see Doorkeeper::OAuth)
|
47
|
+
# `scopes` - the requested scopes (see Doorkeeper::OAuth::Scopes)
|
48
|
+
#
|
49
|
+
# custom_access_token_expires_in do |context|
|
50
|
+
# context.client.application.additional_settings.implicit_oauth_expiration
|
30
51
|
# end
|
31
52
|
|
32
53
|
# Use a custom class for generating the access token.
|
33
|
-
# https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
|
54
|
+
# See https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
|
55
|
+
#
|
34
56
|
# access_token_generator '::Doorkeeper::JWT'
|
35
57
|
|
36
58
|
# The controller Doorkeeper::ApplicationController inherits from.
|
37
59
|
# Defaults to ActionController::Base.
|
38
|
-
# https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
|
60
|
+
# See https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
|
61
|
+
#
|
39
62
|
# base_controller 'ApplicationController'
|
40
63
|
|
41
64
|
# Reuse access token for the same resource owner within an application (disabled by default)
|
42
65
|
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
|
66
|
+
#
|
43
67
|
# reuse_access_token
|
44
68
|
|
45
69
|
# Issue access tokens with refresh token (disabled by default)
|
70
|
+
#
|
46
71
|
# use_refresh_token
|
47
72
|
|
73
|
+
# Forbids creating/updating applications with arbitrary scopes that are
|
74
|
+
# not in configuration, i.e. `default_scopes` or `optional_scopes`.
|
75
|
+
# (disabled by default)
|
76
|
+
#
|
77
|
+
# enforce_configured_scopes
|
78
|
+
|
48
79
|
# Provide support for an owner to be assigned to each registered application (disabled by default)
|
49
80
|
# Optional parameter confirmation: true (default false) if you want to enforce ownership of
|
50
81
|
# a registered application
|
51
82
|
# Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
|
83
|
+
#
|
52
84
|
# enable_application_owner confirmation: false
|
53
85
|
|
54
86
|
# Define access token scopes for your provider
|
55
87
|
# For more information go to
|
56
88
|
# https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
|
89
|
+
#
|
57
90
|
# default_scopes :public
|
58
91
|
# optional_scopes :write, :update
|
59
92
|
|
@@ -62,6 +95,7 @@ Doorkeeper.configure do
|
|
62
95
|
# falls back to the `:client_id` and `:client_secret` params from the `params` object.
|
63
96
|
# Check out https://github.com/doorkeeper-gem/doorkeeper/wiki/Changing-how-clients-are-authenticated
|
64
97
|
# for more information on customization
|
98
|
+
#
|
65
99
|
# client_credentials :from_basic, :from_params
|
66
100
|
|
67
101
|
# Change the way access token is authenticated from the request object.
|
@@ -69,6 +103,7 @@ Doorkeeper.configure do
|
|
69
103
|
# falls back to the `:access_token` or `:bearer_token` params from the `params` object.
|
70
104
|
# Check out https://github.com/doorkeeper-gem/doorkeeper/wiki/Changing-how-clients-are-authenticated
|
71
105
|
# for more information on customization
|
106
|
+
#
|
72
107
|
# access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
|
73
108
|
|
74
109
|
# Change the native redirect uri for client apps
|
@@ -90,8 +125,8 @@ Doorkeeper.configure do
|
|
90
125
|
#
|
91
126
|
# force_ssl_in_redirect_uri { |uri| uri.host != 'localhost' }
|
92
127
|
|
93
|
-
# Specify what redirect URI's you want to block during creation.
|
94
|
-
# URI is whitelisted by default.
|
128
|
+
# Specify what redirect URI's you want to block during Application creation.
|
129
|
+
# Any redirect URI is whitelisted by default.
|
95
130
|
#
|
96
131
|
# You can use this option in order to forbid URI's with 'javascript' scheme
|
97
132
|
# for example.
|
@@ -127,13 +162,29 @@ Doorkeeper.configure do
|
|
127
162
|
# puts "AFTER HOOK FIRED! #{request}, #{response}"
|
128
163
|
# end
|
129
164
|
|
165
|
+
# Hook into Authorization flow in order to implement Single Sign Out
|
166
|
+
# or add ny other functionality.
|
167
|
+
#
|
168
|
+
# before_successful_authorization do |controller|
|
169
|
+
# Rails.logger.info(params.inspect)
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# after_successful_authorization do |controller|
|
173
|
+
# controller.session[:logout_urls] <<
|
174
|
+
# Doorkeeper::Application
|
175
|
+
# .find_by(controller.request.params.slice(:redirect_uri))
|
176
|
+
# .logout_uri
|
177
|
+
# end
|
178
|
+
|
130
179
|
# Under some circumstances you might want to have applications auto-approved,
|
131
180
|
# so that the user skips the authorization step.
|
132
181
|
# For example if dealing with a trusted application.
|
182
|
+
#
|
133
183
|
# skip_authorization do |resource_owner, client|
|
134
184
|
# client.superapp? or resource_owner.admin?
|
135
185
|
# end
|
136
186
|
|
137
187
|
# WWW-Authenticate Realm (default "Doorkeeper").
|
188
|
+
#
|
138
189
|
# realm "Doorkeeper"
|
139
190
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Doorkeeper
|
2
4
|
module Generators
|
3
5
|
class ViewsGenerator < ::Rails::Generators::Base
|
4
|
-
source_root File.expand_path('
|
6
|
+
source_root File.expand_path('../../../app/views', __dir__)
|
5
7
|
|
6
8
|
desc 'Copies default Doorkeeper views and layouts to your application.'
|
7
9
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper_integration'
|
4
|
+
|
5
|
+
describe Doorkeeper::ApplicationMetalController do
|
6
|
+
controller(Doorkeeper::ApplicationMetalController) do
|
7
|
+
def index
|
8
|
+
render json: {}, status: 200
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "lazy run hooks" do
|
13
|
+
i = 0
|
14
|
+
ActiveSupport.on_load(:doorkeeper_metal_controller) { i += 1 }
|
15
|
+
|
16
|
+
expect(i).to eq 1
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'enforce_content_type' do
|
20
|
+
before { allow(Doorkeeper.configuration).to receive(:enforce_content_type).and_return(flag) }
|
21
|
+
|
22
|
+
context 'enabled' do
|
23
|
+
let(:flag) { true }
|
24
|
+
|
25
|
+
it '200 for the correct media type' do
|
26
|
+
get :index, params: {}, as: :url_encoded_form
|
27
|
+
expect(response).to have_http_status 200
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns a 415 for an incorrect media type' do
|
31
|
+
get :index, as: :json
|
32
|
+
expect(response).to have_http_status 415
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'disabled' do
|
37
|
+
let(:flag) { false }
|
38
|
+
|
39
|
+
it 'returns a 200 for the correct media type' do
|
40
|
+
get :index, as: :url_encoded_form
|
41
|
+
expect(response).to have_http_status 200
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns a 200 for an incorrect media type' do
|
45
|
+
get :index, as: :json
|
46
|
+
expect(response).to have_http_status 200
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,7 +1,99 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Doorkeeper
|
4
4
|
describe ApplicationsController do
|
5
|
+
context 'JSON API' do
|
6
|
+
render_views
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
|
10
|
+
allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) { true })
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'creates an application' do
|
14
|
+
expect do
|
15
|
+
post :create, params: {
|
16
|
+
doorkeeper_application: {
|
17
|
+
name: 'Example',
|
18
|
+
redirect_uri: 'https://example.com'
|
19
|
+
}, format: :json
|
20
|
+
}
|
21
|
+
end.to change { Doorkeeper::Application.count }
|
22
|
+
|
23
|
+
expect(response).to be_successful
|
24
|
+
|
25
|
+
expect(json_response).to include('id', 'name', 'uid', 'secret', 'redirect_uri', 'scopes')
|
26
|
+
|
27
|
+
expect(json_response['name']).to eq('Example')
|
28
|
+
expect(json_response['redirect_uri']).to eq('https://example.com')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns validation errors on wrong create params' do
|
32
|
+
expect do
|
33
|
+
post :create, params: {
|
34
|
+
doorkeeper_application: {
|
35
|
+
name: 'Example'
|
36
|
+
}, format: :json
|
37
|
+
}
|
38
|
+
end.not_to change { Doorkeeper::Application.count }
|
39
|
+
|
40
|
+
expect(response).to have_http_status(422)
|
41
|
+
|
42
|
+
expect(json_response).to include('errors')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns application info' do
|
46
|
+
application = FactoryBot.create(:application, name: 'Change me')
|
47
|
+
|
48
|
+
get :show, params: { id: application.id, format: :json }
|
49
|
+
|
50
|
+
expect(response).to be_successful
|
51
|
+
|
52
|
+
expect(json_response).to include('id', 'name', 'uid', 'secret', 'redirect_uri', 'scopes')
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'updates application' do
|
56
|
+
application = FactoryBot.create(:application, name: 'Change me')
|
57
|
+
|
58
|
+
put :update, params: {
|
59
|
+
id: application.id,
|
60
|
+
doorkeeper_application: {
|
61
|
+
name: 'Example App',
|
62
|
+
redirect_uri: 'https://example.com'
|
63
|
+
}, format: :json
|
64
|
+
}
|
65
|
+
|
66
|
+
expect(application.reload.name).to eq 'Example App'
|
67
|
+
|
68
|
+
expect(json_response).to include('id', 'name', 'uid', 'secret', 'redirect_uri', 'scopes')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns validation errors on wrong update params' do
|
72
|
+
application = FactoryBot.create(:application, name: 'Change me')
|
73
|
+
|
74
|
+
put :update, params: {
|
75
|
+
id: application.id,
|
76
|
+
doorkeeper_application: {
|
77
|
+
name: 'Example App',
|
78
|
+
redirect_uri: 'localhost:3000'
|
79
|
+
}, format: :json
|
80
|
+
}
|
81
|
+
|
82
|
+
expect(response).to have_http_status(422)
|
83
|
+
|
84
|
+
expect(json_response).to include('errors')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'destroys an application' do
|
88
|
+
application = FactoryBot.create(:application)
|
89
|
+
|
90
|
+
delete :destroy, params: { id: application.id, format: :json }
|
91
|
+
|
92
|
+
expect(response).to have_http_status(204)
|
93
|
+
expect(Application.count).to be_zero
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
5
97
|
context 'when admin is not authenticated' do
|
6
98
|
before do
|
7
99
|
allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(proc do
|
@@ -16,9 +108,13 @@ module Doorkeeper
|
|
16
108
|
|
17
109
|
it 'does not create application' do
|
18
110
|
expect do
|
19
|
-
post :create,
|
20
|
-
|
21
|
-
|
111
|
+
post :create,
|
112
|
+
params: {
|
113
|
+
doorkeeper_application: {
|
114
|
+
name: 'Example',
|
115
|
+
redirect_uri: 'https://example.com'
|
116
|
+
}
|
117
|
+
}
|
22
118
|
end.not_to change { Doorkeeper::Application.count }
|
23
119
|
end
|
24
120
|
end
|
@@ -34,34 +130,51 @@ module Doorkeeper
|
|
34
130
|
first_application = FactoryBot.create(:application)
|
35
131
|
second_application = FactoryBot.create(:application)
|
36
132
|
expect(Doorkeeper::Application).to receive(:ordered_by).and_call_original
|
133
|
+
|
37
134
|
get :index
|
135
|
+
|
38
136
|
expect(response.body).to have_selector("tbody tr:first-child#application_#{first_application.id}")
|
39
137
|
expect(response.body).to have_selector("tbody tr:last-child#application_#{second_application.id}")
|
40
138
|
end
|
41
139
|
|
42
140
|
it 'creates application' do
|
43
141
|
expect do
|
44
|
-
post :create,
|
45
|
-
|
46
|
-
|
142
|
+
post :create,
|
143
|
+
params: {
|
144
|
+
doorkeeper_application: {
|
145
|
+
name: 'Example',
|
146
|
+
redirect_uri: 'https://example.com'
|
147
|
+
}
|
148
|
+
}
|
47
149
|
end.to change { Doorkeeper::Application.count }.by(1)
|
150
|
+
|
48
151
|
expect(response).to be_redirect
|
49
152
|
end
|
50
153
|
|
51
154
|
it 'does not allow mass assignment of uid or secret' do
|
52
155
|
application = FactoryBot.create(:application)
|
53
|
-
put :update,
|
54
|
-
|
55
|
-
|
156
|
+
put :update,
|
157
|
+
params: {
|
158
|
+
id: application.id,
|
159
|
+
doorkeeper_application: {
|
160
|
+
uid: '1A2B3C4D',
|
161
|
+
secret: '1A2B3C4D'
|
162
|
+
}
|
163
|
+
}
|
56
164
|
|
57
165
|
expect(application.reload.uid).not_to eq '1A2B3C4D'
|
58
166
|
end
|
59
167
|
|
60
168
|
it 'updates application' do
|
61
169
|
application = FactoryBot.create(:application)
|
62
|
-
put :update,
|
63
|
-
|
64
|
-
|
170
|
+
put :update,
|
171
|
+
params: {
|
172
|
+
id: application.id, doorkeeper_application: {
|
173
|
+
name: 'Example',
|
174
|
+
redirect_uri: 'https://example.com'
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
65
178
|
expect(application.reload.name).to eq 'Example'
|
66
179
|
end
|
67
180
|
end
|