doorkeeper 5.1.0.rc2 → 5.1.0
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/.hound.yml +2 -1
- data/.rubocop.yml +37 -4
- data/.travis.yml +4 -27
- data/Appraisals +8 -12
- data/Gemfile +6 -2
- data/NEWS.md +16 -0
- data/README.md +11 -2
- data/Rakefile +10 -8
- data/app/controllers/doorkeeper/application_controller.rb +1 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +2 -13
- data/app/controllers/doorkeeper/applications_controller.rb +17 -5
- data/app/controllers/doorkeeper/token_info_controller.rb +1 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +7 -7
- data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
- data/app/validators/redirect_uri_validator.rb +5 -2
- data/app/views/doorkeeper/applications/_form.html.erb +6 -0
- data/bin/console +5 -4
- data/config/locales/en.yml +1 -0
- data/doorkeeper.gemspec +24 -22
- data/gemfiles/rails_5_0.gemfile +2 -1
- data/gemfiles/rails_5_1.gemfile +2 -1
- data/gemfiles/rails_5_2.gemfile +2 -1
- data/gemfiles/rails_6_0.gemfile +1 -0
- data/gemfiles/rails_master.gemfile +1 -0
- data/lib/doorkeeper.rb +68 -66
- data/lib/doorkeeper/config.rb +53 -90
- data/lib/doorkeeper/config/option.rb +64 -0
- data/lib/doorkeeper/engine.rb +1 -1
- data/lib/doorkeeper/grape/authorization_decorator.rb +4 -4
- data/lib/doorkeeper/grape/helpers.rb +3 -3
- data/lib/doorkeeper/helpers/controller.rb +1 -1
- data/lib/doorkeeper/models/access_grant_mixin.rb +4 -2
- data/lib/doorkeeper/models/access_token_mixin.rb +10 -10
- data/lib/doorkeeper/models/application_mixin.rb +1 -0
- data/lib/doorkeeper/models/concerns/expirable.rb +1 -0
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -6
- data/lib/doorkeeper/models/concerns/revocable.rb +2 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/models/concerns/secret_storable.rb +2 -0
- data/lib/doorkeeper/oauth.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/code.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +5 -3
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -1
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +6 -2
- data/lib/doorkeeper/oauth/invalid_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/pre_authorization.rb +4 -3
- data/lib/doorkeeper/oauth/refresh_token_request.rb +1 -1
- data/lib/doorkeeper/oauth/scopes.rb +5 -3
- data/lib/doorkeeper/oauth/token.rb +2 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +4 -4
- data/lib/doorkeeper/oauth/token_response.rb +9 -9
- data/lib/doorkeeper/orm/active_record.rb +6 -6
- data/lib/doorkeeper/orm/active_record/access_grant.rb +5 -12
- data/lib/doorkeeper/orm/active_record/access_token.rb +6 -13
- data/lib/doorkeeper/orm/active_record/application.rb +6 -5
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -3
- data/lib/doorkeeper/rails/helpers.rb +1 -1
- data/lib/doorkeeper/rails/routes.rb +11 -11
- data/lib/doorkeeper/rails/routes/mapping.rb +7 -7
- data/lib/doorkeeper/rake.rb +1 -1
- data/lib/doorkeeper/rake/db.rake +13 -13
- data/lib/doorkeeper/request.rb +1 -1
- data/lib/doorkeeper/secret_storing/base.rb +7 -6
- data/lib/doorkeeper/secret_storing/bcrypt.rb +4 -3
- data/lib/doorkeeper/secret_storing/plain.rb +4 -4
- data/lib/doorkeeper/secret_storing/sha256_hash.rb +3 -2
- data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
- data/lib/doorkeeper/version.rb +2 -2
- data/lib/generators/doorkeeper/application_owner_generator.rb +10 -9
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +10 -9
- data/lib/generators/doorkeeper/install_generator.rb +11 -9
- data/lib/generators/doorkeeper/migration_generator.rb +9 -9
- data/lib/generators/doorkeeper/pkce_generator.rb +10 -9
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +10 -9
- data/lib/generators/doorkeeper/templates/initializer.rb +30 -5
- data/lib/generators/doorkeeper/templates/migration.rb.erb +15 -7
- data/lib/generators/doorkeeper/views_generator.rb +6 -4
- data/spec/controllers/application_metal_controller_spec.rb +10 -10
- data/spec/controllers/applications_controller_spec.rb +54 -52
- data/spec/controllers/authorizations_controller_spec.rb +136 -142
- data/spec/controllers/protected_resources_controller_spec.rb +78 -76
- data/spec/controllers/token_info_controller_spec.rb +13 -11
- data/spec/controllers/tokens_controller_spec.rb +109 -94
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -2
- data/spec/dummy/app/controllers/home_controller.rb +5 -3
- data/spec/dummy/app/controllers/metal_controller.rb +2 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +4 -2
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/config/application.rb +13 -0
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +3 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -2
- data/spec/dummy/config/initializers/secret_token.rb +3 -1
- data/spec/dummy/config/initializers/session_store.rb +3 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +17 -10
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +2 -0
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/script/rails +5 -3
- data/spec/factories.rb +5 -3
- data/spec/generators/application_owner_generator_spec.rb +13 -26
- data/spec/generators/confidential_applications_generator_spec.rb +12 -28
- data/spec/generators/install_generator_spec.rb +17 -15
- data/spec/generators/migration_generator_spec.rb +13 -26
- data/spec/generators/pkce_generator_spec.rb +11 -26
- data/spec/generators/previous_refresh_token_generator_spec.rb +16 -29
- data/spec/generators/templates/routes.rb +2 -0
- data/spec/generators/views_generator_spec.rb +14 -12
- data/spec/grape/grape_integration_spec.rb +34 -32
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +9 -7
- data/spec/lib/config_spec.rb +137 -136
- data/spec/lib/doorkeeper_spec.rb +3 -1
- data/spec/lib/models/expirable_spec.rb +12 -10
- data/spec/lib/models/reusable_spec.rb +6 -6
- data/spec/lib/models/revocable_spec.rb +8 -6
- data/spec/lib/models/scopes_spec.rb +19 -17
- data/spec/lib/models/secret_storable_spec.rb +71 -49
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +17 -15
- data/spec/lib/oauth/authorization_code_request_spec.rb +18 -12
- data/spec/lib/oauth/base_request_spec.rb +20 -8
- data/spec/lib/oauth/base_response_spec.rb +3 -1
- data/spec/lib/oauth/client/credentials_spec.rb +24 -22
- data/spec/lib/oauth/client_credentials/creator_spec.rb +13 -11
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +27 -18
- data/spec/lib/oauth/client_credentials/validation_spec.rb +17 -15
- data/spec/lib/oauth/client_credentials_integration_spec.rb +7 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +27 -21
- data/spec/lib/oauth/client_spec.rb +15 -13
- data/spec/lib/oauth/code_request_spec.rb +8 -6
- data/spec/lib/oauth/code_response_spec.rb +9 -7
- data/spec/lib/oauth/error_response_spec.rb +14 -12
- data/spec/lib/oauth/error_spec.rb +4 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +7 -5
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +35 -33
- data/spec/lib/oauth/helpers/unique_token_spec.rb +8 -6
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +103 -101
- data/spec/lib/oauth/invalid_token_response_spec.rb +3 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +52 -34
- data/spec/lib/oauth/pre_authorization_spec.rb +64 -62
- data/spec/lib/oauth/refresh_token_request_spec.rb +36 -33
- data/spec/lib/oauth/scopes_spec.rb +63 -61
- data/spec/lib/oauth/token_request_spec.rb +66 -26
- data/spec/lib/oauth/token_response_spec.rb +39 -37
- data/spec/lib/oauth/token_spec.rb +51 -49
- data/spec/lib/request/strategy_spec.rb +3 -1
- data/spec/lib/secret_storing/base_spec.rb +23 -23
- data/spec/lib/secret_storing/bcrypt_spec.rb +18 -18
- data/spec/lib/secret_storing/plain_spec.rb +17 -17
- data/spec/lib/secret_storing/sha256_hash_spec.rb +16 -16
- data/spec/lib/server_spec.rb +16 -14
- data/spec/lib/stale_records_cleaner_spec.rb +17 -17
- data/spec/models/doorkeeper/access_grant_spec.rb +30 -26
- data/spec/models/doorkeeper/access_token_spec.rb +97 -95
- data/spec/models/doorkeeper/application_spec.rb +98 -57
- data/spec/requests/applications/applications_request_spec.rb +98 -66
- data/spec/requests/applications/authorized_applications_spec.rb +20 -18
- data/spec/requests/endpoints/authorization_spec.rb +25 -23
- data/spec/requests/endpoints/token_spec.rb +38 -36
- data/spec/requests/flows/authorization_code_errors_spec.rb +26 -24
- data/spec/requests/flows/authorization_code_spec.rb +161 -159
- data/spec/requests/flows/client_credentials_spec.rb +53 -51
- data/spec/requests/flows/implicit_grant_errors_spec.rb +10 -8
- data/spec/requests/flows/implicit_grant_spec.rb +27 -25
- data/spec/requests/flows/password_spec.rb +56 -54
- data/spec/requests/flows/refresh_token_spec.rb +45 -43
- data/spec/requests/flows/revoke_token_spec.rb +29 -27
- data/spec/requests/flows/skip_authorization_spec.rb +23 -21
- data/spec/requests/protected_resources/metal_spec.rb +7 -5
- data/spec/requests/protected_resources/private_api_spec.rb +35 -33
- data/spec/routing/custom_controller_routes_spec.rb +67 -65
- data/spec/routing/default_routes_spec.rb +22 -20
- data/spec/routing/scoped_routes_spec.rb +20 -18
- data/spec/spec_helper.rb +14 -13
- data/spec/spec_helper_integration.rb +3 -1
- data/spec/support/dependencies/factory_bot.rb +3 -1
- data/spec/support/doorkeeper_rspec.rb +3 -1
- data/spec/support/helpers/access_token_request_helper.rb +3 -1
- data/spec/support/helpers/authorization_request_helper.rb +4 -2
- data/spec/support/helpers/config_helper.rb +2 -0
- data/spec/support/helpers/model_helper.rb +3 -1
- data/spec/support/helpers/request_spec_helper.rb +5 -3
- data/spec/support/helpers/url_helper.rb +9 -7
- data/spec/support/http_method_shim.rb +4 -9
- data/spec/support/orm/active_record.rb +3 -1
- data/spec/support/shared/controllers_shared_context.rb +18 -16
- data/spec/support/shared/hashing_shared_context.rb +3 -3
- data/spec/support/shared/models_shared_examples.rb +12 -10
- data/spec/validators/redirect_uri_validator_spec.rb +74 -45
- data/spec/version/version_spec.rb +7 -5
- metadata +12 -16
- data/gemfiles/rails_4_2.gemfile +0 -17
- data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -8
- data/spec/support/ruby_2_6_rails_4_2_patch.rb +0 -14
@@ -1,34 +1,36 @@
|
|
1
|
-
|
2
|
-
require 'generators/doorkeeper/install_generator'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
require "generators/doorkeeper/install_generator"
|
5
|
+
|
6
|
+
describe "Doorkeeper::InstallGenerator" do
|
5
7
|
include GeneratorSpec::TestCase
|
6
8
|
|
7
9
|
tests Doorkeeper::InstallGenerator
|
8
|
-
destination ::File.expand_path(
|
10
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
9
11
|
|
10
|
-
describe
|
12
|
+
describe "after running the generator" do
|
11
13
|
before :each do
|
12
14
|
prepare_destination
|
13
|
-
FileUtils.mkdir(::File.expand_path(
|
14
|
-
FileUtils.mkdir(::File.expand_path(
|
15
|
+
FileUtils.mkdir(::File.expand_path("config", Pathname(destination_root)))
|
16
|
+
FileUtils.mkdir(::File.expand_path("db", Pathname(destination_root)))
|
15
17
|
FileUtils.copy_file(
|
16
|
-
::File.expand_path(
|
17
|
-
::File.expand_path(
|
18
|
+
::File.expand_path("../templates/routes.rb", __FILE__),
|
19
|
+
::File.expand_path("config/routes.rb", Pathname.new(destination_root))
|
18
20
|
)
|
19
21
|
run_generator
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
23
|
-
assert_file
|
24
|
+
it "creates an initializer file" do
|
25
|
+
assert_file "config/initializers/doorkeeper.rb"
|
24
26
|
end
|
25
27
|
|
26
|
-
it
|
27
|
-
assert_file
|
28
|
+
it "copies the locale file" do
|
29
|
+
assert_file "config/locales/doorkeeper.en.yml"
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
31
|
-
assert_file
|
32
|
+
it "adds sample route" do
|
33
|
+
assert_file "config/routes.rb", /use_doorkeeper/
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -1,40 +1,27 @@
|
|
1
|
-
|
2
|
-
require 'generators/doorkeeper/migration_generator'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
require "generators/doorkeeper/migration_generator"
|
5
|
+
|
6
|
+
describe "Doorkeeper::MigrationGenerator" do
|
5
7
|
include GeneratorSpec::TestCase
|
6
8
|
|
7
9
|
tests Doorkeeper::MigrationGenerator
|
8
|
-
destination ::File.expand_path(
|
10
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
9
11
|
|
10
|
-
describe
|
12
|
+
describe "after running the generator" do
|
11
13
|
before :each do
|
12
14
|
prepare_destination
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
stub_const('ActiveRecord::VERSION::MINOR', 2)
|
19
|
-
|
20
|
-
run_generator
|
21
|
-
|
22
|
-
assert_migration 'db/migrate/create_doorkeeper_tables.rb' do |migration|
|
23
|
-
assert migration.include?("ActiveRecord::Migration\n")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'post Rails 5.0.0' do
|
29
|
-
it 'creates a migration with a version specifier' do
|
30
|
-
stub_const('ActiveRecord::VERSION::MAJOR', 5)
|
31
|
-
stub_const('ActiveRecord::VERSION::MINOR', 0)
|
17
|
+
it "creates a migration with a version specifier" do
|
18
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 5)
|
19
|
+
stub_const("ActiveRecord::VERSION::MINOR", 0)
|
32
20
|
|
33
|
-
|
21
|
+
run_generator
|
34
22
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
23
|
+
assert_migration "db/migrate/create_doorkeeper_tables.rb" do |migration|
|
24
|
+
assert migration.include?("ActiveRecord::Migration[5.0]\n")
|
38
25
|
end
|
39
26
|
end
|
40
27
|
end
|
@@ -1,42 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "generators/doorkeeper/pkce_generator"
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe "Doorkeeper::PkceGenerator" do
|
7
7
|
include GeneratorSpec::TestCase
|
8
8
|
|
9
9
|
tests Doorkeeper::PkceGenerator
|
10
|
-
destination ::File.expand_path(
|
10
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
11
11
|
|
12
|
-
describe
|
12
|
+
describe "after running the generator" do
|
13
13
|
before :each do
|
14
14
|
prepare_destination
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
stub_const("ActiveRecord::VERSION::MINOR", 2)
|
17
|
+
it "creates a migration with a version specifier" do
|
18
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 5)
|
19
|
+
stub_const("ActiveRecord::VERSION::MINOR", 0)
|
21
20
|
|
22
|
-
|
21
|
+
run_generator
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'post Rails 5.0.0' do
|
31
|
-
it 'creates a migration with a version specifier' do
|
32
|
-
stub_const("ActiveRecord::VERSION::MAJOR", 5)
|
33
|
-
stub_const("ActiveRecord::VERSION::MINOR", 0)
|
34
|
-
|
35
|
-
run_generator
|
36
|
-
|
37
|
-
assert_migration 'db/migrate/enable_pkce.rb' do |migration|
|
38
|
-
assert migration.include?("ActiveRecord::Migration[5.0]\n")
|
39
|
-
end
|
23
|
+
assert_migration "db/migrate/enable_pkce.rb" do |migration|
|
24
|
+
assert migration.include?("ActiveRecord::Migration[5.0]\n")
|
40
25
|
end
|
41
26
|
end
|
42
27
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
require 'generators/doorkeeper/previous_refresh_token_generator'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
require "generators/doorkeeper/previous_refresh_token_generator"
|
5
|
+
|
6
|
+
describe "Doorkeeper::PreviousRefreshTokenGenerator" do
|
5
7
|
include GeneratorSpec::TestCase
|
6
8
|
|
7
9
|
tests Doorkeeper::PreviousRefreshTokenGenerator
|
8
|
-
destination ::File.expand_path(
|
10
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
9
11
|
|
10
|
-
describe
|
12
|
+
describe "after running the generator" do
|
11
13
|
before :each do
|
12
14
|
prepare_destination
|
13
15
|
|
@@ -16,41 +18,26 @@ describe 'Doorkeeper::PreviousRefreshTokenGenerator' do
|
|
16
18
|
)
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
stub_const('ActiveRecord::VERSION::MINOR', 2)
|
23
|
-
|
24
|
-
run_generator
|
25
|
-
|
26
|
-
assert_migration 'db/migrate/add_previous_refresh_token_to_access_tokens.rb' do |migration|
|
27
|
-
assert migration.include?("ActiveRecord::Migration\n")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'post Rails 5.0.0' do
|
33
|
-
it 'creates a migration with a version specifier' do
|
34
|
-
stub_const('ActiveRecord::VERSION::MAJOR', 5)
|
35
|
-
stub_const('ActiveRecord::VERSION::MINOR', 0)
|
21
|
+
it "creates a migration with a version specifier" do
|
22
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 5)
|
23
|
+
stub_const("ActiveRecord::VERSION::MINOR", 0)
|
36
24
|
|
37
|
-
|
25
|
+
run_generator
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
27
|
+
assert_migration "db/migrate/add_previous_refresh_token_to_access_tokens.rb" do |migration|
|
28
|
+
assert migration.include?("ActiveRecord::Migration[5.0]\n")
|
42
29
|
end
|
43
30
|
end
|
44
31
|
|
45
|
-
context
|
46
|
-
it
|
32
|
+
context "already exist" do
|
33
|
+
it "does not create a migration" do
|
47
34
|
allow_any_instance_of(Doorkeeper::PreviousRefreshTokenGenerator).to(
|
48
35
|
receive(:no_previous_refresh_token_column?).and_call_original
|
49
36
|
)
|
50
37
|
|
51
38
|
run_generator
|
52
39
|
|
53
|
-
assert_no_migration
|
40
|
+
assert_no_migration "db/migrate/add_previous_refresh_token_to_access_tokens.rb"
|
54
41
|
end
|
55
42
|
end
|
56
43
|
end
|
@@ -1,27 +1,29 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "generators/doorkeeper/views_generator"
|
3
5
|
|
4
6
|
describe Doorkeeper::Generators::ViewsGenerator do
|
5
7
|
include GeneratorSpec::TestCase
|
6
8
|
|
7
9
|
tests Doorkeeper::Generators::ViewsGenerator
|
8
|
-
destination File.expand_path(
|
10
|
+
destination File.expand_path("tmp/dummy", __dir__)
|
9
11
|
|
10
12
|
before :each do
|
11
13
|
prepare_destination
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
16
|
+
it "create all views" do
|
15
17
|
run_generator
|
16
|
-
assert_file
|
17
|
-
assert_file
|
18
|
-
assert_file
|
19
|
-
assert_file
|
20
|
-
assert_file
|
18
|
+
assert_file "app/views/doorkeeper/applications/_form.html.erb"
|
19
|
+
assert_file "app/views/doorkeeper/applications/edit.html.erb"
|
20
|
+
assert_file "app/views/doorkeeper/applications/index.html.erb"
|
21
|
+
assert_file "app/views/doorkeeper/applications/new.html.erb"
|
22
|
+
assert_file "app/views/doorkeeper/applications/show.html.erb"
|
21
23
|
|
22
|
-
assert_file
|
23
|
-
assert_file
|
24
|
+
assert_file "app/views/doorkeeper/authorizations/error.html.erb"
|
25
|
+
assert_file "app/views/doorkeeper/authorizations/new.html.erb"
|
24
26
|
|
25
|
-
assert_file
|
27
|
+
assert_file "app/views/doorkeeper/authorized_applications/index.html.erb"
|
26
28
|
end
|
27
29
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "grape"
|
5
|
+
require "rack/test"
|
6
|
+
require "doorkeeper/grape/helpers"
|
5
7
|
|
6
8
|
# Test Grape API application
|
7
9
|
module GrapeApp
|
8
10
|
class API < Grape::API
|
9
|
-
version
|
11
|
+
version "v1", using: :path
|
10
12
|
format :json
|
11
13
|
prefix :api
|
12
14
|
|
@@ -17,7 +19,7 @@ module GrapeApp
|
|
17
19
|
doorkeeper_authorize!
|
18
20
|
end
|
19
21
|
|
20
|
-
desc
|
22
|
+
desc "Protected resource, requires token."
|
21
23
|
|
22
24
|
get :status do
|
23
25
|
{ token: doorkeeper_token.token }
|
@@ -29,10 +31,10 @@ module GrapeApp
|
|
29
31
|
doorkeeper_authorize!
|
30
32
|
end
|
31
33
|
|
32
|
-
desc
|
34
|
+
desc "Protected resource, requires token with scopes (defined in endpoint)."
|
33
35
|
|
34
36
|
get :status, scopes: [:admin] do
|
35
|
-
{ response:
|
37
|
+
{ response: "OK" }
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -41,10 +43,10 @@ module GrapeApp
|
|
41
43
|
doorkeeper_authorize! :admin
|
42
44
|
end
|
43
45
|
|
44
|
-
desc
|
46
|
+
desc "Protected resource, requires token with scopes (defined in helper)."
|
45
47
|
|
46
48
|
get :status do
|
47
|
-
{ response:
|
49
|
+
{ response: "OK" }
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
@@ -52,13 +54,13 @@ module GrapeApp
|
|
52
54
|
desc "Public resource, no token required."
|
53
55
|
|
54
56
|
get :status do
|
55
|
-
{ response:
|
57
|
+
{ response: "OK" }
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
describe
|
63
|
+
describe "Grape integration" do
|
62
64
|
include Rack::Test::Methods
|
63
65
|
|
64
66
|
def app
|
@@ -70,66 +72,66 @@ describe 'Grape integration' do
|
|
70
72
|
end
|
71
73
|
|
72
74
|
let(:client) { FactoryBot.create(:application) }
|
73
|
-
let(:resource) { FactoryBot.create(:doorkeeper_testing_user, name:
|
75
|
+
let(:resource) { FactoryBot.create(:doorkeeper_testing_user, name: "Joe", password: "sekret") }
|
74
76
|
let(:access_token) { client_is_authorized(client, resource) }
|
75
77
|
|
76
|
-
context
|
77
|
-
it
|
78
|
+
context "with valid Access Token" do
|
79
|
+
it "successfully requests protected resource" do
|
78
80
|
get "api/v1/protected/status.json?access_token=#{access_token.token}"
|
79
81
|
|
80
82
|
expect(last_response).to be_successful
|
81
83
|
|
82
|
-
expect(json_body[
|
84
|
+
expect(json_body["token"]).to eq(access_token.token)
|
83
85
|
end
|
84
86
|
|
85
|
-
it
|
86
|
-
access_token = client_is_authorized(client, resource, scopes:
|
87
|
+
it "successfully requests protected resource with token that has required scopes (Grape endpoint)" do
|
88
|
+
access_token = client_is_authorized(client, resource, scopes: "admin")
|
87
89
|
|
88
90
|
get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
|
89
91
|
|
90
92
|
expect(last_response).to be_successful
|
91
|
-
expect(json_body).to have_key(
|
93
|
+
expect(json_body).to have_key("response")
|
92
94
|
end
|
93
95
|
|
94
|
-
it
|
95
|
-
access_token = client_is_authorized(client, resource, scopes:
|
96
|
+
it "successfully requests protected resource with token that has required scopes (Doorkeeper helper)" do
|
97
|
+
access_token = client_is_authorized(client, resource, scopes: "admin")
|
96
98
|
|
97
99
|
get "api/v1/protected_with_helper_scopes/status.json?access_token=#{access_token.token}"
|
98
100
|
|
99
101
|
expect(last_response).to be_successful
|
100
|
-
expect(json_body).to have_key(
|
102
|
+
expect(json_body).to have_key("response")
|
101
103
|
end
|
102
104
|
|
103
|
-
it
|
105
|
+
it "successfully requests public resource" do
|
104
106
|
get "api/v1/public/status.json"
|
105
107
|
|
106
108
|
expect(last_response).to be_successful
|
107
|
-
expect(json_body).to have_key(
|
109
|
+
expect(json_body).to have_key("response")
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
111
|
-
context
|
112
|
-
it
|
113
|
+
context "with invalid Access Token" do
|
114
|
+
it "fails without access token" do
|
113
115
|
get "api/v1/protected/status.json"
|
114
116
|
|
115
117
|
expect(last_response).not_to be_successful
|
116
|
-
expect(json_body).to have_key(
|
118
|
+
expect(json_body).to have_key("error")
|
117
119
|
end
|
118
120
|
|
119
|
-
it
|
121
|
+
it "fails for access token without scopes" do
|
120
122
|
get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
|
121
123
|
|
122
124
|
expect(last_response).not_to be_successful
|
123
|
-
expect(json_body).to have_key(
|
125
|
+
expect(json_body).to have_key("error")
|
124
126
|
end
|
125
127
|
|
126
|
-
it
|
127
|
-
access_token = client_is_authorized(client, resource, scopes:
|
128
|
+
it "fails for access token with invalid scopes" do
|
129
|
+
access_token = client_is_authorized(client, resource, scopes: "read write")
|
128
130
|
|
129
131
|
get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
|
130
132
|
|
131
133
|
expect(last_response).not_to be_successful
|
132
|
-
expect(json_body).to have_key(
|
134
|
+
expect(json_body).to have_key("error")
|
133
135
|
end
|
134
136
|
end
|
135
137
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
describe Doorkeeper::DashboardHelper do
|
4
|
-
describe
|
6
|
+
describe "#doorkeeper_errors_for" do
|
5
7
|
let(:object) { double errors: { method: messages } }
|
6
|
-
let(:messages) { [
|
8
|
+
let(:messages) { ["first message", "second message"] }
|
7
9
|
|
8
|
-
context
|
9
|
-
it
|
10
|
+
context "when object has errors" do
|
11
|
+
it "returns error messages" do
|
10
12
|
messages.each do |message|
|
11
13
|
expect(helper.doorkeeper_errors_for(object, :method)).to include(
|
12
14
|
message.capitalize
|
@@ -15,8 +17,8 @@ describe Doorkeeper::DashboardHelper do
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
context
|
19
|
-
it
|
20
|
+
context "when object has no errors" do
|
21
|
+
it "returns nil" do
|
20
22
|
expect(helper.doorkeeper_errors_for(object, :amonter_method)).to be_nil
|
21
23
|
end
|
22
24
|
end
|