diff --git a/.codeclimate.yml b/.codeclimate.yml index 5e5fba5..7bb62f4 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -2,7 +2,7 @@ engines: rubocop: enabled: true - channel: rubocop-0-75 + channel: rubocop-1-10-0 bundler-audit: enabled: true ratings: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1591a1f..e661eae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,8 @@ jobs: fail-fast: false matrix: ruby: + - 3.0 + - 2.7 - 2.6 - 2.5 gemfile: diff --git a/.rubocop.yml b/.rubocop.yml index a724b9a..2655b7b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,7 @@ require: rubocop-rails AllCops: TargetRubyVersion: 2.5 + NewCops: enable Exclude: - "bin/**/*" - "test/dummy/bin/**/*" @@ -46,7 +47,7 @@ Style/SymbolArray: Enabled: true # Most readable form. -Layout/AlignHash: +Layout/HashAlignment: EnforcedHashRocketStyle: table EnforcedColonStyle: table @@ -95,7 +96,7 @@ Style/SignalException: # Suppressing exceptions can be perfectly fine, and be it to avoid to # explicitly type nil into the rescue since that's what you want to return, # or suppressing LoadError for optional dependencies -Lint/HandleExceptions: +Lint/SuppressedException: Enabled: false Layout/SpaceInsideBlockBraces: @@ -182,6 +183,19 @@ Rails/Present: Exclude: - "lib/**/*" +# we don't have rails everywhere, so just disable these +Rails/NegateInclude: + Enabled: false +Rails/RakeEnvironment: + Enabled: false + +Lint/ConstantDefinitionInBlock: + Exclude: + - "spec/**/*" + +Naming/InclusiveLanguage: + Enabled: false + Style/SingleLineMethods: Exclude: - "test/dummy/app/models/*" @@ -196,6 +210,10 @@ Style/AccessModifierDeclarations: Exclude: - "lib/diaspora_federation/test/factories.rb" +Style/HashAsLastArrayItem: + Exclude: + - "lib/diaspora_federation/validators/*" + # disable this for now, needs to be rechecked later Style/DateTime: Exclude: diff --git a/.ruby-version b/.ruby-version index 5154b3f..9f55b2c 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6 +3.0 diff --git a/Gemfile b/Gemfile index 749da4e..d5e1b80 100644 --- a/Gemfile +++ b/Gemfile @@ -19,14 +19,10 @@ end group :development do # code style - gem "pronto", "0.10.0", require: false - gem "pronto-rubocop", "0.10.0", require: false - gem "rubocop", "0.75.1", require: false - gem "rubocop-rails", "2.3.2", require: false - - # automatic test runs - gem "guard-rspec", require: false - gem "guard-rubocop", require: false + gem "pronto", "0.11.0", require: false + gem "pronto-rubocop", "0.11.1", require: false + gem "rubocop", "1.18.0", require: false + gem "rubocop-rails", "2.11.1", require: false # debugging gem "pry" @@ -34,15 +30,18 @@ group :development do # documentation gem "yard", require: false + + # rails needs this for development + gem "listen" end group :test do # rspec formatter - gem "fuubar", "2.4.1", require: false + gem "fuubar", "2.5.1", require: false gem "nyan-cat-formatter", require: false # test coverage - gem "simplecov", "0.17.1", require: false + gem "simplecov", "0.21.2", require: false gem "simplecov-rcov", "0.2.3", require: false # test helpers @@ -56,6 +55,6 @@ group :development, :test do gem "rake" # unit tests - gem "rspec", "~> 3.9.0" - gem "rspec-rails", "~> 3.9.0" + gem "rspec", "~> 3.10.0" + gem "rspec-rails", "~> 5.0.1" end diff --git a/Gemfile.lock b/Gemfile.lock index a25f53c..f23d938 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,7 @@ PATH valid (~> 1.0) diaspora_federation-json_schema (0.2.6) diaspora_federation-rails (0.2.6) - actionpack (>= 5, < 7) + actionpack (>= 5.2, < 7) diaspora_federation (= 0.2.6) diaspora_federation-test (0.2.6) diaspora_federation (= 0.2.6) @@ -19,42 +19,42 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (6.0.0) - actionview (= 6.0.0) - activesupport (= 6.0.0) - rack (~> 2.0) + actionpack (6.1.4) + actionview (= 6.1.4) + activesupport (= 6.1.4) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (6.0.0) - activesupport (= 6.0.0) + actionview (6.1.4) + activesupport (= 6.1.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activesupport (6.0.0) + activesupport (6.1.4) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.1, >= 2.1.8) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - ast (2.4.0) - builder (3.2.3) - byebug (11.0.1) - coderay (1.1.2) - concurrent-ruby (1.1.5) - crack (0.4.3) - safe_yaml (~> 1.0.0) - crass (1.0.5) - diff-lcs (1.3) - docile (1.3.2) - erubi (1.9.0) - ethon (0.12.0) - ffi (>= 1.3.0) - fabrication (2.20.2) - faraday (1.4.2) + ast (2.4.2) + builder (3.2.4) + byebug (11.1.3) + coderay (1.1.3) + concurrent-ruby (1.1.9) + crack (0.4.5) + rexml + crass (1.0.6) + diff-lcs (1.4.4) + docile (1.4.0) + erubi (1.10.0) + ethon (0.14.0) + ffi (>= 1.15.0) + fabrication (2.22.0) + faraday (1.4.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -69,92 +69,71 @@ GEM faraday-net_http_persistent (1.1.0) faraday_middleware (1.0.0) faraday (~> 1.0) - ffi (1.11.1) - formatador (0.2.5) - fuubar (2.4.1) + ffi (1.15.3) + fuubar (2.5.1) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) - gitlab (4.12.0) - httparty (~> 0.14, >= 0.14.0) + gitlab (4.17.0) + httparty (~> 0.18) terminal-table (~> 1.5, >= 1.5.1) - guard (2.15.1) - formatador (>= 0.2.4) - listen (>= 2.7, < 4.0) - lumberjack (>= 1.0.12, < 2.0) - nenv (~> 0.1) - notiffany (~> 0.0) - pry (>= 0.9.12) - shellany (~> 0.0) - thor (>= 0.18.1) - guard-compat (1.2.1) - guard-rspec (4.7.3) - guard (~> 2.1) - guard-compat (~> 1.1) - rspec (>= 2.99.0, < 4.0) - guard-rubocop (1.3.0) - guard (~> 2.0) - rubocop (~> 0.20) - hashdiff (1.0.0) - httparty (0.17.1) + hashdiff (1.0.1) + httparty (0.18.1) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.7.0) + i18n (1.8.10) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.3) - json (2.2.0) json-schema (2.8.1) addressable (>= 2.4) json-schema-rspec (0.0.4) json-schema (~> 2.5) rspec - listen (3.2.0) + listen (3.5.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.3.0) + loofah (2.10.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - lumberjack (1.0.13) macaddr (1.7.2) systemu (~> 2.6.5) - method_source (0.9.2) - mime-types (3.3) + method_source (1.0.0) + mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2019.1009) - mini_portile2 (2.4.0) - minitest (5.12.2) + mime-types-data (3.2021.0225) + mini_portile2 (2.5.3) + minitest (5.14.4) multi_xml (0.6.0) multipart-post (2.1.1) - nenv (0.3.0) - nokogiri (1.10.4) - mini_portile2 (~> 2.4.0) - notiffany (0.1.3) - nenv (~> 0.1) - shellany (~> 0.0) + nokogiri (1.11.7) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) nyan-cat-formatter (0.12.0) rspec (>= 2.99, >= 2.14.2, < 4) - octokit (4.14.0) + octokit (4.21.0) + faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) - parallel (1.18.0) - parser (2.6.5.0) - ast (~> 2.4.0) - pronto (0.10.0) - gitlab (~> 4.0, >= 4.0.0) + parallel (1.20.1) + parser (3.0.1.1) + ast (~> 2.4.1) + pronto (0.11.0) + gitlab (~> 4.4, >= 4.4.0) httparty (>= 0.13.7) octokit (~> 4.7, >= 4.7.0) rainbow (>= 2.2, < 4.0) - rugged (~> 0.24, >= 0.23.0) - thor (~> 0.20.0) - pronto-rubocop (0.10.0) - pronto (~> 0.10.0) - rubocop (~> 0.50, >= 0.49.1) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-byebug (3.7.0) + rexml (~> 3.2) + rugged (>= 0.23.0, < 1.1.0) + thor (>= 0.20.3, < 2.0) + pronto-rubocop (0.11.1) + pronto (~> 0.11.0) + rubocop (>= 0.63.1, < 2.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) byebug (~> 11.0) - pry (~> 0.10) - public_suffix (4.0.1) - rack (2.0.7) + pry (~> 0.13.0) + public_suffix (4.0.6) + racc (1.5.2) + rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) rails-dom-testing (2.0.3) @@ -162,85 +141,90 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - railties (6.0.0) - actionpack (= 6.0.0) - activesupport (= 6.0.0) + railties (6.1.4) + actionpack (= 6.1.4) + activesupport (= 6.1.4) method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) + rake (>= 0.13) + thor (~> 1.0) rainbow (3.0.0) - rake (13.0.0) - rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rake (13.0.3) + rb-fsevent (0.11.0) + rb-inotify (0.10.1) ffi (~> 1.0) - rspec (3.9.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) + regexp_parser (2.1.1) + rexml (3.2.5) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) rspec-collection_matchers (1.2.0) rspec-expectations (>= 2.99.0.beta1) - rspec-core (3.9.0) - rspec-support (~> 3.9.0) - rspec-expectations (3.9.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) + rspec-support (~> 3.10.0) rspec-json_expectations (2.2.0) - rspec-mocks (3.9.0) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-rails (3.9.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.0) - rubocop (0.75.1) - jaro_winkler (~> 1.5.1) + rspec-support (~> 3.10.0) + rspec-rails (5.0.1) + actionpack (>= 5.2) + activesupport (>= 5.2) + railties (>= 5.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.10.2) + rubocop (1.18.0) parallel (~> 1.10) - parser (>= 2.6) + parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.7.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - rubocop-rails (2.3.2) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.7.0) + parser (>= 3.0.1.1) + rubocop-rails (2.11.1) + activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.72.0) - ruby-progressbar (1.10.1) + rubocop (>= 1.7.0, < 2.0) + ruby-progressbar (1.11.0) ruby2_keywords (0.0.4) - rugged (0.28.3.1) - safe_yaml (1.0.5) + rugged (1.0.1) sawyer (0.8.2) addressable (>= 2.3.5) faraday (> 0.8, < 2.0) - shellany (0.0.1) - simplecov (0.17.1) + simplecov (0.21.2) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) simplecov-rcov (0.2.3) simplecov (>= 0.4.1) + simplecov_json_formatter (0.1.3) systemu (2.6.5) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) - thor (0.20.3) - thread_safe (0.3.6) + thor (1.1.0) typhoeus (1.4.0) ethon (>= 0.9.0) - tzinfo (1.2.5) - thread_safe (~> 0.1) - unicode-display_width (1.6.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + unicode-display_width (1.7.0) uuid (2.3.9) macaddr (~> 1.0) valid (1.2.0) - webmock (3.7.6) + webmock (3.13.0) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - yard (0.9.20) - zeitwerk (2.2.0) + yard (0.9.26) + zeitwerk (2.4.2) PLATFORMS ruby @@ -250,26 +234,25 @@ DEPENDENCIES diaspora_federation-json_schema! diaspora_federation-rails! diaspora_federation-test! - fuubar (= 2.4.1) - guard-rspec - guard-rubocop + fuubar (= 2.5.1) json-schema-rspec (= 0.0.4) + listen nyan-cat-formatter - pronto (= 0.10.0) - pronto-rubocop (= 0.10.0) + pronto (= 0.11.0) + pronto-rubocop (= 0.11.1) pry pry-byebug rake - rspec (~> 3.9.0) + rspec (~> 3.10.0) rspec-collection_matchers (~> 1.2.0) rspec-json_expectations (~> 2.1) - rspec-rails (~> 3.9.0) - rubocop (= 0.75.1) - rubocop-rails (= 2.3.2) - simplecov (= 0.17.1) + rspec-rails (~> 5.0.1) + rubocop (= 1.18.0) + rubocop-rails (= 2.11.1) + simplecov (= 0.21.2) simplecov-rcov (= 0.2.3) webmock (~> 3.0) yard BUNDLED WITH - 2.1.4 + 2.2.21 diff --git a/Guardfile b/Guardfile deleted file mode 100644 index d0f3e68..0000000 --- a/Guardfile +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -guard :rspec, cmd: "NO_COVERAGE=true bin/rspec" do - require "guard/rspec/dsl" - dsl = Guard::RSpec::Dsl.new(self) - - # RSpec files - rspec = dsl.rspec - watch(rspec.spec_helper) { rspec.spec_dir } - watch(rspec.spec_support) { rspec.spec_dir } - watch(rspec.spec_files) - - # Ruby files - ruby = dsl.ruby - dsl.watch_spec_files_for(ruby.lib_files) - - # Rails files - rails = dsl.rails - dsl.watch_spec_files_for(rails.app_files) - - # Rails config changes - rails.app_controller = "app/controllers/diaspora_federation/application_controller.rb" - watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } - watch(rails.routes) { "#{rspec.spec_dir}/routing" } -end - -guard :rubocop do - watch(/.+\.rb$/) - watch(/\.rubocop\.yml$/) {|m| File.dirname(m[0]) } -end diff --git a/bin/guard b/bin/guard deleted file mode 100755 index 3df2151..0000000 --- a/bin/guard +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'guard' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("guard", "guard") diff --git a/bin/rails b/bin/rails index 4595731..6b5ee87 100755 --- a/bin/rails +++ b/bin/rails @@ -1,12 +1,14 @@ #!/usr/bin/env ruby -# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. +# This command will automatically be run when you run "rails" with Rails gems +# installed from the root of your application. -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/diaspora_federation/engine', __FILE__) +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/diaspora_federation/engine', __dir__) +APP_PATH = File.expand_path('../test/dummy/config/application', __dir__) # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) -require 'rails/all' -require 'rails/engine/commands' +require "rails/all" +require "rails/engine/commands" diff --git a/diaspora_federation-json_schema.gemspec b/diaspora_federation-json_schema.gemspec index 5cae269..4f782b8 100644 --- a/diaspora_federation-json_schema.gemspec +++ b/diaspora_federation-json_schema.gemspec @@ -18,4 +18,6 @@ Gem::Specification.new do |s| s.license = "AGPL-3.0" s.files = Dir["lib/diaspora_federation/schemas.rb", "lib/diaspora_federation/schemas/*.json"] + + s.required_ruby_version = ">= 2.5" end diff --git a/diaspora_federation-rails.gemspec b/diaspora_federation-rails.gemspec index 625372d..223b0e5 100644 --- a/diaspora_federation-rails.gemspec +++ b/diaspora_federation-rails.gemspec @@ -19,9 +19,9 @@ Gem::Specification.new do |s| s.files = Dir["app/**/*", "config/routes.rb", "config/initializers/*", "lib/diaspora_federation/{engine,rails}.rb", "LICENSE", "README.md", "Changelog.md"] - s.required_ruby_version = "~> 2.5" + s.required_ruby_version = ">= 2.5" - s.add_dependency "actionpack", ">= 5", "< 7" + s.add_dependency "actionpack", ">= 5.2", "< 7" s.add_dependency "diaspora_federation", DiasporaFederation::VERSION end diff --git a/diaspora_federation-test.gemspec b/diaspora_federation-test.gemspec index 40a0da8..de886bd 100644 --- a/diaspora_federation-test.gemspec +++ b/diaspora_federation-test.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.files = Dir["lib/diaspora_federation/test.rb", "lib/diaspora_federation/test/*"] - s.required_ruby_version = "~> 2.5" + s.required_ruby_version = ">= 2.5" s.add_dependency "diaspora_federation", DiasporaFederation::VERSION s.add_dependency "fabrication", "~> 2.16" diff --git a/diaspora_federation.gemspec b/diaspora_federation.gemspec index ee0fb02..8e8cc0d 100644 --- a/diaspora_federation.gemspec +++ b/diaspora_federation.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| "lib/diaspora_federation/test/*", "lib/tasks/*.rake"] - s.required_ruby_version = "~> 2.5" + s.required_ruby_version = ">= 2.5" s.add_dependency "faraday", "~> 1.0" s.add_dependency "faraday_middleware", "~> 1.0" diff --git a/lib/diaspora_federation/discovery/discovery.rb b/lib/diaspora_federation/discovery/discovery.rb index 23f2ea0..ac637af 100644 --- a/lib/diaspora_federation/discovery/discovery.rb +++ b/lib/diaspora_federation/discovery/discovery.rb @@ -46,7 +46,7 @@ module DiasporaFederation diaspora_id.strip.sub("acct:", "").to_s.downcase end - def get(url, http_fallback=false) + def get(url, http_fallback: false) logger.info "Fetching #{url} for #{diaspora_id}" response = HttpClient.get(url) raise "Failed to fetch #{url}: #{response.status}" unless response.success? @@ -69,7 +69,7 @@ module DiasporaFederation def legacy_webfinger_url_from_host_meta # This tries the xrd url with https first, then falls back to http. - host_meta = HostMeta.from_xml(get("https://#{domain}/.well-known/host-meta", true)) + host_meta = HostMeta.from_xml(get("https://#{domain}/.well-known/host-meta", http_fallback: true)) host_meta.webfinger_template_url.gsub("{uri}", acct_parameter) end @@ -79,7 +79,7 @@ module DiasporaFederation webfinger_url = "https://#{domain}/.well-known/webfinger?resource=#{acct_parameter}" # This tries the WebFinger URL with https first, then falls back to http if webfinger_http_fallback is enabled. - @webfinger = WebFinger.from_json(get(webfinger_url, DiasporaFederation.webfinger_http_fallback)) + @webfinger = WebFinger.from_json(get(webfinger_url, http_fallback: DiasporaFederation.webfinger_http_fallback)) rescue => e # rubocop:disable Style/RescueStandardError logger.warn "WebFinger failed, retrying with legacy WebFinger for #{diaspora_id}: #{e.class}: #{e.message}" @webfinger = WebFinger.from_xml(get(legacy_webfinger_url_from_host_meta)) diff --git a/lib/diaspora_federation/discovery/host_meta.rb b/lib/diaspora_federation/discovery/host_meta.rb index cc15da0..80de836 100644 --- a/lib/diaspora_federation/discovery/host_meta.rb +++ b/lib/diaspora_federation/discovery/host_meta.rb @@ -77,7 +77,7 @@ module DiasporaFederation # @param [String] url validation subject # @return [Boolean] validation result private_class_method def self.webfinger_url_valid?(url) - !url.nil? && url.instance_of?(String) && url =~ %r{\Ahttps?:\/\/.*\/.*\{uri\}.*}i + !url.nil? && url.instance_of?(String) && url =~ %r{\Ahttps?://.*/.*\{uri\}.*}i end # Gets the webfinger url from an XRD data structure diff --git a/lib/diaspora_federation/discovery/xrd_document.rb b/lib/diaspora_federation/discovery/xrd_document.rb index 6a3bb21..eecab2e 100644 --- a/lib/diaspora_federation/discovery/xrd_document.rb +++ b/lib/diaspora_federation/discovery/xrd_document.rb @@ -89,7 +89,7 @@ module DiasporaFederation aliases: (aliases if aliases.any?), properties: (properties if properties.any?), links: (links if links.any?) - }.reject {|_, v| v.nil? } + }.compact end # Parse the XRD document from the given string and create a hash containing @@ -132,7 +132,7 @@ module DiasporaFederation aliases: json_hash["aliases"], properties: json_hash["properties"], links: symbolize_keys_for_links(json_hash["links"]) - }.reject {|_, v| v.nil? } + }.compact rescue JSON::JSONError => e raise InvalidDocument, "Not a JRD document: #{e.class}: #{e.message[0..255].encode(Encoding.default_external, undef: :replace)}" @@ -140,8 +140,10 @@ module DiasporaFederation private + # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor Style/AccessorGrouping attr_reader :expires attr_reader :subject + # rubocop:enable Layout/EmptyLinesAroundAttributeAccessor Style/AccessorGrouping NS = {xrd: XMLNS}.freeze diff --git a/lib/diaspora_federation/entities/signable.rb b/lib/diaspora_federation/entities/signable.rb index 1301f17..031d25a 100644 --- a/lib/diaspora_federation/entities/signable.rb +++ b/lib/diaspora_federation/entities/signable.rb @@ -7,7 +7,7 @@ module DiasporaFederation include Logging # Digest instance used for signing - DIGEST = OpenSSL::Digest::SHA256.new + DIGEST = OpenSSL::Digest.new("SHA256") # Sign the data with the key # diff --git a/lib/diaspora_federation/entity.rb b/lib/diaspora_federation/entity.rb index 3aa042b..6990616 100644 --- a/lib/diaspora_federation/entity.rb +++ b/lib/diaspora_federation/entity.rb @@ -321,7 +321,7 @@ module DiasporaFederation # Generates a hash with entity properties which is put to the "entity_data" # field of a JSON serialized object. # @return [Hash] object properties in JSON format - def json_data + def json_data # rubocop:disable Metrics/PerceivedComplexity enriched_properties.map {|key, value| type = self.class.class_props[key] next if optional_nil_value?(key, value) @@ -330,7 +330,7 @@ module DiasporaFederation entity_data = value.to_json [key, entity_data] unless entity_data.nil? elsif type.instance_of?(Array) - entity_data = value.nil? ? nil : value.map(&:to_json) + entity_data = value&.map(&:to_json) [key, entity_data] unless entity_data.nil? else [key, value] diff --git a/lib/diaspora_federation/logging.rb b/lib/diaspora_federation/logging.rb index 29fb7b2..ab73376 100644 --- a/lib/diaspora_federation/logging.rb +++ b/lib/diaspora_federation/logging.rb @@ -17,15 +17,15 @@ module DiasporaFederation # # Use the logging-gem if available, else use a default logger. def logger - @logger ||= begin + @logger ||= if defined?(::Logging::Logger) # Use logging-gem if available - return ::Logging::Logger[self] if defined?(::Logging::Logger) - + ::Logging::Logger[self] + elsif defined?(::Rails) # Use rails logger if running in rails and no logging-gem is available - return ::Rails.logger if defined?(::Rails) - + ::Rails.logger + else # fallback logger - @logger = Logger.new(STDOUT) + @logger = Logger.new($stdout) @logger.level = Logger::INFO @logger end diff --git a/lib/diaspora_federation/properties_dsl.rb b/lib/diaspora_federation/properties_dsl.rb index b420c14..715573a 100644 --- a/lib/diaspora_federation/properties_dsl.rb +++ b/lib/diaspora_federation/properties_dsl.rb @@ -57,9 +57,9 @@ module DiasporaFederation # resolved on each call # @return [Hash] default values def default_values - optional_props.map {|name| [name, nil] }.to_h.merge(default_props).map {|name, prop| - [name, prop.respond_to?(:call) ? prop.call : prop] - }.to_h + optional_props.map {|name| [name, nil] }.to_h.merge(default_props).transform_values {|prop| + prop.respond_to?(:call) ? prop.call : prop + } end # @param [Hash] data entity data diff --git a/lib/diaspora_federation/salmon/aes.rb b/lib/diaspora_federation/salmon/aes.rb index cc55e28..dffd706 100644 --- a/lib/diaspora_federation/salmon/aes.rb +++ b/lib/diaspora_federation/salmon/aes.rb @@ -21,7 +21,7 @@ module DiasporaFederation # @param [String] iv AES initialization vector # @return [String] base64 encoded ciphertext # @raise [ArgumentError] if any of the arguments is missing or not the correct type - def self.encrypt(data, key, iv) # rubocop:disable Naming/UncommunicativeMethodParamName + def self.encrypt(data, key, iv) # rubocop:disable Naming/MethodParameterName raise ArgumentError unless data.instance_of?(String) && key.instance_of?(String) && iv.instance_of?(String) @@ -43,7 +43,7 @@ module DiasporaFederation # @param [String] iv AES initialization vector # @return [String] decrypted plain message # @raise [ArgumentError] if any of the arguments is missing or not the correct type - def self.decrypt(ciphertext, key, iv) # rubocop:disable Naming/UncommunicativeMethodParamName + def self.decrypt(ciphertext, key, iv) # rubocop:disable Naming/MethodParameterName raise ArgumentError unless ciphertext.instance_of?(String) && key.instance_of?(String) && iv.instance_of?(String) diff --git a/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb b/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb index 83b585d..df9c044 100644 --- a/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb +++ b/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb @@ -38,7 +38,7 @@ module DiasporaFederation key = AES.generate_key_and_iv encrypted_env = AES.encrypt(magic_env.to_xml, key[:key], key[:iv]) - encoded_key = key.map {|k, v| [k, Base64.strict_encode64(v)] }.to_h + encoded_key = key.transform_values {|v| Base64.strict_encode64(v) } encrypted_key = Base64.strict_encode64(pubkey.public_encrypt(JSON.generate(encoded_key))) JSON.generate(aes_key: encrypted_key, encrypted_magic_envelope: encrypted_env) @@ -53,7 +53,7 @@ module DiasporaFederation encrypted_json = JSON.parse(encrypted_env) encoded_key = JSON.parse(privkey.private_decrypt(Base64.decode64(encrypted_json["aes_key"]))) - key = encoded_key.map {|k, v| [k, Base64.decode64(v)] }.to_h + key = encoded_key.transform_values {|v| Base64.decode64(v) } xml = AES.decrypt(encrypted_json["encrypted_magic_envelope"], key["key"], key["iv"]) Nokogiri::XML(xml).root diff --git a/lib/diaspora_federation/salmon/magic_envelope.rb b/lib/diaspora_federation/salmon/magic_envelope.rb index fafa1cd..042a34f 100644 --- a/lib/diaspora_federation/salmon/magic_envelope.rb +++ b/lib/diaspora_federation/salmon/magic_envelope.rb @@ -35,7 +35,7 @@ module DiasporaFederation DATA_TYPE = "application/xml" # Digest instance used for signing - DIGEST = OpenSSL::Digest::SHA256.new + DIGEST = OpenSSL::Digest.new("SHA256") # XML namespace url XMLNS = "http://salmon-protocol.org/ns/magic-env" @@ -137,10 +137,8 @@ module DiasporaFederation # @yield [xml] Invokes the block with the # {http://www.rubydoc.info/gems/nokogiri/Nokogiri/XML/Builder Nokogiri::XML::Builder} # @return [Nokogiri::XML::Element] XML root node - def build_xml - Nokogiri::XML::Builder.new(encoding: "UTF-8") {|xml| - yield xml - }.doc + def build_xml(&block) + Nokogiri::XML::Builder.new(encoding: "UTF-8", &block).doc end # Creates the signature for all fields according to specification diff --git a/lib/diaspora_federation/test/entity_generator.rb b/lib/diaspora_federation/test/entity_generator.rb index 9e610c0..24a7e63 100644 --- a/lib/diaspora_federation/test/entity_generator.rb +++ b/lib/diaspora_federation/test/entity_generator.rb @@ -14,9 +14,7 @@ module DiasporaFederation def to_hash(attributes=[], _callbacks=[]) process_attributes(attributes) - _attributes.each_with_object({}) do |(name, value), hash| - hash[name.to_sym] = value - end + _attributes.transform_keys(&:to_sym) end end diff --git a/lib/diaspora_federation/validators/rules/birthday.rb b/lib/diaspora_federation/validators/rules/birthday.rb index 21c28a0..751357e 100644 --- a/lib/diaspora_federation/validators/rules/birthday.rb +++ b/lib/diaspora_federation/validators/rules/birthday.rb @@ -22,7 +22,7 @@ module Validation return true if value.nil? || (value.is_a?(String) && value.empty?) return true if value.is_a? Date - if value.is_a?(String) && value.match?(/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/) + if value.is_a?(String) && value.match?(/[0-9]{4}-[0-9]{2}-[0-9]{2}/) date_field = value.split("-").map(&:to_i) return Date.valid_civil?(date_field[0], date_field[1], date_field[2]) end diff --git a/lib/diaspora_federation/validators/rules/boolean.rb b/lib/diaspora_federation/validators/rules/boolean.rb index 01f0e30..6be0c6c 100644 --- a/lib/diaspora_federation/validators/rules/boolean.rb +++ b/lib/diaspora_federation/validators/rules/boolean.rb @@ -19,14 +19,13 @@ module Validation def valid_value?(value) return false if value.nil? - if value.is_a?(String) + case value + when String true if value =~ /\A(true|false|t|f|yes|no|y|n|1|0)\z/i - elsif value.is_a?(Integer) + when Integer true if [1, 0].include?(value) - elsif [true, false].include?(value) - true else - false + [true, false].include?(value) end end diff --git a/lib/tasks/gemfiles.rake b/lib/tasks/gemfiles.rake index 3500bdd..582dd7e 100644 --- a/lib/tasks/gemfiles.rake +++ b/lib/tasks/gemfiles.rake @@ -17,7 +17,7 @@ namespace :gemfiles do no_rails_path = "test/gemfiles/no-rails.Gemfile" File.write(no_rails_path, no_rails_gemfile) - Bundler.with_clean_env do + Bundler.with_unbundled_env do system("BUNDLE_GEMFILE=#{no_rails_path} bundle install") end end diff --git a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb index c1a4fa1..1e0af9d 100644 --- a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb +++ b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb @@ -78,7 +78,7 @@ module DiasporaFederation it "raises when the resource parameter is missing" do expect { get :webfinger, format: :json - }.to raise_error ActionController::ParameterMissing, "param is missing or the value is empty: resource" + }.to raise_error ActionController::ParameterMissing, /param is missing or the value is empty: resource/ end it "calls the fetch_person_for_webfinger callback" do diff --git a/spec/lib/diaspora_federation/callbacks_spec.rb b/spec/lib/diaspora_federation/callbacks_spec.rb index 80e0ff3..41e4872 100644 --- a/spec/lib/diaspora_federation/callbacks_spec.rb +++ b/spec/lib/diaspora_federation/callbacks_spec.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Lint/EmptyBlock module DiasporaFederation describe Callbacks do subject(:callbacks) { Callbacks.new %i[some_event another_event] } @@ -74,3 +75,4 @@ module DiasporaFederation end end end +# rubocop:enable Lint/EmptyBlock diff --git a/spec/lib/diaspora_federation/discovery/h_card_spec.rb b/spec/lib/diaspora_federation/discovery/h_card_spec.rb index 5c2da01..3c548c3 100644 --- a/spec/lib/diaspora_federation/discovery/h_card_spec.rb +++ b/spec/lib/diaspora_federation/discovery/h_card_spec.rb @@ -25,10 +25,9 @@ module DiasporaFederation let(:html) { <<~HTML } - +
- - +