doorkeeper-mongodb 5.3.0 → 5.5.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/README.md +3 -3
- data/Rakefile +18 -4
- data/lib/doorkeeper/orm/mongoid9/access_grant.rb +26 -0
- data/lib/doorkeeper/orm/mongoid9/access_token.rb +38 -0
- data/lib/doorkeeper/orm/mongoid9/application.rb +43 -0
- data/lib/doorkeeper/orm/mongoid9/stale_records_cleaner.rb +11 -0
- data/lib/doorkeeper/orm/mongoid9.rb +50 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +6 -2
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +46 -6
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +2 -2
- data/lib/doorkeeper-mongodb/version.rb +1 -1
- data/lib/doorkeeper-mongodb.rb +1 -0
- data/spec/dummy/app/assets/config/manifest.js +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/controllers/home_controller.rb +0 -0
- data/spec/dummy/app/controllers/metal_controller.rb +0 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -0
- data/spec/dummy/config/application.rb +0 -0
- data/spec/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/database.yml +0 -0
- data/spec/dummy/config/environment.rb +0 -0
- data/spec/dummy/config/environments/development.rb +0 -0
- data/spec/dummy/config/environments/production.rb +0 -0
- data/spec/dummy/config/environments/test.rb +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +7 -2
- data/spec/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +0 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
- data/spec/dummy/config/mongoid8.yml +19 -0
- data/spec/dummy/config/mongoid9.yml +19 -0
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
- data/spec/dummy/db/migrate/20230205064514_add_custom_attributes.rb +8 -0
- data/spec/dummy/db/schema.rb +3 -1
- data/spec/dummy/log/test.log +39440 -0
- data/spec/dummy/public/404.html +0 -0
- data/spec/dummy/public/422.html +0 -0
- data/spec/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2L/2LdlR-88TqZc8vSU7Z58xiNpCGRZj0CIlOxSN4Vx2i4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache → 2r/2r0L9eNOmETsg4Tm1IgBdw3J4ahcko41NpILRXu19_A.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/5y/5ywocFQgpSY36nyF_xDKPExhDRo-eqeiqfDvQee1K9k.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache → 8r/8rW0CpDDUJZ7xvg86t6jZ6WmyvaVZ0uTPEPRjghFIKo.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache → Cs/CsfBL8Dls9-jhjFsNYt4DZxu5LWChDMB-xXKjsEFSsU.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache → Cv/Cv9WXE_0OqtPUZBXfTWaE8uKx9oFIzqO18ZkwVaBLSg.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Mf/MfB2-0nbsmC548XBSLftafi6BZ9nAquBA-6eu7mAmdE.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/N2/N2cUP-Um_nQ5ZTCQr_H0bKIjOSIyV7Ry5sT6-DB9e4A.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache → Ot/OtNAnT3d-csAKBtJ8UBLOSwUDyfmOdCWpS08RaSCGsQ.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/P3/P33RwiTMGEu2wZySBEUmf5U7hnfBhdL49wzdUWXYNRs.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/RZ/RZAL9gIt4aD731Ikf7UZZNPSZXzhPqtDskLB7nQcWH4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/SQ/SQVJeYO2bM0qgQiOaeVBjYo3SWQZmvixa3tXUjsmuUs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache → V2/V2JApVhUSYhvWnNVIbpe58U4xheVkpi0gCStqjDN6-A.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache → VA/VADOUaZFukufOb44ts4KoyQZumPcVJET0bi9RvC7c-o.cache} +1 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Vz/VzdPLfWn16XbpHNJdkDMamAf3QutM29cvvPkDNyy5nE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/W9/W9QfraySVwoRt-SgGOIS0e-iP8R1qP_URwXZw1l6M5E.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wy/Wyiw07ngOzgV6RPis_Lo2hhSRkwo2YSqKTEDAF0crhA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Z6/Z6rAtdVt3OXS26vLVCtdO3vmMlttI3ajdpbC2FHk7iQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache → fP/fPihom3hnc1rQQxpviTvZPRJB_IghWYWP3dDcsGrcLk.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/gD/gDU38plXvosMgFK47_PBI9xGVsmsE2tShWEZzxiek3k.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/gR/gRqL5_jaFW7eA3d2frJmOzw_vFLuvfhwMhotAlsO8J4.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache → jc/jcB8w1gBT7JP10DW4OOvvYpW1ZFeMyedngmMy3QbRLQ.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jg/jgxXkkkXf1NPOPrpNdEJzhDt-2xHGzd_-mLkIHWrOr4.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/nx/nxzZnvk5YyBhTUloQSZZ5zRuaqlsLiHy_AbOzQ3d788.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/wr/wrlf8nUW2yftpcIA97qImyECR8f8o3OiOdHLdfkmw8c.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache → xd/xdD4KJ55W3jy5PIrwT0UnDp1toKpUfgrjJBgB4WaPIc.cache} +0 -0
- data/spec/support/doorkeeper_rspec.rb +0 -0
- data/spec/support/orm/mongoid.rb +18 -2
- data/spec/support/orm/mongoid8.rb +6 -0
- data/spec/support/orm/mongoid9.rb +6 -0
- data/spec/support/render_with_matcher.rb +26 -0
- metadata +126 -241
- data/spec/controllers/application_metal_controller_spec.rb +0 -64
- data/spec/controllers/applications_controller_spec.rb +0 -270
- data/spec/controllers/authorizations_controller_spec.rb +0 -744
- data/spec/controllers/protected_resources_controller_spec.rb +0 -361
- data/spec/controllers/token_info_controller_spec.rb +0 -50
- data/spec/controllers/tokens_controller_spec.rb +0 -542
- data/spec/doorkeeper/redirect_uri_validator_spec.rb +0 -183
- data/spec/doorkeeper/server_spec.rb +0 -50
- data/spec/doorkeeper/stale_records_cleaner_spec.rb +0 -103
- data/spec/doorkeeper/version_spec.rb +0 -17
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
- data/spec/factories.rb +0 -30
- data/spec/grape/grape_integration_spec.rb +0 -137
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
- data/spec/lib/config_spec.rb +0 -824
- data/spec/lib/doorkeeper_spec.rb +0 -27
- data/spec/lib/models/expirable_spec.rb +0 -61
- data/spec/lib/models/reusable_spec.rb +0 -40
- data/spec/lib/models/revocable_spec.rb +0 -55
- data/spec/lib/models/scopes_spec.rb +0 -61
- data/spec/lib/models/secret_storable_spec.rb +0 -136
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -35
- data/spec/lib/oauth/authorization_code_request_spec.rb +0 -180
- data/spec/lib/oauth/base_request_spec.rb +0 -210
- data/spec/lib/oauth/base_response_spec.rb +0 -45
- data/spec/lib/oauth/client/credentials_spec.rb +0 -90
- data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -135
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -110
- data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -92
- data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -27
- data/spec/lib/oauth/client_credentials_request_spec.rb +0 -105
- data/spec/lib/oauth/client_spec.rb +0 -38
- data/spec/lib/oauth/code_request_spec.rb +0 -46
- data/spec/lib/oauth/code_response_spec.rb +0 -36
- data/spec/lib/oauth/error_response_spec.rb +0 -65
- data/spec/lib/oauth/error_spec.rb +0 -21
- data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -20
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -110
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -262
- data/spec/lib/oauth/invalid_request_response_spec.rb +0 -73
- data/spec/lib/oauth/invalid_token_response_spec.rb +0 -53
- data/spec/lib/oauth/password_access_token_request_spec.rb +0 -202
- data/spec/lib/oauth/pre_authorization_spec.rb +0 -230
- data/spec/lib/oauth/refresh_token_request_spec.rb +0 -166
- data/spec/lib/oauth/scopes_spec.rb +0 -146
- data/spec/lib/oauth/token_request_spec.rb +0 -164
- data/spec/lib/oauth/token_response_spec.rb +0 -84
- data/spec/lib/oauth/token_spec.rb +0 -156
- data/spec/lib/option_spec.rb +0 -51
- data/spec/lib/request/strategy_spec.rb +0 -51
- data/spec/lib/secret_storing/base_spec.rb +0 -61
- data/spec/lib/secret_storing/bcrypt_spec.rb +0 -50
- data/spec/lib/secret_storing/plain_spec.rb +0 -45
- data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -49
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -173
- data/spec/models/doorkeeper/access_token_spec.rb +0 -644
- data/spec/models/doorkeeper/application_spec.rb +0 -499
- data/spec/requests/applications/applications_request_spec.rb +0 -257
- data/spec/requests/applications/authorized_applications_spec.rb +0 -32
- data/spec/requests/endpoints/authorization_spec.rb +0 -91
- data/spec/requests/endpoints/token_spec.rb +0 -85
- data/spec/requests/flows/authorization_code_errors_spec.rb +0 -86
- data/spec/requests/flows/authorization_code_spec.rb +0 -559
- data/spec/requests/flows/client_credentials_spec.rb +0 -219
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -46
- data/spec/requests/flows/implicit_grant_spec.rb +0 -91
- data/spec/requests/flows/password_spec.rb +0 -356
- data/spec/requests/flows/refresh_token_spec.rb +0 -255
- data/spec/requests/flows/revoke_token_spec.rb +0 -196
- data/spec/requests/flows/skip_authorization_spec.rb +0 -66
- data/spec/requests/protected_resources/metal_spec.rb +0 -16
- data/spec/requests/protected_resources/private_api_spec.rb +0 -83
- data/spec/routing/custom_controller_routes_spec.rb +0 -133
- data/spec/routing/default_routes_spec.rb +0 -41
- data/spec/routing/scoped_routes_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -54
- data/spec/spec_helper_integration.rb +0 -4
- data/spec/support/dependencies/factory_bot.rb +0 -4
- data/spec/support/helpers/access_token_request_helper.rb +0 -14
- data/spec/support/helpers/authorization_request_helper.rb +0 -43
- data/spec/support/helpers/config_helper.rb +0 -11
- data/spec/support/helpers/model_helper.rb +0 -78
- data/spec/support/helpers/request_spec_helper.rb +0 -98
- data/spec/support/helpers/url_helper.rb +0 -62
- data/spec/support/orm/active_record.rb +0 -5
- data/spec/support/shared/controllers_shared_context.rb +0 -100
- data/spec/support/shared/hashing_shared_context.rb +0 -40
- data/spec/support/shared/models_shared_examples.rb +0 -56
| @@ -1,356 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require "spec_helper"
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            RSpec.describe "Resource Owner Password Credentials Flow" do
         | 
| 6 | 
            -
              context "when not setup properly" do
         | 
| 7 | 
            -
                before do
         | 
| 8 | 
            -
                  client_exists
         | 
| 9 | 
            -
                  create_resource_owner
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                context "with valid user credentials" do
         | 
| 13 | 
            -
                  it "does not issue new token" do
         | 
| 14 | 
            -
                    expect do
         | 
| 15 | 
            -
                      post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 16 | 
            -
                    end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 17 | 
            -
                  end
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
              end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              context "when grant type configured" do
         | 
| 22 | 
            -
                let(:client_attributes) { { redirect_uri: nil } }
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                before do
         | 
| 25 | 
            -
                  config_is_set(:grant_flows, ["password"])
         | 
| 26 | 
            -
                  config_is_set(:resource_owner_from_credentials) { User.authenticate! params[:username], params[:password] }
         | 
| 27 | 
            -
                  client_exists(client_attributes)
         | 
| 28 | 
            -
                  create_resource_owner
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                context "with valid user credentials" do
         | 
| 32 | 
            -
                  context "with confidential client authorized using Basic auth" do
         | 
| 33 | 
            -
                    it "issues a new token" do
         | 
| 34 | 
            -
                      expect do
         | 
| 35 | 
            -
                        post password_token_endpoint_url(
         | 
| 36 | 
            -
                          resource_owner: @resource_owner,
         | 
| 37 | 
            -
                        ), headers: { "HTTP_AUTHORIZATION" => basic_auth_header_for_client(@client) }
         | 
| 38 | 
            -
                      end.to(change { Doorkeeper::AccessToken.count })
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                      token = Doorkeeper::AccessToken.first
         | 
| 41 | 
            -
                      expect(token.application_id).to eq(@client.id)
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                      expect(json_response).to match(
         | 
| 44 | 
            -
                        "access_token" => token.token,
         | 
| 45 | 
            -
                        "expires_in" => an_instance_of(Integer),
         | 
| 46 | 
            -
                        "token_type" => "Bearer",
         | 
| 47 | 
            -
                        "created_at" => an_instance_of(Integer),
         | 
| 48 | 
            -
                      )
         | 
| 49 | 
            -
                    end
         | 
| 50 | 
            -
                  end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                  context "with non-confidential/public client" do
         | 
| 53 | 
            -
                    let(:client_attributes) { { confidential: false } }
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                    context "when configured to check application supported grant flow" do
         | 
| 56 | 
            -
                      before do
         | 
| 57 | 
            -
                        Doorkeeper.configuration.instance_variable_set(
         | 
| 58 | 
            -
                          :@allow_grant_flow_for_client,
         | 
| 59 | 
            -
                          ->(_grant_flow, client) { client.name == "admin" },
         | 
| 60 | 
            -
                        )
         | 
| 61 | 
            -
                      end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                      scenario "forbids the request when doesn't satisfy condition" do
         | 
| 64 | 
            -
                        @client.update(name: "sample app")
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                        expect do
         | 
| 67 | 
            -
                          post password_token_endpoint_url(
         | 
| 68 | 
            -
                            client_id: @client.uid,
         | 
| 69 | 
            -
                            client_secret: "foobar",
         | 
| 70 | 
            -
                            resource_owner: @resource_owner,
         | 
| 71 | 
            -
                          )
         | 
| 72 | 
            -
                        end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                        expect(response.status).to eq(401)
         | 
| 75 | 
            -
                        expect(json_response).to match(
         | 
| 76 | 
            -
                          "error" => "invalid_client",
         | 
| 77 | 
            -
                          "error_description" => an_instance_of(String),
         | 
| 78 | 
            -
                        )
         | 
| 79 | 
            -
                      end
         | 
| 80 | 
            -
             | 
| 81 | 
            -
                      scenario "allows the request when satisfies condition" do
         | 
| 82 | 
            -
                        @client.update(name: "admin")
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                        expect do
         | 
| 85 | 
            -
                          post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
         | 
| 86 | 
            -
                        end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 87 | 
            -
             | 
| 88 | 
            -
                        token = Doorkeeper::AccessToken.first
         | 
| 89 | 
            -
                        expect(token.application_id).to eq(@client.id)
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                        expect(json_response).to include("access_token" => token.token)
         | 
| 92 | 
            -
                      end
         | 
| 93 | 
            -
                    end
         | 
| 94 | 
            -
             | 
| 95 | 
            -
                    context "when client_secret absent" do
         | 
| 96 | 
            -
                      it "issues a new token" do
         | 
| 97 | 
            -
                        expect do
         | 
| 98 | 
            -
                          post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
         | 
| 99 | 
            -
                        end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 100 | 
            -
             | 
| 101 | 
            -
                        token = Doorkeeper::AccessToken.first
         | 
| 102 | 
            -
             | 
| 103 | 
            -
                        expect(token.application_id).to eq(@client.id)
         | 
| 104 | 
            -
                        expect(json_response).to include("access_token" => token.token)
         | 
| 105 | 
            -
                      end
         | 
| 106 | 
            -
                    end
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                    context "when client_secret present" do
         | 
| 109 | 
            -
                      it "issues a new token" do
         | 
| 110 | 
            -
                        expect do
         | 
| 111 | 
            -
                          post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 112 | 
            -
                        end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                        token = Doorkeeper::AccessToken.first
         | 
| 115 | 
            -
             | 
| 116 | 
            -
                        expect(token.application_id).to eq(@client.id)
         | 
| 117 | 
            -
                        expect(json_response).to include("access_token" => token.token)
         | 
| 118 | 
            -
                      end
         | 
| 119 | 
            -
             | 
| 120 | 
            -
                      context "when client_secret incorrect" do
         | 
| 121 | 
            -
                        it "doesn't issue new token" do
         | 
| 122 | 
            -
                          expect do
         | 
| 123 | 
            -
                            post password_token_endpoint_url(
         | 
| 124 | 
            -
                              client_id: @client.uid,
         | 
| 125 | 
            -
                              client_secret: "foobar",
         | 
| 126 | 
            -
                              resource_owner: @resource_owner,
         | 
| 127 | 
            -
                            )
         | 
| 128 | 
            -
                          end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 129 | 
            -
             | 
| 130 | 
            -
                          expect(response.status).to eq(401)
         | 
| 131 | 
            -
                          expect(json_response).to include(
         | 
| 132 | 
            -
                            "error" => "invalid_client",
         | 
| 133 | 
            -
                            "error_description" => an_instance_of(String),
         | 
| 134 | 
            -
                          )
         | 
| 135 | 
            -
                        end
         | 
| 136 | 
            -
                      end
         | 
| 137 | 
            -
                    end
         | 
| 138 | 
            -
                  end
         | 
| 139 | 
            -
             | 
| 140 | 
            -
                  context "with confidential/private client" do
         | 
| 141 | 
            -
                    it "issues a new token" do
         | 
| 142 | 
            -
                      expect do
         | 
| 143 | 
            -
                        post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 144 | 
            -
                      end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 145 | 
            -
             | 
| 146 | 
            -
                      token = Doorkeeper::AccessToken.first
         | 
| 147 | 
            -
             | 
| 148 | 
            -
                      expect(token.application_id).to eq(@client.id)
         | 
| 149 | 
            -
                      expect(json_response).to include("access_token" => token.token)
         | 
| 150 | 
            -
                    end
         | 
| 151 | 
            -
             | 
| 152 | 
            -
                    context "when client_secret absent" do
         | 
| 153 | 
            -
                      it "doesn't issue new token" do
         | 
| 154 | 
            -
                        expect do
         | 
| 155 | 
            -
                          post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
         | 
| 156 | 
            -
                        end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 157 | 
            -
             | 
| 158 | 
            -
                        expect(response.status).to eq(401)
         | 
| 159 | 
            -
                        expect(json_response).to match(
         | 
| 160 | 
            -
                          "error" => "invalid_client",
         | 
| 161 | 
            -
                          "error_description" => an_instance_of(String),
         | 
| 162 | 
            -
                        )
         | 
| 163 | 
            -
                      end
         | 
| 164 | 
            -
                    end
         | 
| 165 | 
            -
                  end
         | 
| 166 | 
            -
             | 
| 167 | 
            -
                  it "issues new token without client credentials" do
         | 
| 168 | 
            -
                    expect do
         | 
| 169 | 
            -
                      post password_token_endpoint_url(resource_owner: @resource_owner)
         | 
| 170 | 
            -
                    end.to(change { Doorkeeper::AccessToken.count }.by(1))
         | 
| 171 | 
            -
             | 
| 172 | 
            -
                    token = Doorkeeper::AccessToken.first
         | 
| 173 | 
            -
             | 
| 174 | 
            -
                    expect(token.application_id).to be_nil
         | 
| 175 | 
            -
                    expect(json_response).to include("access_token" => token.token)
         | 
| 176 | 
            -
                  end
         | 
| 177 | 
            -
             | 
| 178 | 
            -
                  it "issues a refresh token if enabled" do
         | 
| 179 | 
            -
                    config_is_set(:refresh_token_enabled, true)
         | 
| 180 | 
            -
             | 
| 181 | 
            -
                    post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 182 | 
            -
             | 
| 183 | 
            -
                    token = Doorkeeper::AccessToken.first
         | 
| 184 | 
            -
                    expect(json_response).to include("refresh_token" => token.refresh_token)
         | 
| 185 | 
            -
                  end
         | 
| 186 | 
            -
             | 
| 187 | 
            -
                  it "returns the same token if it is still accessible" do
         | 
| 188 | 
            -
                    allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
         | 
| 189 | 
            -
             | 
| 190 | 
            -
                    client_is_authorized(@client, @resource_owner)
         | 
| 191 | 
            -
             | 
| 192 | 
            -
                    post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 193 | 
            -
             | 
| 194 | 
            -
                    expect(Doorkeeper::AccessToken.count).to be(1)
         | 
| 195 | 
            -
                    expect(json_response).to include("access_token" => Doorkeeper::AccessToken.first.token)
         | 
| 196 | 
            -
                  end
         | 
| 197 | 
            -
             | 
| 198 | 
            -
                  context "with valid, default scope" do
         | 
| 199 | 
            -
                    before do
         | 
| 200 | 
            -
                      default_scopes_exist :public
         | 
| 201 | 
            -
                    end
         | 
| 202 | 
            -
             | 
| 203 | 
            -
                    it "issues new token" do
         | 
| 204 | 
            -
                      expect do
         | 
| 205 | 
            -
                        post password_token_endpoint_url(client: @client, resource_owner: @resource_owner, scope: "public")
         | 
| 206 | 
            -
                      end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 207 | 
            -
             | 
| 208 | 
            -
                      token = Doorkeeper::AccessToken.first
         | 
| 209 | 
            -
             | 
| 210 | 
            -
                      expect(token.application_id).to eq(@client.id)
         | 
| 211 | 
            -
                      expect(json_response).to include(
         | 
| 212 | 
            -
                        "access_token" => token.token,
         | 
| 213 | 
            -
                        "scope" => "public",
         | 
| 214 | 
            -
                      )
         | 
| 215 | 
            -
                    end
         | 
| 216 | 
            -
                  end
         | 
| 217 | 
            -
                end
         | 
| 218 | 
            -
             | 
| 219 | 
            -
                context "when application scopes are present and differs from configured default scopes and no scope is passed" do
         | 
| 220 | 
            -
                  before do
         | 
| 221 | 
            -
                    default_scopes_exist :public
         | 
| 222 | 
            -
                    @client.update(scopes: "abc")
         | 
| 223 | 
            -
                  end
         | 
| 224 | 
            -
             | 
| 225 | 
            -
                  it "issues new token without any scope" do
         | 
| 226 | 
            -
                    expect do
         | 
| 227 | 
            -
                      post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 228 | 
            -
                    end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 229 | 
            -
             | 
| 230 | 
            -
                    token = Doorkeeper::AccessToken.first
         | 
| 231 | 
            -
             | 
| 232 | 
            -
                    expect(token.application_id).to eq(@client.id)
         | 
| 233 | 
            -
                    expect(token.scopes).to be_empty
         | 
| 234 | 
            -
                    expect(json_response).to include("access_token" => token.token)
         | 
| 235 | 
            -
                    expect(json_response).not_to include("scope")
         | 
| 236 | 
            -
                  end
         | 
| 237 | 
            -
                end
         | 
| 238 | 
            -
             | 
| 239 | 
            -
                context "when application scopes contain some of the default scopes and no scope is passed" do
         | 
| 240 | 
            -
                  before do
         | 
| 241 | 
            -
                    @client.update(scopes: "read write public")
         | 
| 242 | 
            -
                  end
         | 
| 243 | 
            -
             | 
| 244 | 
            -
                  it "issues new token with one default scope that are present in application scopes" do
         | 
| 245 | 
            -
                    default_scopes_exist :public, :admin
         | 
| 246 | 
            -
             | 
| 247 | 
            -
                    expect do
         | 
| 248 | 
            -
                      post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 249 | 
            -
                    end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 250 | 
            -
             | 
| 251 | 
            -
                    token = Doorkeeper::AccessToken.first
         | 
| 252 | 
            -
             | 
| 253 | 
            -
                    expect(token.application_id).to eq(@client.id)
         | 
| 254 | 
            -
                    expect(json_response).to include(
         | 
| 255 | 
            -
                      "access_token" => token.token,
         | 
| 256 | 
            -
                      "scope" => "public",
         | 
| 257 | 
            -
                    )
         | 
| 258 | 
            -
                  end
         | 
| 259 | 
            -
             | 
| 260 | 
            -
                  it "issues new token with multiple default scopes that are present in application scopes" do
         | 
| 261 | 
            -
                    default_scopes_exist :public, :read, :update
         | 
| 262 | 
            -
             | 
| 263 | 
            -
                    expect do
         | 
| 264 | 
            -
                      post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
         | 
| 265 | 
            -
                    end.to change { Doorkeeper::AccessToken.count }.by(1)
         | 
| 266 | 
            -
             | 
| 267 | 
            -
                    token = Doorkeeper::AccessToken.first
         | 
| 268 | 
            -
             | 
| 269 | 
            -
                    expect(token.application_id).to eq(@client.id)
         | 
| 270 | 
            -
                    expect(json_response).to include(
         | 
| 271 | 
            -
                      "access_token" => token.token,
         | 
| 272 | 
            -
                      "scope" => "public read",
         | 
| 273 | 
            -
                    )
         | 
| 274 | 
            -
                  end
         | 
| 275 | 
            -
                end
         | 
| 276 | 
            -
             | 
| 277 | 
            -
                context "with invalid scopes" do
         | 
| 278 | 
            -
                  subject do
         | 
| 279 | 
            -
                    post password_token_endpoint_url(
         | 
| 280 | 
            -
                      client: @client,
         | 
| 281 | 
            -
                      resource_owner: @resource_owner,
         | 
| 282 | 
            -
                      scope: "random",
         | 
| 283 | 
            -
                    )
         | 
| 284 | 
            -
                  end
         | 
| 285 | 
            -
             | 
| 286 | 
            -
                  it "doesn't issue new token" do
         | 
| 287 | 
            -
                    expect { subject }.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 288 | 
            -
                  end
         | 
| 289 | 
            -
             | 
| 290 | 
            -
                  it "returns invalid_scope error" do
         | 
| 291 | 
            -
                    subject
         | 
| 292 | 
            -
             | 
| 293 | 
            -
                    expect(json_response).to include(
         | 
| 294 | 
            -
                      "error" => "invalid_scope",
         | 
| 295 | 
            -
                      "error_description" => translated_error_message(:invalid_scope),
         | 
| 296 | 
            -
                    )
         | 
| 297 | 
            -
             | 
| 298 | 
            -
                    expect(json_response).not_to include("access_token")
         | 
| 299 | 
            -
             | 
| 300 | 
            -
                    expect(response.status).to eq(400)
         | 
| 301 | 
            -
                  end
         | 
| 302 | 
            -
                end
         | 
| 303 | 
            -
             | 
| 304 | 
            -
                context "with invalid user credentials" do
         | 
| 305 | 
            -
                  it "doesn't issue new token with bad password" do
         | 
| 306 | 
            -
                    expect do
         | 
| 307 | 
            -
                      post password_token_endpoint_url(
         | 
| 308 | 
            -
                        client: @client,
         | 
| 309 | 
            -
                        resource_owner_username: @resource_owner.name,
         | 
| 310 | 
            -
                        resource_owner_password: "wrongpassword",
         | 
| 311 | 
            -
                      )
         | 
| 312 | 
            -
                    end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 313 | 
            -
                  end
         | 
| 314 | 
            -
             | 
| 315 | 
            -
                  it "doesn't issue new token without credentials" do
         | 
| 316 | 
            -
                    expect do
         | 
| 317 | 
            -
                      post password_token_endpoint_url(client: @client)
         | 
| 318 | 
            -
                    end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 319 | 
            -
                  end
         | 
| 320 | 
            -
             | 
| 321 | 
            -
                  it "doesn't issue new token if resource_owner_from_credentials returned false or nil" do
         | 
| 322 | 
            -
                    config_is_set(:resource_owner_from_credentials) { false }
         | 
| 323 | 
            -
             | 
| 324 | 
            -
                    expect do
         | 
| 325 | 
            -
                      post password_token_endpoint_url(client: @client)
         | 
| 326 | 
            -
                    end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 327 | 
            -
             | 
| 328 | 
            -
                    config_is_set(:resource_owner_from_credentials) { nil }
         | 
| 329 | 
            -
             | 
| 330 | 
            -
                    expect do
         | 
| 331 | 
            -
                      post password_token_endpoint_url(client: @client)
         | 
| 332 | 
            -
                    end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 333 | 
            -
                  end
         | 
| 334 | 
            -
                end
         | 
| 335 | 
            -
             | 
| 336 | 
            -
                context "with invalid confidential client credentials" do
         | 
| 337 | 
            -
                  it "doesn't issue new token with bad client credentials" do
         | 
| 338 | 
            -
                    expect do
         | 
| 339 | 
            -
                      post password_token_endpoint_url(
         | 
| 340 | 
            -
                        client_id: @client.uid,
         | 
| 341 | 
            -
                        client_secret: "bad_secret",
         | 
| 342 | 
            -
                        resource_owner: @resource_owner,
         | 
| 343 | 
            -
                      )
         | 
| 344 | 
            -
                    end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 345 | 
            -
                  end
         | 
| 346 | 
            -
                end
         | 
| 347 | 
            -
             | 
| 348 | 
            -
                context "with invalid public client id" do
         | 
| 349 | 
            -
                  it "doesn't issue new token with bad client id" do
         | 
| 350 | 
            -
                    expect do
         | 
| 351 | 
            -
                      post password_token_endpoint_url(client_id: "bad_id", resource_owner: @resource_owner)
         | 
| 352 | 
            -
                    end.not_to(change { Doorkeeper::AccessToken.count })
         | 
| 353 | 
            -
                  end
         | 
| 354 | 
            -
                end
         | 
| 355 | 
            -
              end
         | 
| 356 | 
            -
            end
         | 
| @@ -1,255 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require "spec_helper"
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            RSpec.describe "Refresh Token Flow" do
         | 
| 6 | 
            -
              before do
         | 
| 7 | 
            -
                Doorkeeper.configure do
         | 
| 8 | 
            -
                  orm DOORKEEPER_ORM
         | 
| 9 | 
            -
                  use_refresh_token
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                client_exists
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              let(:resource_owner) { FactoryBot.create(:resource_owner) }
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              describe "issuing a refresh token" do
         | 
| 18 | 
            -
                before do
         | 
| 19 | 
            -
                  authorization_code_exists application: @client,
         | 
| 20 | 
            -
                                            resource_owner_id: resource_owner.id,
         | 
| 21 | 
            -
                                            resource_owner_type: resource_owner.class.name
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                it "client gets the refresh token and refreshes it" do
         | 
| 25 | 
            -
                  post token_endpoint_url(code: @authorization.token, client: @client)
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  token = Doorkeeper::AccessToken.first
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                  expect(json_response).to include(
         | 
| 30 | 
            -
                    "access_token" => token.token,
         | 
| 31 | 
            -
                    "refresh_token" => token.refresh_token,
         | 
| 32 | 
            -
                  )
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                  expect(@authorization.reload).to be_revoked
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                  post refresh_token_endpoint_url(client: @client, refresh_token: token.refresh_token)
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                  new_token = Doorkeeper::AccessToken.last
         | 
| 39 | 
            -
                  expect(json_response).to include(
         | 
| 40 | 
            -
                    "access_token" => new_token.token,
         | 
| 41 | 
            -
                    "refresh_token" => new_token.refresh_token,
         | 
| 42 | 
            -
                  )
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                  expect(token.token).not_to eq(new_token.token)
         | 
| 45 | 
            -
                  expect(token.refresh_token).not_to eq(new_token.refresh_token)
         | 
| 46 | 
            -
                end
         | 
| 47 | 
            -
              end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
              describe "refreshing the token" do
         | 
| 50 | 
            -
                before do
         | 
| 51 | 
            -
                  @token = FactoryBot.create(
         | 
| 52 | 
            -
                    :access_token,
         | 
| 53 | 
            -
                    application: @client,
         | 
| 54 | 
            -
                    resource_owner_id: resource_owner.id,
         | 
| 55 | 
            -
                    resource_owner_type: resource_owner.class.name,
         | 
| 56 | 
            -
                    use_refresh_token: true,
         | 
| 57 | 
            -
                  )
         | 
| 58 | 
            -
                end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                context "when refresh_token revoked on use" do
         | 
| 61 | 
            -
                  it "client requests a token with refresh token" do
         | 
| 62 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 63 | 
            -
                      client: @client, refresh_token: @token.refresh_token,
         | 
| 64 | 
            -
                    )
         | 
| 65 | 
            -
                    expect(json_response).to include(
         | 
| 66 | 
            -
                      "refresh_token" => Doorkeeper::AccessToken.last.refresh_token,
         | 
| 67 | 
            -
                    )
         | 
| 68 | 
            -
                    expect(@token.reload).not_to be_revoked
         | 
| 69 | 
            -
                  end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                  it "client requests a token with expired access token" do
         | 
| 72 | 
            -
                    @token.update_attribute :expires_in, -100
         | 
| 73 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 74 | 
            -
                      client: @client, refresh_token: @token.refresh_token,
         | 
| 75 | 
            -
                    )
         | 
| 76 | 
            -
                    expect(json_response).to include(
         | 
| 77 | 
            -
                      "refresh_token" => Doorkeeper::AccessToken.last.refresh_token,
         | 
| 78 | 
            -
                    )
         | 
| 79 | 
            -
                    expect(@token.reload).not_to be_revoked
         | 
| 80 | 
            -
                  end
         | 
| 81 | 
            -
                end
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                context "when refresh_token revoked on refresh_token request" do
         | 
| 84 | 
            -
                  before do
         | 
| 85 | 
            -
                    allow(Doorkeeper::AccessToken).to receive(:refresh_token_revoked_on_use?).and_return(false)
         | 
| 86 | 
            -
                  end
         | 
| 87 | 
            -
             | 
| 88 | 
            -
                  it "client request a token with refresh token" do
         | 
| 89 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 90 | 
            -
                      client: @client, refresh_token: @token.refresh_token,
         | 
| 91 | 
            -
                    )
         | 
| 92 | 
            -
                    expect(json_response).to include(
         | 
| 93 | 
            -
                      "refresh_token" => Doorkeeper::AccessToken.last.refresh_token,
         | 
| 94 | 
            -
                    )
         | 
| 95 | 
            -
                    expect(@token.reload).to be_revoked
         | 
| 96 | 
            -
                  end
         | 
| 97 | 
            -
             | 
| 98 | 
            -
                  it "client request a token with expired access token" do
         | 
| 99 | 
            -
                    @token.update_attribute :expires_in, -100
         | 
| 100 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 101 | 
            -
                      client: @client, refresh_token: @token.refresh_token,
         | 
| 102 | 
            -
                    )
         | 
| 103 | 
            -
                    expect(json_response).to include(
         | 
| 104 | 
            -
                      "refresh_token" => Doorkeeper::AccessToken.last.refresh_token,
         | 
| 105 | 
            -
                    )
         | 
| 106 | 
            -
                    expect(@token.reload).to be_revoked
         | 
| 107 | 
            -
                  end
         | 
| 108 | 
            -
                end
         | 
| 109 | 
            -
             | 
| 110 | 
            -
                context "with public & private clients" do
         | 
| 111 | 
            -
                  let(:public_client) do
         | 
| 112 | 
            -
                    FactoryBot.create(
         | 
| 113 | 
            -
                      :application,
         | 
| 114 | 
            -
                      confidential: false,
         | 
| 115 | 
            -
                    )
         | 
| 116 | 
            -
                  end
         | 
| 117 | 
            -
             | 
| 118 | 
            -
                  let(:token_for_private_client) do
         | 
| 119 | 
            -
                    FactoryBot.create(
         | 
| 120 | 
            -
                      :access_token,
         | 
| 121 | 
            -
                      application: @client,
         | 
| 122 | 
            -
                      resource_owner_id: resource_owner.id,
         | 
| 123 | 
            -
                      resource_owner_type: resource_owner.class.name,
         | 
| 124 | 
            -
                      use_refresh_token: true,
         | 
| 125 | 
            -
                    )
         | 
| 126 | 
            -
                  end
         | 
| 127 | 
            -
             | 
| 128 | 
            -
                  let(:token_for_public_client) do
         | 
| 129 | 
            -
                    FactoryBot.create(
         | 
| 130 | 
            -
                      :access_token,
         | 
| 131 | 
            -
                      application: public_client,
         | 
| 132 | 
            -
                      resource_owner_id: resource_owner.id,
         | 
| 133 | 
            -
                      resource_owner_type: resource_owner.class.name,
         | 
| 134 | 
            -
                      use_refresh_token: true,
         | 
| 135 | 
            -
                    )
         | 
| 136 | 
            -
                  end
         | 
| 137 | 
            -
             | 
| 138 | 
            -
                  it "issues a new token without client_secret when refresh token was issued to a public client" do
         | 
| 139 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 140 | 
            -
                      client_id: public_client.uid,
         | 
| 141 | 
            -
                      refresh_token: token_for_public_client.refresh_token,
         | 
| 142 | 
            -
                    )
         | 
| 143 | 
            -
             | 
| 144 | 
            -
                    new_token = Doorkeeper::AccessToken.last
         | 
| 145 | 
            -
                    expect(json_response).to include(
         | 
| 146 | 
            -
                      "access_token" => new_token.token,
         | 
| 147 | 
            -
                      "refresh_token" => new_token.refresh_token,
         | 
| 148 | 
            -
                    )
         | 
| 149 | 
            -
                  end
         | 
| 150 | 
            -
             | 
| 151 | 
            -
                  it "returns an error without credentials" do
         | 
| 152 | 
            -
                    post refresh_token_endpoint_url(refresh_token: token_for_private_client.refresh_token)
         | 
| 153 | 
            -
             | 
| 154 | 
            -
                    expect(json_response).to include("error" => "invalid_grant")
         | 
| 155 | 
            -
                  end
         | 
| 156 | 
            -
             | 
| 157 | 
            -
                  it "returns an error with wrong credentials" do
         | 
| 158 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 159 | 
            -
                      client_id: "1",
         | 
| 160 | 
            -
                      client_secret: "1",
         | 
| 161 | 
            -
                      refresh_token: token_for_private_client.refresh_token,
         | 
| 162 | 
            -
                    )
         | 
| 163 | 
            -
                    expect(json_response).to match(
         | 
| 164 | 
            -
                      "error" => "invalid_client",
         | 
| 165 | 
            -
                      "error_description" => an_instance_of(String),
         | 
| 166 | 
            -
                    )
         | 
| 167 | 
            -
                  end
         | 
| 168 | 
            -
                end
         | 
| 169 | 
            -
             | 
| 170 | 
            -
                it "client gets an error for invalid refresh token" do
         | 
| 171 | 
            -
                  post refresh_token_endpoint_url(client: @client, refresh_token: "invalid")
         | 
| 172 | 
            -
             | 
| 173 | 
            -
                  expect(json_response).to match(
         | 
| 174 | 
            -
                    "error" => "invalid_grant",
         | 
| 175 | 
            -
                    "error_description" => an_instance_of(String),
         | 
| 176 | 
            -
                  )
         | 
| 177 | 
            -
                end
         | 
| 178 | 
            -
             | 
| 179 | 
            -
                it "client gets an error for revoked access token" do
         | 
| 180 | 
            -
                  @token.revoke
         | 
| 181 | 
            -
                  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
         | 
| 182 | 
            -
             | 
| 183 | 
            -
                  expect(json_response).to match(
         | 
| 184 | 
            -
                    "error" => "invalid_grant",
         | 
| 185 | 
            -
                    "error_description" => an_instance_of(String),
         | 
| 186 | 
            -
                  )
         | 
| 187 | 
            -
                end
         | 
| 188 | 
            -
             | 
| 189 | 
            -
                it "second of simultaneous client requests get an error for revoked access token" do
         | 
| 190 | 
            -
                  allow_any_instance_of(Doorkeeper::AccessToken).to receive(:revoked?).and_return(false, true)
         | 
| 191 | 
            -
                  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
         | 
| 192 | 
            -
             | 
| 193 | 
            -
                  expect(json_response).to match(
         | 
| 194 | 
            -
                    "error" => "invalid_grant",
         | 
| 195 | 
            -
                    "error_description" => an_instance_of(String),
         | 
| 196 | 
            -
                  )
         | 
| 197 | 
            -
                end
         | 
| 198 | 
            -
              end
         | 
| 199 | 
            -
             | 
| 200 | 
            -
              context "when refreshing the token with multiple sessions (devices)" do
         | 
| 201 | 
            -
                before do
         | 
| 202 | 
            -
                  # enable password auth to simulate other devices
         | 
| 203 | 
            -
                  config_is_set(:grant_flows, ["password"])
         | 
| 204 | 
            -
                  config_is_set(:resource_owner_from_credentials) do
         | 
| 205 | 
            -
                    User.authenticate! params[:username], params[:password]
         | 
| 206 | 
            -
                  end
         | 
| 207 | 
            -
                  create_resource_owner
         | 
| 208 | 
            -
                  _another_token = post password_token_endpoint_url(
         | 
| 209 | 
            -
                    client: @client, resource_owner: resource_owner,
         | 
| 210 | 
            -
                  )
         | 
| 211 | 
            -
                  last_token.update(created_at: 5.seconds.ago)
         | 
| 212 | 
            -
             | 
| 213 | 
            -
                  @token = FactoryBot.create(
         | 
| 214 | 
            -
                    :access_token,
         | 
| 215 | 
            -
                    application: @client,
         | 
| 216 | 
            -
                    resource_owner_id: resource_owner.id,
         | 
| 217 | 
            -
                    resource_owner_type: resource_owner.class.name,
         | 
| 218 | 
            -
                    use_refresh_token: true,
         | 
| 219 | 
            -
                  )
         | 
| 220 | 
            -
                  @token.update_attribute :expires_in, -100
         | 
| 221 | 
            -
                end
         | 
| 222 | 
            -
             | 
| 223 | 
            -
                context "when refresh_token revoked on use" do
         | 
| 224 | 
            -
                  it "client request a token after creating another token with the same user" do
         | 
| 225 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 226 | 
            -
                      client: @client, refresh_token: @token.refresh_token,
         | 
| 227 | 
            -
                    )
         | 
| 228 | 
            -
             | 
| 229 | 
            -
                    expect(json_response).to include("refresh_token" => last_token.refresh_token)
         | 
| 230 | 
            -
                    expect(@token.reload).not_to be_revoked
         | 
| 231 | 
            -
                  end
         | 
| 232 | 
            -
                end
         | 
| 233 | 
            -
             | 
| 234 | 
            -
                context "when refresh_token revoked on refresh_token request" do
         | 
| 235 | 
            -
                  before do
         | 
| 236 | 
            -
                    allow(Doorkeeper::AccessToken).to receive(:refresh_token_revoked_on_use?).and_return(false)
         | 
| 237 | 
            -
                  end
         | 
| 238 | 
            -
             | 
| 239 | 
            -
                  it "client request a token after creating another token with the same user" do
         | 
| 240 | 
            -
                    post refresh_token_endpoint_url(
         | 
| 241 | 
            -
                      client: @client, refresh_token: @token.refresh_token,
         | 
| 242 | 
            -
                    )
         | 
| 243 | 
            -
             | 
| 244 | 
            -
                    expect(json_response).to include("refresh_token" => last_token.refresh_token)
         | 
| 245 | 
            -
                    expect(@token.reload).to be_revoked
         | 
| 246 | 
            -
                  end
         | 
| 247 | 
            -
                end
         | 
| 248 | 
            -
             | 
| 249 | 
            -
                def last_token
         | 
| 250 | 
            -
                  Doorkeeper::AccessToken.last_authorized_token_for(
         | 
| 251 | 
            -
                    @client.id, resource_owner,
         | 
| 252 | 
            -
                  )
         | 
| 253 | 
            -
                end
         | 
| 254 | 
            -
              end
         | 
| 255 | 
            -
            end
         |