From 614ec7d4b9db3bda309e118536e6f0533977ab69 Mon Sep 17 00:00:00 2001 From: Nikita Bulai Date: Thu, 4 Oct 2018 10:21:30 +0300 Subject: [PATCH] Refactoring --- .travis.yml | 5 ++ Dangerfile | 57 +++++++++++++++++++ NEWS.md | 3 +- .../doorkeeper/application_controller.rb | 2 + .../application_metal_controller.rb | 2 + .../doorkeeper/applications_controller.rb | 2 + .../doorkeeper/authorizations_controller.rb | 2 + .../authorized_applications_controller.rb | 2 + .../doorkeeper/token_info_controller.rb | 2 + .../doorkeeper/tokens_controller.rb | 2 + app/helpers/doorkeeper/dashboard_helper.rb | 2 + app/validators/redirect_uri_validator.rb | 2 + doorkeeper.gemspec | 45 ++++++++------- lib/doorkeeper.rb | 1 + lib/doorkeeper/engine.rb | 2 + lib/doorkeeper/errors.rb | 3 + .../grape/authorization_decorator.rb | 2 + lib/doorkeeper/grape/helpers.rb | 2 + lib/doorkeeper/helpers/controller.rb | 2 + lib/doorkeeper/models/access_grant_mixin.rb | 2 + lib/doorkeeper/models/access_token_mixin.rb | 2 + lib/doorkeeper/models/application_mixin.rb | 2 + lib/doorkeeper/models/concerns/accessible.rb | 2 + lib/doorkeeper/models/concerns/expirable.rb | 2 + lib/doorkeeper/models/concerns/orderable.rb | 2 + lib/doorkeeper/models/concerns/ownership.rb | 2 + lib/doorkeeper/models/concerns/revocable.rb | 2 + lib/doorkeeper/models/concerns/scopes.rb | 2 + lib/doorkeeper/oauth/authorization/code.rb | 2 + lib/doorkeeper/oauth/authorization/context.rb | 2 + lib/doorkeeper/oauth/authorization/token.rb | 2 + .../oauth/authorization/uri_builder.rb | 2 + .../oauth/authorization_code_request.rb | 2 + lib/doorkeeper/oauth/base_request.rb | 2 + lib/doorkeeper/oauth/base_response.rb | 2 + lib/doorkeeper/oauth/client.rb | 2 + lib/doorkeeper/oauth/client/credentials.rb | 2 + .../oauth/client_credentials/creator.rb | 2 + .../oauth/client_credentials/issuer.rb | 2 + .../oauth/client_credentials/validation.rb | 2 + .../oauth/client_credentials_request.rb | 2 + lib/doorkeeper/oauth/code_request.rb | 2 + lib/doorkeeper/oauth/code_response.rb | 2 + lib/doorkeeper/oauth/error.rb | 2 + lib/doorkeeper/oauth/error_response.rb | 2 + .../oauth/forbidden_token_response.rb | 2 + lib/doorkeeper/oauth/helpers/scope_checker.rb | 2 + lib/doorkeeper/oauth/helpers/unique_token.rb | 2 + lib/doorkeeper/oauth/helpers/uri_checker.rb | 2 + .../oauth/invalid_token_response.rb | 2 + .../oauth/password_access_token_request.rb | 2 + lib/doorkeeper/oauth/pre_authorization.rb | 2 + lib/doorkeeper/oauth/refresh_token_request.rb | 2 + lib/doorkeeper/oauth/scopes.rb | 2 + lib/doorkeeper/oauth/token.rb | 2 + lib/doorkeeper/oauth/token_introspection.rb | 2 + lib/doorkeeper/oauth/token_request.rb | 2 + lib/doorkeeper/oauth/token_response.rb | 2 + lib/doorkeeper/orm/active_record.rb | 2 + lib/doorkeeper/rails/helpers.rb | 2 + lib/doorkeeper/rails/routes.rb | 2 + lib/doorkeeper/rails/routes/mapper.rb | 2 + lib/doorkeeper/rails/routes/mapping.rb | 2 + lib/doorkeeper/rake/db.rake | 8 +-- lib/doorkeeper/request.rb | 2 + lib/doorkeeper/request/authorization_code.rb | 2 + lib/doorkeeper/request/client_credentials.rb | 2 + lib/doorkeeper/request/code.rb | 2 + lib/doorkeeper/request/password.rb | 2 + lib/doorkeeper/request/refresh_token.rb | 2 + lib/doorkeeper/request/strategy.rb | 2 + lib/doorkeeper/request/token.rb | 2 + lib/doorkeeper/server.rb | 2 + lib/doorkeeper/stale_records_cleaner.rb | 20 +++++++ lib/doorkeeper/validations.rb | 2 + lib/doorkeeper/version.rb | 2 + spec/factories.rb | 12 ++-- .../stale_records_cleaner_spec.rb | 2 +- .../requests/flows/authorization_code_spec.rb | 2 +- spec/support/doorkeeper_rspec.rb | 3 +- 80 files changed, 261 insertions(+), 36 deletions(-) create mode 100644 Dangerfile create mode 100644 lib/doorkeeper/stale_records_cleaner.rb rename spec/lib/{orm/active_record => }/stale_records_cleaner_spec.rb (97%) diff --git a/.travis.yml b/.travis.yml index e40cd1ee8..900b7b656 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,11 @@ gemfile: matrix: fast_finish: true + # Run Danger only once + include: + - rvm: 2.5 + gemfile: gemfiles/rails_5_2.gemfile + script: bundle exec danger exclude: - gemfile: gemfiles/rails_5_0.gemfile rvm: 2.1 diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 000000000..d10260cba --- /dev/null +++ b/Dangerfile @@ -0,0 +1,57 @@ +CHANGELOG_FILE = 'NEWS.md' +GITHUB_REPO = 'https://github.com/doorkeeper-gem/doorkeeper' + +def changelog_changed? + git.modified_files.include?(CHANGELOG_FILE) || git.added_files.include?(CHANGELOG_FILE) +end + +def changelog_entry_example + pr_number = github.pr_json['number'] + pr_url = github.pr_json['html_url'] + pr_title = github.pr_title + .sub(/[?.!,;]?$/, '') + .capitalize + + "- [##{pr_number}](#{pr_url}): #{pr_title}." +end + +# -------------------------------------------------------------------------------------------------------------------- +# Has any changes happened inside the actual library code? +# -------------------------------------------------------------------------------------------------------------------- +has_app_changes = !git.modified_files.grep(/lib/).empty? +has_spec_changes = !git.modified_files.grep(/spec/).empty? + +# -------------------------------------------------------------------------------------------------------------------- +# You've made changes to lib, but didn't write any tests? +# -------------------------------------------------------------------------------------------------------------------- +if has_app_changes && !has_spec_changes + warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false) +end + +# -------------------------------------------------------------------------------------------------------------------- +# You've made changes to specs, but no library code has changed? +# -------------------------------------------------------------------------------------------------------------------- +if !has_app_changes && has_spec_changes + message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false) +end + +# Mainly to encourage writing up some reasoning about the PR, rather than +# just leaving a title +if github.pr_body.length < 10 + fail "Please provide a summary in the Pull Request description" +end + +# -------------------------------------------------------------------------------------------------------------------- +# Have you updated CHANGELOG.md? +# -------------------------------------------------------------------------------------------------------------------- +# Add a CHANGELOG entry for app changes +if has_app_changes && !changelog_changed? + markdown <<-MARKDOWN +Here's an example of a #{CHANGELOG_FILE} entry: +```markdown +#{changelog_entry_example} +``` + MARKDOWN + + fail("Please include a changelog entry. \nYou can find it at [#{CHANGELOG_FILE}](#{GITHUB_REPO}/blob/master/#{CHANGELOG_FILE}).") +end diff --git a/NEWS.md b/NEWS.md index 4ce02a0a7..ce17213cc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,7 +12,8 @@ User-visible changes worth mentioning. triggers every time) - [#1149] Fix for `URIChecker#valid_for_authorization?` false negative when query is blank, but `?` present. - [#1151] Fix Refresh Token strategy: add proper validation of client credentials both for Public & Private clients. -- [#1152] Fixmigration template: change resource owner data type from integer to references +- [#1152] Fix migration template: change resource owner data type from integer to Rails generic `references` +- [#1154] Refactor `StaleRecordsCleaner` to be ORM agnostic. ## 5.0.0 diff --git a/app/controllers/doorkeeper/application_controller.rb b/app/controllers/doorkeeper/application_controller.rb index e9b4d960f..5d0a10c7d 100644 --- a/app/controllers/doorkeeper/application_controller.rb +++ b/app/controllers/doorkeeper/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class ApplicationController < Doorkeeper.configuration.base_controller.constantize diff --git a/app/controllers/doorkeeper/application_metal_controller.rb b/app/controllers/doorkeeper/application_metal_controller.rb index dac3e0d05..167cd210e 100644 --- a/app/controllers/doorkeeper/application_metal_controller.rb +++ b/app/controllers/doorkeeper/application_metal_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class ApplicationMetalController < ActionController::Metal MODULES = [ diff --git a/app/controllers/doorkeeper/applications_controller.rb b/app/controllers/doorkeeper/applications_controller.rb index 550368271..e4a2bf914 100644 --- a/app/controllers/doorkeeper/applications_controller.rb +++ b/app/controllers/doorkeeper/applications_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class ApplicationsController < Doorkeeper::ApplicationController layout 'doorkeeper/admin' unless Doorkeeper.configuration.api_only diff --git a/app/controllers/doorkeeper/authorizations_controller.rb b/app/controllers/doorkeeper/authorizations_controller.rb index ddd27677d..21473849e 100644 --- a/app/controllers/doorkeeper/authorizations_controller.rb +++ b/app/controllers/doorkeeper/authorizations_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class AuthorizationsController < Doorkeeper::ApplicationController before_action :authenticate_resource_owner! diff --git a/app/controllers/doorkeeper/authorized_applications_controller.rb b/app/controllers/doorkeeper/authorized_applications_controller.rb index 755106029..d56bd4a95 100644 --- a/app/controllers/doorkeeper/authorized_applications_controller.rb +++ b/app/controllers/doorkeeper/authorized_applications_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class AuthorizedApplicationsController < Doorkeeper::ApplicationController before_action :authenticate_resource_owner! diff --git a/app/controllers/doorkeeper/token_info_controller.rb b/app/controllers/doorkeeper/token_info_controller.rb index 79249d5b7..bdf4ccc73 100644 --- a/app/controllers/doorkeeper/token_info_controller.rb +++ b/app/controllers/doorkeeper/token_info_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class TokenInfoController < Doorkeeper::ApplicationMetalController def show diff --git a/app/controllers/doorkeeper/tokens_controller.rb b/app/controllers/doorkeeper/tokens_controller.rb index af5134c5c..07033d7e0 100644 --- a/app/controllers/doorkeeper/tokens_controller.rb +++ b/app/controllers/doorkeeper/tokens_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class TokensController < Doorkeeper::ApplicationMetalController def create diff --git a/app/helpers/doorkeeper/dashboard_helper.rb b/app/helpers/doorkeeper/dashboard_helper.rb index 5925a2e83..23cedab3f 100644 --- a/app/helpers/doorkeeper/dashboard_helper.rb +++ b/app/helpers/doorkeeper/dashboard_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module DashboardHelper def doorkeeper_errors_for(object, method) diff --git a/app/validators/redirect_uri_validator.rb b/app/validators/redirect_uri_validator.rb index 3e56c5533..8e7f0d6dc 100644 --- a/app/validators/redirect_uri_validator.rb +++ b/app/validators/redirect_uri_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'uri' class RedirectUriValidator < ActiveModel::EachValidator diff --git a/doorkeeper.gemspec b/doorkeeper.gemspec index e426cb624..27d46bcec 100644 --- a/doorkeeper.gemspec +++ b/doorkeeper.gemspec @@ -2,29 +2,30 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'doorkeeper/version' -Gem::Specification.new do |s| - s.name = 'doorkeeper' - s.version = Doorkeeper.gem_version - s.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai'] - s.email = %w(bulaj.nikita@gmail.com) - s.homepage = 'https://github.com/doorkeeper-gem/doorkeeper' - s.summary = 'OAuth 2 provider for Rails and Grape' - s.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.' - s.license = 'MIT' +Gem::Specification.new do |gem| + gem.name = 'doorkeeper' + gem.version = Doorkeeper.gem_version + gem.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai'] + gem.email = %w(bulaj.nikita@gmail.com) + gem.homepage = 'https://github.com/doorkeeper-gem/doorkeeper' + gem.summary = 'OAuth 2 provider for Rails and Grape' + gem.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.' + gem.license = 'MIT' - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- spec/*`.split("\n") - s.require_paths = ['lib'] + gem.files = `git ls-files`.split("\n") + gem.test_files = `git ls-files -- spec/*`.split("\n") + gem.require_paths = ['lib'] - s.add_dependency 'railties', '>= 4.2' - s.required_ruby_version = '>= 2.1' + gem.add_dependency 'railties', '>= 4.2' + gem.required_ruby_version = '>= 2.1' - s.add_development_dependency 'capybara', '~> 2.18' - s.add_development_dependency 'coveralls' - s.add_development_dependency 'grape' - s.add_development_dependency 'database_cleaner', '~> 1.6' - s.add_development_dependency 'factory_bot', '~> 4.8' - s.add_development_dependency 'generator_spec', '~> 0.9.3' - s.add_development_dependency 'rake', '>= 11.3.0' - s.add_development_dependency 'rspec-rails' + gem.add_development_dependency 'capybara', '~> 2.18' + gem.add_development_dependency 'coveralls' + gem.add_development_dependency 'danger', '~> 5.0' + gem.add_development_dependency 'grape' + gem.add_development_dependency 'database_cleaner', '~> 1.6' + gem.add_development_dependency 'factory_bot', '~> 4.8' + gem.add_development_dependency 'generator_spec', '~> 0.9.3' + gem.add_development_dependency 'rake', '>= 11.3.0' + gem.add_development_dependency 'rspec-rails' end diff --git a/lib/doorkeeper.rb b/lib/doorkeeper.rb index d20966614..348c67ece 100644 --- a/lib/doorkeeper.rb +++ b/lib/doorkeeper.rb @@ -67,6 +67,7 @@ require 'doorkeeper/rails/helpers' require 'doorkeeper/rake' +require 'doorkeeper/stale_records_cleaner' require 'doorkeeper/orm/active_record' diff --git a/lib/doorkeeper/engine.rb b/lib/doorkeeper/engine.rb index 4834d2b43..6da4ab711 100644 --- a/lib/doorkeeper/engine.rb +++ b/lib/doorkeeper/engine.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class Engine < Rails::Engine initializer "doorkeeper.params.filter" do |app| diff --git a/lib/doorkeeper/errors.rb b/lib/doorkeeper/errors.rb index ca28dac95..0a73f3a85 100644 --- a/lib/doorkeeper/errors.rb +++ b/lib/doorkeeper/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Errors class DoorkeeperError < StandardError @@ -46,6 +48,7 @@ def initialize(response) UnableToGenerateToken = Class.new(DoorkeeperError) TokenGeneratorNotFound = Class.new(DoorkeeperError) + NoOrmCleaner = Class.new(DoorkeeperError) InvalidToken = Class.new BaseResponseError TokenExpired = Class.new InvalidToken diff --git a/lib/doorkeeper/grape/authorization_decorator.rb b/lib/doorkeeper/grape/authorization_decorator.rb index f5b71a398..414fc4156 100644 --- a/lib/doorkeeper/grape/authorization_decorator.rb +++ b/lib/doorkeeper/grape/authorization_decorator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Grape class AuthorizationDecorator < SimpleDelegator diff --git a/lib/doorkeeper/grape/helpers.rb b/lib/doorkeeper/grape/helpers.rb index 0ed73e8bc..31da6b1f1 100644 --- a/lib/doorkeeper/grape/helpers.rb +++ b/lib/doorkeeper/grape/helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'doorkeeper/grape/authorization_decorator' module Doorkeeper diff --git a/lib/doorkeeper/helpers/controller.rb b/lib/doorkeeper/helpers/controller.rb index ea3449529..e71a4f319 100644 --- a/lib/doorkeeper/helpers/controller.rb +++ b/lib/doorkeeper/helpers/controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Define methods that can be called in any controller that inherits from # Doorkeeper::ApplicationMetalController or Doorkeeper::ApplicationController module Doorkeeper diff --git a/lib/doorkeeper/models/access_grant_mixin.rb b/lib/doorkeeper/models/access_grant_mixin.rb index 2665db1bc..e016b28e5 100644 --- a/lib/doorkeeper/models/access_grant_mixin.rb +++ b/lib/doorkeeper/models/access_grant_mixin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module AccessGrantMixin extend ActiveSupport::Concern diff --git a/lib/doorkeeper/models/access_token_mixin.rb b/lib/doorkeeper/models/access_token_mixin.rb index 71dcb611b..098d6ed98 100644 --- a/lib/doorkeeper/models/access_token_mixin.rb +++ b/lib/doorkeeper/models/access_token_mixin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module AccessTokenMixin extend ActiveSupport::Concern diff --git a/lib/doorkeeper/models/application_mixin.rb b/lib/doorkeeper/models/application_mixin.rb index 10c871610..a8bfdd994 100644 --- a/lib/doorkeeper/models/application_mixin.rb +++ b/lib/doorkeeper/models/application_mixin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module ApplicationMixin extend ActiveSupport::Concern diff --git a/lib/doorkeeper/models/concerns/accessible.rb b/lib/doorkeeper/models/concerns/accessible.rb index f2f0044f9..a0bc125f6 100644 --- a/lib/doorkeeper/models/concerns/accessible.rb +++ b/lib/doorkeeper/models/concerns/accessible.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Models module Accessible diff --git a/lib/doorkeeper/models/concerns/expirable.rb b/lib/doorkeeper/models/concerns/expirable.rb index 541a09931..2b7721294 100644 --- a/lib/doorkeeper/models/concerns/expirable.rb +++ b/lib/doorkeeper/models/concerns/expirable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Models module Expirable diff --git a/lib/doorkeeper/models/concerns/orderable.rb b/lib/doorkeeper/models/concerns/orderable.rb index 072c8c42c..6d5938839 100644 --- a/lib/doorkeeper/models/concerns/orderable.rb +++ b/lib/doorkeeper/models/concerns/orderable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Models module Orderable diff --git a/lib/doorkeeper/models/concerns/ownership.rb b/lib/doorkeeper/models/concerns/ownership.rb index 535e4622b..22ab88493 100644 --- a/lib/doorkeeper/models/concerns/ownership.rb +++ b/lib/doorkeeper/models/concerns/ownership.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Models module Ownership diff --git a/lib/doorkeeper/models/concerns/revocable.rb b/lib/doorkeeper/models/concerns/revocable.rb index fac80c217..24159c9f6 100644 --- a/lib/doorkeeper/models/concerns/revocable.rb +++ b/lib/doorkeeper/models/concerns/revocable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Models module Revocable diff --git a/lib/doorkeeper/models/concerns/scopes.rb b/lib/doorkeeper/models/concerns/scopes.rb index 8d0788c11..4f475dcb4 100644 --- a/lib/doorkeeper/models/concerns/scopes.rb +++ b/lib/doorkeeper/models/concerns/scopes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Models module Scopes diff --git a/lib/doorkeeper/oauth/authorization/code.rb b/lib/doorkeeper/oauth/authorization/code.rb index 960662e5e..73e631f5a 100644 --- a/lib/doorkeeper/oauth/authorization/code.rb +++ b/lib/doorkeeper/oauth/authorization/code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth module Authorization diff --git a/lib/doorkeeper/oauth/authorization/context.rb b/lib/doorkeeper/oauth/authorization/context.rb index 1281d576e..b0524214b 100644 --- a/lib/doorkeeper/oauth/authorization/context.rb +++ b/lib/doorkeeper/oauth/authorization/context.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth module Authorization diff --git a/lib/doorkeeper/oauth/authorization/token.rb b/lib/doorkeeper/oauth/authorization/token.rb index e881df4c4..a022b926c 100644 --- a/lib/doorkeeper/oauth/authorization/token.rb +++ b/lib/doorkeeper/oauth/authorization/token.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth module Authorization diff --git a/lib/doorkeeper/oauth/authorization/uri_builder.rb b/lib/doorkeeper/oauth/authorization/uri_builder.rb index d8546aa42..bb6ce20fd 100644 --- a/lib/doorkeeper/oauth/authorization/uri_builder.rb +++ b/lib/doorkeeper/oauth/authorization/uri_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack/utils' module Doorkeeper diff --git a/lib/doorkeeper/oauth/authorization_code_request.rb b/lib/doorkeeper/oauth/authorization_code_request.rb index f4c3eed45..b93fac8c7 100644 --- a/lib/doorkeeper/oauth/authorization_code_request.rb +++ b/lib/doorkeeper/oauth/authorization_code_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class AuthorizationCodeRequest < BaseRequest diff --git a/lib/doorkeeper/oauth/base_request.rb b/lib/doorkeeper/oauth/base_request.rb index 636e42346..573b128e4 100644 --- a/lib/doorkeeper/oauth/base_request.rb +++ b/lib/doorkeeper/oauth/base_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class BaseRequest diff --git a/lib/doorkeeper/oauth/base_response.rb b/lib/doorkeeper/oauth/base_response.rb index dd7c1bebd..84c29f640 100644 --- a/lib/doorkeeper/oauth/base_response.rb +++ b/lib/doorkeeper/oauth/base_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class BaseResponse diff --git a/lib/doorkeeper/oauth/client.rb b/lib/doorkeeper/oauth/client.rb index d8ce77e17..3a31b0531 100644 --- a/lib/doorkeeper/oauth/client.rb +++ b/lib/doorkeeper/oauth/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class Client diff --git a/lib/doorkeeper/oauth/client/credentials.rb b/lib/doorkeeper/oauth/client/credentials.rb index 62cc8dac5..d9b69e4c7 100644 --- a/lib/doorkeeper/oauth/client/credentials.rb +++ b/lib/doorkeeper/oauth/client/credentials.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class Client diff --git a/lib/doorkeeper/oauth/client_credentials/creator.rb b/lib/doorkeeper/oauth/client_credentials/creator.rb index 09ad284d5..287c979b8 100644 --- a/lib/doorkeeper/oauth/client_credentials/creator.rb +++ b/lib/doorkeeper/oauth/client_credentials/creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class ClientCredentialsRequest < BaseRequest diff --git a/lib/doorkeeper/oauth/client_credentials/issuer.rb b/lib/doorkeeper/oauth/client_credentials/issuer.rb index 7c8edaf57..f9bb67b13 100644 --- a/lib/doorkeeper/oauth/client_credentials/issuer.rb +++ b/lib/doorkeeper/oauth/client_credentials/issuer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class ClientCredentialsRequest < BaseRequest diff --git a/lib/doorkeeper/oauth/client_credentials/validation.rb b/lib/doorkeeper/oauth/client_credentials/validation.rb index 964f97b89..fadd62933 100644 --- a/lib/doorkeeper/oauth/client_credentials/validation.rb +++ b/lib/doorkeeper/oauth/client_credentials/validation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class ClientCredentialsRequest < BaseRequest diff --git a/lib/doorkeeper/oauth/client_credentials_request.rb b/lib/doorkeeper/oauth/client_credentials_request.rb index f9df39d65..05422b078 100644 --- a/lib/doorkeeper/oauth/client_credentials_request.rb +++ b/lib/doorkeeper/oauth/client_credentials_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class ClientCredentialsRequest < BaseRequest diff --git a/lib/doorkeeper/oauth/code_request.rb b/lib/doorkeeper/oauth/code_request.rb index a81f4b8c7..b7583dcaa 100644 --- a/lib/doorkeeper/oauth/code_request.rb +++ b/lib/doorkeeper/oauth/code_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class CodeRequest diff --git a/lib/doorkeeper/oauth/code_response.rb b/lib/doorkeeper/oauth/code_response.rb index 83cc32f19..cf193c931 100644 --- a/lib/doorkeeper/oauth/code_response.rb +++ b/lib/doorkeeper/oauth/code_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class CodeResponse < BaseResponse diff --git a/lib/doorkeeper/oauth/error.rb b/lib/doorkeeper/oauth/error.rb index 93505ccf5..a6c99fb0f 100644 --- a/lib/doorkeeper/oauth/error.rb +++ b/lib/doorkeeper/oauth/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth Error = Struct.new(:name, :state) do diff --git a/lib/doorkeeper/oauth/error_response.rb b/lib/doorkeeper/oauth/error_response.rb index 1fb7549ff..afcc561aa 100644 --- a/lib/doorkeeper/oauth/error_response.rb +++ b/lib/doorkeeper/oauth/error_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class ErrorResponse < BaseResponse diff --git a/lib/doorkeeper/oauth/forbidden_token_response.rb b/lib/doorkeeper/oauth/forbidden_token_response.rb index d87ce0aae..ed004d4c2 100644 --- a/lib/doorkeeper/oauth/forbidden_token_response.rb +++ b/lib/doorkeeper/oauth/forbidden_token_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class ForbiddenTokenResponse < ErrorResponse diff --git a/lib/doorkeeper/oauth/helpers/scope_checker.rb b/lib/doorkeeper/oauth/helpers/scope_checker.rb index 3cf853e08..c1754eceb 100644 --- a/lib/doorkeeper/oauth/helpers/scope_checker.rb +++ b/lib/doorkeeper/oauth/helpers/scope_checker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth module Helpers diff --git a/lib/doorkeeper/oauth/helpers/unique_token.rb b/lib/doorkeeper/oauth/helpers/unique_token.rb index f506a85da..13f012596 100644 --- a/lib/doorkeeper/oauth/helpers/unique_token.rb +++ b/lib/doorkeeper/oauth/helpers/unique_token.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth module Helpers diff --git a/lib/doorkeeper/oauth/helpers/uri_checker.rb b/lib/doorkeeper/oauth/helpers/uri_checker.rb index eda3d3859..7cb7f1db2 100644 --- a/lib/doorkeeper/oauth/helpers/uri_checker.rb +++ b/lib/doorkeeper/oauth/helpers/uri_checker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth module Helpers diff --git a/lib/doorkeeper/oauth/invalid_token_response.rb b/lib/doorkeeper/oauth/invalid_token_response.rb index 8e507f95c..8034d169e 100644 --- a/lib/doorkeeper/oauth/invalid_token_response.rb +++ b/lib/doorkeeper/oauth/invalid_token_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class InvalidTokenResponse < ErrorResponse diff --git a/lib/doorkeeper/oauth/password_access_token_request.rb b/lib/doorkeeper/oauth/password_access_token_request.rb index 5f6aac605..9d2b088fd 100644 --- a/lib/doorkeeper/oauth/password_access_token_request.rb +++ b/lib/doorkeeper/oauth/password_access_token_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class PasswordAccessTokenRequest < BaseRequest diff --git a/lib/doorkeeper/oauth/pre_authorization.rb b/lib/doorkeeper/oauth/pre_authorization.rb index 9ec0a1a69..64a22bb35 100644 --- a/lib/doorkeeper/oauth/pre_authorization.rb +++ b/lib/doorkeeper/oauth/pre_authorization.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class PreAuthorization diff --git a/lib/doorkeeper/oauth/refresh_token_request.rb b/lib/doorkeeper/oauth/refresh_token_request.rb index af80850d2..b033131d4 100644 --- a/lib/doorkeeper/oauth/refresh_token_request.rb +++ b/lib/doorkeeper/oauth/refresh_token_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class RefreshTokenRequest < BaseRequest diff --git a/lib/doorkeeper/oauth/scopes.rb b/lib/doorkeeper/oauth/scopes.rb index 5da0a5342..1865c621c 100644 --- a/lib/doorkeeper/oauth/scopes.rb +++ b/lib/doorkeeper/oauth/scopes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class Scopes diff --git a/lib/doorkeeper/oauth/token.rb b/lib/doorkeeper/oauth/token.rb index 36fb581b8..c3a9d672f 100644 --- a/lib/doorkeeper/oauth/token.rb +++ b/lib/doorkeeper/oauth/token.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class Token diff --git a/lib/doorkeeper/oauth/token_introspection.rb b/lib/doorkeeper/oauth/token_introspection.rb index 26a63de48..a87371ccd 100644 --- a/lib/doorkeeper/oauth/token_introspection.rb +++ b/lib/doorkeeper/oauth/token_introspection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth # RFC7662 OAuth 2.0 Token Introspection diff --git a/lib/doorkeeper/oauth/token_request.rb b/lib/doorkeeper/oauth/token_request.rb index 9908c23ef..b8aa38429 100644 --- a/lib/doorkeeper/oauth/token_request.rb +++ b/lib/doorkeeper/oauth/token_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class TokenRequest diff --git a/lib/doorkeeper/oauth/token_response.rb b/lib/doorkeeper/oauth/token_response.rb index 93f6bbe7e..aa3c31119 100644 --- a/lib/doorkeeper/oauth/token_response.rb +++ b/lib/doorkeeper/oauth/token_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module OAuth class TokenResponse diff --git a/lib/doorkeeper/orm/active_record.rb b/lib/doorkeeper/orm/active_record.rb index 5cda5f1ab..0cbb4f94b 100644 --- a/lib/doorkeeper/orm/active_record.rb +++ b/lib/doorkeeper/orm/active_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/lazy_load_hooks' require 'doorkeeper/orm/active_record/stale_records_cleaner' diff --git a/lib/doorkeeper/rails/helpers.rb b/lib/doorkeeper/rails/helpers.rb index 780bcf5cd..70c9b0148 100644 --- a/lib/doorkeeper/rails/helpers.rb +++ b/lib/doorkeeper/rails/helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Rails module Helpers diff --git a/lib/doorkeeper/rails/routes.rb b/lib/doorkeeper/rails/routes.rb index a44b2df99..cd88e4139 100644 --- a/lib/doorkeeper/rails/routes.rb +++ b/lib/doorkeeper/rails/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'doorkeeper/rails/routes/mapping' require 'doorkeeper/rails/routes/mapper' diff --git a/lib/doorkeeper/rails/routes/mapper.rb b/lib/doorkeeper/rails/routes/mapper.rb index bfee19b52..7ec5fd75b 100644 --- a/lib/doorkeeper/rails/routes/mapper.rb +++ b/lib/doorkeeper/rails/routes/mapper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Rails class Routes # :nodoc: diff --git a/lib/doorkeeper/rails/routes/mapping.rb b/lib/doorkeeper/rails/routes/mapping.rb index d2f129ce1..71b543972 100644 --- a/lib/doorkeeper/rails/routes/mapping.rb +++ b/lib/doorkeeper/rails/routes/mapping.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Rails class Routes # :nodoc: diff --git a/lib/doorkeeper/rake/db.rake b/lib/doorkeeper/rake/db.rake index f3dd5f0af..caaa7bb27 100644 --- a/lib/doorkeeper/rake/db.rake +++ b/lib/doorkeeper/rake/db.rake @@ -13,26 +13,26 @@ namespace :doorkeeper do namespace :cleanup do desc 'Removes stale access tokens' task revoked_tokens: 'doorkeeper:setup' do - cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessToken) + cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper::AccessToken) cleaner.clean_revoked end desc 'Removes expired (TTL passed) access tokens' task expired_tokens: 'doorkeeper:setup' do expirable_tokens = Doorkeeper::AccessToken.where(refresh_token: nil) - cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(expirable_tokens) + cleaner = Doorkeeper::StaleRecordsCleaner.new(expirable_tokens) cleaner.clean_expired(Doorkeeper.configuration.access_token_expires_in) end desc 'Removes stale access grants' task revoked_grants: 'doorkeeper:setup' do - cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessGrant) + cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper::AccessGrant) cleaner.clean_revoked end desc 'Removes expired (TTL passed) access grants' task expired_grants: 'doorkeeper:setup' do - cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessGrant) + cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper::AccessGrant) cleaner.clean_expired(Doorkeeper.configuration.authorization_code_expires_in) end end diff --git a/lib/doorkeeper/request.rb b/lib/doorkeeper/request.rb index f1b231762..e8366b651 100644 --- a/lib/doorkeeper/request.rb +++ b/lib/doorkeeper/request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class << self diff --git a/lib/doorkeeper/request/authorization_code.rb b/lib/doorkeeper/request/authorization_code.rb index 51cf3abe5..d4a46a3ee 100644 --- a/lib/doorkeeper/request/authorization_code.rb +++ b/lib/doorkeeper/request/authorization_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class AuthorizationCode < Strategy diff --git a/lib/doorkeeper/request/client_credentials.rb b/lib/doorkeeper/request/client_credentials.rb index d05f39916..00d89ff3d 100644 --- a/lib/doorkeeper/request/client_credentials.rb +++ b/lib/doorkeeper/request/client_credentials.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class ClientCredentials < Strategy diff --git a/lib/doorkeeper/request/code.rb b/lib/doorkeeper/request/code.rb index 39782b0f2..d4cadb5d0 100644 --- a/lib/doorkeeper/request/code.rb +++ b/lib/doorkeeper/request/code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class Code < Strategy diff --git a/lib/doorkeeper/request/password.rb b/lib/doorkeeper/request/password.rb index 9ee966424..4f1379d2c 100644 --- a/lib/doorkeeper/request/password.rb +++ b/lib/doorkeeper/request/password.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class Password < Strategy diff --git a/lib/doorkeeper/request/refresh_token.rb b/lib/doorkeeper/request/refresh_token.rb index cfc5ace52..c47ce6b14 100644 --- a/lib/doorkeeper/request/refresh_token.rb +++ b/lib/doorkeeper/request/refresh_token.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class RefreshToken < Strategy diff --git a/lib/doorkeeper/request/strategy.rb b/lib/doorkeeper/request/strategy.rb index ecf6f4157..a4f379ba8 100644 --- a/lib/doorkeeper/request/strategy.rb +++ b/lib/doorkeeper/request/strategy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class Strategy diff --git a/lib/doorkeeper/request/token.rb b/lib/doorkeeper/request/token.rb index 93528d992..4e609835d 100644 --- a/lib/doorkeeper/request/token.rb +++ b/lib/doorkeeper/request/token.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Request class Token < Strategy diff --git a/lib/doorkeeper/server.rb b/lib/doorkeeper/server.rb index 697c2d903..2fa8fadea 100644 --- a/lib/doorkeeper/server.rb +++ b/lib/doorkeeper/server.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper class Server attr_accessor :context diff --git a/lib/doorkeeper/stale_records_cleaner.rb b/lib/doorkeeper/stale_records_cleaner.rb new file mode 100644 index 000000000..45c2b5669 --- /dev/null +++ b/lib/doorkeeper/stale_records_cleaner.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Doorkeeper + class StaleRecordsCleaner + CLEANER_CLASS = 'StaleRecordsCleaner'.freeze + + def self.for(base_scope) + orm_adapter = "doorkeeper/orm/#{Doorkeeper.configuration.orm}".classify + + orm_cleaner = "#{orm_adapter}::#{CLEANER_CLASS}".constantize + orm_cleaner.new(base_scope) + rescue NameError + raise NoOrmCleaner, "'#{Doorkeeper.configuration.orm}' ORM has no cleaner!" + end + + def self.new(base_scope) + self.for(base_scope) + end + end +end diff --git a/lib/doorkeeper/validations.rb b/lib/doorkeeper/validations.rb index 1fe8e5bab..d82ced79e 100644 --- a/lib/doorkeeper/validations.rb +++ b/lib/doorkeeper/validations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper module Validations extend ActiveSupport::Concern diff --git a/lib/doorkeeper/version.rb b/lib/doorkeeper/version.rb index af5e4cecc..5f2da8dad 100644 --- a/lib/doorkeeper/version.rb +++ b/lib/doorkeeper/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Doorkeeper def self.gem_version Gem::Version.new VERSION::STRING diff --git a/spec/factories.rb b/spec/factories.rb index 4c91b355b..719393fce 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,24 +2,24 @@ factory :access_grant, class: Doorkeeper::AccessGrant do sequence(:resource_owner_id) { |n| n } application - redirect_uri 'https://app.com/callback' - expires_in 100 - scopes 'public write' + redirect_uri { 'https://app.com/callback' } + expires_in { 100 } + scopes { 'public write' } end factory :access_token, class: Doorkeeper::AccessToken do sequence(:resource_owner_id) { |n| n } application - expires_in 2.hours + expires_in { 2.hours } factory :clientless_access_token do - application nil + application { nil } end end factory :application, class: Doorkeeper::Application do sequence(:name) { |n| "Application #{n}" } - redirect_uri 'https://app.com/callback' + redirect_uri { 'https://app.com/callback' } end # do not name this factory :user, otherwise it will conflict with factories diff --git a/spec/lib/orm/active_record/stale_records_cleaner_spec.rb b/spec/lib/stale_records_cleaner_spec.rb similarity index 97% rename from spec/lib/orm/active_record/stale_records_cleaner_spec.rb rename to spec/lib/stale_records_cleaner_spec.rb index 981dabd66..9e35894a7 100644 --- a/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +++ b/spec/lib/stale_records_cleaner_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner do +describe Doorkeeper::StaleRecordsCleaner do let(:cleaner) { described_class.new(model) } let(:models_by_name) do { diff --git a/spec/requests/flows/authorization_code_spec.rb b/spec/requests/flows/authorization_code_spec.rb index 5730abf9d..602c7f7e1 100644 --- a/spec/requests/flows/authorization_code_spec.rb +++ b/spec/requests/flows/authorization_code_spec.rb @@ -66,7 +66,7 @@ page.driver.post token_endpoint_url(code: authorization_code, client_id: @client.uid, redirect_uri: @client.redirect_uri) - expect(Doorkeeper::AccessToken).not_to exist + expect(Doorkeeper::AccessToken.count).to be_zero should_have_json 'error', 'invalid_client' end diff --git a/spec/support/doorkeeper_rspec.rb b/spec/support/doorkeeper_rspec.rb index 4b6f90fc1..08ac52ddc 100644 --- a/spec/support/doorkeeper_rspec.rb +++ b/spec/support/doorkeeper_rspec.rb @@ -4,7 +4,8 @@ class RSpec # Doorkeeper configuration, etc. def self.print_configuration_info puts <<-INFO.strip_heredoc - ====> Doorkeeper ORM = #{Doorkeeper.configuration.orm} + ====> Doorkeeper ORM: '#{Doorkeeper.configuration.orm}' + ====> Doorkeeper version: #{Doorkeeper.gem_version} ====> Rails version: #{::Rails.version} ====> Ruby version: #{RUBY_VERSION} on #{RUBY_PLATFORM} INFO