doorkeeper 5.0.3 → 5.1.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.
- checksums.yaml +4 -4
- data/.hound.yml +2 -1
- data/.rubocop.yml +37 -4
- data/.travis.yml +11 -21
- data/Appraisals +29 -7
- data/Dangerfile +5 -2
- data/Gemfile +19 -5
- data/NEWS.md +81 -21
- data/README.md +75 -485
- 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 +20 -8
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +2 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +11 -11
- 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/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/layouts/doorkeeper/admin.html.erb +5 -3
- data/bin/console +16 -0
- data/config/locales/en.yml +1 -0
- data/doorkeeper.gemspec +24 -21
- data/gemfiles/rails_5_0.gemfile +9 -4
- data/gemfiles/rails_5_1.gemfile +9 -4
- data/gemfiles/rails_5_2.gemfile +10 -5
- data/gemfiles/rails_6_0.gemfile +17 -0
- data/gemfiles/rails_master.gemfile +9 -9
- data/lib/doorkeeper/config/option.rb +64 -0
- data/lib/doorkeeper/config.rb +191 -75
- 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 +3 -2
- data/lib/doorkeeper/models/access_grant_mixin.rb +20 -3
- data/lib/doorkeeper/models/access_token_mixin.rb +63 -19
- data/lib/doorkeeper/models/application_mixin.rb +43 -1
- data/lib/doorkeeper/models/concerns/expirable.rb +4 -2
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -6
- data/lib/doorkeeper/models/concerns/reusable.rb +19 -0
- data/lib/doorkeeper/models/concerns/revocable.rb +2 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
- data/lib/doorkeeper/models/concerns/secret_storable.rb +108 -0
- data/lib/doorkeeper/oauth/authorization/code.rb +2 -2
- data/lib/doorkeeper/oauth/authorization/token.rb +12 -7
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +6 -4
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +5 -4
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
- data/lib/doorkeeper/oauth/code_response.rb +2 -2
- data/lib/doorkeeper/oauth/error_response.rb +10 -6
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +23 -8
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +13 -1
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +37 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -2
- data/lib/doorkeeper/oauth/pre_authorization.rb +11 -5
- data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -2
- data/lib/doorkeeper/oauth/scopes.rb +5 -3
- data/lib/doorkeeper/oauth/token.rb +2 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +74 -8
- data/lib/doorkeeper/oauth/token_response.rb +9 -9
- data/lib/doorkeeper/oauth.rb +5 -5
- data/lib/doorkeeper/orm/active_record/access_grant.rb +27 -13
- data/lib/doorkeeper/orm/active_record/access_token.rb +6 -13
- data/lib/doorkeeper/orm/active_record/application.rb +21 -57
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -3
- data/lib/doorkeeper/orm/active_record.rb +6 -6
- data/lib/doorkeeper/rails/helpers.rb +1 -1
- data/lib/doorkeeper/rails/routes/mapping.rb +7 -7
- data/lib/doorkeeper/rails/routes.rb +11 -11
- data/lib/doorkeeper/rake/db.rake +13 -13
- data/lib/doorkeeper/rake.rb +1 -1
- data/lib/doorkeeper/request.rb +1 -1
- data/lib/doorkeeper/secret_storing/base.rb +64 -0
- data/lib/doorkeeper/secret_storing/bcrypt.rb +60 -0
- data/lib/doorkeeper/secret_storing/plain.rb +33 -0
- data/lib/doorkeeper/secret_storing/sha256_hash.rb +26 -0
- data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
- data/lib/doorkeeper/version.rb +3 -3
- data/lib/doorkeeper.rb +69 -60
- 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 +120 -13
- 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 +24 -10
- data/spec/controllers/applications_controller_spec.rb +54 -52
- data/spec/controllers/authorizations_controller_spec.rb +139 -145
- data/spec/controllers/protected_resources_controller_spec.rb +78 -76
- data/spec/controllers/token_info_controller_spec.rb +14 -12
- data/spec/controllers/tokens_controller_spec.rb +167 -108
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +3 -1
- 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/application.rb +25 -1
- 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/config.ru +3 -1
- 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 +8 -6
- 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 +268 -99
- data/spec/lib/doorkeeper_spec.rb +3 -1
- data/spec/lib/models/expirable_spec.rb +22 -8
- data/spec/lib/models/reusable_spec.rb +40 -0
- data/spec/lib/models/revocable_spec.rb +8 -6
- data/spec/lib/models/scopes_spec.rb +27 -13
- data/spec/lib/models/secret_storable_spec.rb +135 -0
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +17 -15
- data/spec/lib/oauth/authorization_code_request_spec.rb +34 -11
- 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 +56 -10
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +27 -18
- data/spec/lib/oauth/client_credentials/validation_spec.rb +20 -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 +19 -11
- 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 +68 -31
- data/spec/lib/oauth/helpers/unique_token_spec.rb +8 -6
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +115 -95
- data/spec/lib/oauth/invalid_token_response_spec.rb +3 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +79 -30
- data/spec/lib/oauth/pre_authorization_spec.rb +80 -54
- 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 +79 -24
- data/spec/lib/oauth/token_response_spec.rb +40 -38
- data/spec/lib/oauth/token_spec.rb +60 -44
- data/spec/lib/request/strategy_spec.rb +3 -1
- data/spec/lib/secret_storing/base_spec.rb +60 -0
- data/spec/lib/secret_storing/bcrypt_spec.rb +49 -0
- data/spec/lib/secret_storing/plain_spec.rb +44 -0
- data/spec/lib/secret_storing/sha256_hash_spec.rb +48 -0
- 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 +80 -15
- data/spec/models/doorkeeper/access_token_spec.rb +198 -73
- data/spec/models/doorkeeper/application_spec.rb +280 -288
- 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 +193 -151
- data/spec/requests/flows/client_credentials_spec.rb +54 -52
- 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 +59 -55
- data/spec/requests/flows/refresh_token_spec.rb +45 -43
- data/spec/requests/flows/revoke_token_spec.rb +40 -54
- 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 +71 -65
- data/spec/routing/default_routes_spec.rb +22 -20
- data/spec/routing/scoped_routes_spec.rb +20 -18
- data/spec/spec_helper.rb +15 -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 +36 -0
- 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 +60 -26
- data/gemfiles/rails_4_2.gemfile +0 -13
- data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -8
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Custom controller for routes" do
|
|
4
6
|
before :all do
|
|
7
|
+
Doorkeeper.configure do
|
|
8
|
+
orm DOORKEEPER_ORM
|
|
9
|
+
end
|
|
10
|
+
|
|
5
11
|
Rails.application.routes.disable_clear_and_finalize = true
|
|
6
12
|
|
|
7
13
|
Rails.application.routes.draw do
|
|
8
|
-
scope
|
|
9
|
-
use_doorkeeper scope:
|
|
10
|
-
controllers authorizations:
|
|
11
|
-
tokens:
|
|
12
|
-
applications:
|
|
13
|
-
token_info:
|
|
14
|
-
|
|
15
|
-
as authorizations:
|
|
16
|
-
tokens:
|
|
17
|
-
token_info:
|
|
14
|
+
scope "inner_space" do
|
|
15
|
+
use_doorkeeper scope: "scope" do
|
|
16
|
+
controllers authorizations: "custom_authorizations",
|
|
17
|
+
tokens: "custom_authorizations",
|
|
18
|
+
applications: "custom_authorizations",
|
|
19
|
+
token_info: "custom_authorizations"
|
|
20
|
+
|
|
21
|
+
as authorizations: "custom_auth",
|
|
22
|
+
tokens: "custom_token",
|
|
23
|
+
token_info: "custom_token_info"
|
|
18
24
|
end
|
|
19
25
|
end
|
|
20
26
|
|
|
21
|
-
scope
|
|
27
|
+
scope "space" do
|
|
22
28
|
use_doorkeeper do
|
|
23
|
-
controllers authorizations:
|
|
24
|
-
tokens:
|
|
25
|
-
applications:
|
|
26
|
-
token_info:
|
|
27
|
-
|
|
28
|
-
as authorizations:
|
|
29
|
-
tokens:
|
|
30
|
-
token_info:
|
|
29
|
+
controllers authorizations: "custom_authorizations",
|
|
30
|
+
tokens: "custom_authorizations",
|
|
31
|
+
applications: "custom_authorizations",
|
|
32
|
+
token_info: "custom_authorizations"
|
|
33
|
+
|
|
34
|
+
as authorizations: "custom_auth",
|
|
35
|
+
tokens: "custom_token",
|
|
36
|
+
token_info: "custom_token_info"
|
|
31
37
|
end
|
|
32
38
|
end
|
|
33
39
|
|
|
34
|
-
scope
|
|
40
|
+
scope "outer_space" do
|
|
35
41
|
use_doorkeeper do
|
|
36
|
-
controllers authorizations:
|
|
37
|
-
tokens:
|
|
38
|
-
token_info:
|
|
42
|
+
controllers authorizations: "custom_authorizations",
|
|
43
|
+
tokens: "custom_authorizations",
|
|
44
|
+
token_info: "custom_authorizations"
|
|
39
45
|
|
|
40
|
-
as authorizations:
|
|
41
|
-
tokens:
|
|
42
|
-
token_info:
|
|
46
|
+
as authorizations: "custom_auth",
|
|
47
|
+
tokens: "custom_token",
|
|
48
|
+
token_info: "custom_token_info"
|
|
43
49
|
|
|
44
50
|
skip_controllers :tokens, :applications, :token_info
|
|
45
51
|
end
|
|
@@ -50,78 +56,78 @@ describe 'Custom controller for routes' do
|
|
|
50
56
|
after :all do
|
|
51
57
|
Rails.application.routes.clear!
|
|
52
58
|
|
|
53
|
-
load File.expand_path(
|
|
59
|
+
load File.expand_path("../dummy/config/routes.rb", __dir__)
|
|
54
60
|
end
|
|
55
61
|
|
|
56
|
-
it
|
|
57
|
-
expect(get(
|
|
62
|
+
it "GET /inner_space/scope/authorize routes to custom authorizations controller" do
|
|
63
|
+
expect(get("/inner_space/scope/authorize")).to route_to("custom_authorizations#new")
|
|
58
64
|
end
|
|
59
65
|
|
|
60
|
-
it
|
|
61
|
-
expect(post(
|
|
66
|
+
it "POST /inner_space/scope/authorize routes to custom authorizations controller" do
|
|
67
|
+
expect(post("/inner_space/scope/authorize")).to route_to("custom_authorizations#create")
|
|
62
68
|
end
|
|
63
69
|
|
|
64
|
-
it
|
|
65
|
-
expect(delete(
|
|
70
|
+
it "DELETE /inner_space/scope/authorize routes to custom authorizations controller" do
|
|
71
|
+
expect(delete("/inner_space/scope/authorize")).to route_to("custom_authorizations#destroy")
|
|
66
72
|
end
|
|
67
73
|
|
|
68
|
-
it
|
|
69
|
-
expect(post(
|
|
74
|
+
it "POST /inner_space/scope/token routes to tokens controller" do
|
|
75
|
+
expect(post("/inner_space/scope/token")).to route_to("custom_authorizations#create")
|
|
70
76
|
end
|
|
71
77
|
|
|
72
|
-
it
|
|
73
|
-
expect(get(
|
|
78
|
+
it "GET /inner_space/scope/applications routes to applications controller" do
|
|
79
|
+
expect(get("/inner_space/scope/applications")).to route_to("custom_authorizations#index")
|
|
74
80
|
end
|
|
75
81
|
|
|
76
|
-
it
|
|
77
|
-
expect(get(
|
|
82
|
+
it "GET /inner_space/scope/token/info routes to the token_info controller" do
|
|
83
|
+
expect(get("/inner_space/scope/token/info")).to route_to("custom_authorizations#show")
|
|
78
84
|
end
|
|
79
85
|
|
|
80
|
-
it
|
|
81
|
-
expect(get(
|
|
86
|
+
it "GET /space/oauth/authorize routes to custom authorizations controller" do
|
|
87
|
+
expect(get("/space/oauth/authorize")).to route_to("custom_authorizations#new")
|
|
82
88
|
end
|
|
83
89
|
|
|
84
|
-
it
|
|
85
|
-
expect(post(
|
|
90
|
+
it "POST /space/oauth/authorize routes to custom authorizations controller" do
|
|
91
|
+
expect(post("/space/oauth/authorize")).to route_to("custom_authorizations#create")
|
|
86
92
|
end
|
|
87
93
|
|
|
88
|
-
it
|
|
89
|
-
expect(delete(
|
|
94
|
+
it "DELETE /space/oauth/authorize routes to custom authorizations controller" do
|
|
95
|
+
expect(delete("/space/oauth/authorize")).to route_to("custom_authorizations#destroy")
|
|
90
96
|
end
|
|
91
97
|
|
|
92
|
-
it
|
|
93
|
-
expect(post(
|
|
98
|
+
it "POST /space/oauth/token routes to tokens controller" do
|
|
99
|
+
expect(post("/space/oauth/token")).to route_to("custom_authorizations#create")
|
|
94
100
|
end
|
|
95
101
|
|
|
96
|
-
it
|
|
97
|
-
expect(post(
|
|
102
|
+
it "POST /space/oauth/revoke routes to tokens controller" do
|
|
103
|
+
expect(post("/space/oauth/revoke")).to route_to("custom_authorizations#revoke")
|
|
98
104
|
end
|
|
99
105
|
|
|
100
|
-
it
|
|
101
|
-
expect(post(
|
|
106
|
+
it "POST /space/oauth/introspect routes to tokens controller" do
|
|
107
|
+
expect(post("/space/oauth/introspect")).to route_to("custom_authorizations#introspect")
|
|
102
108
|
end
|
|
103
109
|
|
|
104
|
-
it
|
|
105
|
-
expect(get(
|
|
110
|
+
it "GET /space/oauth/applications routes to applications controller" do
|
|
111
|
+
expect(get("/space/oauth/applications")).to route_to("custom_authorizations#index")
|
|
106
112
|
end
|
|
107
113
|
|
|
108
|
-
it
|
|
109
|
-
expect(get(
|
|
114
|
+
it "GET /space/oauth/token/info routes to the token_info controller" do
|
|
115
|
+
expect(get("/space/oauth/token/info")).to route_to("custom_authorizations#show")
|
|
110
116
|
end
|
|
111
117
|
|
|
112
|
-
it
|
|
113
|
-
expect(post(
|
|
118
|
+
it "POST /outer_space/oauth/token is not be routable" do
|
|
119
|
+
expect(post("/outer_space/oauth/token")).not_to be_routable
|
|
114
120
|
end
|
|
115
121
|
|
|
116
|
-
it
|
|
117
|
-
expect(get(
|
|
122
|
+
it "GET /outer_space/oauth/authorize routes to custom authorizations controller" do
|
|
123
|
+
expect(get("/outer_space/oauth/authorize")).to be_routable
|
|
118
124
|
end
|
|
119
125
|
|
|
120
|
-
it
|
|
121
|
-
expect(get(
|
|
126
|
+
it "GET /outer_space/oauth/applications is not routable" do
|
|
127
|
+
expect(get("/outer_space/oauth/applications")).not_to be_routable
|
|
122
128
|
end
|
|
123
129
|
|
|
124
|
-
it
|
|
125
|
-
expect(get(
|
|
130
|
+
it "GET /outer_space/oauth/token_info is not routable" do
|
|
131
|
+
expect(get("/outer_space/oauth/token/info")).not_to be_routable
|
|
126
132
|
end
|
|
127
133
|
end
|
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Default routes" do
|
|
6
|
+
it "GET /oauth/authorize routes to authorizations controller" do
|
|
7
|
+
expect(get("/oauth/authorize")).to route_to("doorkeeper/authorizations#new")
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
it
|
|
9
|
-
expect(post(
|
|
10
|
+
it "POST /oauth/authorize routes to authorizations controller" do
|
|
11
|
+
expect(post("/oauth/authorize")).to route_to("doorkeeper/authorizations#create")
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
it
|
|
13
|
-
expect(delete(
|
|
14
|
+
it "DELETE /oauth/authorize routes to authorizations controller" do
|
|
15
|
+
expect(delete("/oauth/authorize")).to route_to("doorkeeper/authorizations#destroy")
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
it
|
|
17
|
-
expect(post(
|
|
18
|
+
it "POST /oauth/token routes to tokens controller" do
|
|
19
|
+
expect(post("/oauth/token")).to route_to("doorkeeper/tokens#create")
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
it
|
|
21
|
-
expect(post(
|
|
22
|
+
it "POST /oauth/revoke routes to tokens controller" do
|
|
23
|
+
expect(post("/oauth/revoke")).to route_to("doorkeeper/tokens#revoke")
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
it
|
|
25
|
-
expect(post(
|
|
26
|
+
it "POST /oauth/introspect routes to tokens controller" do
|
|
27
|
+
expect(post("/oauth/introspect")).to route_to("doorkeeper/tokens#introspect")
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
it
|
|
29
|
-
expect(get(
|
|
30
|
+
it "GET /oauth/applications routes to applications controller" do
|
|
31
|
+
expect(get("/oauth/applications")).to route_to("doorkeeper/applications#index")
|
|
30
32
|
end
|
|
31
33
|
|
|
32
|
-
it
|
|
33
|
-
expect(get(
|
|
34
|
+
it "GET /oauth/authorized_applications routes to authorized applications controller" do
|
|
35
|
+
expect(get("/oauth/authorized_applications")).to route_to("doorkeeper/authorized_applications#index")
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
it
|
|
37
|
-
expect(get(
|
|
38
|
+
it "GET /oauth/token/info route to authorized TokenInfo controller" do
|
|
39
|
+
expect(get("/oauth/token/info")).to route_to("doorkeeper/token_info#show")
|
|
38
40
|
end
|
|
39
41
|
end
|
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Scoped routes" do
|
|
4
6
|
before :all do
|
|
5
7
|
Rails.application.routes.disable_clear_and_finalize = true
|
|
6
8
|
|
|
7
9
|
Rails.application.routes.draw do
|
|
8
|
-
use_doorkeeper scope:
|
|
10
|
+
use_doorkeeper scope: "scope"
|
|
9
11
|
end
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
after :all do
|
|
13
15
|
Rails.application.routes.clear!
|
|
14
16
|
|
|
15
|
-
load File.expand_path(
|
|
17
|
+
load File.expand_path("../dummy/config/routes.rb", __dir__)
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
it
|
|
19
|
-
expect(get(
|
|
20
|
+
it "GET /scope/authorize routes to authorizations controller" do
|
|
21
|
+
expect(get("/scope/authorize")).to route_to("doorkeeper/authorizations#new")
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
it
|
|
23
|
-
expect(post(
|
|
24
|
+
it "POST /scope/authorize routes to authorizations controller" do
|
|
25
|
+
expect(post("/scope/authorize")).to route_to("doorkeeper/authorizations#create")
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
it
|
|
27
|
-
expect(delete(
|
|
28
|
+
it "DELETE /scope/authorize routes to authorizations controller" do
|
|
29
|
+
expect(delete("/scope/authorize")).to route_to("doorkeeper/authorizations#destroy")
|
|
28
30
|
end
|
|
29
31
|
|
|
30
|
-
it
|
|
31
|
-
expect(post(
|
|
32
|
+
it "POST /scope/token routes to tokens controller" do
|
|
33
|
+
expect(post("/scope/token")).to route_to("doorkeeper/tokens#create")
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
it
|
|
35
|
-
expect(get(
|
|
36
|
+
it "GET /scope/applications routes to applications controller" do
|
|
37
|
+
expect(get("/scope/applications")).to route_to("doorkeeper/applications#index")
|
|
36
38
|
end
|
|
37
39
|
|
|
38
|
-
it
|
|
39
|
-
expect(get(
|
|
40
|
+
it "GET /scope/authorized_applications routes to authorized applications controller" do
|
|
41
|
+
expect(get("/scope/authorized_applications")).to route_to("doorkeeper/authorized_applications#index")
|
|
40
42
|
end
|
|
41
43
|
|
|
42
|
-
it
|
|
43
|
-
expect(get(
|
|
44
|
+
it "GET /scope/token/info route to authorized TokenInfo controller" do
|
|
45
|
+
expect(get("/scope/token/info")).to route_to("doorkeeper/token_info#show")
|
|
44
46
|
end
|
|
45
47
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require "coveralls"
|
|
4
|
+
|
|
5
|
+
Coveralls.wear!("rails") do
|
|
6
|
+
add_filter("/spec/")
|
|
7
|
+
add_filter("/lib/generators/doorkeeper/templates/")
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
ENV[
|
|
10
|
+
ENV["RAILS_ENV"] ||= "test"
|
|
9
11
|
|
|
10
12
|
$LOAD_PATH.unshift File.dirname(__FILE__)
|
|
11
13
|
|
|
@@ -13,22 +15,22 @@ require "#{File.dirname(__FILE__)}/support/doorkeeper_rspec.rb"
|
|
|
13
15
|
|
|
14
16
|
DOORKEEPER_ORM = Doorkeeper::RSpec.detect_orm
|
|
15
17
|
|
|
16
|
-
require
|
|
17
|
-
require
|
|
18
|
-
require
|
|
19
|
-
require
|
|
20
|
-
require
|
|
18
|
+
require "dummy/config/environment"
|
|
19
|
+
require "rspec/rails"
|
|
20
|
+
require "capybara/rspec"
|
|
21
|
+
require "database_cleaner"
|
|
22
|
+
require "generator_spec/test_case"
|
|
21
23
|
|
|
22
24
|
# Load JRuby SQLite3 if in that platform
|
|
23
25
|
if defined? JRUBY_VERSION
|
|
24
|
-
require
|
|
26
|
+
require "jdbc/sqlite3"
|
|
25
27
|
Jdbc::SQLite3.load_driver
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
Doorkeeper::RSpec.print_configuration_info
|
|
29
31
|
|
|
30
32
|
# Remove after dropping support of Rails 4.2
|
|
31
|
-
require "#{File.dirname(__FILE__)}/support/http_method_shim
|
|
33
|
+
require "#{File.dirname(__FILE__)}/support/http_method_shim"
|
|
32
34
|
|
|
33
35
|
require "support/orm/#{DOORKEEPER_ORM}"
|
|
34
36
|
|
|
@@ -51,5 +53,5 @@ RSpec.configure do |config|
|
|
|
51
53
|
DatabaseCleaner.clean
|
|
52
54
|
end
|
|
53
55
|
|
|
54
|
-
config.order =
|
|
56
|
+
config.order = "random"
|
|
55
57
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Doorkeeper
|
|
2
4
|
class RSpec
|
|
3
5
|
# Print's useful information about env: Ruby / Rails versions,
|
|
@@ -13,7 +15,7 @@ module Doorkeeper
|
|
|
13
15
|
|
|
14
16
|
# Tries to find ORM from the Gemfile used to run test suite
|
|
15
17
|
def self.detect_orm
|
|
16
|
-
orm = (ENV[
|
|
18
|
+
orm = (ENV["BUNDLE_GEMFILE"] || "").match(/Gemfile\.(.+)\.rb/)
|
|
17
19
|
(orm && orm[1] || :active_record).to_sym
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module AccessTokenRequestHelper
|
|
2
4
|
def client_is_authorized(client, resource_owner, access_token_attributes = {})
|
|
3
5
|
attributes = {
|
|
4
6
|
application: client,
|
|
5
|
-
resource_owner_id: resource_owner.id
|
|
7
|
+
resource_owner_id: resource_owner.id,
|
|
6
8
|
}.merge(access_token_attributes)
|
|
7
9
|
FactoryBot.create(:access_token, attributes)
|
|
8
10
|
end
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module AuthorizationRequestHelper
|
|
2
4
|
def resource_owner_is_authenticated(resource_owner = nil)
|
|
3
|
-
resource_owner ||= User.create!(name:
|
|
5
|
+
resource_owner ||= User.create!(name: "Joe", password: "sekret")
|
|
4
6
|
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { resource_owner })
|
|
5
7
|
end
|
|
6
8
|
|
|
7
9
|
def resource_owner_is_not_authenticated
|
|
8
|
-
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { redirect_to(
|
|
10
|
+
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { redirect_to("/sign_in") })
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def default_scopes_exist(*scopes)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ModelHelper
|
|
2
4
|
def client_exists(client_attributes = {})
|
|
3
5
|
@client = FactoryBot.create(:application, client_attributes)
|
|
4
6
|
end
|
|
5
7
|
|
|
6
8
|
def create_resource_owner
|
|
7
|
-
@resource_owner = User.create!(name:
|
|
9
|
+
@resource_owner = User.create!(name: "Joe", password: "sekret")
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def authorization_code_exists(options = {})
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RequestSpecHelper
|
|
2
4
|
def i_am_logged_in
|
|
3
5
|
allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) {})
|
|
@@ -48,7 +50,7 @@ module RequestSpecHelper
|
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
def with_access_token_header(token)
|
|
51
|
-
with_header
|
|
53
|
+
with_header "Authorization", "Bearer #{token}"
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
def with_header(header, value)
|
|
@@ -72,8 +74,8 @@ module RequestSpecHelper
|
|
|
72
74
|
end
|
|
73
75
|
|
|
74
76
|
def sign_in
|
|
75
|
-
visit
|
|
76
|
-
click_on
|
|
77
|
+
visit "/"
|
|
78
|
+
click_on "Sign in"
|
|
77
79
|
end
|
|
78
80
|
|
|
79
81
|
def create_access_token(authorization_code, client, code_verifier = nil)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module UrlHelper
|
|
2
4
|
def token_endpoint_url(options = {})
|
|
3
5
|
parameters = {
|
|
@@ -5,9 +7,9 @@ module UrlHelper
|
|
|
5
7
|
client_id: options[:client_id] || options[:client].try(:uid),
|
|
6
8
|
client_secret: options[:client_secret] || options[:client].try(:secret),
|
|
7
9
|
redirect_uri: options[:redirect_uri] || options[:client].try(:redirect_uri),
|
|
8
|
-
grant_type: options[:grant_type] ||
|
|
10
|
+
grant_type: options[:grant_type] || "authorization_code",
|
|
9
11
|
code_verifier: options[:code_verifier],
|
|
10
|
-
code_challenge_method: options[:code_challenge_method]
|
|
12
|
+
code_challenge_method: options[:code_challenge_method],
|
|
11
13
|
}.reject { |_, v| v.blank? }
|
|
12
14
|
"/oauth/token?#{build_query(parameters)}"
|
|
13
15
|
end
|
|
@@ -20,7 +22,7 @@ module UrlHelper
|
|
|
20
22
|
username: options[:resource_owner_username] || options[:resource_owner].try(:name),
|
|
21
23
|
password: options[:resource_owner_password] || options[:resource_owner].try(:password),
|
|
22
24
|
scope: options[:scope],
|
|
23
|
-
grant_type:
|
|
25
|
+
grant_type: "password",
|
|
24
26
|
}
|
|
25
27
|
"/oauth/token?#{build_query(parameters)}"
|
|
26
28
|
end
|
|
@@ -29,11 +31,11 @@ module UrlHelper
|
|
|
29
31
|
parameters = {
|
|
30
32
|
client_id: options[:client_id] || options[:client].try(:uid),
|
|
31
33
|
redirect_uri: options[:redirect_uri] || options[:client].try(:redirect_uri),
|
|
32
|
-
response_type: options[:response_type] ||
|
|
34
|
+
response_type: options[:response_type] || "code",
|
|
33
35
|
scope: options[:scope],
|
|
34
36
|
state: options[:state],
|
|
35
37
|
code_challenge: options[:code_challenge],
|
|
36
|
-
code_challenge_method: options[:code_challenge_method]
|
|
38
|
+
code_challenge_method: options[:code_challenge_method],
|
|
37
39
|
}.reject { |_, v| v.blank? }
|
|
38
40
|
"/oauth/authorize?#{build_query(parameters)}"
|
|
39
41
|
end
|
|
@@ -43,13 +45,13 @@ module UrlHelper
|
|
|
43
45
|
refresh_token: options[:refresh_token],
|
|
44
46
|
client_id: options[:client_id] || options[:client].try(:uid),
|
|
45
47
|
client_secret: options[:client_secret] || options[:client].try(:secret),
|
|
46
|
-
grant_type: options[:grant_type] ||
|
|
48
|
+
grant_type: options[:grant_type] || "refresh_token",
|
|
47
49
|
}
|
|
48
50
|
"/oauth/token?#{build_query(parameters)}"
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
def revocation_token_endpoint_url
|
|
52
|
-
|
|
54
|
+
"/oauth/revoke"
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
def build_query(hash)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Rails 5 deprecates calling HTTP action methods with positional arguments
|
|
2
4
|
# in favor of keyword arguments. However, the keyword argument form is only
|
|
3
5
|
# supported in Rails 5+. Since we support back to 4, we need some sort of shim
|
|
@@ -17,18 +19,11 @@ module RoutingHTTPMethodShim
|
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
module ControllerHTTPMethodShim
|
|
20
|
-
def process(action, http_method =
|
|
22
|
+
def process(action, http_method = "GET", **args)
|
|
21
23
|
if (as = args.delete(:as))
|
|
22
|
-
@request.headers[
|
|
24
|
+
@request.headers["Content-Type"] = Mime[as].to_s
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
super(action, http_method, args[:params], args[:session], args[:flash])
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
|
-
|
|
29
|
-
if ::Rails::VERSION::MAJOR < 5
|
|
30
|
-
RSpec.configure do |config|
|
|
31
|
-
config.include ControllerHTTPMethodShim, type: :controller
|
|
32
|
-
config.include RoutingHTTPMethodShim, type: :request
|
|
33
|
-
end
|
|
34
|
-
end
|