doorkeeper 4.2.0 → 4.2.5
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/.coveralls.yml +1 -0
- data/.gitignore +5 -0
- data/.travis.yml +11 -6
- data/Appraisals +14 -0
- data/Gemfile +4 -8
- data/NEWS.md +10 -1
- data/README.md +6 -1
- data/app/controllers/doorkeeper/applications_controller.rb +1 -5
- data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -2
- data/app/views/doorkeeper/authorized_applications/_delete_form.html.erb +1 -2
- data/config/locales/en.yml +2 -2
- data/doorkeeper.gemspec +9 -7
- data/gemfiles/rails_4_2.gemfile +11 -0
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/gemfiles/rails_5_1.gemfile +13 -0
- data/lib/doorkeeper.rb +7 -1
- data/lib/doorkeeper/config.rb +55 -0
- data/lib/doorkeeper/grape/helpers.rb +2 -1
- data/lib/doorkeeper/helpers/controller.rb +6 -6
- data/lib/doorkeeper/models/access_grant_mixin.rb +12 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +117 -1
- data/lib/doorkeeper/models/application_mixin.rb +18 -2
- data/lib/doorkeeper/models/concerns/accessible.rb +4 -0
- data/lib/doorkeeper/models/concerns/expirable.rb +8 -0
- data/lib/doorkeeper/models/concerns/revocable.rb +18 -0
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +20 -18
- data/lib/doorkeeper/oauth/authorization_code_request.rb +1 -4
- data/lib/doorkeeper/oauth/{request_concern.rb → base_request.rb} +3 -1
- data/lib/doorkeeper/oauth/base_response.rb +29 -0
- data/lib/doorkeeper/oauth/client.rb +0 -1
- data/lib/doorkeeper/oauth/client/credentials.rb +17 -6
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -4
- data/lib/doorkeeper/oauth/code_response.rb +7 -6
- data/lib/doorkeeper/oauth/error_response.rb +9 -8
- data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +1 -3
- data/lib/doorkeeper/oauth/refresh_token_request.rb +3 -7
- data/lib/doorkeeper/oauth/token.rb +17 -19
- data/lib/doorkeeper/oauth/token_request.rb +1 -2
- data/lib/doorkeeper/orm/active_record/access_token.rb +17 -0
- data/lib/doorkeeper/orm/active_record/application.rb +10 -5
- data/lib/doorkeeper/rails/helpers.rb +0 -2
- data/lib/doorkeeper/rails/routes.rb +3 -4
- data/lib/doorkeeper/rails/routes/mapper.rb +3 -3
- data/lib/doorkeeper/rails/routes/mapping.rb +1 -1
- data/lib/doorkeeper/request/authorization_code.rb +7 -1
- data/lib/doorkeeper/request/refresh_token.rb +1 -1
- data/lib/doorkeeper/server.rb +0 -8
- data/lib/doorkeeper/version.rb +1 -1
- data/spec/controllers/authorizations_controller_spec.rb +17 -3
- data/spec/lib/doorkeeper_spec.rb +135 -13
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +1 -2
- data/spec/lib/oauth/base_request_spec.rb +160 -0
- data/spec/lib/oauth/base_response_spec.rb +45 -0
- data/spec/lib/oauth/client/credentials_spec.rb +41 -0
- data/spec/lib/oauth/error_response_spec.rb +9 -9
- data/spec/lib/oauth/invalid_token_response_spec.rb +36 -8
- data/spec/lib/server_spec.rb +0 -3
- data/spec/requests/endpoints/authorization_spec.rb +5 -6
- data/spec/requests/flows/authorization_code_spec.rb +4 -12
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helper_integration.rb +5 -0
- data/spec/support/helpers/request_spec_helper.rb +12 -4
- data/spec/support/http_method_shim.rb +20 -6
- metadata +43 -21
- data/lib/doorkeeper/oauth/client/methods.rb +0 -18
- data/spec/lib/oauth/client/methods_spec.rb +0 -54
@@ -4,10 +4,7 @@ require 'doorkeeper/oauth/client_credentials/validation'
|
|
4
4
|
|
5
5
|
module Doorkeeper
|
6
6
|
module OAuth
|
7
|
-
class ClientCredentialsRequest
|
8
|
-
include Validations
|
9
|
-
include OAuth::RequestConcern
|
10
|
-
|
7
|
+
class ClientCredentialsRequest < BaseRequest
|
11
8
|
attr_accessor :server, :client, :original_scopes
|
12
9
|
attr_reader :response
|
13
10
|
attr_writer :issuer
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
module OAuth
|
3
|
-
class CodeResponse
|
4
|
-
include OAuth::Authorization::URIBuilder
|
3
|
+
class CodeResponse < BaseResponse
|
5
4
|
include OAuth::Helpers
|
6
5
|
|
7
6
|
attr_accessor :pre_auth, :auth, :response_on_fragment
|
@@ -20,7 +19,7 @@ module Doorkeeper
|
|
20
19
|
if URIChecker.native_uri? pre_auth.redirect_uri
|
21
20
|
auth.native_redirect
|
22
21
|
elsif response_on_fragment
|
23
|
-
uri_with_fragment(
|
22
|
+
Authorization::URIBuilder.uri_with_fragment(
|
24
23
|
pre_auth.redirect_uri,
|
25
24
|
access_token: auth.token.token,
|
26
25
|
token_type: auth.token.token_type,
|
@@ -28,9 +27,11 @@ module Doorkeeper
|
|
28
27
|
state: pre_auth.state
|
29
28
|
)
|
30
29
|
else
|
31
|
-
uri_with_query
|
32
|
-
|
33
|
-
|
30
|
+
Authorization::URIBuilder.uri_with_query(
|
31
|
+
pre_auth.redirect_uri,
|
32
|
+
code: auth.token.token,
|
33
|
+
state: pre_auth.state
|
34
|
+
)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
module OAuth
|
3
|
-
class ErrorResponse
|
4
|
-
include OAuth::Authorization::URIBuilder
|
3
|
+
class ErrorResponse < BaseResponse
|
5
4
|
include OAuth::Helpers
|
6
5
|
|
7
6
|
def self.from_request(request, attributes = {})
|
@@ -36,16 +35,12 @@ module Doorkeeper
|
|
36
35
|
|
37
36
|
def redirect_uri
|
38
37
|
if @response_on_fragment
|
39
|
-
uri_with_fragment @redirect_uri, body
|
38
|
+
Authorization::URIBuilder.uri_with_fragment @redirect_uri, body
|
40
39
|
else
|
41
|
-
uri_with_query @redirect_uri, body
|
40
|
+
Authorization::URIBuilder.uri_with_query @redirect_uri, body
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
def authenticate_info
|
46
|
-
%(Bearer realm="#{realm}", error="#{name}", error_description="#{description}")
|
47
|
-
end
|
48
|
-
|
49
44
|
def headers
|
50
45
|
{ 'Cache-Control' => 'no-store',
|
51
46
|
'Pragma' => 'no-cache',
|
@@ -60,6 +55,12 @@ module Doorkeeper
|
|
60
55
|
def configuration
|
61
56
|
Doorkeeper.configuration
|
62
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def authenticate_info
|
62
|
+
%(Bearer realm="#{realm}", error="#{name}", error_description="#{description}")
|
63
|
+
end
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
module OAuth
|
3
|
-
class RefreshTokenRequest
|
4
|
-
include Validations
|
5
|
-
include OAuth::RequestConcern
|
3
|
+
class RefreshTokenRequest < BaseRequest
|
6
4
|
include OAuth::Helpers
|
7
5
|
|
8
6
|
validate :token_presence, error: :invalid_request
|
@@ -12,9 +10,7 @@ module Doorkeeper
|
|
12
10
|
validate :scope, error: :invalid_scope
|
13
11
|
|
14
12
|
attr_accessor :access_token, :client, :credentials, :refresh_token,
|
15
|
-
:server
|
16
|
-
|
17
|
-
private :refresh_token_parameter, :refresh_token_parameter=
|
13
|
+
:server
|
18
14
|
|
19
15
|
def initialize(server, refresh_token, credentials, parameters = {})
|
20
16
|
@server = server
|
@@ -72,7 +68,7 @@ module Doorkeeper
|
|
72
68
|
end
|
73
69
|
|
74
70
|
def validate_token_presence
|
75
|
-
refresh_token.present? || refresh_token_parameter.present?
|
71
|
+
refresh_token.present? || @refresh_token_parameter.present?
|
76
72
|
end
|
77
73
|
|
78
74
|
def validate_token
|
@@ -1,7 +1,23 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
module OAuth
|
3
3
|
class Token
|
4
|
-
|
4
|
+
class << self
|
5
|
+
def from_request(request, *methods)
|
6
|
+
methods.inject(nil) do |credentials, method|
|
7
|
+
method = self.method(method) if method.is_a?(Symbol)
|
8
|
+
credentials = method.call(request)
|
9
|
+
break credentials unless credentials.blank?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticate(request, *methods)
|
14
|
+
if token = from_request(request, *methods)
|
15
|
+
access_token = AccessToken.by_token(token)
|
16
|
+
access_token.revoke_previous_refresh_token! if access_token
|
17
|
+
access_token
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
5
21
|
def from_access_token_param(request)
|
6
22
|
request.parameters[:access_token]
|
7
23
|
end
|
@@ -41,24 +57,6 @@ module Doorkeeper
|
|
41
57
|
header && header.match(pattern)
|
42
58
|
end
|
43
59
|
end
|
44
|
-
|
45
|
-
extend Methods
|
46
|
-
|
47
|
-
def self.from_request(request, *methods)
|
48
|
-
methods.inject(nil) do |credentials, method|
|
49
|
-
method = self.method(method) if method.is_a?(Symbol)
|
50
|
-
credentials = method.call(request)
|
51
|
-
break credentials unless credentials.blank?
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.authenticate(request, *methods)
|
56
|
-
if token = from_request(request, *methods)
|
57
|
-
access_token = AccessToken.by_token(token)
|
58
|
-
access_token.revoke_previous_refresh_token! if access_token
|
59
|
-
access_token
|
60
|
-
end
|
61
|
-
end
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
module OAuth
|
3
3
|
class TokenRequest
|
4
|
-
attr_accessor :pre_auth, :resource_owner
|
4
|
+
attr_accessor :pre_auth, :resource_owner
|
5
5
|
|
6
6
|
def initialize(pre_auth, resource_owner)
|
7
7
|
@pre_auth = pre_auth
|
8
|
-
@client = pre_auth.client
|
9
8
|
@resource_owner = resource_owner
|
10
9
|
end
|
11
10
|
|
@@ -4,16 +4,32 @@ module Doorkeeper
|
|
4
4
|
|
5
5
|
include AccessTokenMixin
|
6
6
|
|
7
|
+
# Deletes all the Access Tokens created for the specific
|
8
|
+
# Application and Resource Owner.
|
9
|
+
#
|
10
|
+
# @param application_id [Integer] Application ID
|
11
|
+
# @param resource_owner [ActiveRecord::Base] Resource Owner model instance
|
12
|
+
#
|
7
13
|
def self.delete_all_for(application_id, resource_owner)
|
8
14
|
where(application_id: application_id,
|
9
15
|
resource_owner_id: resource_owner.id).delete_all
|
10
16
|
end
|
11
17
|
private_class_method :delete_all_for
|
12
18
|
|
19
|
+
# Searches for not revoked Access Tokens associated with the
|
20
|
+
# specific Resource Owner.
|
21
|
+
#
|
22
|
+
# @param resource_owner [ActiveRecord::Base]
|
23
|
+
# Resource Owner model instance
|
24
|
+
#
|
25
|
+
# @return [ActiveRecord::Relation]
|
26
|
+
# active Access Tokens for Resource Owner
|
27
|
+
#
|
13
28
|
def self.active_for(resource_owner)
|
14
29
|
where(resource_owner_id: resource_owner.id, revoked_at: nil)
|
15
30
|
end
|
16
31
|
|
32
|
+
# ORM-specific order method.
|
17
33
|
def self.order_method
|
18
34
|
:order
|
19
35
|
end
|
@@ -22,6 +38,7 @@ module Doorkeeper
|
|
22
38
|
column_names.include?('previous_refresh_token')
|
23
39
|
end
|
24
40
|
|
41
|
+
# ORM-specific DESC order for `:created_at` column.
|
25
42
|
def self.created_at_desc
|
26
43
|
'created_at desc'
|
27
44
|
end
|
@@ -4,13 +4,18 @@ module Doorkeeper
|
|
4
4
|
|
5
5
|
include ApplicationMixin
|
6
6
|
|
7
|
-
|
8
|
-
has_many :authorized_tokens, -> { where(revoked_at: nil) }, class_name: 'AccessToken'
|
9
|
-
else
|
10
|
-
has_many :authorized_tokens, class_name: 'AccessToken', conditions: { revoked_at: nil }
|
11
|
-
end
|
7
|
+
has_many :authorized_tokens, -> { where(revoked_at: nil) }, class_name: 'AccessToken'
|
12
8
|
has_many :authorized_applications, through: :authorized_tokens, source: :application
|
13
9
|
|
10
|
+
# Returns Applications associated with active (not revoked) Access Tokens
|
11
|
+
# that are owned by the specific Resource Owner.
|
12
|
+
#
|
13
|
+
# @param resource_owner [ActiveRecord::Base]
|
14
|
+
# Resource Owner model instance
|
15
|
+
#
|
16
|
+
# @return [ActiveRecord::Relation]
|
17
|
+
# Applications authorized for the Resource Owner
|
18
|
+
#
|
14
19
|
def self.authorized_for(resource_owner)
|
15
20
|
resource_access_tokens = AccessToken.active_for(resource_owner)
|
16
21
|
where(id: resource_access_tokens.select(:application_id).distinct)
|
@@ -3,7 +3,7 @@ require 'doorkeeper/rails/routes/mapper'
|
|
3
3
|
|
4
4
|
module Doorkeeper
|
5
5
|
module Rails
|
6
|
-
class Routes
|
6
|
+
class Routes # :nodoc:
|
7
7
|
module Helper
|
8
8
|
# TODO: options hash is not being used
|
9
9
|
def use_doorkeeper(options = {}, &block)
|
@@ -15,15 +15,14 @@ module Doorkeeper
|
|
15
15
|
ActionDispatch::Routing::Mapper.send :include, Doorkeeper::Rails::Routes::Helper
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
attr_reader :routes
|
19
19
|
|
20
20
|
def initialize(routes, &block)
|
21
21
|
@routes = routes
|
22
|
-
@
|
22
|
+
@mapping = Mapper.new.map(&block)
|
23
23
|
end
|
24
24
|
|
25
25
|
def generate_routes!(options)
|
26
|
-
@mapping = Mapper.new.map(&@block)
|
27
26
|
routes.scope options[:scope] || 'oauth', as: 'oauth' do
|
28
27
|
map_route(:authorizations, :authorization_routes)
|
29
28
|
map_route(:tokens, :token_routes)
|
@@ -3,7 +3,7 @@ require 'doorkeeper/request/strategy'
|
|
3
3
|
module Doorkeeper
|
4
4
|
module Request
|
5
5
|
class AuthorizationCode < Strategy
|
6
|
-
delegate :
|
6
|
+
delegate :client, :parameters, to: :server
|
7
7
|
|
8
8
|
def request
|
9
9
|
@request ||= OAuth::AuthorizationCodeRequest.new(
|
@@ -13,6 +13,12 @@ module Doorkeeper
|
|
13
13
|
parameters
|
14
14
|
)
|
15
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def grant
|
20
|
+
AccessGrant.by_token(parameters[:code])
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
data/lib/doorkeeper/server.rb
CHANGED
@@ -33,14 +33,6 @@ module Doorkeeper
|
|
33
33
|
context.send :current_resource_owner
|
34
34
|
end
|
35
35
|
|
36
|
-
def current_refresh_token
|
37
|
-
AccessToken.by_refresh_token(parameters[:refresh_token])
|
38
|
-
end
|
39
|
-
|
40
|
-
def grant
|
41
|
-
AccessGrant.by_token(parameters[:code])
|
42
|
-
end
|
43
|
-
|
44
36
|
# TODO: Use configuration and evaluate proper context on block
|
45
37
|
def resource_owner
|
46
38
|
context.send :resource_owner_from_credentials
|
data/lib/doorkeeper/version.rb
CHANGED
@@ -12,8 +12,9 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
|
|
12
12
|
I18n.translate key, scope: [:doorkeeper, :errors, :messages]
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:client)
|
16
|
-
let(:user)
|
15
|
+
let(:client) { FactoryGirl.create :application }
|
16
|
+
let(:user) { User.create!(name: 'Joe', password: 'sekret') }
|
17
|
+
let(:access_token) { FactoryGirl.build :access_token, resource_owner_id: user.id, application_id: client.id }
|
17
18
|
|
18
19
|
before do
|
19
20
|
allow(Doorkeeper.configuration).to receive(:grant_flows).and_return(["implicit"])
|
@@ -86,7 +87,20 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
|
|
86
87
|
end
|
87
88
|
|
88
89
|
describe 'POST #create with application already authorized' do
|
89
|
-
|
90
|
+
before do
|
91
|
+
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
|
92
|
+
|
93
|
+
access_token.save!
|
94
|
+
post :create, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns the existing access token in a fragment' do
|
98
|
+
expect(fragments('access_token')).to eq(access_token.token)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'does not creates a new access token' do
|
102
|
+
expect(Doorkeeper::AccessToken.count).to eq(1)
|
103
|
+
end
|
90
104
|
end
|
91
105
|
|
92
106
|
describe 'GET #new token request with native url and skip_authorization true' do
|
data/spec/lib/doorkeeper_spec.rb
CHANGED
@@ -1,28 +1,150 @@
|
|
1
1
|
require 'spec_helper_integration'
|
2
2
|
|
3
3
|
describe Doorkeeper do
|
4
|
-
describe
|
5
|
-
let(:
|
6
|
-
|
4
|
+
describe "#authenticate" do
|
5
|
+
let(:request) { double }
|
6
|
+
|
7
|
+
it "calls OAuth::Token#authenticate" do
|
8
|
+
token_strategies = Doorkeeper.configuration.access_token_methods
|
9
|
+
|
10
|
+
expect(Doorkeeper::OAuth::Token).to receive(:authenticate).
|
11
|
+
with(request, *token_strategies)
|
12
|
+
|
13
|
+
Doorkeeper.authenticate(request)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "accepts custom token strategies" do
|
17
|
+
token_strategies = [:first_way, :second_way]
|
18
|
+
|
19
|
+
expect(Doorkeeper::OAuth::Token).to receive(:authenticate).
|
20
|
+
with(request, *token_strategies)
|
21
|
+
|
22
|
+
Doorkeeper.authenticate(request, token_strategies)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#configured?" do
|
27
|
+
after do
|
28
|
+
Doorkeeper.remove_instance_variable(:@config)
|
29
|
+
end
|
30
|
+
|
31
|
+
context "@config is set" do
|
32
|
+
it "returns true" do
|
33
|
+
Doorkeeper.instance_variable_set(:@config, "hi")
|
34
|
+
|
35
|
+
expect(Doorkeeper.configured?).to eq(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "@config is not set" do
|
40
|
+
it "returns false" do
|
41
|
+
Doorkeeper.instance_variable_set(:@config, nil)
|
42
|
+
|
43
|
+
expect(Doorkeeper.configured?).to eq(false)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "is deprecated" do
|
48
|
+
expect(ActiveSupport::Deprecation).to receive(:warn).
|
49
|
+
with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
|
50
|
+
|
51
|
+
Doorkeeper.configured?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#database_installed?" do
|
7
56
|
before do
|
8
|
-
|
9
|
-
|
57
|
+
["AccessToken", "AccessGrant", "Application"].each do |klass|
|
58
|
+
@original_classes ||= {}
|
59
|
+
@original_classes[klass] = Doorkeeper.const_get(klass)
|
60
|
+
Doorkeeper.send(:remove_const, klass)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
after do
|
65
|
+
["AccessToken", "AccessGrant", "Application"].each do |klass|
|
66
|
+
Doorkeeper.send(:remove_const, klass)
|
67
|
+
Doorkeeper.const_set(klass, @original_classes[klass])
|
68
|
+
end
|
10
69
|
end
|
11
70
|
|
12
|
-
context
|
13
|
-
|
71
|
+
context "all tables exist" do
|
72
|
+
before do
|
73
|
+
klass = double table_exists?: true
|
74
|
+
|
75
|
+
Doorkeeper.const_set(:AccessToken, klass)
|
76
|
+
Doorkeeper.const_set(:AccessGrant, klass)
|
77
|
+
Doorkeeper.const_set(:Application, klass)
|
78
|
+
end
|
14
79
|
|
15
|
-
it
|
16
|
-
expect(Doorkeeper.
|
80
|
+
it "returns true" do
|
81
|
+
expect(Doorkeeper.database_installed?).to eq(true)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "is deprecated" do
|
85
|
+
expect(ActiveSupport::Deprecation).to receive(:warn).
|
86
|
+
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
87
|
+
|
88
|
+
Doorkeeper.database_installed?
|
17
89
|
end
|
18
90
|
end
|
19
91
|
|
20
|
-
context
|
21
|
-
|
92
|
+
context "all tables do not exist" do
|
93
|
+
before do
|
94
|
+
klass = double table_exists?: false
|
95
|
+
|
96
|
+
Doorkeeper.const_set(:AccessToken, klass)
|
97
|
+
Doorkeeper.const_set(:AccessGrant, klass)
|
98
|
+
Doorkeeper.const_set(:Application, klass)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "returns false" do
|
102
|
+
expect(Doorkeeper.database_installed?).to eq(false)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "is deprecated" do
|
106
|
+
expect(ActiveSupport::Deprecation).to receive(:warn).
|
107
|
+
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
22
108
|
|
23
|
-
|
24
|
-
expect(Doorkeeper.authenticate(request)).to eq(token)
|
109
|
+
Doorkeeper.database_installed?
|
25
110
|
end
|
26
111
|
end
|
27
112
|
end
|
113
|
+
|
114
|
+
describe "#installed?" do
|
115
|
+
context "methods return true" do
|
116
|
+
before do
|
117
|
+
allow(Doorkeeper).to receive(:configured?).and_return(true).once
|
118
|
+
allow(Doorkeeper).to receive(:database_installed?).and_return(true).once
|
119
|
+
end
|
120
|
+
|
121
|
+
it "returns true" do
|
122
|
+
expect(Doorkeeper.installed?).to eq(true)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "methods return false" do
|
127
|
+
before do
|
128
|
+
allow(Doorkeeper).to receive(:configured?).and_return(false).once
|
129
|
+
allow(Doorkeeper).to receive(:database_installed?).and_return(false).once
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns false" do
|
133
|
+
expect(Doorkeeper.installed?).to eq(false)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it "is deprecated" do
|
138
|
+
expect(ActiveSupport::Deprecation).to receive(:warn).
|
139
|
+
with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
|
140
|
+
|
141
|
+
expect(ActiveSupport::Deprecation).to receive(:warn).
|
142
|
+
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
143
|
+
|
144
|
+
expect(ActiveSupport::Deprecation).to receive(:warn).
|
145
|
+
with("Method `Doorkeeper#installed?` has been deprecated without replacement.")
|
146
|
+
|
147
|
+
Doorkeeper.installed?
|
148
|
+
end
|
149
|
+
end
|
28
150
|
end
|