diff --git a/.envrc b/.envrc deleted file mode 100644 index 234188d..0000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -PATH_add bin diff --git a/.gitignore b/.gitignore index 0a48702..921a949 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ doc # dummmy app test/dummy/log/*.log test/dummy/log/*.log* +test/dummy/tmp rspec-persistence.txt diff --git a/.rubocop.yml b/.rubocop.yml index 2564b28..a724b9a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,7 @@ +require: rubocop-rails + AllCops: - TargetRubyVersion: 2.1 + TargetRubyVersion: 2.5 Exclude: - "bin/**/*" - "test/dummy/bin/**/*" @@ -199,16 +201,3 @@ Style/DateTime: Exclude: - "lib/diaspora_federation/discovery/xrd_document.rb" - "spec/lib/diaspora_federation/discovery/xrd_document_spec.rb" - -### backward compatibility - -# only with ruby >= 2.3 -Layout/IndentHeredoc: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false - -# for rails 4 and ruby < 2.2.2 -Rails/HttpPositionalArguments: - Exclude: - - "spec/controllers/diaspora_federation/rails4_spec.rb" diff --git a/.ruby-version b/.ruby-version index 6b4950e..5154b3f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4 +2.6 diff --git a/.travis.yml b/.travis.yml index 6622592..69c695b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,12 @@ language: ruby rvm: - - 2.5.5 - - 2.4.5 - - 2.3.8 - - 2.2.10 - - 2.1 + - 2.6.5 + - 2.5.7 gemfile: - Gemfile - - test/gemfiles/rails4.Gemfile - test/gemfiles/no-rails.Gemfile -matrix: - exclude: - - rvm: 2.1 - gemfile: Gemfile - sudo: false cache: bundler: true diff --git a/Gemfile b/Gemfile index 0897dae..c67d4fc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" # Declare your gem's dependencies in diaspora_federation.gemspec. @@ -17,9 +19,10 @@ end group :development do # code style - gem "pronto", "0.9.5", require: false - gem "pronto-rubocop", "0.9.1", require: false - gem "rubocop", "0.57.2", require: false + 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 @@ -40,16 +43,16 @@ end group :test do # rspec formatter - gem "fuubar", "2.3.2", require: false + gem "fuubar", "2.4.1", require: false gem "nyan-cat-formatter", require: false # test coverage - gem "simplecov", "0.16.1", require: false + gem "simplecov", "0.17.1", require: false gem "simplecov-rcov", "0.2.3", require: false # test helpers gem "json-schema-rspec", "0.0.4" - gem "rspec-collection_matchers", "~> 1.1.2" + gem "rspec-collection_matchers", "~> 1.2.0" gem "rspec-json_expectations", "~> 2.1" gem "webmock", "~> 3.0" end @@ -58,6 +61,6 @@ group :development, :test do gem "rake" # unit tests - gem "rspec", "~> 3.8.0" - gem "rspec-rails", "~> 3.8.0" + gem "rspec", "~> 3.9.0" + gem "rspec-rails", "~> 3.9.0" end diff --git a/Gemfile.lock b/Gemfile.lock index 9ebdd4b..f729fb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,14 +2,14 @@ PATH remote: . specs: diaspora_federation (0.2.6) - faraday (>= 0.9.0, < 0.16.0) + faraday (>= 0.9.0, < 0.18.0) faraday_middleware (>= 0.10.0, < 0.14.0) nokogiri (~> 1.6, >= 1.6.8) typhoeus (~> 1.0) valid (~> 1.0) diaspora_federation-json_schema (0.2.6) diaspora_federation-rails (0.2.6) - actionpack (>= 4.2, < 6) + actionpack (>= 5, < 7) diaspora_federation (= 0.2.6) diaspora_federation-test (0.2.6) diaspora_federation (= 0.2.6) @@ -19,26 +19,27 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (5.2.2.1) - actionview (= 5.2.2.1) - activesupport (= 5.2.2.1) + actionpack (6.0.0) + actionview (= 6.0.0) + activesupport (= 6.0.0) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.2.1) - activesupport (= 5.2.2.1) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actionview (6.0.0) + activesupport (= 6.0.0) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activesupport (5.2.2.1) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activesupport (6.0.0) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) + zeitwerk (~> 2.1, >= 2.1.8) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) ast (2.4.0) builder (3.2.3) byebug (11.0.1) @@ -46,26 +47,26 @@ GEM concurrent-ruby (1.1.5) crack (0.4.3) safe_yaml (~> 1.0.0) - crass (1.0.4) + crass (1.0.5) diff-lcs (1.3) - docile (1.3.1) - erubi (1.8.0) + docile (1.3.2) + erubi (1.9.0) ethon (0.12.0) ffi (>= 1.3.0) - fabrication (2.20.1) - faraday (0.15.4) + fabrication (2.20.2) + faraday (0.17.0) multipart-post (>= 1.2, < 3) faraday_middleware (0.13.1) faraday (>= 0.7.4, < 1.0) - ffi (1.10.0) + ffi (1.11.1) formatador (0.2.5) - fuubar (2.3.2) + fuubar (2.4.1) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) - gitlab (4.10.0) + gitlab (4.12.0) httparty (~> 0.14, >= 0.14.0) terminal-table (~> 1.5, >= 1.5.1) - guard (2.15.0) + guard (2.15.1) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) lumberjack (>= 1.0.12, < 2.0) @@ -82,60 +83,58 @@ GEM guard-rubocop (1.3.0) guard (~> 2.0) rubocop (~> 0.20) - hashdiff (0.3.8) - httparty (0.16.4) + hashdiff (1.0.0) + httparty (0.17.1) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.4.0) + i18n (1.7.0) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.2) + 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.1.5) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - ruby_dep (~> 1.2) - loofah (2.2.3) + listen (3.2.0) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + loofah (2.3.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.0.13) - macaddr (1.7.1) - systemu (~> 2.6.2) + macaddr (1.7.2) + systemu (~> 2.6.5) method_source (0.9.2) - mime-types (3.2.2) + mime-types (3.3) mime-types-data (~> 3.2015) - mime-types-data (3.2018.0812) + mime-types-data (3.2019.1009) mini_portile2 (2.4.0) - minitest (5.11.3) + minitest (5.12.2) multi_xml (0.6.0) - multipart-post (2.0.0) + multipart-post (2.1.1) nenv (0.3.0) - nokogiri (1.9.1) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) - notiffany (0.1.1) + notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) nyan-cat-formatter (0.12.0) rspec (>= 2.99, >= 2.14.2, < 4) - octokit (4.13.0) + octokit (4.14.0) sawyer (~> 0.8.0, >= 0.5.3) - parallel (1.14.0) - parser (2.6.2.0) + parallel (1.18.0) + parser (2.6.5.0) ast (~> 2.4.0) - powerpack (0.1.2) - pronto (0.9.5) + pronto (0.10.0) gitlab (~> 4.0, >= 4.0.0) httparty (>= 0.13.7) octokit (~> 4.7, >= 4.7.0) - rainbow (~> 2.1) + rainbow (>= 2.2, < 4.0) rugged (~> 0.24, >= 0.23.0) - thor (~> 0.19.0) - pronto-rubocop (0.9.1) - pronto (~> 0.9.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) @@ -143,76 +142,75 @@ GEM pry-byebug (3.7.0) byebug (~> 11.0) pry (~> 0.10) - public_suffix (3.0.3) - rack (2.0.6) + public_suffix (4.0.1) + rack (2.0.7) rack-test (1.1.0) rack (>= 1.0, < 3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.2.2.1) - actionpack (= 5.2.2.1) - activesupport (= 5.2.2.1) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (6.0.0) + actionpack (= 6.0.0) + activesupport (= 6.0.0) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rainbow (2.2.2) - rake - rake (12.3.2) + thor (>= 0.20.3, < 2.0) + rainbow (3.0.0) + rake (13.0.0) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-collection_matchers (1.1.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-collection_matchers (1.2.0) rspec-expectations (>= 2.99.0.beta1) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-json_expectations (2.1.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.9.0) + rspec-json_expectations (2.2.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.2) + rspec-support (~> 3.9.0) + rspec-rails (3.9.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - rubocop (0.57.2) + 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) parallel (~> 1.10) - parser (>= 2.5) - powerpack (~> 0.1) + parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.10.0) - ruby_dep (1.5.0) - rugged (0.28.1) + unicode-display_width (>= 1.4.0, < 1.7) + rubocop-rails (2.3.2) + rack (>= 1.1) + rubocop (>= 0.72.0) + ruby-progressbar (1.10.1) + rugged (0.28.3.1) safe_yaml (1.0.5) - sawyer (0.8.1) - addressable (>= 2.3.5, < 2.6) - faraday (~> 0.8, < 1.0) + sawyer (0.8.2) + addressable (>= 2.3.5) + faraday (> 0.8, < 2.0) shellany (0.0.1) - simplecov (0.16.1) + simplecov (0.17.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) simplecov-rcov (0.2.3) simplecov (>= 0.4.1) - spring (2.0.2) - activesupport (>= 4.2) + spring (2.1.0) spring-commands-rspec (1.0.4) spring (>= 0.9.1) spring-watcher-listen (2.0.1) @@ -221,21 +219,22 @@ GEM systemu (2.6.5) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) - thor (0.19.4) + thor (0.20.3) thread_safe (0.3.6) typhoeus (1.3.1) ethon (>= 0.9.0) tzinfo (1.2.5) thread_safe (~> 0.1) - unicode-display_width (1.5.0) + unicode-display_width (1.6.0) uuid (2.3.9) macaddr (~> 1.0) valid (1.2.0) - webmock (3.5.1) + webmock (3.7.6) addressable (>= 2.3.6) crack (>= 0.3.2) - hashdiff + hashdiff (>= 0.4.0, < 2.0.0) yard (0.9.20) + zeitwerk (2.2.0) PLATFORMS ruby @@ -245,22 +244,23 @@ DEPENDENCIES diaspora_federation-json_schema! diaspora_federation-rails! diaspora_federation-test! - fuubar (= 2.3.2) + fuubar (= 2.4.1) guard-rspec guard-rubocop json-schema-rspec (= 0.0.4) nyan-cat-formatter - pronto (= 0.9.5) - pronto-rubocop (= 0.9.1) + pronto (= 0.10.0) + pronto-rubocop (= 0.10.0) pry pry-byebug rake - rspec (~> 3.8.0) - rspec-collection_matchers (~> 1.1.2) + rspec (~> 3.9.0) + rspec-collection_matchers (~> 1.2.0) rspec-json_expectations (~> 2.1) - rspec-rails (~> 3.8.0) - rubocop (= 0.57.2) - simplecov (= 0.16.1) + rspec-rails (~> 3.9.0) + rubocop (= 0.75.1) + rubocop-rails (= 2.3.2) + simplecov (= 0.17.1) simplecov-rcov (= 0.2.3) spring spring-commands-rspec @@ -269,4 +269,4 @@ DEPENDENCIES yard BUNDLED WITH - 1.17.3 + 2.0.2 diff --git a/Guardfile b/Guardfile index ef40b68..d0f3e68 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + guard :rspec, cmd: "NO_COVERAGE=true bin/rspec" do require "guard/rspec/dsl" dsl = Guard::RSpec::Dsl.new(self) diff --git a/Rakefile b/Rakefile index ad80011..a3a1bb9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + begin require "bundler/setup" rescue LoadError diff --git a/app/controllers/diaspora_federation/application_controller.rb b/app/controllers/diaspora_federation/application_controller.rb index 820394f..47eefd3 100644 --- a/app/controllers/diaspora_federation/application_controller.rb +++ b/app/controllers/diaspora_federation/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # Base controller for all DiasporaFederation controllers class ApplicationController < ActionController::Base diff --git a/app/controllers/diaspora_federation/fetch_controller.rb b/app/controllers/diaspora_federation/fetch_controller.rb index de5d651..24ec5fd 100644 --- a/app/controllers/diaspora_federation/fetch_controller.rb +++ b/app/controllers/diaspora_federation/fetch_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency "diaspora_federation/application_controller" module DiasporaFederation diff --git a/app/controllers/diaspora_federation/h_card_controller.rb b/app/controllers/diaspora_federation/h_card_controller.rb index b7d2f2e..b7af1f8 100644 --- a/app/controllers/diaspora_federation/h_card_controller.rb +++ b/app/controllers/diaspora_federation/h_card_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency "diaspora_federation/application_controller" module DiasporaFederation diff --git a/app/controllers/diaspora_federation/receive_controller.rb b/app/controllers/diaspora_federation/receive_controller.rb index 9155a8a..a477dfd 100644 --- a/app/controllers/diaspora_federation/receive_controller.rb +++ b/app/controllers/diaspora_federation/receive_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency "diaspora_federation/application_controller" module DiasporaFederation diff --git a/app/controllers/diaspora_federation/webfinger_controller.rb b/app/controllers/diaspora_federation/webfinger_controller.rb index 542eb8f..da275de 100644 --- a/app/controllers/diaspora_federation/webfinger_controller.rb +++ b/app/controllers/diaspora_federation/webfinger_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency "diaspora_federation/application_controller" module DiasporaFederation diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 67516e1..4a8838c 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # Don't log received xml data. Rails.application.config.filter_parameters += %i[xml aes_key encrypted_magic_envelope] diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 10cadb2..27cecfb 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # mime types for webfinger Mime::Type.register "application/jrd+json", :jrd Mime::Type.register "application/xrd+xml", :xrd diff --git a/config/routes.rb b/config/routes.rb index 30c1a98..2c34046 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + DiasporaFederation::Engine.routes.draw do controller :receive do post "receive/public" => :public, :as => "receive_public" diff --git a/config/spring.rb b/config/spring.rb index d8a7f92..69680fe 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,11 @@ +# frozen_string_literal: true + Spring.application_root = "./test/dummy" root_path = Pathname.new(File.expand_path(".")) Spring.watcher = Spring::Watcher::Listen.new(root_path, 0.2) -Spring.watch("./lib/") +Spring.watch( + "./lib/", + ".ruby-version" +) diff --git a/diaspora_federation-json_schema.gemspec b/diaspora_federation-json_schema.gemspec index d078a28..5cae269 100644 --- a/diaspora_federation-json_schema.gemspec +++ b/diaspora_federation-json_schema.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path("lib", __dir__) # Maintain your gem's version: diff --git a/diaspora_federation-rails.gemspec b/diaspora_federation-rails.gemspec index edc4fba..625372d 100644 --- a/diaspora_federation-rails.gemspec +++ b/diaspora_federation-rails.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path("lib", __dir__) # Maintain your gem's version: @@ -17,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.1" + s.required_ruby_version = "~> 2.5" - s.add_dependency "actionpack", ">= 4.2", "< 6" + s.add_dependency "actionpack", ">= 5", "< 7" s.add_dependency "diaspora_federation", DiasporaFederation::VERSION end diff --git a/diaspora_federation-test.gemspec b/diaspora_federation-test.gemspec index b37a076..40a0da8 100644 --- a/diaspora_federation-test.gemspec +++ b/diaspora_federation-test.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path("lib", __dir__) # Maintain your gem's version: @@ -17,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.1" + 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 447d0bb..0dd0723 100644 --- a/diaspora_federation.gemspec +++ b/diaspora_federation.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path("lib", __dir__) # Maintain your gem's version: @@ -22,9 +24,9 @@ Gem::Specification.new do |s| "lib/diaspora_federation/test/*", "lib/tasks/*.rake"] - s.required_ruby_version = "~> 2.1" + s.required_ruby_version = "~> 2.5" - s.add_dependency "faraday", ">= 0.9.0", "< 0.16.0" + s.add_dependency "faraday", ">= 0.9.0", "< 0.18.0" s.add_dependency "faraday_middleware", ">= 0.10.0", "< 0.14.0" s.add_dependency "nokogiri", "~> 1.6", ">= 1.6.8" s.add_dependency "typhoeus", "~> 1.0" diff --git a/lib/diaspora_federation.rb b/lib/diaspora_federation.rb index 08c360a..ec2b036 100644 --- a/lib/diaspora_federation.rb +++ b/lib/diaspora_federation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "nokogiri" require "openssl" @@ -256,6 +258,7 @@ module DiasporaFederation configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Integer) return unless !@http_verbose.is_a?(TrueClass) && !@http_verbose.is_a?(FalseClass) + configuration_error "http_verbose: please configure a boolean" end diff --git a/lib/diaspora_federation/callbacks.rb b/lib/diaspora_federation/callbacks.rb index fae3689..c58fa34 100644 --- a/lib/diaspora_federation/callbacks.rb +++ b/lib/diaspora_federation/callbacks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # Callbacks are used to communicate with the application. They are called to # fetch data and after data is received. diff --git a/lib/diaspora_federation/discovery.rb b/lib/diaspora_federation/discovery.rb index f4bd28d..ab587c9 100644 --- a/lib/diaspora_federation/discovery.rb +++ b/lib/diaspora_federation/discovery.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # This module provides the namespace for the various classes implementing # WebFinger and other protocols used for metadata discovery on remote servers diff --git a/lib/diaspora_federation/discovery/discovery.rb b/lib/diaspora_federation/discovery/discovery.rb index 5f24513..23f2ea0 100644 --- a/lib/diaspora_federation/discovery/discovery.rb +++ b/lib/diaspora_federation/discovery/discovery.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Discovery # This class contains the logic to fetch all data for the given diaspora* ID. @@ -35,6 +37,7 @@ module DiasporaFederation def validate_diaspora_id # Validates if the diaspora* ID matches the diaspora* ID in the webfinger response return if diaspora_id == clean_diaspora_id(webfinger.acct_uri) + raise DiscoveryError, "diaspora* ID does not match: Wanted #{diaspora_id} but got" \ " #{clean_diaspora_id(webfinger.acct_uri)}" end @@ -47,15 +50,13 @@ module DiasporaFederation logger.info "Fetching #{url} for #{diaspora_id}" response = HttpClient.get(url) raise "Failed to fetch #{url}: #{response.status}" unless response.success? + response.body rescue => e # rubocop:disable Style/RescueStandardError - unless http_fallback && url.start_with?("https://") - raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}" - end + raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}" unless http_fallback logger.warn "Retry with http: #{url} for #{diaspora_id}: #{e.class}: #{e.message}" - url.sub!("https://", "http://") - retry + get(url.sub("https://", "http://")) end def domain @@ -74,6 +75,7 @@ module DiasporaFederation def webfinger return @webfinger if @webfinger + 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. diff --git a/lib/diaspora_federation/discovery/exceptions.rb b/lib/diaspora_federation/discovery/exceptions.rb index caba207..3985b5b 100644 --- a/lib/diaspora_federation/discovery/exceptions.rb +++ b/lib/diaspora_federation/discovery/exceptions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Discovery # Raised, if there is an error while discover a new person diff --git a/lib/diaspora_federation/discovery/h_card.rb b/lib/diaspora_federation/discovery/h_card.rb index 69d7526..562979a 100644 --- a/lib/diaspora_federation/discovery/h_card.rb +++ b/lib/diaspora_federation/discovery/h_card.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Discovery # This class provides the means of generating and parsing account data to and @@ -260,6 +262,7 @@ module DiasporaFederation doc = Nokogiri::HTML::Document.parse(html_string) raise InvalidData, "hcard html incomplete" unless html_document_complete?(doc) + doc end diff --git a/lib/diaspora_federation/discovery/host_meta.rb b/lib/diaspora_federation/discovery/host_meta.rb index b7a8b95..cc15da0 100644 --- a/lib/diaspora_federation/discovery/host_meta.rb +++ b/lib/diaspora_federation/discovery/host_meta.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Discovery # Generates and parses Host Meta documents. @@ -25,7 +27,7 @@ module DiasporaFederation end # URL fragment to append to the base URL - WEBFINGER_SUFFIX = "/.well-known/webfinger.xml?resource={uri}".freeze + WEBFINGER_SUFFIX = "/.well-known/webfinger.xml?resource={uri}" # Returns the WebFinger URL that was used to build this instance (either from # xml or by giving a base URL). diff --git a/lib/diaspora_federation/discovery/web_finger.rb b/lib/diaspora_federation/discovery/web_finger.rb index 295038e..b56fb9c 100644 --- a/lib/diaspora_federation/discovery/web_finger.rb +++ b/lib/diaspora_federation/discovery/web_finger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Discovery # The WebFinger document used for diaspora* user discovery is based on an @@ -69,23 +71,23 @@ module DiasporaFederation property :subscribe_url, :string, optional: true # +hcard_url+ link relation - REL_HCARD = "http://microformats.org/profile/hcard".freeze + REL_HCARD = "http://microformats.org/profile/hcard" # +seed_url+ link relation - REL_SEED = "http://joindiaspora.com/seed_location".freeze + REL_SEED = "http://joindiaspora.com/seed_location" # +profile_url+ link relation. # @note This might just as well be an +Alias+ instead of a +Link+. - REL_PROFILE = "http://webfinger.net/rel/profile-page".freeze + REL_PROFILE = "http://webfinger.net/rel/profile-page" # +atom_url+ link relation - REL_ATOM = "http://schemas.google.com/g/2010#updates-from".freeze + REL_ATOM = "http://schemas.google.com/g/2010#updates-from" # +salmon_url+ link relation - REL_SALMON = "salmon".freeze + REL_SALMON = "salmon" # +subscribe_url+ link relation - REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe".freeze + REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe" # Additional WebFinger data # @return [Hash] additional elements @@ -110,7 +112,7 @@ module DiasporaFederation to_xrd.to_xml end - def to_json + def to_json(*_args) to_xrd.to_json end diff --git a/lib/diaspora_federation/discovery/xrd_document.rb b/lib/diaspora_federation/discovery/xrd_document.rb index 354594c..6a3bb21 100644 --- a/lib/diaspora_federation/discovery/xrd_document.rb +++ b/lib/diaspora_federation/discovery/xrd_document.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Discovery # This class implements basic handling of XRD documents as far as it is @@ -29,13 +31,13 @@ module DiasporaFederation # @see http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html Extensible Resource Descriptor (XRD) Version 1.0 class XrdDocument # xml namespace url - XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0".freeze + XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0" # +Link+ element attributes LINK_ATTRS = %i[rel type href template].freeze # format string for datetime (+Expires+ element) - DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ".freeze + DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" # The element contains a time value which specifies the instant at # and after which the document has expired and SHOULD NOT be used. @@ -80,7 +82,7 @@ module DiasporaFederation }.to_xml end - def to_json + def to_json(*_args) { subject: subject, expires: (expires.strftime(DATETIME_FORMAT) if expires.instance_of?(DateTime)), @@ -146,6 +148,7 @@ module DiasporaFederation def add_aliases_to(xml) aliases.each do |a| next if !a.instance_of?(String) || a.empty? + xml.Alias(a.to_s) end end @@ -171,6 +174,7 @@ module DiasporaFederation doc = Nokogiri::XML(xrd_doc) raise InvalidDocument, "Not an XRD document" if !doc.root || doc.root.name != "XRD" + doc end diff --git a/lib/diaspora_federation/engine.rb b/lib/diaspora_federation/engine.rb index 0941467..3ab91df 100644 --- a/lib/diaspora_federation/engine.rb +++ b/lib/diaspora_federation/engine.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # diaspora* federation rails engine class Engine < ::Rails::Engine diff --git a/lib/diaspora_federation/entities.rb b/lib/diaspora_federation/entities.rb index a7689d0..d29388b 100644 --- a/lib/diaspora_federation/entities.rb +++ b/lib/diaspora_federation/entities.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # This namespace contains all the entities used to encapsulate data that is # passed around in the diaspora* network as part of the federation protocol. diff --git a/lib/diaspora_federation/entities/account_deletion.rb b/lib/diaspora_federation/entities/account_deletion.rb index 88e087e..d969b24 100644 --- a/lib/diaspora_federation/entities/account_deletion.rb +++ b/lib/diaspora_federation/entities/account_deletion.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity is sent when an account was deleted on a remote pod. diff --git a/lib/diaspora_federation/entities/account_migration.rb b/lib/diaspora_federation/entities/account_migration.rb index 82deed3..7ea7ef8 100644 --- a/lib/diaspora_federation/entities/account_migration.rb +++ b/lib/diaspora_federation/entities/account_migration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity is sent when a person changes their diaspora* ID (e.g. when a user migration @@ -37,13 +39,14 @@ module DiasporaFederation # @return [String] diaspora* ID of the old person identity def old_identity return @old_identity if author_is_new_id? + author end # Returns diaspora* ID of the new person identity. # @return [String] diaspora* ID of the new person identity def new_identity - profile.author if profile + profile&.author end # @return [String] string representation of this object @@ -85,6 +88,7 @@ module DiasporaFederation def sign_with_respective_key privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, signer_id) raise PrivateKeyNotFound, "signer=#{signer_id} obj=#{self}" if privkey.nil? + sign_with_key(privkey).tap do logger.info "event=sign status=complete signature=signature signer=#{signer_id} obj=#{self}" end diff --git a/lib/diaspora_federation/entities/account_migration/signable.rb b/lib/diaspora_federation/entities/account_migration/signable.rb index 40cb5f1..fe8825d 100644 --- a/lib/diaspora_federation/entities/account_migration/signable.rb +++ b/lib/diaspora_federation/entities/account_migration/signable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities class AccountMigration < Entity diff --git a/lib/diaspora_federation/entities/comment.rb b/lib/diaspora_federation/entities/comment.rb index b3f05e7..f271b1d 100644 --- a/lib/diaspora_federation/entities/comment.rb +++ b/lib/diaspora_federation/entities/comment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a comment to some kind of post (e.g. status message). @@ -5,7 +7,7 @@ module DiasporaFederation # @see Validators::CommentValidator class Comment < Entity # The {Comment} parent is a {Post} - PARENT_TYPE = "Post".freeze + PARENT_TYPE = "Post" include Relayable diff --git a/lib/diaspora_federation/entities/contact.rb b/lib/diaspora_federation/entities/contact.rb index bd5c0f2..52e8d0e 100644 --- a/lib/diaspora_federation/entities/contact.rb +++ b/lib/diaspora_federation/entities/contact.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a contact with another person. A user issues it diff --git a/lib/diaspora_federation/entities/conversation.rb b/lib/diaspora_federation/entities/conversation.rb index 57898d0..b3720d3 100644 --- a/lib/diaspora_federation/entities/conversation.rb +++ b/lib/diaspora_federation/entities/conversation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a private conversation between users. diff --git a/lib/diaspora_federation/entities/embed.rb b/lib/diaspora_federation/entities/embed.rb index 166b99a..76136f5 100644 --- a/lib/diaspora_federation/entities/embed.rb +++ b/lib/diaspora_federation/entities/embed.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity is used to specify embed information about an URL that should be embedded. diff --git a/lib/diaspora_federation/entities/event.rb b/lib/diaspora_federation/entities/event.rb index 274c1e3..02ddba7 100644 --- a/lib/diaspora_federation/entities/event.rb +++ b/lib/diaspora_federation/entities/event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents an event and it is federated as a part of a status message. diff --git a/lib/diaspora_federation/entities/event_participation.rb b/lib/diaspora_federation/entities/event_participation.rb index 1dfa504..fd1eaac 100644 --- a/lib/diaspora_federation/entities/event_participation.rb +++ b/lib/diaspora_federation/entities/event_participation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a participation in an event, i.e. it is issued when a user responds to en event. @@ -5,7 +7,7 @@ module DiasporaFederation # @see Validators::EventParticipationValidator class EventParticipation < Entity # The {EventParticipation} parent is an {Event} - PARENT_TYPE = "Event".freeze + PARENT_TYPE = "Event" include Relayable diff --git a/lib/diaspora_federation/entities/like.rb b/lib/diaspora_federation/entities/like.rb index b1b7b2e..b589058 100644 --- a/lib/diaspora_federation/entities/like.rb +++ b/lib/diaspora_federation/entities/like.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a like to some kind of post (e.g. status message). diff --git a/lib/diaspora_federation/entities/location.rb b/lib/diaspora_federation/entities/location.rb index 5bd8501..3d0a134 100644 --- a/lib/diaspora_federation/entities/location.rb +++ b/lib/diaspora_federation/entities/location.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity is used to specify location data and used embedded in a status message. diff --git a/lib/diaspora_federation/entities/message.rb b/lib/diaspora_federation/entities/message.rb index c43b53b..81c631a 100644 --- a/lib/diaspora_federation/entities/message.rb +++ b/lib/diaspora_federation/entities/message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a private message exchanged in private conversation. diff --git a/lib/diaspora_federation/entities/participation.rb b/lib/diaspora_federation/entities/participation.rb index d0cc815..554d9bd 100644 --- a/lib/diaspora_federation/entities/participation.rb +++ b/lib/diaspora_federation/entities/participation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # Participation is sent to subscribe a user on updates for some post. @@ -35,7 +37,7 @@ module DiasporaFederation # Validates that the parent exists and the parent author is local def validate_parent parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, parent_type, parent_guid) - raise ParentNotLocal, "obj=#{self}" unless parent && parent.local + raise ParentNotLocal, "obj=#{self}" unless parent&.local end # Validate that the parent is local. diff --git a/lib/diaspora_federation/entities/person.rb b/lib/diaspora_federation/entities/person.rb index ab48857..e4ad225 100644 --- a/lib/diaspora_federation/entities/person.rb +++ b/lib/diaspora_federation/entities/person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity contains the base data of a person. diff --git a/lib/diaspora_federation/entities/photo.rb b/lib/diaspora_federation/entities/photo.rb index 0e60f31..4f11179 100644 --- a/lib/diaspora_federation/entities/photo.rb +++ b/lib/diaspora_federation/entities/photo.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a photo and it is federated as a part of a status message. diff --git a/lib/diaspora_federation/entities/poll.rb b/lib/diaspora_federation/entities/poll.rb index 47fd2dc..6f3ba16 100644 --- a/lib/diaspora_federation/entities/poll.rb +++ b/lib/diaspora_federation/entities/poll.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a poll and it is federated as an optional part of a status message. diff --git a/lib/diaspora_federation/entities/poll_answer.rb b/lib/diaspora_federation/entities/poll_answer.rb index 7c1ee17..2eb34dc 100644 --- a/lib/diaspora_federation/entities/poll_answer.rb +++ b/lib/diaspora_federation/entities/poll_answer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a poll answer and is federated as a part of the Poll entity. diff --git a/lib/diaspora_federation/entities/poll_participation.rb b/lib/diaspora_federation/entities/poll_participation.rb index d1ce464..ec7eb86 100644 --- a/lib/diaspora_federation/entities/poll_participation.rb +++ b/lib/diaspora_federation/entities/poll_participation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a participation in poll, i.e. it is issued when a user votes for an answer in a poll. @@ -5,7 +7,7 @@ module DiasporaFederation # @see Validators::PollParticipationValidator class PollParticipation < Entity # The {PollParticipation} parent is a {Poll} - PARENT_TYPE = "Poll".freeze + PARENT_TYPE = "Poll" include Relayable diff --git a/lib/diaspora_federation/entities/post.rb b/lib/diaspora_federation/entities/post.rb index 6957cdf..a5c0a48 100644 --- a/lib/diaspora_federation/entities/post.rb +++ b/lib/diaspora_federation/entities/post.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This is a module that defines common properties for a post which diff --git a/lib/diaspora_federation/entities/profile.rb b/lib/diaspora_federation/entities/profile.rb index ea851b1..b6ba0ff 100644 --- a/lib/diaspora_federation/entities/profile.rb +++ b/lib/diaspora_federation/entities/profile.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity contains all the profile data of a person. diff --git a/lib/diaspora_federation/entities/related_entity.rb b/lib/diaspora_federation/entities/related_entity.rb index b384748..4811cfd 100644 --- a/lib/diaspora_federation/entities/related_entity.rb +++ b/lib/diaspora_federation/entities/related_entity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # Entity meta informations for a related entity (parent or target of @@ -50,7 +52,7 @@ module DiasporaFederation end # never add {RelatedEntity} to json - def to_json + def to_json(*_args) nil end end diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index 4ee3ffa..3fe94c8 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This is a module that defines common properties for relayable entities @@ -88,7 +90,7 @@ module DiasporaFederation "#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}" end - def to_json + def to_json(*_args) super.merge!(property_order: signature_order).tap {|json_hash| missing_properties = json_hash[:property_order] - json_hash[:entity_data].keys missing_properties.each {|property| @@ -113,6 +115,7 @@ module DiasporaFederation def sign_with_author privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author) raise AuthorPrivateKeyNotFound, "author=#{author} obj=#{self}" if privkey.nil? + sign_with_key(privkey).tap do logger.info "event=sign status=complete signature=author_signature author=#{author} obj=#{self}" end diff --git a/lib/diaspora_federation/entities/relayable_retraction.rb b/lib/diaspora_federation/entities/relayable_retraction.rb index aa7b03f..d0365f1 100644 --- a/lib/diaspora_federation/entities/relayable_retraction.rb +++ b/lib/diaspora_federation/entities/relayable_retraction.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a claim of deletion of a previously federated diff --git a/lib/diaspora_federation/entities/request.rb b/lib/diaspora_federation/entities/request.rb index a60aab1..6627f36 100644 --- a/lib/diaspora_federation/entities/request.rb +++ b/lib/diaspora_federation/entities/request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a sharing request for a user. A user issues it diff --git a/lib/diaspora_federation/entities/reshare.rb b/lib/diaspora_federation/entities/reshare.rb index 7c0bcc6..aa38b29 100644 --- a/lib/diaspora_federation/entities/reshare.rb +++ b/lib/diaspora_federation/entities/reshare.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents the fact that a user reshared another user's post. diff --git a/lib/diaspora_federation/entities/retraction.rb b/lib/diaspora_federation/entities/retraction.rb index 217c0a6..5c53eda 100644 --- a/lib/diaspora_federation/entities/retraction.rb +++ b/lib/diaspora_federation/entities/retraction.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a claim of deletion of a previously federated entity. @@ -28,7 +30,7 @@ module DiasporaFederation def sender_valid?(sender) case target_type when "Comment", "Like", "PollParticipation" - sender == target.author || sender == target.root.author + [target.root.author, target.author].include?(sender) else sender == target.author end diff --git a/lib/diaspora_federation/entities/signable.rb b/lib/diaspora_federation/entities/signable.rb index d78d4a5..1301f17 100644 --- a/lib/diaspora_federation/entities/signable.rb +++ b/lib/diaspora_federation/entities/signable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # Signable is a module that encapsulates basic signature generation/verification flow for entities. diff --git a/lib/diaspora_federation/entities/signed_retraction.rb b/lib/diaspora_federation/entities/signed_retraction.rb index af850b9..77e474c 100644 --- a/lib/diaspora_federation/entities/signed_retraction.rb +++ b/lib/diaspora_federation/entities/signed_retraction.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a claim of deletion of a previously federated diff --git a/lib/diaspora_federation/entities/status_message.rb b/lib/diaspora_federation/entities/status_message.rb index 6a50b61..1da0d8b 100644 --- a/lib/diaspora_federation/entities/status_message.rb +++ b/lib/diaspora_federation/entities/status_message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities # This entity represents a status message sent by a user. diff --git a/lib/diaspora_federation/entity.rb b/lib/diaspora_federation/entity.rb index 7b564be..26526d1 100644 --- a/lib/diaspora_federation/entity.rb +++ b/lib/diaspora_federation/entity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # +Entity+ is the base class for all other objects used to encapsulate data # for federation messages in the diaspora* network. @@ -38,10 +40,10 @@ module DiasporaFederation # Invalid XML characters # @see https://www.w3.org/TR/REC-xml/#charsets "Extensible Markup Language (XML) 1.0" - INVALID_XML_REGEX = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/ + INVALID_XML_REGEX = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/.freeze # Regex to validate and find entity names - ENTITY_NAME_REGEX = "[a-z]*(?:_[a-z]*)*".freeze + ENTITY_NAME_REGEX = "[a-z]*(?:_[a-z]*)*" # Initializes the Entity with the given attribute hash and freezes the created # instance it returns. @@ -149,6 +151,7 @@ module DiasporaFederation # @return [Class] entity class def self.entity_class(entity_name) raise InvalidEntityName, "'#{entity_name}' is invalid" unless entity_name =~ /\A#{ENTITY_NAME_REGEX}\z/ + class_name = entity_name.sub(/\A[a-z]/, &:upcase) class_name.gsub!(/_([a-z])/) { Regexp.last_match[1].upcase } @@ -169,7 +172,7 @@ module DiasporaFederation # Renders entity to a hash representation of the entity JSON format # @return [Hash] Returns a hash that is equal by structure to the entity in JSON format - def to_json + def to_json(*_args) { entity_type: self.class.entity_name, entity_data: json_data @@ -231,12 +234,14 @@ module DiasporaFederation def nilify(value) return nil if value.respond_to?(:empty?) && value.empty? && !value.instance_of?(Array) + value end def instantiate_nested(name, value) if value.instance_of?(Array) return value unless value.first.instance_of?(Hash) + value.map {|hash| self.class.class_props[name].first.new(hash) } elsif value.instance_of?(Hash) self.class.class_props[name].new(value) diff --git a/lib/diaspora_federation/federation.rb b/lib/diaspora_federation/federation.rb index b279cfd..e1ccd95 100644 --- a/lib/diaspora_federation/federation.rb +++ b/lib/diaspora_federation/federation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # This module contains the federation logic module Federation diff --git a/lib/diaspora_federation/federation/diaspora_url_parser.rb b/lib/diaspora_federation/federation/diaspora_url_parser.rb index 5b59da2..d9ead05 100644 --- a/lib/diaspora_federation/federation/diaspora_url_parser.rb +++ b/lib/diaspora_federation/federation/diaspora_url_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation # This module is for parsing and fetching linked entities. @@ -10,7 +12,7 @@ module DiasporaFederation (#{Validation::Rule::DiasporaId::DIASPORA_ID_REGEX})/ (#{Entity::ENTITY_NAME_REGEX})/ (#{Validation::Rule::Guid::VALID_CHARS}) - }ux + }ux.freeze # Parses all diaspora:// URLs from the text and fetches the entities from # the remote server if needed. @@ -25,6 +27,7 @@ module DiasporaFederation private_class_method def self.fetch_entity(author, type, guid) class_name = Entity.entity_class(type).to_s.rpartition("::").last return if DiasporaFederation.callbacks.trigger(:fetch_related_entity, class_name, guid) + Fetcher.fetch_public(author, type, guid) rescue => e # rubocop:disable Style/RescueStandardError logger.error "Failed to fetch linked entity #{type}:#{guid}: #{e.class}: #{e.message}" diff --git a/lib/diaspora_federation/federation/fetcher.rb b/lib/diaspora_federation/federation/fetcher.rb index d9b85cf..b6a2136 100644 --- a/lib/diaspora_federation/federation/fetcher.rb +++ b/lib/diaspora_federation/federation/fetcher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation # This module is for fetching entities from other pods. @@ -10,6 +12,7 @@ module DiasporaFederation def self.fetch_public(author, entity_type, guid) type = entity_name(entity_type).to_s raise "Already fetching ..." if fetching[type].include?(guid) + fetch_from_url(author, type, guid) rescue => e # rubocop:disable Style/RescueStandardError raise NotFetchable, "Failed to fetch #{entity_type}:#{guid} from #{author}: #{e.class}: #{e.message}" diff --git a/lib/diaspora_federation/federation/receiver.rb b/lib/diaspora_federation/federation/receiver.rb index 76903e5..4b6eb76 100644 --- a/lib/diaspora_federation/federation/receiver.rb +++ b/lib/diaspora_federation/federation/receiver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation # This module parses and receives entities. @@ -29,6 +31,7 @@ module DiasporaFederation # @param [Boolean] legacy use old slap parser def self.receive_private(data, recipient_private_key, recipient_id, legacy=false) raise ArgumentError, "no recipient key provided" unless recipient_private_key.instance_of?(OpenSSL::PKey::RSA) + magic_env = if legacy Salmon::EncryptedSlap.from_xml(data, recipient_private_key) else diff --git a/lib/diaspora_federation/federation/receiver/abstract_receiver.rb b/lib/diaspora_federation/federation/receiver/abstract_receiver.rb index c244c1d..74b8abd 100644 --- a/lib/diaspora_federation/federation/receiver/abstract_receiver.rb +++ b/lib/diaspora_federation/federation/receiver/abstract_receiver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation module Receiver diff --git a/lib/diaspora_federation/federation/receiver/exceptions.rb b/lib/diaspora_federation/federation/receiver/exceptions.rb index 5c1a0b8..a48a20e 100644 --- a/lib/diaspora_federation/federation/receiver/exceptions.rb +++ b/lib/diaspora_federation/federation/receiver/exceptions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation module Receiver diff --git a/lib/diaspora_federation/federation/receiver/private.rb b/lib/diaspora_federation/federation/receiver/private.rb index 18115cf..4267f9b 100644 --- a/lib/diaspora_federation/federation/receiver/private.rb +++ b/lib/diaspora_federation/federation/receiver/private.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation module Receiver @@ -7,6 +9,7 @@ module DiasporaFederation def validate raise RecipientRequired if recipient_id.nil? + super end end diff --git a/lib/diaspora_federation/federation/receiver/public.rb b/lib/diaspora_federation/federation/receiver/public.rb index 7711088..d56611d 100644 --- a/lib/diaspora_federation/federation/receiver/public.rb +++ b/lib/diaspora_federation/federation/receiver/public.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation module Receiver diff --git a/lib/diaspora_federation/federation/sender.rb b/lib/diaspora_federation/federation/sender.rb index ab15662..37f7a72 100644 --- a/lib/diaspora_federation/federation/sender.rb +++ b/lib/diaspora_federation/federation/sender.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Federation # Federation logic to send messages to other pods diff --git a/lib/diaspora_federation/federation/sender/hydra_wrapper.rb b/lib/diaspora_federation/federation/sender/hydra_wrapper.rb index b300b07..df1adf1 100644 --- a/lib/diaspora_federation/federation/sender/hydra_wrapper.rb +++ b/lib/diaspora_federation/federation/sender/hydra_wrapper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "typhoeus" module DiasporaFederation diff --git a/lib/diaspora_federation/http_client.rb b/lib/diaspora_federation/http_client.rb index 8cf0fa1..df536a0 100644 --- a/lib/diaspora_federation/http_client.rb +++ b/lib/diaspora_federation/http_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "faraday" require "faraday_middleware/response/follow_redirects" diff --git a/lib/diaspora_federation/logging.rb b/lib/diaspora_federation/logging.rb index 4593c28..29fb7b2 100644 --- a/lib/diaspora_federation/logging.rb +++ b/lib/diaspora_federation/logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # Logging module for the diaspora* federation # diff --git a/lib/diaspora_federation/parsers.rb b/lib/diaspora_federation/parsers.rb index a08ba5c..783ab8e 100644 --- a/lib/diaspora_federation/parsers.rb +++ b/lib/diaspora_federation/parsers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # This namespace contains parsers which are used to deserialize federation entities # objects from supported formats (XML, JSON) to objects of DiasporaFederation::Entity diff --git a/lib/diaspora_federation/parsers/base_parser.rb b/lib/diaspora_federation/parsers/base_parser.rb index 50b48b9..a874209 100644 --- a/lib/diaspora_federation/parsers/base_parser.rb +++ b/lib/diaspora_federation/parsers/base_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Parsers # +BaseParser+ is an abstract class which is used for defining parsers for different @@ -36,6 +38,7 @@ module DiasporaFederation text.to_i if text =~ /\A\d+\z/ when :boolean return true if text =~ /\A(true|t|yes|y|1)\z/i + false if text =~ /\A(false|f|no|n|0)\z/i else text @@ -44,6 +47,7 @@ module DiasporaFederation def assert_parsability_of(entity_class) return if entity_class == entity_type.entity_name + raise InvalidRootNode, "'#{entity_class}' can't be parsed by #{entity_type.name}" end diff --git a/lib/diaspora_federation/parsers/json_parser.rb b/lib/diaspora_federation/parsers/json_parser.rb index ff7c0aa..1a8642f 100644 --- a/lib/diaspora_federation/parsers/json_parser.rb +++ b/lib/diaspora_federation/parsers/json_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Parsers # This is a parser of JSON serialized object. JSON object format is defined by @@ -30,12 +32,14 @@ module DiasporaFederation def parse_element_from_value(type, value) return if value.nil? + if %i[integer boolean timestamp].include?(type) && !value.is_a?(String) value elsif type.instance_of?(Symbol) parse_string(type, value) elsif type.instance_of?(Array) raise DeserializationError, "Expected array for #{type}" unless value.respond_to?(:map) + value.map {|element| type.first.from_json(element) } @@ -49,6 +53,7 @@ module DiasporaFederation prop if json_hash[prop].nil? }.compact.join(", ") raise DeserializationError, "Required properties are missing in JSON object: #{missing}" unless missing.empty? + assert_parsability_of(json_hash["entity_type"]) end diff --git a/lib/diaspora_federation/parsers/relayable_json_parser.rb b/lib/diaspora_federation/parsers/relayable_json_parser.rb index 192a572..1517737 100644 --- a/lib/diaspora_federation/parsers/relayable_json_parser.rb +++ b/lib/diaspora_federation/parsers/relayable_json_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Parsers # This is a parser of JSON serialized object, that is normally used for parsing data of relayables. @@ -18,6 +20,7 @@ module DiasporaFederation def from_json_sanity_validation(json_hash) super return unless json_hash["property_order"].nil? + raise DeserializationError, "Required property is missing in JSON object: property_order" end end diff --git a/lib/diaspora_federation/parsers/relayable_xml_parser.rb b/lib/diaspora_federation/parsers/relayable_xml_parser.rb index 272a4ca..4372854 100644 --- a/lib/diaspora_federation/parsers/relayable_xml_parser.rb +++ b/lib/diaspora_federation/parsers/relayable_xml_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Parsers # This is a parser of XML serialized object that is normally used for parsing data of relayables. diff --git a/lib/diaspora_federation/parsers/xml_parser.rb b/lib/diaspora_federation/parsers/xml_parser.rb index 2e04418..40acfda 100644 --- a/lib/diaspora_federation/parsers/xml_parser.rb +++ b/lib/diaspora_federation/parsers/xml_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Parsers # This is a parser of XML serialized object. @@ -77,6 +79,7 @@ module DiasporaFederation def from_xml_sanity_validation(root_node) raise ArgumentError, "only Nokogiri::XML::Element allowed" unless root_node.instance_of?(Nokogiri::XML::Element) + assert_parsability_of(root_node.name) end end diff --git a/lib/diaspora_federation/properties_dsl.rb b/lib/diaspora_federation/properties_dsl.rb index 2b4cef8..b473529 100644 --- a/lib/diaspora_federation/properties_dsl.rb +++ b/lib/diaspora_federation/properties_dsl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation # Provides a simple DSL for specifying {Entity} properties during class # definition. @@ -69,6 +71,7 @@ module DiasporaFederation if class_prop_aliases.has_key? name prop_name = class_prop_aliases[name] raise InvalidData, "only use '#{name}' OR '#{prop_name}'" if data.has_key? prop_name + [prop_name, value] else [name, value] @@ -86,7 +89,7 @@ module DiasporaFederation # @param [String] xml_name name of the property from the received xml # @return [Hash] the property data def find_property_for_xml_name(xml_name) - class_props.keys.find {|name| name.to_s == xml_name || xml_names[name].to_s == xml_name } + class_props.keys.find {|name| [name.to_s, xml_names[name].to_s].include?(xml_name) } end private @@ -100,6 +103,7 @@ module DiasporaFederation if type.instance_of?(Symbol) if opts.has_key? :xml_name raise InvalidName, "invalid xml_name" unless name_valid?(opts[:xml_name]) + opts[:xml_name] else name diff --git a/lib/diaspora_federation/rails.rb b/lib/diaspora_federation/rails.rb index dd551a7..cd2577a 100644 --- a/lib/diaspora_federation/rails.rb +++ b/lib/diaspora_federation/rails.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "diaspora_federation/engine" require "diaspora_federation" diff --git a/lib/diaspora_federation/salmon.rb b/lib/diaspora_federation/salmon.rb index 79c0216..0fc3ef9 100644 --- a/lib/diaspora_federation/salmon.rb +++ b/lib/diaspora_federation/salmon.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + module DiasporaFederation # This module contains a diaspora*-specific implementation of parts of the # {http://www.salmon-protocol.org/ Salmon Protocol}. module Salmon # XML namespace url - XMLNS = "https://joindiaspora.com/protocol".freeze + XMLNS = "https://joindiaspora.com/protocol" end end diff --git a/lib/diaspora_federation/salmon/aes.rb b/lib/diaspora_federation/salmon/aes.rb index 9a717c3..cc55e28 100644 --- a/lib/diaspora_federation/salmon/aes.rb +++ b/lib/diaspora_federation/salmon/aes.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + module DiasporaFederation module Salmon # Class for AES encryption and decryption class AES # OpenSSL aes cipher definition - CIPHER = "AES-256-CBC".freeze + CIPHER = "AES-256-CBC" # Generates a random AES key and initialization vector # @return [Hash] { key: "...", iv: "..." } diff --git a/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb b/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb index a883474..83b585d 100644 --- a/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb +++ b/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Salmon # This is a simple crypt-wrapper for {MagicEnvelope}. diff --git a/lib/diaspora_federation/salmon/encrypted_slap.rb b/lib/diaspora_federation/salmon/encrypted_slap.rb index 2fa772f..23da393 100644 --- a/lib/diaspora_federation/salmon/encrypted_slap.rb +++ b/lib/diaspora_federation/salmon/encrypted_slap.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "json" module DiasporaFederation @@ -67,10 +69,12 @@ module DiasporaFederation # @raise [MissingMagicEnvelope] if the +me:env+ element is missing in the XML def self.from_xml(slap_xml, privkey) raise ArgumentError unless slap_xml.instance_of?(String) && privkey.instance_of?(OpenSSL::PKey::RSA) + doc = Nokogiri::XML(slap_xml) header_elem = doc.at_xpath("d:diaspora/d:encrypted_header", Slap::NS) raise MissingHeader if header_elem.nil? + header = header_data(header_elem.content, privkey) sender = header[:author_id] cipher_params = {key: Base64.decode64(header[:aes_key]), iv: Base64.decode64(header[:iv])} diff --git a/lib/diaspora_federation/salmon/exceptions.rb b/lib/diaspora_federation/salmon/exceptions.rb index 9dd0f96..07061be 100644 --- a/lib/diaspora_federation/salmon/exceptions.rb +++ b/lib/diaspora_federation/salmon/exceptions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Salmon # Raised, if the element containing the Magic Envelope is missing from the XML diff --git a/lib/diaspora_federation/salmon/magic_envelope.rb b/lib/diaspora_federation/salmon/magic_envelope.rb index ac53e95..fcc3f53 100644 --- a/lib/diaspora_federation/salmon/magic_envelope.rb +++ b/lib/diaspora_federation/salmon/magic_envelope.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Salmon # Represents a Magic Envelope for diaspora* federation messages @@ -24,19 +26,19 @@ module DiasporaFederation include Logging # Encoding used for the payload data - ENCODING = "base64url".freeze + ENCODING = "base64url" # Algorithm used for signing the payload data - ALGORITHM = "RSA-SHA256".freeze + ALGORITHM = "RSA-SHA256" # Mime type describing the payload data - DATA_TYPE = "application/xml".freeze + DATA_TYPE = "application/xml" # Digest instance used for signing DIGEST = OpenSSL::Digest::SHA256.new # XML namespace url - XMLNS = "http://salmon-protocol.org/ns/magic-env".freeze + XMLNS = "http://salmon-protocol.org/ns/magic-env" # The payload entity of the magic envelope # @return [Entity] payload entity @@ -153,6 +155,7 @@ module DiasporaFederation # @raise [InvalidEnvelope] if the envelope XML structure is malformed private_class_method def self.validate_envelope(env) raise InvalidEnvelope unless env.instance_of?(Nokogiri::XML::Element) && env.name == "env" + validate_element(env, "me:data") validate_element(env, "me:sig") end @@ -188,6 +191,7 @@ module DiasporaFederation private_class_method def self.sender(env) key_id = env.at_xpath("me:sig")["key_id"] raise InvalidEnvelope, "no key_id" unless key_id # TODO: move to `envelope_valid?` + Base64.urlsafe_decode64(key_id) end diff --git a/lib/diaspora_federation/salmon/slap.rb b/lib/diaspora_federation/salmon/slap.rb index f0daa92..242337d 100644 --- a/lib/diaspora_federation/salmon/slap.rb +++ b/lib/diaspora_federation/salmon/slap.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Salmon # +Slap+ provides class methods to create unencrypted Slap XML from payload @@ -33,10 +35,12 @@ module DiasporaFederation # @raise [MissingMagicEnvelope] if the +me:env+ element is missing from the XML def self.from_xml(slap_xml) raise ArgumentError unless slap_xml.instance_of?(String) + doc = Nokogiri::XML(slap_xml) author_elem = doc.at_xpath("d:diaspora/d:header/d:author_id", Slap::NS) raise MissingAuthor if author_elem.nil? || author_elem.content.empty? + sender = author_elem.content MagicEnvelope.unenvelop(magic_env_from_doc(doc), sender) diff --git a/lib/diaspora_federation/salmon/xml_payload.rb b/lib/diaspora_federation/salmon/xml_payload.rb index 90d8557..32ea453 100644 --- a/lib/diaspora_federation/salmon/xml_payload.rb +++ b/lib/diaspora_federation/salmon/xml_payload.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Salmon # +XmlPayload+ provides methods to wrap a XML-serialized {Entity} inside a diff --git a/lib/diaspora_federation/schemas.rb b/lib/diaspora_federation/schemas.rb index 5b7120a..d04de47 100644 --- a/lib/diaspora_federation/schemas.rb +++ b/lib/diaspora_federation/schemas.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pathname" require "json" @@ -5,7 +7,7 @@ module DiasporaFederation # A helper class to access the JSON schema. module Schemas # federation_entities schema uri - FEDERATION_ENTITIES_URI = "https://diaspora.github.io/diaspora_federation/schemas/federation_entities.json".freeze + FEDERATION_ENTITIES_URI = "https://diaspora.github.io/diaspora_federation/schemas/federation_entities.json" # Parsed federation_entities schema def self.federation_entities diff --git a/lib/diaspora_federation/test.rb b/lib/diaspora_federation/test.rb index db81377..60e136f 100644 --- a/lib/diaspora_federation/test.rb +++ b/lib/diaspora_federation/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "fabrication" require "diaspora_federation" diff --git a/lib/diaspora_federation/test/entity_generator.rb b/lib/diaspora_federation/test/entity_generator.rb index 1f9c7e6..9e610c0 100644 --- a/lib/diaspora_federation/test/entity_generator.rb +++ b/lib/diaspora_federation/test/entity_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Test # Generator to instantiate entities diff --git a/lib/diaspora_federation/test/factories.rb b/lib/diaspora_federation/test/factories.rb index 38e8d99..92dd1c0 100644 --- a/lib/diaspora_federation/test/factories.rb +++ b/lib/diaspora_federation/test/factories.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "uuid" require "securerandom" require "diaspora_federation/test" diff --git a/lib/diaspora_federation/validators.rb b/lib/diaspora_federation/validators.rb index 986daef..4ab6a70 100644 --- a/lib/diaspora_federation/validators.rb +++ b/lib/diaspora_federation/validators.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "validation" require "validation/rule/regular_expression" require "validation/rule/length" diff --git a/lib/diaspora_federation/validators/account_deletion_validator.rb b/lib/diaspora_federation/validators/account_deletion_validator.rb index 60a32cf..f297e37 100644 --- a/lib/diaspora_federation/validators/account_deletion_validator.rb +++ b/lib/diaspora_federation/validators/account_deletion_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::AccountDeletion}. diff --git a/lib/diaspora_federation/validators/account_migration_validator.rb b/lib/diaspora_federation/validators/account_migration_validator.rb index 36c38be..206a2ff 100644 --- a/lib/diaspora_federation/validators/account_migration_validator.rb +++ b/lib/diaspora_federation/validators/account_migration_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::AccountMigration}. diff --git a/lib/diaspora_federation/validators/comment_validator.rb b/lib/diaspora_federation/validators/comment_validator.rb index 4669f50..3f4ac65 100644 --- a/lib/diaspora_federation/validators/comment_validator.rb +++ b/lib/diaspora_federation/validators/comment_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Comment}. diff --git a/lib/diaspora_federation/validators/contact_validator.rb b/lib/diaspora_federation/validators/contact_validator.rb index cf313cc..d8f4f2c 100644 --- a/lib/diaspora_federation/validators/contact_validator.rb +++ b/lib/diaspora_federation/validators/contact_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Contact}. diff --git a/lib/diaspora_federation/validators/conversation_validator.rb b/lib/diaspora_federation/validators/conversation_validator.rb index 1e66994..da984c6 100644 --- a/lib/diaspora_federation/validators/conversation_validator.rb +++ b/lib/diaspora_federation/validators/conversation_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Conversation}. diff --git a/lib/diaspora_federation/validators/embed_validator.rb b/lib/diaspora_federation/validators/embed_validator.rb index de766cc..6486035 100644 --- a/lib/diaspora_federation/validators/embed_validator.rb +++ b/lib/diaspora_federation/validators/embed_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Embed}. diff --git a/lib/diaspora_federation/validators/event_participation_validator.rb b/lib/diaspora_federation/validators/event_participation_validator.rb index 8e1209f..cfa6f61 100644 --- a/lib/diaspora_federation/validators/event_participation_validator.rb +++ b/lib/diaspora_federation/validators/event_participation_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::EventParticipation}. diff --git a/lib/diaspora_federation/validators/event_validator.rb b/lib/diaspora_federation/validators/event_validator.rb index a6c0aa6..ce37dbe 100644 --- a/lib/diaspora_federation/validators/event_validator.rb +++ b/lib/diaspora_federation/validators/event_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Event}. diff --git a/lib/diaspora_federation/validators/h_card_validator.rb b/lib/diaspora_federation/validators/h_card_validator.rb index 236d88e..6612e1b 100644 --- a/lib/diaspora_federation/validators/h_card_validator.rb +++ b/lib/diaspora_federation/validators/h_card_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Discovery::HCard}. diff --git a/lib/diaspora_federation/validators/like_validator.rb b/lib/diaspora_federation/validators/like_validator.rb index 60bb64c..97490b3 100644 --- a/lib/diaspora_federation/validators/like_validator.rb +++ b/lib/diaspora_federation/validators/like_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Like}. diff --git a/lib/diaspora_federation/validators/location_validator.rb b/lib/diaspora_federation/validators/location_validator.rb index cd6e952..656f82e 100644 --- a/lib/diaspora_federation/validators/location_validator.rb +++ b/lib/diaspora_federation/validators/location_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Location}. diff --git a/lib/diaspora_federation/validators/message_validator.rb b/lib/diaspora_federation/validators/message_validator.rb index 6ded966..9064a06 100644 --- a/lib/diaspora_federation/validators/message_validator.rb +++ b/lib/diaspora_federation/validators/message_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Message}. diff --git a/lib/diaspora_federation/validators/optional_aware_validator.rb b/lib/diaspora_federation/validators/optional_aware_validator.rb index 1c0b467..d7eceaf 100644 --- a/lib/diaspora_federation/validators/optional_aware_validator.rb +++ b/lib/diaspora_federation/validators/optional_aware_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # Abstract validator which only validates optional fields when they are not nil. @@ -14,6 +16,7 @@ module DiasporaFederation def optional_props return [] unless @obj.class.respond_to?(:optional_props) + @obj.class.optional_props end end diff --git a/lib/diaspora_federation/validators/participation_validator.rb b/lib/diaspora_federation/validators/participation_validator.rb index c3c4917..315887b 100644 --- a/lib/diaspora_federation/validators/participation_validator.rb +++ b/lib/diaspora_federation/validators/participation_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Participation}. diff --git a/lib/diaspora_federation/validators/person_validator.rb b/lib/diaspora_federation/validators/person_validator.rb index ddfad99..147da56 100644 --- a/lib/diaspora_federation/validators/person_validator.rb +++ b/lib/diaspora_federation/validators/person_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Person}. diff --git a/lib/diaspora_federation/validators/photo_validator.rb b/lib/diaspora_federation/validators/photo_validator.rb index 7c18107..02af975 100644 --- a/lib/diaspora_federation/validators/photo_validator.rb +++ b/lib/diaspora_federation/validators/photo_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Photo}. diff --git a/lib/diaspora_federation/validators/poll_answer_validator.rb b/lib/diaspora_federation/validators/poll_answer_validator.rb index 4c55f05..b22668b 100644 --- a/lib/diaspora_federation/validators/poll_answer_validator.rb +++ b/lib/diaspora_federation/validators/poll_answer_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::PollAnswer}. diff --git a/lib/diaspora_federation/validators/poll_participation_validator.rb b/lib/diaspora_federation/validators/poll_participation_validator.rb index 65cb7db..8410c22 100644 --- a/lib/diaspora_federation/validators/poll_participation_validator.rb +++ b/lib/diaspora_federation/validators/poll_participation_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::PollParticipation}. diff --git a/lib/diaspora_federation/validators/poll_validator.rb b/lib/diaspora_federation/validators/poll_validator.rb index 103b85f..1a8a49e 100644 --- a/lib/diaspora_federation/validators/poll_validator.rb +++ b/lib/diaspora_federation/validators/poll_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Poll}. diff --git a/lib/diaspora_federation/validators/profile_validator.rb b/lib/diaspora_federation/validators/profile_validator.rb index 38ef3e3..cea39be 100644 --- a/lib/diaspora_federation/validators/profile_validator.rb +++ b/lib/diaspora_federation/validators/profile_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Profile}. diff --git a/lib/diaspora_federation/validators/related_entity_validator.rb b/lib/diaspora_federation/validators/related_entity_validator.rb index 17c2726..0c6e99f 100644 --- a/lib/diaspora_federation/validators/related_entity_validator.rb +++ b/lib/diaspora_federation/validators/related_entity_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::RelatedEntity}. diff --git a/lib/diaspora_federation/validators/relayable_validator.rb b/lib/diaspora_federation/validators/relayable_validator.rb index 618f3ce..11f155f 100644 --- a/lib/diaspora_federation/validators/relayable_validator.rb +++ b/lib/diaspora_federation/validators/relayable_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This is included to validatros which validate entities which include {Entities::Relayable}. diff --git a/lib/diaspora_federation/validators/reshare_validator.rb b/lib/diaspora_federation/validators/reshare_validator.rb index 343e36b..46de5e6 100644 --- a/lib/diaspora_federation/validators/reshare_validator.rb +++ b/lib/diaspora_federation/validators/reshare_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Reshare}. diff --git a/lib/diaspora_federation/validators/retraction_validator.rb b/lib/diaspora_federation/validators/retraction_validator.rb index 922b44f..6400ae0 100644 --- a/lib/diaspora_federation/validators/retraction_validator.rb +++ b/lib/diaspora_federation/validators/retraction_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::Retraction}. diff --git a/lib/diaspora_federation/validators/rules/birthday.rb b/lib/diaspora_federation/validators/rules/birthday.rb index c780f34..21c28a0 100644 --- a/lib/diaspora_federation/validators/rules/birthday.rb +++ b/lib/diaspora_federation/validators/rules/birthday.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "date" module Validation @@ -20,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 =~ /[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 6c0418d..01f0e30 100644 --- a/lib/diaspora_federation/validators/rules/boolean.rb +++ b/lib/diaspora_federation/validators/rules/boolean.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Validation module Rule # Boolean validation rule diff --git a/lib/diaspora_federation/validators/rules/diaspora_id.rb b/lib/diaspora_federation/validators/rules/diaspora_id.rb index 42bcc0b..b2b696a 100644 --- a/lib/diaspora_federation/validators/rules/diaspora_id.rb +++ b/lib/diaspora_federation/validators/rules/diaspora_id.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Validation module Rule # diaspora* ID validation rule @@ -22,7 +24,7 @@ module Validation end # The Regex for validating a full diaspora* ID - DIASPORA_ID = /\A#{DIASPORA_ID_REGEX}\z/u + DIASPORA_ID = /\A#{DIASPORA_ID_REGEX}\z/u.freeze # The error key for this rule # @return [Symbol] error key diff --git a/lib/diaspora_federation/validators/rules/diaspora_id_list.rb b/lib/diaspora_federation/validators/rules/diaspora_id_list.rb index 85e1937..322eb98 100644 --- a/lib/diaspora_federation/validators/rules/diaspora_id_list.rb +++ b/lib/diaspora_federation/validators/rules/diaspora_id_list.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Validation module Rule # Rule for validating the number of diaspora* IDs in a string. @@ -31,6 +33,7 @@ module Validation ids = value.split(";") return false if params.include?(:maximum) && ids.count > params[:maximum] return false if params.include?(:minimum) && ids.count < params[:minimum] + ids.each do |id| return false if DiasporaId::DIASPORA_ID.match(id).nil? end diff --git a/lib/diaspora_federation/validators/rules/guid.rb b/lib/diaspora_federation/validators/rules/guid.rb index 3e30874..23f1748 100644 --- a/lib/diaspora_federation/validators/rules/guid.rb +++ b/lib/diaspora_federation/validators/rules/guid.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Validation module Rule # GUID validation rule @@ -9,7 +11,7 @@ module Validation # Special chars aren't allowed at the end. class Guid # Allowed chars to validate a GUID with a regex - VALID_CHARS = "[0-9A-Za-z\\-_@.:]{15,254}[0-9A-Za-z]".freeze + VALID_CHARS = "[0-9A-Za-z\\-_@.:]{15,254}[0-9A-Za-z]" # The error key for this rule # @return [Symbol] error key diff --git a/lib/diaspora_federation/validators/rules/not_nil.rb b/lib/diaspora_federation/validators/rules/not_nil.rb index 3fb6950..ce3b2c0 100644 --- a/lib/diaspora_federation/validators/rules/not_nil.rb +++ b/lib/diaspora_federation/validators/rules/not_nil.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Validation module Rule # Validates that a property is not +nil+ diff --git a/lib/diaspora_federation/validators/rules/public_key.rb b/lib/diaspora_federation/validators/rules/public_key.rb index 7b94802..77a2227 100644 --- a/lib/diaspora_federation/validators/rules/public_key.rb +++ b/lib/diaspora_federation/validators/rules/public_key.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Validation module Rule # Public key validation rule diff --git a/lib/diaspora_federation/validators/rules/tag_count.rb b/lib/diaspora_federation/validators/rules/tag_count.rb index 4033605..ccf249a 100644 --- a/lib/diaspora_federation/validators/rules/tag_count.rb +++ b/lib/diaspora_federation/validators/rules/tag_count.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Validation module Rule # Rule for validating the number of tags in a string. diff --git a/lib/diaspora_federation/validators/status_message_validator.rb b/lib/diaspora_federation/validators/status_message_validator.rb index 62eee98..6b70b55 100644 --- a/lib/diaspora_federation/validators/status_message_validator.rb +++ b/lib/diaspora_federation/validators/status_message_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Entities::StatusMessage}. diff --git a/lib/diaspora_federation/validators/web_finger_validator.rb b/lib/diaspora_federation/validators/web_finger_validator.rb index 596f14c..8769750 100644 --- a/lib/diaspora_federation/validators/web_finger_validator.rb +++ b/lib/diaspora_federation/validators/web_finger_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Validators # This validates a {Discovery::WebFinger}. diff --git a/lib/diaspora_federation/version.rb b/lib/diaspora_federation/version.rb index 1255d74..7f64d6c 100644 --- a/lib/diaspora_federation/version.rb +++ b/lib/diaspora_federation/version.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + module DiasporaFederation # the gem version - VERSION = "0.2.6".freeze + VERSION = "0.2.6" end diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index ef74168..945f47b 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + desc "Build gem into the pkg directory" task build: :test do FileUtils.rm_rf("pkg") diff --git a/lib/tasks/gemfiles.rake b/lib/tasks/gemfiles.rake index 124f386..3500bdd 100644 --- a/lib/tasks/gemfiles.rake +++ b/lib/tasks/gemfiles.rake @@ -1,5 +1,7 @@ +# frozen_string_literal: true + namespace :gemfiles do - desc "Generates rails4.Gemfile and no-rails.Gemfile" + desc "Generates no-rails.Gemfile" task :generate do FileUtils.mkdir_p("test/gemfiles") FileUtils.rm(Dir["test/gemfiles/*.Gemfile.lock"]) @@ -8,12 +10,6 @@ namespace :gemfiles do original_gemfile.sub!(/(gemspec name:.*)/) { "#{Regexp.last_match[1]}, path: \"../../\"" } original_gemfile.sub!(/(gemspec\(name:.*)\)/) { "#{Regexp.last_match[1]}, path: \"../../\")" } original_gemfile.sub!(/^group :development do$.*?^end$\n\n/m, "") - original_gemfile << "\n gem \"fabrication\", \"< 2.17.0\"\n" # new versions are not compatible with ruby 2.1 - - rails4_version = "4.2.8" - rails4_gemfile = "#{original_gemfile}\ngem \"actionpack\", \"#{rails4_version}\"\n" - rails4_path = "test/gemfiles/rails4.Gemfile" - File.write(rails4_path, rails4_gemfile) no_rails_gemfile = original_gemfile.dup no_rails_gemfile.sub!(/(gemspec\(name:.*)/) { "#{Regexp.last_match[1]} unless plugin == \"rails\"" } @@ -22,7 +18,6 @@ namespace :gemfiles do File.write(no_rails_path, no_rails_gemfile) Bundler.with_clean_env do - system("BUNDLE_GEMFILE=#{rails4_path} bundle install") system("BUNDLE_GEMFILE=#{no_rails_path} bundle install") end end diff --git a/spec/controllers/diaspora_federation/application_controller_spec.rb b/spec/controllers/diaspora_federation/application_controller_spec.rb index 79084c4..70bf828 100644 --- a/spec/controllers/diaspora_federation/application_controller_spec.rb +++ b/spec/controllers/diaspora_federation/application_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe ApplicationController, type: :controller do controller do diff --git a/spec/controllers/diaspora_federation/fetch_controller_spec.rb b/spec/controllers/diaspora_federation/fetch_controller_spec.rb index 235783b..ec80207 100644 --- a/spec/controllers/diaspora_federation/fetch_controller_spec.rb +++ b/spec/controllers/diaspora_federation/fetch_controller_spec.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module DiasporaFederation - describe FetchController, type: :controller, rails: 5 do + describe FetchController, type: :controller do routes { DiasporaFederation::Engine.routes } let(:guid) { "12345678901234567890" } diff --git a/spec/controllers/diaspora_federation/h_card_controller_spec.rb b/spec/controllers/diaspora_federation/h_card_controller_spec.rb index 9ebbfd9..1cf805b 100644 --- a/spec/controllers/diaspora_federation/h_card_controller_spec.rb +++ b/spec/controllers/diaspora_federation/h_card_controller_spec.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module DiasporaFederation - describe HCardController, type: :controller, rails: 5 do + describe HCardController, type: :controller do routes { DiasporaFederation::Engine.routes } describe "GET #hcard" do diff --git a/spec/controllers/diaspora_federation/rails4_spec.rb b/spec/controllers/diaspora_federation/rails4_spec.rb deleted file mode 100644 index 7225c9a..0000000 --- a/spec/controllers/diaspora_federation/rails4_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -# only some basic controller tests for rails 4 -module DiasporaFederation - describe WebfingerController, type: :controller, rails: 4 do - routes { DiasporaFederation::Engine.routes } - - it "contains the webfinger result" do - webfinger_xrd = DiasporaFederation::Discovery::WebFinger.new( - acct_uri: "acct:#{alice.diaspora_id}", - alias_url: alice.alias_url, - hcard_url: alice.hcard_url, - seed_url: alice.url, - profile_url: alice.profile_url, - atom_url: alice.atom_url, - salmon_url: alice.salmon_url, - subscribe_url: alice.subscribe_url, - guid: alice.guid, - public_key: alice.serialized_public_key - ).to_xml - - get :webfinger, format: :xml, resource: alice.diaspora_id - expect(response).to be_success - expect(response.body).to eq(webfinger_xrd) - end - - it "404s when the person does not exist" do - get :webfinger, format: :xml, resource: "me@mydiaspora.pod.com" - expect(response).to be_not_found - end - end - - describe HCardController, type: :controller, rails: 4 do - routes { DiasporaFederation::Engine.routes } - - it "contains the hcard result" do - hcard_html = DiasporaFederation::Discovery::HCard.new( - guid: alice.guid, - nickname: alice.nickname, - full_name: alice.full_name, - url: alice.url, - photo_large_url: alice.photo_default_url, - photo_medium_url: alice.photo_default_url, - photo_small_url: alice.photo_default_url, - public_key: alice.serialized_public_key, - searchable: alice.searchable, - first_name: alice.first_name, - last_name: alice.last_name - ).to_html - - get :hcard, guid: alice.guid - expect(response).to be_success - expect(response.body).to eq(hcard_html) - end - - it "404s when the person does not exist" do - get :hcard, guid: "unknown_guid" - expect(response).to be_not_found - end - end - - describe ReceiveController, type: :controller, rails: 4 do - routes { DiasporaFederation::Engine.routes } - - describe "POST #public" do - it "returns a 202 if queued correctly" do - expect_callback(:queue_public_receive, "", true) - - post :public, xml: "" - expect(response.code).to eq("202") - end - end - - describe "POST #private" do - it "returns a 202 if the callback returned true" do - expect_callback(:queue_private_receive, "any-guid", "", true).and_return(true) - - post :private, guid: "any-guid", xml: "" - expect(response.code).to eq("202") - end - end - end -end diff --git a/spec/controllers/diaspora_federation/receive_controller_spec.rb b/spec/controllers/diaspora_federation/receive_controller_spec.rb index b480f48..0d5b684 100644 --- a/spec/controllers/diaspora_federation/receive_controller_spec.rb +++ b/spec/controllers/diaspora_federation/receive_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe ReceiveController, type: :controller do routes { DiasporaFederation::Engine.routes } @@ -15,21 +17,21 @@ module DiasporaFederation expect(response.code).to eq("422") end - it "returns a 202 if queued correctly", rails: 5 do + it "returns a 202 if queued correctly" do expect_callback(:queue_public_receive, "", true) post :public, params: {xml: ""} expect(response.code).to eq("202") end - it "unescapes the xml before sending it to the callback", rails: 5 do + it "unescapes the xml before sending it to the callback" do expect_callback(:queue_public_receive, "", true) post :public, params: {xml: CGI.escape("")} end end - context "magic envelope", rails: 5 do + context "magic envelope" do before do Mime::Type.register("application/magic-envelope+xml", :magic_envelope) @request.env["CONTENT_TYPE"] = "application/magic-envelope+xml" @@ -38,13 +40,13 @@ module DiasporaFederation it "returns a 202 if queued correctly" do expect_callback(:queue_public_receive, "", false) - post :public, body: "" + post :public, body: +"" expect(response.code).to eq("202") end end end - describe "POST #private", rails: 5 do + describe "POST #private" do context "legacy salmon slap" do it "return a 404 if not queued successfully (unknown user guid)" do expect_callback(:queue_private_receive, "any-guid", "", true).and_return(false) @@ -89,7 +91,7 @@ module DiasporaFederation ).and_return(false) post :private, - body: "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", + body: +"{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", params: {guid: "any-guid"} expect(response.code).to eq("404") end @@ -100,7 +102,7 @@ module DiasporaFederation ).and_return(true) post :private, - body: "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", + body: +"{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", params: {guid: "any-guid"} expect(response.code).to eq("202") end diff --git a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb index b1796c6..c1a4fa1 100644 --- a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb +++ b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe WebfingerController, type: :controller do routes { DiasporaFederation::Engine.routes } @@ -35,7 +37,7 @@ module DiasporaFederation end end - describe "GET #webfinger", rails: 5 do + describe "GET #webfinger" do it "uses the JRD format as default" do get :webfinger, params: {resource: alice.diaspora_id} expect(response).to be_successful diff --git a/spec/entities.rb b/spec/entities.rb index c370a91..429ea8a 100644 --- a/spec/entities.rb +++ b/spec/entities.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation module Entities class TestEntity < DiasporaFederation::Entity @@ -70,7 +72,7 @@ module DiasporaFederation end class SomeRelayable < DiasporaFederation::Entity - PARENT_TYPE = "Parent".freeze + PARENT_TYPE = "Parent" include Entities::Relayable @@ -78,7 +80,7 @@ module DiasporaFederation end class TestRelayableWithBoolean < DiasporaFederation::Entity - PARENT_TYPE = "Parent".freeze + PARENT_TYPE = "Parent" include Entities::Relayable diff --git a/spec/factories.rb b/spec/factories.rb index 8bd3e67..bbba632 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "diaspora_federation/test/factories" Fabricator(:person) do diff --git a/spec/integration/comment_integration_spec.rb b/spec/integration/comment_integration_spec.rb index 838f7b4..f713699 100644 --- a/spec/integration/comment_integration_spec.rb +++ b/spec/integration/comment_integration_spec.rb @@ -1,22 +1,24 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Relayable do - let(:author_serialized_key) { <<-KEY } ------BEGIN RSA PRIVATE KEY----- -MIICXgIBAAKBgQCxTbMp+M5sCUDVi9k1wMxedSwyLQcjBKQa0Qs6Qpnflz0k90hh -btau0cy9jTK6S3CK2GhERXD6EecDlhZCbnSI9Bwmco5j6NbGPN5ai9tWgiBZzaEr -yOVMQ4qCh1fKOMPX/LCvPzH+K7f8Q92zCuSvKSofg6zpg1zxGahpmxwqFQIDAQAB -AoGBAKEXD2la/XF7FsTuwvLrsMNBgl40Ov+9/7u9oo3UZSmYp50mb0TXB4beZz7x -Qt2wHRiJdnJRBUyvZ00C2EaTRJyFJA8p5J2qzHSjGpbPGyRCZUB6r6y+9vbM4ouj -m5Vo47TQ7ob2D835BHJGR8dWM1zeAwWc6uLhNIu+/5lHQ90BAkEA6aVQFSXNYjmO -fo6Oro+2nDaoa4jJ9qO1S23P2HF9N2f7CHDB4WKTdYnZpXs7ZPbnMEz62LeSC1MZ -QOKGYkMuDQJBAMJEZWvfWtp+Zwm+IF1xGbNPzGrvHGJarE/QGUGYs7BR7tHFlepR -aV3g56eGWfCWk8oWZRbjC2eQ2we96CU4cikCQQCqp3BCwgWthNSrY3yby6RZnSKO -yK6bUx+MJHz3Xo1S9sPIenNiKBoEc9dgow3SxPQ/tzpRKGOnmd6MIeh9xQvRAkAV -6WEHKco1msxEbQ15fKhJcVa9OPsanN+SoQY4P+EEojktr/uY0lXwIM4AN0ctu84v -nRcJ3dILfGs4FFN630MBAkEA3zMOyNTeNdHrVhZc5b0qw2T6FUJGieDpOWLsff4w -84yW10oS2CCmqEhbfh4Wu22amglytrATwD9hDzsTNAt8Mg== ------END RSA PRIVATE KEY----- -KEY + let(:author_serialized_key) { <<~KEY } + -----BEGIN RSA PRIVATE KEY----- + MIICXgIBAAKBgQCxTbMp+M5sCUDVi9k1wMxedSwyLQcjBKQa0Qs6Qpnflz0k90hh + btau0cy9jTK6S3CK2GhERXD6EecDlhZCbnSI9Bwmco5j6NbGPN5ai9tWgiBZzaEr + yOVMQ4qCh1fKOMPX/LCvPzH+K7f8Q92zCuSvKSofg6zpg1zxGahpmxwqFQIDAQAB + AoGBAKEXD2la/XF7FsTuwvLrsMNBgl40Ov+9/7u9oo3UZSmYp50mb0TXB4beZz7x + Qt2wHRiJdnJRBUyvZ00C2EaTRJyFJA8p5J2qzHSjGpbPGyRCZUB6r6y+9vbM4ouj + m5Vo47TQ7ob2D835BHJGR8dWM1zeAwWc6uLhNIu+/5lHQ90BAkEA6aVQFSXNYjmO + fo6Oro+2nDaoa4jJ9qO1S23P2HF9N2f7CHDB4WKTdYnZpXs7ZPbnMEz62LeSC1MZ + QOKGYkMuDQJBAMJEZWvfWtp+Zwm+IF1xGbNPzGrvHGJarE/QGUGYs7BR7tHFlepR + aV3g56eGWfCWk8oWZRbjC2eQ2we96CU4cikCQQCqp3BCwgWthNSrY3yby6RZnSKO + yK6bUx+MJHz3Xo1S9sPIenNiKBoEc9dgow3SxPQ/tzpRKGOnmd6MIeh9xQvRAkAV + 6WEHKco1msxEbQ15fKhJcVa9OPsanN+SoQY4P+EEojktr/uY0lXwIM4AN0ctu84v + nRcJ3dILfGs4FFN630MBAkEA3zMOyNTeNdHrVhZc5b0qw2T6FUJGieDpOWLsff4w + 84yW10oS2CCmqEhbfh4Wu22amglytrATwD9hDzsTNAt8Mg== + -----END RSA PRIVATE KEY----- + KEY let(:author_key) { OpenSSL::PKey::RSA.new(author_serialized_key) } # -----BEGIN PUBLIC KEY----- # MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxTbMp+M5sCUDVi9k1wMxedSwy @@ -25,23 +27,23 @@ KEY # g6zpg1zxGahpmxwqFQIDAQAB # -----END PUBLIC KEY----- - let(:parent_serialized_key) { <<-KEY } ------BEGIN RSA PRIVATE KEY----- -MIICXgIBAAKBgQDrOvW1UArKoUOg54XWXcTD3jU0zKG3Pm9IeaEzfQtApogQ3+M/ -F9nz0i3q8UhTDEPBQ3hMbqJ/4qfY+wFulxMR58DbqxFx9QcNZISUd0CPx/fJOYMx -R7bygTbiCet4FAiyMjxOX3Oei/DedUNps1RAP1bu+80iibze/Kk9BgMm0QIDAQAB -AoGAMHvikRCCaOl8SvnteBWzrLtsNAnJez9/KG0JcNdhLl4kxXWgHS0JW1wC4t4A -jj2E6ZzCet6C1+Ebv3lc/jJdV3pCK3wgX0YAt/oBW5kcuvpLHLSWusWHnHkYU+qO -4SdC3bRhdLV9o3u/oCWzmdeKTdqIyNd2yAbb3W1TsD4EsQECQQD6w+vWVKhWbVOj -Ky3ZkLCxPcWNUt+7OIzDA1OLKhdhe44hIoRMfDT6iLK3sJTSjgOv0OFTfsdOqh5y -ZqYp/CTpAkEA8CQFKkAYt4qG1lKMPsU/Tme0/Z24VozDRnyw7r663f0De+25kXGY -PSBiOHYcAE6poYQEtR/leLTSaG3YZm7hqQJBAOLAWLg1Uwbb0v4/pDUQlgWfQsy4 -/KAx0W7hyiCTzhKTBAFIUfNLeSh2hYx+ewQt8H2B1s6GXDjwsZlm4qgiXUkCQQC9 -B12ZeIL8V2r0Yl5LOvEuQqxRx0lHt94vKhAMns5x16xabTLZrlVsKIWodDBufX1B -yq359XWooo3N7kmduEKhAkEAppzKLuVtX1XPL4VZBex/M2ewngjkSg964BvxIBwv -bFzeSqlMpnbEoOJ9hhx6CsP6Y7V19DRRXi0XgwcAjHLz8g== ------END RSA PRIVATE KEY----- -KEY + let(:parent_serialized_key) { <<~KEY } + -----BEGIN RSA PRIVATE KEY----- + MIICXgIBAAKBgQDrOvW1UArKoUOg54XWXcTD3jU0zKG3Pm9IeaEzfQtApogQ3+M/ + F9nz0i3q8UhTDEPBQ3hMbqJ/4qfY+wFulxMR58DbqxFx9QcNZISUd0CPx/fJOYMx + R7bygTbiCet4FAiyMjxOX3Oei/DedUNps1RAP1bu+80iibze/Kk9BgMm0QIDAQAB + AoGAMHvikRCCaOl8SvnteBWzrLtsNAnJez9/KG0JcNdhLl4kxXWgHS0JW1wC4t4A + jj2E6ZzCet6C1+Ebv3lc/jJdV3pCK3wgX0YAt/oBW5kcuvpLHLSWusWHnHkYU+qO + 4SdC3bRhdLV9o3u/oCWzmdeKTdqIyNd2yAbb3W1TsD4EsQECQQD6w+vWVKhWbVOj + Ky3ZkLCxPcWNUt+7OIzDA1OLKhdhe44hIoRMfDT6iLK3sJTSjgOv0OFTfsdOqh5y + ZqYp/CTpAkEA8CQFKkAYt4qG1lKMPsU/Tme0/Z24VozDRnyw7r663f0De+25kXGY + PSBiOHYcAE6poYQEtR/leLTSaG3YZm7hqQJBAOLAWLg1Uwbb0v4/pDUQlgWfQsy4 + /KAx0W7hyiCTzhKTBAFIUfNLeSh2hYx+ewQt8H2B1s6GXDjwsZlm4qgiXUkCQQC9 + B12ZeIL8V2r0Yl5LOvEuQqxRx0lHt94vKhAMns5x16xabTLZrlVsKIWodDBufX1B + yq359XWooo3N7kmduEKhAkEAppzKLuVtX1XPL4VZBex/M2ewngjkSg964BvxIBwv + bFzeSqlMpnbEoOJ9hhx6CsP6Y7V19DRRXi0XgwcAjHLz8g== + -----END RSA PRIVATE KEY----- + KEY let(:parent_key) { OpenSSL::PKey::RSA.new(parent_serialized_key) } # -----BEGIN PUBLIC KEY----- # MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrOvW1UArKoUOg54XWXcTD3jU0 @@ -63,116 +65,116 @@ KEY ) } - let(:legacy_format_comment_xml_alice) { <<-XML } - - - - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - XU5X1uqTh8SY6JMG9uhEVR5Rg7FURV6lpRwl/HYOu6DJ3Hd9tpA2aSFFibUxxsMgJXKNrrc5SykrrEdTiQoEei+j0QqZf3B5R7r84qgK7M46KazwIpqRPwVl2MdA/0DdQyYJLA/oavNj1nwll9vtR87M7e/C94qG6P+iQTMBQzo= - - this is a very informative comment - alice@pod-a.org - - - -XML - let(:new_format_comment_xml_alice) { <<-XML } - - alice@pod-a.org - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - SQbLeqsEpFmSl74G1fFJXKQcsq6jp5B2ZjmfEOF/LbBccYP2oZEyEqOq18K3Fa71OYTp6Nddb38hCmHWWHvnGUltGfxKBnQ0WHafJUi40VM4VmeRoU8cac6m+1hslwe5SNmK6oh47EV3mRCXlgGGjLIrw7iEwjKL2g9x1gkNp2s= - - -XML - let(:new_data_comment_xml_alice) { <<-XML } - - alice@pod-a.org - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - foobar - SFYXSvCX/DhTFiOUALp2Nf1kfNkGKXrnoBPikAyhaIogGydVBm+8tIlu1U/vsnpyKO3yfC3JReJ00/UBd4J16VO1IxStntq8NUqbSv4me5A/6kdK9Xg6eYbXrqQGm8fUQ5Xuh2UzeB71p7SVySXX3OZHVe0dvHCxH/lsfSDpEjc= - - -XML + let(:legacy_format_comment_xml_alice) { <<~XML } + + + + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + XU5X1uqTh8SY6JMG9uhEVR5Rg7FURV6lpRwl/HYOu6DJ3Hd9tpA2aSFFibUxxsMgJXKNrrc5SykrrEdTiQoEei+j0QqZf3B5R7r84qgK7M46KazwIpqRPwVl2MdA/0DdQyYJLA/oavNj1nwll9vtR87M7e/C94qG6P+iQTMBQzo= + + this is a very informative comment + alice@pod-a.org + + + + XML + let(:new_format_comment_xml_alice) { <<~XML } + + alice@pod-a.org + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + SQbLeqsEpFmSl74G1fFJXKQcsq6jp5B2ZjmfEOF/LbBccYP2oZEyEqOq18K3Fa71OYTp6Nddb38hCmHWWHvnGUltGfxKBnQ0WHafJUi40VM4VmeRoU8cac6m+1hslwe5SNmK6oh47EV3mRCXlgGGjLIrw7iEwjKL2g9x1gkNp2s= + + + XML + let(:new_data_comment_xml_alice) { <<~XML } + + alice@pod-a.org + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + foobar + SFYXSvCX/DhTFiOUALp2Nf1kfNkGKXrnoBPikAyhaIogGydVBm+8tIlu1U/vsnpyKO3yfC3JReJ00/UBd4J16VO1IxStntq8NUqbSv4me5A/6kdK9Xg6eYbXrqQGm8fUQ5Xuh2UzeB71p7SVySXX3OZHVe0dvHCxH/lsfSDpEjc= + + + XML - let(:legacy_format_comment_xml_bob) { <<-XML } - - - - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - alice@pod-a.org - XU5X1uqTh8SY6JMG9uhEVR5Rg7FURV6lpRwl/HYOu6DJ3Hd9tpA2aSFFibUxxsMgJXKNrrc5SykrrEdTiQoEei+j0QqZf3B5R7r84qgK7M46KazwIpqRPwVl2MdA/0DdQyYJLA/oavNj1nwll9vtR87M7e/C94qG6P+iQTMBQzo= - QqWSdwpb+/dcJUxuKKVe7aiz1NivXzlIdWZ71xyrxnhFxFYd+7EIittyTcp1cVehjg96pwDbn++P/rWyCffqenWu025DHvUfSmQkC93Z0dX6r3OIUlZqwEggtOdbunybiE++F3BVsGt5wC4YbAESB5ZFuhFVhBXh1X+EaZ/qoKo= - - - -XML - let(:legacy_order_new_format_comment_xml_bob) { <<-XML } - - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - alice@pod-a.org - XU5X1uqTh8SY6JMG9uhEVR5Rg7FURV6lpRwl/HYOu6DJ3Hd9tpA2aSFFibUxxsMgJXKNrrc5SykrrEdTiQoEei+j0QqZf3B5R7r84qgK7M46KazwIpqRPwVl2MdA/0DdQyYJLA/oavNj1nwll9vtR87M7e/C94qG6P+iQTMBQzo= - QqWSdwpb+/dcJUxuKKVe7aiz1NivXzlIdWZ71xyrxnhFxFYd+7EIittyTcp1cVehjg96pwDbn++P/rWyCffqenWu025DHvUfSmQkC93Z0dX6r3OIUlZqwEggtOdbunybiE++F3BVsGt5wC4YbAESB5ZFuhFVhBXh1X+EaZ/qoKo= - -XML - let(:new_order_legacy_format_comment_xml_bob) { <<-XML } - - - - alice@pod-a.org - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - SQbLeqsEpFmSl74G1fFJXKQcsq6jp5B2ZjmfEOF/LbBccYP2oZEyEqOq18K3Fa71OYTp6Nddb38hCmHWWHvnGUltGfxKBnQ0WHafJUi40VM4VmeRoU8cac6m+1hslwe5SNmK6oh47EV3mRCXlgGGjLIrw7iEwjKL2g9x1gkNp2s= - hWsagsczmZD6d36d6MFdTt3hKAdnRtupSIU6464G2kkMJ+WlExxMgbF6kWR+jVCBTeKipWCYK3Arnj0YkuIZM9d14bJGVMTsW/ZzNfJ69bXZhsyawI8dPnZnLVydo+hU/XmGJBEuh2TOj9Emq6/HCYiWzPTF5qhYAtyJ1oxJ4Yk= - - - -XML - let(:new_format_comment_xml_bob) { <<-XML } - - alice@pod-a.org - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - SQbLeqsEpFmSl74G1fFJXKQcsq6jp5B2ZjmfEOF/LbBccYP2oZEyEqOq18K3Fa71OYTp6Nddb38hCmHWWHvnGUltGfxKBnQ0WHafJUi40VM4VmeRoU8cac6m+1hslwe5SNmK6oh47EV3mRCXlgGGjLIrw7iEwjKL2g9x1gkNp2s= - hWsagsczmZD6d36d6MFdTt3hKAdnRtupSIU6464G2kkMJ+WlExxMgbF6kWR+jVCBTeKipWCYK3Arnj0YkuIZM9d14bJGVMTsW/ZzNfJ69bXZhsyawI8dPnZnLVydo+hU/XmGJBEuh2TOj9Emq6/HCYiWzPTF5qhYAtyJ1oxJ4Yk= - -XML - let(:legacy_format_new_data_comment_xml_bob) { <<-XML } - - - - alice@pod-a.org - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - foobar - SFYXSvCX/DhTFiOUALp2Nf1kfNkGKXrnoBPikAyhaIogGydVBm+8tIlu1U/vsnpyKO3yfC3JReJ00/UBd4J16VO1IxStntq8NUqbSv4me5A/6kdK9Xg6eYbXrqQGm8fUQ5Xuh2UzeB71p7SVySXX3OZHVe0dvHCxH/lsfSDpEjc= - NxXuEUVeXwUMR77osIbaNlp2oB3bpl8rBEFgQoO6cnoN5ewDbiGADK0x6EhcmJptjwhGVcZiNJNpq7k3/pjJtKaH++3ToCAtcuZoIKwPDsneLnjPhVjE2GXM1TiZKwoHrq41qSp/8Vl5UPbtC6sPiOzIvPKaILXUG8XCiVWuB0M= - - - -XML - let(:new_data_comment_xml_bob) { <<-XML } - - alice@pod-a.org - e21589b0b41101333b870f77ba60fa73 - 9e269ae0b41201333b8c0f77ba60fa73 - this is a very informative comment - foobar - SFYXSvCX/DhTFiOUALp2Nf1kfNkGKXrnoBPikAyhaIogGydVBm+8tIlu1U/vsnpyKO3yfC3JReJ00/UBd4J16VO1IxStntq8NUqbSv4me5A/6kdK9Xg6eYbXrqQGm8fUQ5Xuh2UzeB71p7SVySXX3OZHVe0dvHCxH/lsfSDpEjc= - NxXuEUVeXwUMR77osIbaNlp2oB3bpl8rBEFgQoO6cnoN5ewDbiGADK0x6EhcmJptjwhGVcZiNJNpq7k3/pjJtKaH++3ToCAtcuZoIKwPDsneLnjPhVjE2GXM1TiZKwoHrq41qSp/8Vl5UPbtC6sPiOzIvPKaILXUG8XCiVWuB0M= - -XML + let(:legacy_format_comment_xml_bob) { <<~XML } + + + + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + alice@pod-a.org + XU5X1uqTh8SY6JMG9uhEVR5Rg7FURV6lpRwl/HYOu6DJ3Hd9tpA2aSFFibUxxsMgJXKNrrc5SykrrEdTiQoEei+j0QqZf3B5R7r84qgK7M46KazwIpqRPwVl2MdA/0DdQyYJLA/oavNj1nwll9vtR87M7e/C94qG6P+iQTMBQzo= + QqWSdwpb+/dcJUxuKKVe7aiz1NivXzlIdWZ71xyrxnhFxFYd+7EIittyTcp1cVehjg96pwDbn++P/rWyCffqenWu025DHvUfSmQkC93Z0dX6r3OIUlZqwEggtOdbunybiE++F3BVsGt5wC4YbAESB5ZFuhFVhBXh1X+EaZ/qoKo= + + + + XML + let(:legacy_order_new_format_comment_xml_bob) { <<~XML } + + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + alice@pod-a.org + XU5X1uqTh8SY6JMG9uhEVR5Rg7FURV6lpRwl/HYOu6DJ3Hd9tpA2aSFFibUxxsMgJXKNrrc5SykrrEdTiQoEei+j0QqZf3B5R7r84qgK7M46KazwIpqRPwVl2MdA/0DdQyYJLA/oavNj1nwll9vtR87M7e/C94qG6P+iQTMBQzo= + QqWSdwpb+/dcJUxuKKVe7aiz1NivXzlIdWZ71xyrxnhFxFYd+7EIittyTcp1cVehjg96pwDbn++P/rWyCffqenWu025DHvUfSmQkC93Z0dX6r3OIUlZqwEggtOdbunybiE++F3BVsGt5wC4YbAESB5ZFuhFVhBXh1X+EaZ/qoKo= + + XML + let(:new_order_legacy_format_comment_xml_bob) { <<~XML } + + + + alice@pod-a.org + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + SQbLeqsEpFmSl74G1fFJXKQcsq6jp5B2ZjmfEOF/LbBccYP2oZEyEqOq18K3Fa71OYTp6Nddb38hCmHWWHvnGUltGfxKBnQ0WHafJUi40VM4VmeRoU8cac6m+1hslwe5SNmK6oh47EV3mRCXlgGGjLIrw7iEwjKL2g9x1gkNp2s= + hWsagsczmZD6d36d6MFdTt3hKAdnRtupSIU6464G2kkMJ+WlExxMgbF6kWR+jVCBTeKipWCYK3Arnj0YkuIZM9d14bJGVMTsW/ZzNfJ69bXZhsyawI8dPnZnLVydo+hU/XmGJBEuh2TOj9Emq6/HCYiWzPTF5qhYAtyJ1oxJ4Yk= + + + + XML + let(:new_format_comment_xml_bob) { <<~XML } + + alice@pod-a.org + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + SQbLeqsEpFmSl74G1fFJXKQcsq6jp5B2ZjmfEOF/LbBccYP2oZEyEqOq18K3Fa71OYTp6Nddb38hCmHWWHvnGUltGfxKBnQ0WHafJUi40VM4VmeRoU8cac6m+1hslwe5SNmK6oh47EV3mRCXlgGGjLIrw7iEwjKL2g9x1gkNp2s= + hWsagsczmZD6d36d6MFdTt3hKAdnRtupSIU6464G2kkMJ+WlExxMgbF6kWR+jVCBTeKipWCYK3Arnj0YkuIZM9d14bJGVMTsW/ZzNfJ69bXZhsyawI8dPnZnLVydo+hU/XmGJBEuh2TOj9Emq6/HCYiWzPTF5qhYAtyJ1oxJ4Yk= + + XML + let(:legacy_format_new_data_comment_xml_bob) { <<~XML } + + + + alice@pod-a.org + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + foobar + SFYXSvCX/DhTFiOUALp2Nf1kfNkGKXrnoBPikAyhaIogGydVBm+8tIlu1U/vsnpyKO3yfC3JReJ00/UBd4J16VO1IxStntq8NUqbSv4me5A/6kdK9Xg6eYbXrqQGm8fUQ5Xuh2UzeB71p7SVySXX3OZHVe0dvHCxH/lsfSDpEjc= + NxXuEUVeXwUMR77osIbaNlp2oB3bpl8rBEFgQoO6cnoN5ewDbiGADK0x6EhcmJptjwhGVcZiNJNpq7k3/pjJtKaH++3ToCAtcuZoIKwPDsneLnjPhVjE2GXM1TiZKwoHrq41qSp/8Vl5UPbtC6sPiOzIvPKaILXUG8XCiVWuB0M= + + + + XML + let(:new_data_comment_xml_bob) { <<~XML } + + alice@pod-a.org + e21589b0b41101333b870f77ba60fa73 + 9e269ae0b41201333b8c0f77ba60fa73 + this is a very informative comment + foobar + SFYXSvCX/DhTFiOUALp2Nf1kfNkGKXrnoBPikAyhaIogGydVBm+8tIlu1U/vsnpyKO3yfC3JReJ00/UBd4J16VO1IxStntq8NUqbSv4me5A/6kdK9Xg6eYbXrqQGm8fUQ5Xuh2UzeB71p7SVySXX3OZHVe0dvHCxH/lsfSDpEjc= + NxXuEUVeXwUMR77osIbaNlp2oB3bpl8rBEFgQoO6cnoN5ewDbiGADK0x6EhcmJptjwhGVcZiNJNpq7k3/pjJtKaH++3ToCAtcuZoIKwPDsneLnjPhVjE2GXM1TiZKwoHrq41qSp/8Vl5UPbtC6sPiOzIvPKaILXUG8XCiVWuB0M= + + XML # this was used to create the XMLs above context "test-data creation" do diff --git a/spec/lib/diaspora_federation/callbacks_spec.rb b/spec/lib/diaspora_federation/callbacks_spec.rb index e6adfe8..80e0ff3 100644 --- a/spec/lib/diaspora_federation/callbacks_spec.rb +++ b/spec/lib/diaspora_federation/callbacks_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Callbacks do subject(:callbacks) { Callbacks.new %i[some_event another_event] } diff --git a/spec/lib/diaspora_federation/discovery/discovery_spec.rb b/spec/lib/diaspora_federation/discovery/discovery_spec.rb index 7ee024e..d298d04 100644 --- a/spec/lib/diaspora_federation/discovery/discovery_spec.rb +++ b/spec/lib/diaspora_federation/discovery/discovery_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Discovery::Discovery do let(:host_meta_xrd) { Discovery::HostMeta.from_base_url("http://localhost:3000/").to_xml } diff --git a/spec/lib/diaspora_federation/discovery/h_card_spec.rb b/spec/lib/diaspora_federation/discovery/h_card_spec.rb index 5644891..5c2da01 100644 --- a/spec/lib/diaspora_federation/discovery/h_card_spec.rb +++ b/spec/lib/diaspora_federation/discovery/h_card_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Discovery::HCard do let(:person) { Fabricate(:person) } @@ -21,90 +23,90 @@ module DiasporaFederation } } - let(:html) { <<-HTML } - - - - - - #{person.full_name} - - -
-

#{person.full_name}

-
-

User profile

-
-
Uid
-
- #{person.guid} -
-
-
-
Nickname
-
- #{person.nickname} -
-
-
-
Full_name
-
- #{person.full_name} -
-
-
-
Searchable
-
- #{person.searchable} -
-
-
-
Key
-
-
#{person.serialized_public_key}
-
-
-
-
First_name
-
- #{person.first_name} -
-
-
-
Family_name
-
- #{person.last_name} -
-
-
-
Url
-
- #{person.url} -
-
-
-
Photo
-
- -
-
-
-
Photo_medium
-
- -
-
-
-
Photo_small
-
- -
-
-
-
- - -HTML + let(:html) { <<~HTML } + + + + + + #{person.full_name} + + +
+

#{person.full_name}

+
+

User profile

+
+
Uid
+
+ #{person.guid} +
+
+
+
Nickname
+
+ #{person.nickname} +
+
+
+
Full_name
+
+ #{person.full_name} +
+
+
+
Searchable
+
+ #{person.searchable} +
+
+
+
Key
+
+
#{person.serialized_public_key}
+
+
+
+
First_name
+
+ #{person.first_name} +
+
+
+
Family_name
+
+ #{person.last_name} +
+
+
+
Url
+
+ #{person.url} +
+
+
+
Photo
+
+ +
+
+
+
Photo_medium
+
+ +
+
+
+
Photo_small
+
+ +
+
+
+
+ + + HTML let(:string) { "HCard:#{data[:guid]}" } @@ -134,78 +136,78 @@ HTML end it "reads minimal hCard" do - minimal_html = <<-HTML - - - - - - #{person.full_name} - - -
-

#{person.full_name}

-
-

User profile

-
-
Uid
-
- #{person.guid} -
-
-
-
Full_name
-
- #{person.full_name} -
-
-
-
Searchable
-
- #{person.searchable} -
-
-
-
Key
-
-
#{person.serialized_public_key}
-
-
-
-
First_name
-
- #{person.first_name} -
-
-
-
Family_name
-
- #{person.last_name} -
-
-
-
Photo
-
- -
-
-
-
Photo_medium
-
- -
-
-
-
Photo_small
-
- -
-
-
-
- - -HTML + minimal_html = <<~HTML + + + + + + #{person.full_name} + + +
+

#{person.full_name}

+
+

User profile

+
+
Uid
+
+ #{person.guid} +
+
+
+
Full_name
+
+ #{person.full_name} +
+
+
+
Searchable
+
+ #{person.searchable} +
+
+
+
Key
+
+
#{person.serialized_public_key}
+
+
+
+
First_name
+
+ #{person.first_name} +
+
+
+
Family_name
+
+ #{person.last_name} +
+
+
+
Photo
+
+ +
+
+
+
Photo_medium
+
+ +
+
+
+
Photo_small
+
+ +
+
+
+
+ + + HTML hcard = Discovery::HCard.from_html(minimal_html) expect(hcard.guid).to eq(person.guid) @@ -259,11 +261,11 @@ HTML end it "fails if the document is incomplete" do - invalid_html = <<-HTML -
- #{person.full_name} -
-HTML + invalid_html = <<~HTML +
+ #{person.full_name} +
+ HTML expect { Discovery::HCard.from_html(invalid_html) }.to raise_error Discovery::InvalidData end diff --git a/spec/lib/diaspora_federation/discovery/host_meta_spec.rb b/spec/lib/diaspora_federation/discovery/host_meta_spec.rb index aeb6fa6..0db73d5 100644 --- a/spec/lib/diaspora_federation/discovery/host_meta_spec.rb +++ b/spec/lib/diaspora_federation/discovery/host_meta_spec.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + module DiasporaFederation describe Discovery::HostMeta do let(:base_url) { "https://pod.example.tld/" } - let(:xml) { <<-XML } - - - - -XML + let(:xml) { <<~XML } + + + + + XML it "must not create blank instances" do expect { Discovery::HostMeta.new }.to raise_error NoMethodError @@ -40,56 +42,56 @@ XML end it "also reads old-style XML" do - historic_xml = <<-XML - - + historic_xml = <<~XML + + - + - + - -XML + + XML hm = Discovery::HostMeta.from_xml(historic_xml) expect(hm.webfinger_template_url).to eq("#{base_url}webfinger?q={uri}") end it "also reads friendica/redmatrix XML" do - friendica_redmatrix_xml = <<-XML - - + friendica_redmatrix_xml = <<~XML + + - pod.example.tld + pod.example.tld - - + + - + XML hm = Discovery::HostMeta.from_xml(friendica_redmatrix_xml) expect(hm.webfinger_template_url).to eq("#{base_url}xrd/?uri={uri}") end it "fails if the document does not contain a webfinger url" do - invalid_xml = < - - -XML + invalid_xml = <<~XML + + + + XML expect { Discovery::HostMeta.from_xml(invalid_xml) }.to raise_error Discovery::InvalidData end it "fails if the document contains a malformed webfinger url" do - invalid_xml = < - - - -XML + invalid_xml = <<~XML + + + + + XML expect { Discovery::HostMeta.from_xml(invalid_xml) }.to raise_error Discovery::InvalidData end diff --git a/spec/lib/diaspora_federation/discovery/web_finger_spec.rb b/spec/lib/diaspora_federation/discovery/web_finger_spec.rb index fb0a2a4..1818e58 100644 --- a/spec/lib/diaspora_federation/discovery/web_finger_spec.rb +++ b/spec/lib/diaspora_federation/discovery/web_finger_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Discovery::WebFinger do let(:person) { Fabricate(:person) } @@ -16,85 +18,85 @@ module DiasporaFederation } } - let(:xml) { <<-XML } - - - #{acct} - #{person.alias_url} - - - - - - - -XML + let(:xml) { <<~XML } + + + #{acct} + #{person.alias_url} + + + + + + + + XML - let(:minimal_xml) { <<-XML } - - - #{acct} - - - -XML + let(:minimal_xml) { <<~XML } + + + #{acct} + + + + XML - let(:json) { <<-JSON } -{ - "subject": "#{acct}", - "aliases": [ - "#{person.alias_url}" - ], - "links": [ - { - "rel": "http://microformats.org/profile/hcard", - "type": "text/html", - "href": "#{person.hcard_url}" - }, - { - "rel": "http://joindiaspora.com/seed_location", - "type": "text/html", - "href": "#{person.url}" - }, - { - "rel": "http://webfinger.net/rel/profile-page", - "type": "text/html", - "href": "#{person.profile_url}" - }, - { - "rel": "http://schemas.google.com/g/2010#updates-from", - "type": "application/atom+xml", - "href": "#{person.atom_url}" - }, - { - "rel": "salmon", - "href": "#{person.salmon_url}" - }, - { - "rel": "http://ostatus.org/schema/1.0/subscribe", - "template": "http://somehost:3000/people?q={uri}" - } - ] -} -JSON + let(:json) { <<~JSON } + { + "subject": "#{acct}", + "aliases": [ + "#{person.alias_url}" + ], + "links": [ + { + "rel": "http://microformats.org/profile/hcard", + "type": "text/html", + "href": "#{person.hcard_url}" + }, + { + "rel": "http://joindiaspora.com/seed_location", + "type": "text/html", + "href": "#{person.url}" + }, + { + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html", + "href": "#{person.profile_url}" + }, + { + "rel": "http://schemas.google.com/g/2010#updates-from", + "type": "application/atom+xml", + "href": "#{person.atom_url}" + }, + { + "rel": "salmon", + "href": "#{person.salmon_url}" + }, + { + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": "http://somehost:3000/people?q={uri}" + } + ] + } + JSON - let(:minimal_json) { <<-JSON } -{ - "subject": "#{acct}", - "links": [ - { - "rel": "http://microformats.org/profile/hcard", - "type": "text/html", - "href": "#{person.hcard_url}" - }, - { - "rel": "http://joindiaspora.com/seed_location", - "type": "text/html", - "href": "#{person.url}" - } - ] -} -JSON + let(:minimal_json) { <<~JSON } + { + "subject": "#{acct}", + "links": [ + { + "rel": "http://microformats.org/profile/hcard", + "type": "text/html", + "href": "#{person.hcard_url}" + }, + { + "rel": "http://joindiaspora.com/seed_location", + "type": "text/html", + "href": "#{person.url}" + } + ] + } + JSON let(:string) { "WebFinger:#{data[:acct_uri]}" } @@ -130,20 +132,20 @@ JSON end it "creates XML document with additional data" do - xml_with_additional_data = <<-XML - - - #{acct} - #{person.alias_url} - #{person.profile_url} - Bob Smith - - - - - - -XML + xml_with_additional_data = <<~XML + + + #{acct} + #{person.alias_url} + #{person.profile_url} + Bob Smith + + + + + + + XML wf = Discovery::WebFinger.new(minimal_data, additional_data) expect(wf.to_xml).to eq(xml_with_additional_data) @@ -162,43 +164,43 @@ XML end it "creates JSON document with additional data" do - json_with_additional_data = <<-JSON -{ - "subject": "#{acct}", - "aliases": [ - "#{person.alias_url}", - "#{person.profile_url}" - ], - "properties": { - "http://webfinger.example/ns/name": "Bob Smith" - }, - "links": [ - { - "rel": "http://microformats.org/profile/hcard", - "type": "text/html", - "href": "#{person.hcard_url}" - }, - { - "rel": "http://joindiaspora.com/seed_location", - "type": "text/html", - "href": "#{person.url}" - }, - { - "rel": "http://portablecontacts.net/spec/1.0", - "href": "https://pod.example.tld/poco/trouble" - }, - { - "rel": "http://webfinger.net/rel/avatar", - "type": "image/jpeg", - "href": "http://localhost:3000/assets/user/default.png" - }, - { - "rel": "http://openid.net/specs/connect/1.0/issuer", - "href": "https://pod.example.tld/" - } - ] -} -JSON + json_with_additional_data = <<~JSON + { + "subject": "#{acct}", + "aliases": [ + "#{person.alias_url}", + "#{person.profile_url}" + ], + "properties": { + "http://webfinger.example/ns/name": "Bob Smith" + }, + "links": [ + { + "rel": "http://microformats.org/profile/hcard", + "type": "text/html", + "href": "#{person.hcard_url}" + }, + { + "rel": "http://joindiaspora.com/seed_location", + "type": "text/html", + "href": "#{person.url}" + }, + { + "rel": "http://portablecontacts.net/spec/1.0", + "href": "https://pod.example.tld/poco/trouble" + }, + { + "rel": "http://webfinger.net/rel/avatar", + "type": "image/jpeg", + "href": "http://localhost:3000/assets/user/default.png" + }, + { + "rel": "http://openid.net/specs/connect/1.0/issuer", + "href": "https://pod.example.tld/" + } + ] + } + JSON wf = Discovery::WebFinger.new(minimal_data, additional_data) expect(JSON.pretty_generate(wf.to_json)).to eq(json_with_additional_data.strip) @@ -249,50 +251,50 @@ JSON end it "reads friendica XML (two aliases, first with acct)" do - friendica_xml = <<-XML - - + friendica_xml = <<~XML + + - #{acct} - #{acct} - #{person.alias_url} + #{acct} + #{acct} + #{person.alias_url} - - - - - - - - - + + + + + + + + + - - - - - + + + + + - RSA.abcdef1234567890 + RSA.abcdef1234567890 - + XML wf = Discovery::WebFinger.from_xml(friendica_xml) @@ -306,35 +308,35 @@ JSON end it "reads redmatrix XML (no alias)" do - redmatrix_xml = <<-XML - - + redmatrix_xml = <<~XML + + - #{person.diaspora_id} + #{person.diaspora_id} - - - - - + + + + + - + - - - + + + - + XML wf = Discovery::WebFinger.from_xml(redmatrix_xml) @@ -347,11 +349,11 @@ JSON end it "fails if the document is empty" do - invalid_xml = <<-XML - - - -XML + invalid_xml = <<~XML + + + + XML expect { Discovery::WebFinger.from_xml(invalid_xml) }.to raise_error Discovery::InvalidData end diff --git a/spec/lib/diaspora_federation/discovery/xrd_document_spec.rb b/spec/lib/diaspora_federation/discovery/xrd_document_spec.rb index 3fe8a3b..8b99a23 100644 --- a/spec/lib/diaspora_federation/discovery/xrd_document_spec.rb +++ b/spec/lib/diaspora_federation/discovery/xrd_document_spec.rb @@ -1,49 +1,51 @@ +# frozen_string_literal: true + module DiasporaFederation describe Discovery::XrdDocument do - let(:xml) { <<-XML } - - - 2010-01-30T09:30:00Z - http://blog.example.com/article/id/314 - http://blog.example.com/cool_new_thing - http://blog.example.com/steve/article/7 - 1.3 - - - - - -XML + let(:xml) { <<~XML } + + + 2010-01-30T09:30:00Z + http://blog.example.com/article/id/314 + http://blog.example.com/cool_new_thing + http://blog.example.com/steve/article/7 + 1.3 + + + + + + XML - let(:json) { <<-JSON } -{ - "subject": "http://blog.example.com/article/id/314", - "expires": "2010-01-30T09:30:00Z", - "aliases": [ - "http://blog.example.com/cool_new_thing", - "http://blog.example.com/steve/article/7" - ], - "properties": { - "http://blgx.example.net/ns/version": "1.3", - "http://blgx.example.net/ns/ext": null - }, - "links": [ - { - "rel": "author", - "type": "text/html", - "href": "http://blog.example.com/author/steve" - }, - { - "rel": "author", - "href": "http://example.com/author/john" - }, - { - "rel": "copyright", - "template": "http://example.com/copyright?id={uri}" - } - ] -} -JSON + let(:json) { <<~JSON } + { + "subject": "http://blog.example.com/article/id/314", + "expires": "2010-01-30T09:30:00Z", + "aliases": [ + "http://blog.example.com/cool_new_thing", + "http://blog.example.com/steve/article/7" + ], + "properties": { + "http://blgx.example.net/ns/version": "1.3", + "http://blgx.example.net/ns/ext": null + }, + "links": [ + { + "rel": "author", + "type": "text/html", + "href": "http://blog.example.com/author/steve" + }, + { + "rel": "author", + "href": "http://example.com/author/john" + }, + { + "rel": "copyright", + "template": "http://example.com/copyright?id={uri}" + } + ] + } + JSON let(:data) { { diff --git a/spec/lib/diaspora_federation/entities/account_deletion_spec.rb b/spec/lib/diaspora_federation/entities/account_deletion_spec.rb index 1de2ecf..1d3fb53 100644 --- a/spec/lib/diaspora_federation/entities/account_deletion_spec.rb +++ b/spec/lib/diaspora_federation/entities/account_deletion_spec.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::AccountDeletion do let(:data) { Fabricate.attributes_for(:account_deletion_entity) } - let(:xml) { <<-XML } - - #{data[:author]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + + XML let(:string) { "AccountDeletion:#{data[:author]}" } diff --git a/spec/lib/diaspora_federation/entities/account_migration/signable_spec.rb b/spec/lib/diaspora_federation/entities/account_migration/signable_spec.rb index 5b6b784..0d150d9 100644 --- a/spec/lib/diaspora_federation/entities/account_migration/signable_spec.rb +++ b/spec/lib/diaspora_federation/entities/account_migration/signable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::AccountMigration::Signable do let(:entity) { TestAMSignableEntity.new({}) } diff --git a/spec/lib/diaspora_federation/entities/account_migration_spec.rb b/spec/lib/diaspora_federation/entities/account_migration_spec.rb index 37852df..cf79218 100644 --- a/spec/lib/diaspora_federation/entities/account_migration_spec.rb +++ b/spec/lib/diaspora_federation/entities/account_migration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::AccountMigration do let(:old_user) { Fabricate(:user) } @@ -105,29 +107,29 @@ module DiasporaFederation } } - let(:xml) { <<-XML } - - #{data[:author]} - - #{data[:profile].author} - #{data[:profile].full_name} - #{data[:profile].first_name} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].bio} - #{data[:profile].birthday} - #{data[:profile].gender} - #{data[:profile].location} - #{data[:profile].searchable} - #{data[:profile].public} - #{data[:profile].nsfw} - #{data[:profile].tag_string} - - #{data[:signature]} - #{data[:old_identity]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + + #{data[:profile].author} + #{data[:profile].full_name} + #{data[:profile].first_name} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].bio} + #{data[:profile].birthday} + #{data[:profile].gender} + #{data[:profile].location} + #{data[:profile].searchable} + #{data[:profile].public} + #{data[:profile].nsfw} + #{data[:profile].tag_string} + + #{data[:signature]} + #{data[:old_identity]} + + XML it_behaves_like "an account migration entity" end @@ -144,29 +146,29 @@ XML } } - let(:xml) { <<-XML } - - #{data[:author]} - - #{data[:profile].author} - #{data[:profile].full_name} - #{data[:profile].first_name} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].bio} - #{data[:profile].birthday} - #{data[:profile].gender} - #{data[:profile].location} - #{data[:profile].searchable} - #{data[:profile].public} - #{data[:profile].nsfw} - #{data[:profile].tag_string} - - #{data[:signature]} - #{data[:old_identity]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + + #{data[:profile].author} + #{data[:profile].full_name} + #{data[:profile].first_name} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].bio} + #{data[:profile].birthday} + #{data[:profile].gender} + #{data[:profile].location} + #{data[:profile].searchable} + #{data[:profile].public} + #{data[:profile].nsfw} + #{data[:profile].tag_string} + + #{data[:signature]} + #{data[:old_identity]} + + XML it_behaves_like "an account migration entity" end @@ -182,28 +184,28 @@ XML } } - let(:xml) { <<-XML } - - #{data[:author]} - - #{data[:profile].author} - #{data[:profile].full_name} - #{data[:profile].first_name} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].bio} - #{data[:profile].birthday} - #{data[:profile].gender} - #{data[:profile].location} - #{data[:profile].searchable} - #{data[:profile].public} - #{data[:profile].nsfw} - #{data[:profile].tag_string} - - #{data[:signature]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + + #{data[:profile].author} + #{data[:profile].full_name} + #{data[:profile].first_name} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].bio} + #{data[:profile].birthday} + #{data[:profile].gender} + #{data[:profile].location} + #{data[:profile].searchable} + #{data[:profile].public} + #{data[:profile].nsfw} + #{data[:profile].tag_string} + + #{data[:signature]} + + XML it "fails validation on construction" do expect { diff --git a/spec/lib/diaspora_federation/entities/comment_spec.rb b/spec/lib/diaspora_federation/entities/comment_spec.rb index 1263510..042f706 100644 --- a/spec/lib/diaspora_federation/entities/comment_spec.rb +++ b/spec/lib/diaspora_federation/entities/comment_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Comment do let(:parent) { Fabricate(:post, author: bob) } @@ -12,41 +14,41 @@ module DiasporaFederation ).tap {|hash| add_signatures(hash) } } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{parent.guid} - #{data[:text]} - #{data[:created_at].utc.iso8601} - #{data[:edited_at].utc.iso8601} - #{data[:author_signature]} - #{data[:parent_author_signature]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{parent.guid} + #{data[:text]} + #{data[:created_at].utc.iso8601} + #{data[:edited_at].utc.iso8601} + #{data[:author_signature]} + #{data[:parent_author_signature]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "comment", - "entity_data": { - "author": "#{data[:author]}", - "guid": "#{data[:guid]}", - "parent_guid": "#{parent.guid}", - "author_signature": "#{data[:author_signature]}", - "text": "#{data[:text]}", - "created_at": "#{data[:created_at].iso8601}", - "edited_at": "#{data[:edited_at].iso8601}" - }, - "property_order": [ - "author", - "guid", - "parent_guid", - "text", - "created_at", - "edited_at" - ] -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "comment", + "entity_data": { + "author": "#{data[:author]}", + "guid": "#{data[:guid]}", + "parent_guid": "#{parent.guid}", + "author_signature": "#{data[:author_signature]}", + "text": "#{data[:text]}", + "created_at": "#{data[:created_at].iso8601}", + "edited_at": "#{data[:edited_at].iso8601}" + }, + "property_order": [ + "author", + "guid", + "parent_guid", + "text", + "created_at", + "edited_at" + ] + } + JSON let(:string) { "Comment:#{data[:guid]}:#{parent.guid}" } diff --git a/spec/lib/diaspora_federation/entities/contact_spec.rb b/spec/lib/diaspora_federation/entities/contact_spec.rb index aea9ef8..7430708 100644 --- a/spec/lib/diaspora_federation/entities/contact_spec.rb +++ b/spec/lib/diaspora_federation/entities/contact_spec.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Contact do let(:data) { Fabricate.attributes_for(:contact_entity) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:recipient]} - #{data[:following]} - #{data[:sharing]} - #{data[:blocking]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:recipient]} + #{data[:following]} + #{data[:sharing]} + #{data[:blocking]} + + XML let(:string) { "Contact:#{data[:author]}:#{data[:recipient]}" } diff --git a/spec/lib/diaspora_federation/entities/conversation_spec.rb b/spec/lib/diaspora_federation/entities/conversation_spec.rb index 0c263b0..9522873 100644 --- a/spec/lib/diaspora_federation/entities/conversation_spec.rb +++ b/spec/lib/diaspora_federation/entities/conversation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Conversation do let(:parent) { Fabricate(:conversation, author: bob) } @@ -27,16 +29,16 @@ module DiasporaFederation ) } - let(:xml) { <<-XML } - - #{data[:author]} - #{parent.guid} - #{data[:subject]} - #{data[:created_at].utc.iso8601} - #{data[:participants]} -#{data[:messages].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{parent.guid} + #{data[:subject]} + #{data[:created_at].utc.iso8601} + #{data[:participants]} + #{data[:messages].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")} + + XML let(:string) { "Conversation:#{data[:guid]}" } @@ -46,15 +48,15 @@ XML context "default values" do it "allows no nested messages" do - minimal_xml = <<-XML - - #{data[:author]} - #{parent.guid} - #{data[:subject]} - #{data[:created_at]} - #{data[:participants]} - -XML + minimal_xml = <<~XML + + #{data[:author]} + #{parent.guid} + #{data[:subject]} + #{data[:created_at]} + #{data[:participants]} + + XML parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML(minimal_xml).root) expect(parsed_instance.messages).to eq([]) diff --git a/spec/lib/diaspora_federation/entities/embed_spec.rb b/spec/lib/diaspora_federation/entities/embed_spec.rb index 7b857e4..c019813 100644 --- a/spec/lib/diaspora_federation/entities/embed_spec.rb +++ b/spec/lib/diaspora_federation/entities/embed_spec.rb @@ -1,27 +1,29 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Embed do let(:data) { Fabricate.attributes_for(:embed_entity) } - let(:xml) { <<-XML } - - #{data[:url]} - #{data[:title]} - #{data[:description]} - #{data[:image]} - -XML + let(:xml) { <<~XML } + + #{data[:url]} + #{data[:title]} + #{data[:description]} + #{data[:image]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "embed", - "entity_data": { - "url": "#{data[:url]}", - "title": "#{data[:title]}", - "description": "#{data[:description]}", - "image": "#{data[:image]}" - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "embed", + "entity_data": { + "url": "#{data[:url]}", + "title": "#{data[:title]}", + "description": "#{data[:description]}", + "image": "#{data[:image]}" + } + } + JSON let(:string) { "Embed:#{data[:url]}" } diff --git a/spec/lib/diaspora_federation/entities/event_participation_spec.rb b/spec/lib/diaspora_federation/entities/event_participation_spec.rb index b6c7ce1..b06c5d4 100644 --- a/spec/lib/diaspora_federation/entities/event_participation_spec.rb +++ b/spec/lib/diaspora_federation/entities/event_participation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::EventParticipation do let(:parent) { Fabricate(:event, author: bob) } @@ -11,17 +13,17 @@ module DiasporaFederation ).tap {|hash| add_signatures(hash) } } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{parent.guid} - #{data[:status]} - #{data[:edited_at].utc.iso8601} - #{data[:author_signature]} - #{data[:parent_author_signature]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{parent.guid} + #{data[:status]} + #{data[:edited_at].utc.iso8601} + #{data[:author_signature]} + #{data[:parent_author_signature]} + + XML let(:string) { "EventParticipation:#{data[:guid]}:#{parent.guid}" } diff --git a/spec/lib/diaspora_federation/entities/event_spec.rb b/spec/lib/diaspora_federation/entities/event_spec.rb index 29f5e77..78568ef 100644 --- a/spec/lib/diaspora_federation/entities/event_spec.rb +++ b/spec/lib/diaspora_federation/entities/event_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Event do let(:location) { Fabricate(:location_entity) } @@ -5,24 +7,24 @@ module DiasporaFederation Fabricate.attributes_for(:event_entity).merge(author: alice.diaspora_id, location: location) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{data[:edited_at].utc.iso8601} - #{data[:summary]} - #{data[:description]} - #{data[:start].utc.iso8601} - #{data[:end].utc.iso8601} - #{data[:all_day]} - #{data[:timezone]} - -
#{location.address}
- #{location.lat} - #{location.lng} -
-
-XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{data[:edited_at].utc.iso8601} + #{data[:summary]} + #{data[:description]} + #{data[:start].utc.iso8601} + #{data[:end].utc.iso8601} + #{data[:all_day]} + #{data[:timezone]} + +
#{location.address}
+ #{location.lat} + #{location.lng} +
+
+ XML let(:string) { "Event:#{data[:guid]}" } @@ -32,14 +34,14 @@ XML context "default values" do it "uses default values" do - minimal_xml = <<-XML - - #{data[:author]} - #{data[:guid]} - #{data[:summary]} - #{data[:start].utc.iso8601} - -XML + minimal_xml = <<~XML + + #{data[:author]} + #{data[:guid]} + #{data[:summary]} + #{data[:start].utc.iso8601} + + XML parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML(minimal_xml).root) expect(parsed_instance.end).to be_nil diff --git a/spec/lib/diaspora_federation/entities/like_spec.rb b/spec/lib/diaspora_federation/entities/like_spec.rb index 5983c94..307f530 100644 --- a/spec/lib/diaspora_federation/entities/like_spec.rb +++ b/spec/lib/diaspora_federation/entities/like_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Like do let(:parent) { Fabricate(:post, author: bob) } @@ -12,38 +14,38 @@ module DiasporaFederation ).tap {|hash| add_signatures(hash) } } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{parent.guid} - #{parent.entity_type} - #{data[:positive]} - #{data[:author_signature]} - #{data[:parent_author_signature]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{parent.guid} + #{parent.entity_type} + #{data[:positive]} + #{data[:author_signature]} + #{data[:parent_author_signature]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "like", - "entity_data": { - "author": "#{data[:author]}", - "guid": "#{data[:guid]}", - "parent_guid": "#{parent.guid}", - "author_signature": "#{data[:author_signature]}", - "parent_type": "#{parent.entity_type}", - "positive": #{data[:positive]} - }, - "property_order": [ - "author", - "guid", - "parent_guid", - "parent_type", - "positive" - ] -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "like", + "entity_data": { + "author": "#{data[:author]}", + "guid": "#{data[:guid]}", + "parent_guid": "#{parent.guid}", + "author_signature": "#{data[:author_signature]}", + "parent_type": "#{parent.entity_type}", + "positive": #{data[:positive]} + }, + "property_order": [ + "author", + "guid", + "parent_guid", + "parent_type", + "positive" + ] + } + JSON let(:string) { "Like:#{data[:guid]}:Post:#{parent.guid}" } @@ -59,11 +61,11 @@ JSON context "invalid XML" do it "raises a ValidationError if the parent_type is missing" do - broken_xml = <<-XML - - #{parent.guid} - -XML + broken_xml = <<~XML + + #{parent.guid} + + XML expect { DiasporaFederation::Entities::Like.from_xml(Nokogiri::XML(broken_xml).root) @@ -71,11 +73,11 @@ XML end it "raises a ValidationError if the parent_guid is missing" do - broken_xml = <<-XML - - #{parent.entity_type} - -XML + broken_xml = <<~XML + + #{parent.entity_type} + + XML expect { DiasporaFederation::Entities::Like.from_xml(Nokogiri::XML(broken_xml).root) diff --git a/spec/lib/diaspora_federation/entities/location_spec.rb b/spec/lib/diaspora_federation/entities/location_spec.rb index 0ba629e..afae5aa 100644 --- a/spec/lib/diaspora_federation/entities/location_spec.rb +++ b/spec/lib/diaspora_federation/entities/location_spec.rb @@ -1,25 +1,27 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Location do let(:data) { Fabricate.attributes_for(:location_entity) } - let(:xml) { <<-XML } - -
#{data[:address]}
- #{data[:lat]} - #{data[:lng]} -
-XML + let(:xml) { <<~XML } + +
#{data[:address]}
+ #{data[:lat]} + #{data[:lng]} +
+ XML - let(:json) { <<-JSON } -{ - "entity_type": "location", - "entity_data": { - "address": "#{data[:address]}", - "lat": "#{data[:lat]}", - "lng": "#{data[:lng]}" - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "location", + "entity_data": { + "address": "#{data[:address]}", + "lat": "#{data[:lat]}", + "lng": "#{data[:lng]}" + } + } + JSON let(:string) { "Location" } diff --git a/spec/lib/diaspora_federation/entities/message_spec.rb b/spec/lib/diaspora_federation/entities/message_spec.rb index d8aa86d..7657b79 100644 --- a/spec/lib/diaspora_federation/entities/message_spec.rb +++ b/spec/lib/diaspora_federation/entities/message_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Message do let(:data) { Fabricate.attributes_for(:message_entity, author: alice.diaspora_id) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{data[:text]} - #{data[:created_at].utc.iso8601} - #{data[:edited_at].utc.iso8601} - #{data[:conversation_guid]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{data[:text]} + #{data[:created_at].utc.iso8601} + #{data[:edited_at].utc.iso8601} + #{data[:conversation_guid]} + + XML let(:string) { "Message:#{data[:guid]}:#{data[:conversation_guid]}" } diff --git a/spec/lib/diaspora_federation/entities/participation_spec.rb b/spec/lib/diaspora_federation/entities/participation_spec.rb index 819e4a0..00e96aa 100644 --- a/spec/lib/diaspora_federation/entities/participation_spec.rb +++ b/spec/lib/diaspora_federation/entities/participation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Participation do let(:parent) { Fabricate(:post, author: bob) } @@ -10,26 +12,26 @@ module DiasporaFederation ) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{parent.guid} - #{parent.entity_type} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{parent.guid} + #{parent.entity_type} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "participation", - "entity_data": { - "author": "#{data[:author]}", - "guid": "#{data[:guid]}", - "parent_guid": "#{parent.guid}", - "parent_type": "#{parent.entity_type}" - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "participation", + "entity_data": { + "author": "#{data[:author]}", + "guid": "#{data[:guid]}", + "parent_guid": "#{parent.guid}", + "parent_type": "#{parent.entity_type}" + } + } + JSON let(:string) { "Participation:#{data[:guid]}:Post:#{parent.guid}" } diff --git a/spec/lib/diaspora_federation/entities/person_spec.rb b/spec/lib/diaspora_federation/entities/person_spec.rb index 615a41e..a75c35f 100644 --- a/spec/lib/diaspora_federation/entities/person_spec.rb +++ b/spec/lib/diaspora_federation/entities/person_spec.rb @@ -1,32 +1,34 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Person do let(:data) { Fabricate.attributes_for(:person_entity) } - let(:xml) { <<-XML } - - #{data[:guid]} - #{data[:author]} - #{data[:url]} - - #{data[:profile].author} - #{data[:profile].edited_at.utc.iso8601} - #{data[:profile].full_name} - #{data[:profile].first_name} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].image_url} - #{data[:profile].bio} - #{data[:profile].birthday} - #{data[:profile].gender} - #{data[:profile].location} - #{data[:profile].searchable} - #{data[:profile].public} - #{data[:profile].nsfw} - #{data[:profile].tag_string} - - #{data[:exported_key]} - -XML + let(:xml) { <<~XML } + + #{data[:guid]} + #{data[:author]} + #{data[:url]} + + #{data[:profile].author} + #{data[:profile].edited_at.utc.iso8601} + #{data[:profile].full_name} + #{data[:profile].first_name} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].image_url} + #{data[:profile].bio} + #{data[:profile].birthday} + #{data[:profile].gender} + #{data[:profile].location} + #{data[:profile].searchable} + #{data[:profile].public} + #{data[:profile].nsfw} + #{data[:profile].tag_string} + + #{data[:exported_key]} + + XML let(:string) { "Person:#{data[:guid]}" } diff --git a/spec/lib/diaspora_federation/entities/photo_spec.rb b/spec/lib/diaspora_federation/entities/photo_spec.rb index 742f3f9..92d55e9 100644 --- a/spec/lib/diaspora_federation/entities/photo_spec.rb +++ b/spec/lib/diaspora_federation/entities/photo_spec.rb @@ -1,41 +1,43 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Photo do let(:data) { Fabricate.attributes_for(:photo_entity) } - let(:xml) { <<-XML } - - #{data[:guid]} - #{data[:author]} - #{data[:public]} - #{data[:created_at].utc.iso8601} - #{data[:edited_at].utc.iso8601} - #{data[:remote_photo_path]} - #{data[:remote_photo_name]} - #{data[:text]} - #{data[:status_message_guid]} - #{data[:height]} - #{data[:width]} - -XML + let(:xml) { <<~XML } + + #{data[:guid]} + #{data[:author]} + #{data[:public]} + #{data[:created_at].utc.iso8601} + #{data[:edited_at].utc.iso8601} + #{data[:remote_photo_path]} + #{data[:remote_photo_name]} + #{data[:text]} + #{data[:status_message_guid]} + #{data[:height]} + #{data[:width]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "photo", - "entity_data": { - "guid": "#{data[:guid]}", - "author": "#{data[:author]}", - "public": #{data[:public]}, - "created_at": "#{data[:created_at].utc.iso8601}", - "edited_at": "#{data[:edited_at].iso8601}", - "remote_photo_path": "#{data[:remote_photo_path]}", - "remote_photo_name": "#{data[:remote_photo_name]}", - "text": "#{data[:text]}", - "status_message_guid": "#{data[:status_message_guid]}", - "height": #{data[:height]}, - "width": #{data[:width]} - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "photo", + "entity_data": { + "guid": "#{data[:guid]}", + "author": "#{data[:author]}", + "public": #{data[:public]}, + "created_at": "#{data[:created_at].utc.iso8601}", + "edited_at": "#{data[:edited_at].iso8601}", + "remote_photo_path": "#{data[:remote_photo_path]}", + "remote_photo_name": "#{data[:remote_photo_name]}", + "text": "#{data[:text]}", + "status_message_guid": "#{data[:status_message_guid]}", + "height": #{data[:height]}, + "width": #{data[:width]} + } + } + JSON let(:string) { "Photo:#{data[:guid]}" } @@ -47,18 +49,18 @@ JSON context "default values" do it "uses default values" do - minimal_xml = <<-XML - - #{data[:guid]} - #{data[:author]} - #{data[:created_at]} - #{data[:remote_photo_path]} - #{data[:remote_photo_name]} - #{data[:status_message_guid]} - #{data[:height]} - #{data[:width]} - -XML + minimal_xml = <<~XML + + #{data[:guid]} + #{data[:author]} + #{data[:created_at]} + #{data[:remote_photo_path]} + #{data[:remote_photo_name]} + #{data[:status_message_guid]} + #{data[:height]} + #{data[:width]} + + XML parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML(minimal_xml).root) expect(parsed_instance.public).to be_falsey diff --git a/spec/lib/diaspora_federation/entities/poll_answer_spec.rb b/spec/lib/diaspora_federation/entities/poll_answer_spec.rb index b16d23e..c17ec04 100644 --- a/spec/lib/diaspora_federation/entities/poll_answer_spec.rb +++ b/spec/lib/diaspora_federation/entities/poll_answer_spec.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::PollAnswer do let(:data) { Fabricate.attributes_for(:poll_answer_entity) } - let(:xml) { <<-XML } - - #{data[:guid]} - #{data[:answer]} - -XML + let(:xml) { <<~XML } + + #{data[:guid]} + #{data[:answer]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "poll_answer", - "entity_data": { - "guid": "#{data[:guid]}", - "answer": "#{data[:answer]}" - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "poll_answer", + "entity_data": { + "guid": "#{data[:guid]}", + "answer": "#{data[:answer]}" + } + } + JSON let(:string) { "PollAnswer:#{data[:guid]}" } diff --git a/spec/lib/diaspora_federation/entities/poll_participation_spec.rb b/spec/lib/diaspora_federation/entities/poll_participation_spec.rb index 424d767..83848b0 100644 --- a/spec/lib/diaspora_federation/entities/poll_participation_spec.rb +++ b/spec/lib/diaspora_federation/entities/poll_participation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::PollParticipation do let(:parent) { Fabricate(:poll, author: bob) } @@ -11,35 +13,35 @@ module DiasporaFederation ).tap {|hash| add_signatures(hash) } } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{parent.guid} - #{data[:poll_answer_guid]} - #{data[:author_signature]} - #{data[:parent_author_signature]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{parent.guid} + #{data[:poll_answer_guid]} + #{data[:author_signature]} + #{data[:parent_author_signature]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "poll_participation", - "entity_data": { - "author": "#{data[:author]}", - "guid": "#{data[:guid]}", - "parent_guid": "#{parent.guid}", - "author_signature": "#{data[:author_signature]}", - "poll_answer_guid": "#{data[:poll_answer_guid]}" - }, - "property_order": [ - "author", - "guid", - "parent_guid", - "poll_answer_guid" - ] -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "poll_participation", + "entity_data": { + "author": "#{data[:author]}", + "guid": "#{data[:guid]}", + "parent_guid": "#{parent.guid}", + "author_signature": "#{data[:author_signature]}", + "poll_answer_guid": "#{data[:poll_answer_guid]}" + }, + "property_order": [ + "author", + "guid", + "parent_guid", + "poll_answer_guid" + ] + } + JSON let(:string) { "PollParticipation:#{data[:guid]}:#{parent.guid}" } diff --git a/spec/lib/diaspora_federation/entities/poll_spec.rb b/spec/lib/diaspora_federation/entities/poll_spec.rb index 2065785..3478afb 100644 --- a/spec/lib/diaspora_federation/entities/poll_spec.rb +++ b/spec/lib/diaspora_federation/entities/poll_spec.rb @@ -1,27 +1,29 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Poll do let(:data) { Fabricate.attributes_for(:poll_entity) } - let(:xml) { <<-XML } - - #{data[:guid]} - #{data[:question]} -#{data[:poll_answers].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")} - -XML + let(:xml) { <<~XML } + + #{data[:guid]} + #{data[:question]} + #{data[:poll_answers].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "poll", - "entity_data": { - "guid": "#{data[:guid]}", - "question": "#{data[:question]}", - "poll_answers": [ -#{data[:poll_answers].map {|a| indent(JSON.pretty_generate(a.to_json), 6) }.join(",\n")} - ] - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "poll", + "entity_data": { + "guid": "#{data[:guid]}", + "question": "#{data[:question]}", + "poll_answers": [ + #{data[:poll_answers].map {|a| indent(JSON.pretty_generate(a.to_json), 6) }.join(",\n")} + ] + } + } + JSON let(:string) { "Poll:#{data[:guid]}" } diff --git a/spec/lib/diaspora_federation/entities/profile_spec.rb b/spec/lib/diaspora_federation/entities/profile_spec.rb index fa42faf..4cc7d59 100644 --- a/spec/lib/diaspora_federation/entities/profile_spec.rb +++ b/spec/lib/diaspora_federation/entities/profile_spec.rb @@ -1,49 +1,51 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Profile do let(:data) { Fabricate.attributes_for(:profile_entity) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:edited_at].utc.iso8601} - #{data[:full_name]} - #{data[:first_name]} - #{data[:image_url]} - #{data[:image_url]} - #{data[:image_url]} - #{data[:bio]} - #{data[:birthday]} - #{data[:gender]} - #{data[:location]} - #{data[:searchable]} - #{data[:public]} - #{data[:nsfw]} - #{data[:tag_string]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:edited_at].utc.iso8601} + #{data[:full_name]} + #{data[:first_name]} + #{data[:image_url]} + #{data[:image_url]} + #{data[:image_url]} + #{data[:bio]} + #{data[:birthday]} + #{data[:gender]} + #{data[:location]} + #{data[:searchable]} + #{data[:public]} + #{data[:nsfw]} + #{data[:tag_string]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "profile", - "entity_data": { - "author": "#{data[:author]}", - "edited_at": "#{data[:edited_at].iso8601}", - "full_name": "#{data[:full_name]}", - "first_name": "#{data[:first_name]}", - "image_url": "#{data[:image_url]}", - "image_url_medium": "#{data[:image_url]}", - "image_url_small": "#{data[:image_url]}", - "bio": "#{data[:bio]}", - "birthday": "#{data[:birthday]}", - "gender": "#{data[:gender]}", - "location": "#{data[:location]}", - "searchable": #{data[:searchable]}, - "public": #{data[:public]}, - "nsfw": #{data[:nsfw]}, - "tag_string": "#{data[:tag_string]}" - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "profile", + "entity_data": { + "author": "#{data[:author]}", + "edited_at": "#{data[:edited_at].iso8601}", + "full_name": "#{data[:full_name]}", + "first_name": "#{data[:first_name]}", + "image_url": "#{data[:image_url]}", + "image_url_medium": "#{data[:image_url]}", + "image_url_small": "#{data[:image_url]}", + "bio": "#{data[:bio]}", + "birthday": "#{data[:birthday]}", + "gender": "#{data[:gender]}", + "location": "#{data[:location]}", + "searchable": #{data[:searchable]}, + "public": #{data[:public]}, + "nsfw": #{data[:nsfw]}, + "tag_string": "#{data[:tag_string]}" + } + } + JSON let(:string) { "Profile:#{data[:author]}" } @@ -55,11 +57,11 @@ JSON context "default values" do it "uses default values" do - minimal_xml = <<-XML - - #{data[:author]} - -XML + minimal_xml = <<~XML + + #{data[:author]} + + XML parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML(minimal_xml).root) expect(parsed_instance.full_name).to be_nil diff --git a/spec/lib/diaspora_federation/entities/related_entity_spec.rb b/spec/lib/diaspora_federation/entities/related_entity_spec.rb index 902eab3..7b02c81 100644 --- a/spec/lib/diaspora_federation/entities/related_entity_spec.rb +++ b/spec/lib/diaspora_federation/entities/related_entity_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::RelatedEntity do let(:data) { Fabricate.attributes_for(:related_entity) } diff --git a/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb b/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb index 09bfce4..6bf22d6 100644 --- a/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::RelayableRetraction do let(:target) { Fabricate(:comment, author: bob) } @@ -10,15 +12,15 @@ module DiasporaFederation } let(:data) { {author: alice.diaspora_id, target_guid: target.guid, target_type: target.entity_type} } - let(:xml) { <<-XML } - - - #{data[:target_guid]} - #{data[:target_type]} - #{data[:author]} - - -XML + let(:xml) { <<~XML } + + + #{data[:target_guid]} + #{data[:target_type]} + #{data[:author]} + + + XML describe "#initialize" do it "raises because it is not supported anymore" do diff --git a/spec/lib/diaspora_federation/entities/relayable_spec.rb b/spec/lib/diaspora_federation/entities/relayable_spec.rb index f80e143..4daa408 100644 --- a/spec/lib/diaspora_federation/entities/relayable_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Relayable do let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) } @@ -120,17 +122,17 @@ module DiasporaFederation end describe "#to_xml" do - let(:expected_xml) { <<-XML } - - #{author} - #{guid} - #{parent_guid} - #{property} - #{new_property} - aa - bb - -XML + let(:expected_xml) { <<~XML } + + #{author} + #{guid} + #{parent_guid} + #{property} + #{new_property} + aa + bb + + XML it "adds new unknown xml elements to the xml again" do signature_order = [:author, :guid, :parent_guid, :property, "new_property"] @@ -159,17 +161,17 @@ XML end it "adds nil properties to xml when needed for signature_order" do - expected_xml = <<-XML - - #{author} - #{guid} - #{parent_guid} - - #{new_property} - aa - bb - -XML + expected_xml = <<~XML + + #{author} + #{guid} + #{parent_guid} + + #{new_property} + aa + bb + + XML signature_order = [:author, :guid, :parent_guid, :property, "new_property"] xml = Entities::SomeRelayable.new( @@ -180,15 +182,15 @@ XML end it "does not add nil properties to xml when not needed for signature_order" do - expected_xml = <<-XML - - #{author} - #{guid} - #{parent_guid} - aa - bb - -XML + expected_xml = <<~XML + + #{author} + #{guid} + #{parent_guid} + aa + bb + + XML xml = Entities::SomeRelayable.new(hash_with_fake_signatures.merge(property: nil)).to_xml @@ -281,16 +283,16 @@ XML end it "adds 'false' booleans" do - expected_xml = <<-XML - - #{author} - #{guid} - #{parent_guid} - false - aa - bb - -XML + expected_xml = <<~XML + + #{author} + #{guid} + #{parent_guid} + false + aa + bb + + XML xml = Entities::TestRelayableWithBoolean.new(hash_with_fake_signatures.merge(test: false)).to_xml @@ -306,17 +308,17 @@ XML end let(:new_signature_data) { "#{author};#{guid};#{parent_guid};#{new_property};#{property}" } - let(:new_xml) { <<-XML } - - #{author} - #{guid} - #{parent_guid} - #{new_property} - #{property} - #{sign_with_key(author_pkey, new_signature_data)} - #{sign_with_key(parent_pkey, new_signature_data)} - -XML + let(:new_xml) { <<~XML } + + #{author} + #{guid} + #{parent_guid} + #{new_property} + #{property} + #{sign_with_key(author_pkey, new_signature_data)} + #{sign_with_key(parent_pkey, new_signature_data)} + + XML it "doesn't drop unknown properties" do entity = Entities::SomeRelayable.from_xml(Nokogiri::XML(new_xml).root) @@ -350,10 +352,10 @@ XML context "parse invalid XML" do it "raises a ValidationError if the parent_guid is missing" do - broken_xml = <<-XML - - -XML + broken_xml = <<~XML + + + XML expect { Entities::SomeRelayable.from_xml(Nokogiri::XML(broken_xml).root) @@ -361,11 +363,11 @@ XML end it "adds the guid to the error message if available" do - broken_xml = <<-XML - - #{guid} - -XML + broken_xml = <<~XML + + #{guid} + + XML expect { Entities::SomeRelayable.from_xml(Nokogiri::XML(broken_xml).root) @@ -373,11 +375,11 @@ XML end it "adds the author to the error message if available" do - broken_xml = <<-XML - - #{author} - -XML + broken_xml = <<~XML + + #{author} + + XML expect { Entities::SomeRelayable.from_xml(Nokogiri::XML(broken_xml).root) diff --git a/spec/lib/diaspora_federation/entities/request_spec.rb b/spec/lib/diaspora_federation/entities/request_spec.rb index 1826217..0d07035 100644 --- a/spec/lib/diaspora_federation/entities/request_spec.rb +++ b/spec/lib/diaspora_federation/entities/request_spec.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Request do let(:data) { {author: Fabricate.sequence(:diaspora_id), recipient: Fabricate.sequence(:diaspora_id)} } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:recipient]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:recipient]} + + XML describe "#initialize" do it "raises because it is not supported anymore" do diff --git a/spec/lib/diaspora_federation/entities/reshare_spec.rb b/spec/lib/diaspora_federation/entities/reshare_spec.rb index 7a15a85..61c5a03 100644 --- a/spec/lib/diaspora_federation/entities/reshare_spec.rb +++ b/spec/lib/diaspora_federation/entities/reshare_spec.rb @@ -1,30 +1,32 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Reshare do let(:root) { Fabricate(:post, author: bob) } let(:data) { Fabricate.attributes_for(:reshare_entity, root_guid: root.guid, root_author: bob.diaspora_id) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{data[:created_at].utc.iso8601} - #{data[:root_author]} - #{data[:root_guid]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{data[:created_at].utc.iso8601} + #{data[:root_author]} + #{data[:root_guid]} + + XML - let(:json) { <<-JSON } -{ - "entity_type": "reshare", - "entity_data": { - "author": "#{data[:author]}", - "guid": "#{data[:guid]}", - "created_at": "#{data[:created_at].utc.iso8601}", - "root_author": "#{data[:root_author]}", - "root_guid": "#{data[:root_guid]}" - } -} -JSON + let(:json) { <<~JSON } + { + "entity_type": "reshare", + "entity_data": { + "author": "#{data[:author]}", + "guid": "#{data[:guid]}", + "created_at": "#{data[:created_at].utc.iso8601}", + "root_author": "#{data[:root_author]}", + "root_guid": "#{data[:root_guid]}" + } + } + JSON let(:string) { "Reshare:#{data[:guid]}:#{data[:root_guid]}" } diff --git a/spec/lib/diaspora_federation/entities/retraction_spec.rb b/spec/lib/diaspora_federation/entities/retraction_spec.rb index c3d1e9d..b6ec821 100644 --- a/spec/lib/diaspora_federation/entities/retraction_spec.rb +++ b/spec/lib/diaspora_federation/entities/retraction_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Retraction do let(:target) { Fabricate(:post, author: bob) } @@ -11,13 +13,13 @@ module DiasporaFederation ) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:target_guid]} - #{data[:target_type]} - -XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:target_guid]} + #{data[:target_type]} + + XML let(:string) { "Retraction:#{data[:target_type]}:#{data[:target_guid]}" } diff --git a/spec/lib/diaspora_federation/entities/signable_spec.rb b/spec/lib/diaspora_federation/entities/signable_spec.rb index 6ae9e7f..051e52a 100644 --- a/spec/lib/diaspora_federation/entities/signable_spec.rb +++ b/spec/lib/diaspora_federation/entities/signable_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::Signable do - TEST_STRING_VALUE = "abc123".freeze + TEST_STRING_VALUE = "abc123" class TestSignableEntity < Entity include Entities::Signable diff --git a/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb b/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb index 0547299..d9d9513 100644 --- a/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb +++ b/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::SignedRetraction do let(:target) { Fabricate(:post, author: alice) } let(:target_entity) { Fabricate(:related_entity, author: alice.diaspora_id) } let(:data) { {author: alice.diaspora_id, target_guid: target.guid, target_type: target.entity_type} } - let(:xml) { <<-XML } - - #{data[:target_guid]} - #{data[:target_type]} - #{data[:author]} - - -XML + let(:xml) { <<~XML } + + #{data[:target_guid]} + #{data[:target_type]} + #{data[:author]} + + + XML describe "#initialize" do it "raises because it is not supported anymore" do diff --git a/spec/lib/diaspora_federation/entities/status_message_spec.rb b/spec/lib/diaspora_federation/entities/status_message_spec.rb index 4fe600a..9424030 100644 --- a/spec/lib/diaspora_federation/entities/status_message_spec.rb +++ b/spec/lib/diaspora_federation/entities/status_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entities::StatusMessage do let(:photo1) { Fabricate(:photo_entity, author: alice.diaspora_id) } @@ -15,105 +17,105 @@ module DiasporaFederation ) } - let(:xml) { <<-XML } - - #{data[:author]} - #{data[:guid]} - #{data[:created_at].utc.iso8601} - #{data[:public]} - #{data[:provider_display_name]} - #{data[:text]} - #{data[:edited_at].utc.iso8601} - - #{photo1.guid} - #{photo1.author} - #{photo1.public} - #{photo1.created_at.utc.iso8601} - #{photo1.edited_at.utc.iso8601} - #{photo1.remote_photo_path} - #{photo1.remote_photo_name} - #{photo1.text} - #{photo1.status_message_guid} - #{photo1.height} - #{photo1.width} - - - #{photo2.guid} - #{photo2.author} - #{photo2.public} - #{photo2.created_at.utc.iso8601} - #{photo2.edited_at.utc.iso8601} - #{photo2.remote_photo_path} - #{photo2.remote_photo_name} - #{photo2.text} - #{photo2.status_message_guid} - #{photo2.height} - #{photo2.width} - - -
#{location.address}
- #{location.lat} - #{location.lng} -
-
-XML + let(:xml) { <<~XML } + + #{data[:author]} + #{data[:guid]} + #{data[:created_at].utc.iso8601} + #{data[:public]} + #{data[:provider_display_name]} + #{data[:text]} + #{data[:edited_at].utc.iso8601} + + #{photo1.guid} + #{photo1.author} + #{photo1.public} + #{photo1.created_at.utc.iso8601} + #{photo1.edited_at.utc.iso8601} + #{photo1.remote_photo_path} + #{photo1.remote_photo_name} + #{photo1.text} + #{photo1.status_message_guid} + #{photo1.height} + #{photo1.width} + + + #{photo2.guid} + #{photo2.author} + #{photo2.public} + #{photo2.created_at.utc.iso8601} + #{photo2.edited_at.utc.iso8601} + #{photo2.remote_photo_path} + #{photo2.remote_photo_name} + #{photo2.text} + #{photo2.status_message_guid} + #{photo2.height} + #{photo2.width} + + +
#{location.address}
+ #{location.lat} + #{location.lng} +
+
+ XML - let(:json) { <<-JSON } -{ - "entity_type": "status_message", - "entity_data": { - "author": "#{data[:author]}", - "guid": "#{data[:guid]}", - "created_at": "#{data[:created_at].utc.iso8601}", - "public": #{data[:public]}, - "provider_display_name": "#{data[:provider_display_name]}", - "text": "#{data[:text]}", - "edited_at": "#{data[:edited_at].iso8601}", - "photos": [ + let(:json) { <<~JSON } { - "entity_type": "photo", + "entity_type": "status_message", "entity_data": { - "guid": "#{photo1.guid}", - "author": "#{photo1.author}", - "public": #{photo1.public}, - "created_at": "#{photo1.created_at.utc.iso8601}", - "edited_at": "#{photo1.edited_at.utc.iso8601}", - "remote_photo_path": "#{photo1.remote_photo_path}", - "remote_photo_name": "#{photo1.remote_photo_name}", - "text": "#{photo1.text}", - "status_message_guid": "#{photo1.status_message_guid}", - "height": #{photo1.height}, - "width": #{photo1.width} - } - }, - { - "entity_type": "photo", - "entity_data": { - "guid": "#{photo2.guid}", - "author": "#{photo2.author}", - "public": #{photo2.public}, - "created_at": "#{photo2.created_at.utc.iso8601}", - "edited_at": "#{photo2.edited_at.utc.iso8601}", - "remote_photo_path": "#{photo2.remote_photo_path}", - "remote_photo_name": "#{photo2.remote_photo_name}", - "text": "#{photo2.text}", - "status_message_guid": "#{photo2.status_message_guid}", - "height": #{photo2.height}, - "width": #{photo2.width} + "author": "#{data[:author]}", + "guid": "#{data[:guid]}", + "created_at": "#{data[:created_at].utc.iso8601}", + "public": #{data[:public]}, + "provider_display_name": "#{data[:provider_display_name]}", + "text": "#{data[:text]}", + "edited_at": "#{data[:edited_at].iso8601}", + "photos": [ + { + "entity_type": "photo", + "entity_data": { + "guid": "#{photo1.guid}", + "author": "#{photo1.author}", + "public": #{photo1.public}, + "created_at": "#{photo1.created_at.utc.iso8601}", + "edited_at": "#{photo1.edited_at.utc.iso8601}", + "remote_photo_path": "#{photo1.remote_photo_path}", + "remote_photo_name": "#{photo1.remote_photo_name}", + "text": "#{photo1.text}", + "status_message_guid": "#{photo1.status_message_guid}", + "height": #{photo1.height}, + "width": #{photo1.width} + } + }, + { + "entity_type": "photo", + "entity_data": { + "guid": "#{photo2.guid}", + "author": "#{photo2.author}", + "public": #{photo2.public}, + "created_at": "#{photo2.created_at.utc.iso8601}", + "edited_at": "#{photo2.edited_at.utc.iso8601}", + "remote_photo_path": "#{photo2.remote_photo_path}", + "remote_photo_name": "#{photo2.remote_photo_name}", + "text": "#{photo2.text}", + "status_message_guid": "#{photo2.status_message_guid}", + "height": #{photo2.height}, + "width": #{photo2.width} + } + } + ], + "location": { + "entity_type": "location", + "entity_data": { + "address": "#{location.address}", + "lat": "#{location.lat}", + "lng": "#{location.lng}" + } + } } } - ], - "location": { - "entity_type": "location", - "entity_data": { - "address": "#{location.address}", - "lat": "#{location.lat}", - "lng": "#{location.lng}" - } - } - } -} -JSON + JSON let(:string) { "StatusMessage:#{data[:guid]}" } @@ -125,14 +127,14 @@ JSON context "default values" do it "uses default values" do - minimal_xml = <<-XML - - #{data[:author]} - #{data[:guid]} - #{data[:created_at]} - #{data[:text]} - -XML + minimal_xml = <<~XML + + #{data[:author]} + #{data[:guid]} + #{data[:created_at]} + #{data[:text]} + + XML parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML(minimal_xml).root) expect(parsed_instance.photos).to eq([]) diff --git a/spec/lib/diaspora_federation/entity_spec.rb b/spec/lib/diaspora_federation/entity_spec.rb index 3039338..cd52a27 100644 --- a/spec/lib/diaspora_federation/entity_spec.rb +++ b/spec/lib/diaspora_federation/entity_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Entity do let(:data) { {test1: "asdf", test2: 1234, test3: false, test4: false} } @@ -202,13 +204,13 @@ module DiasporaFederation test2: "qwer", test3: true ) - Entities::TestDefaultEntity.from_xml(Nokogiri::XML(<<-XML).root) - - asdf - qwer - true - -XML + Entities::TestDefaultEntity.from_xml(Nokogiri::XML(<<~XML).root) + + asdf + qwer + true + + XML end it "forms .from_hash arguments basing on parse return array" do @@ -284,38 +286,38 @@ XML describe ".from_json" do it "parses entity properties from the input JSON data" do now = change_time(Time.now.utc) - entity_data = <<-JSON -{ - "entity_type": "test_complex_entity", - "entity_data": { - "test1": "abc", - "test2": false, - "test3": "def", - "test4": 123, - "test5": "#{now.iso8601}", - "test6": { - "entity_type": "test_entity", - "entity_data": { - "test": "nested" - } - }, - "multi": [ - { - "entity_type": "other_entity", - "entity_data": { - "asdf": "01" - } - }, - { - "entity_type": "other_entity", - "entity_data": { - "asdf": "02" - } - } - ] - } -} -JSON + entity_data = <<~JSON + { + "entity_type": "test_complex_entity", + "entity_data": { + "test1": "abc", + "test2": false, + "test3": "def", + "test4": 123, + "test5": "#{now.iso8601}", + "test6": { + "entity_type": "test_entity", + "entity_data": { + "test": "nested" + } + }, + "multi": [ + { + "entity_type": "other_entity", + "entity_data": { + "asdf": "01" + } + }, + { + "entity_type": "other_entity", + "entity_data": { + "asdf": "02" + } + } + ] + } + } + JSON entity = Entities::TestComplexEntity.from_json(JSON.parse(entity_data)) expect(entity).to be_an_instance_of(Entities::TestComplexEntity) @@ -511,13 +513,13 @@ JSON end it "handles empty xml-element for nested entities" do - xml = <<-XML - - FDSA - - - -XML + xml = <<~XML + + FDSA + + + + XML entity = Entities::TestNestedEntity.from_xml(Nokogiri::XML(xml).root) diff --git a/spec/lib/diaspora_federation/federation/diaspora_url_parser_spec.rb b/spec/lib/diaspora_federation/federation/diaspora_url_parser_spec.rb index 2649d80..dee3354 100644 --- a/spec/lib/diaspora_federation/federation/diaspora_url_parser_spec.rb +++ b/spec/lib/diaspora_federation/federation/diaspora_url_parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Federation::DiasporaUrlParser do let(:author) { Fabricate.sequence(:diaspora_id) } diff --git a/spec/lib/diaspora_federation/federation/fetcher_spec.rb b/spec/lib/diaspora_federation/federation/fetcher_spec.rb index 51997eb..d1cdd8f 100644 --- a/spec/lib/diaspora_federation/federation/fetcher_spec.rb +++ b/spec/lib/diaspora_federation/federation/fetcher_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Federation::Fetcher do let(:post) { Fabricate(:status_message_entity, public: true) } diff --git a/spec/lib/diaspora_federation/federation/receiver/private_spec.rb b/spec/lib/diaspora_federation/federation/receiver/private_spec.rb index e0fbb37..8d9cb6a 100644 --- a/spec/lib/diaspora_federation/federation/receiver/private_spec.rb +++ b/spec/lib/diaspora_federation/federation/receiver/private_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Federation::Receiver::Private do let(:recipient) { 42 } diff --git a/spec/lib/diaspora_federation/federation/receiver/public_spec.rb b/spec/lib/diaspora_federation/federation/receiver/public_spec.rb index 9815490..5aa3220 100644 --- a/spec/lib/diaspora_federation/federation/receiver/public_spec.rb +++ b/spec/lib/diaspora_federation/federation/receiver/public_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Federation::Receiver::Public do let(:post) { Fabricate(:status_message_entity) } diff --git a/spec/lib/diaspora_federation/federation/receiver_spec.rb b/spec/lib/diaspora_federation/federation/receiver_spec.rb index 5779a37..b5b2d33 100644 --- a/spec/lib/diaspora_federation/federation/receiver_spec.rb +++ b/spec/lib/diaspora_federation/federation/receiver_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Federation::Receiver do let(:sender_key) { OpenSSL::PKey::RSA.generate(1024) } diff --git a/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb b/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb index 66f9698..170729e 100644 --- a/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb +++ b/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Federation::Sender::HydraWrapper do let(:sender_id) { Fabricate.sequence(:diaspora_id) } diff --git a/spec/lib/diaspora_federation/federation/sender_spec.rb b/spec/lib/diaspora_federation/federation/sender_spec.rb index 8f1dce9..0a8e3ad 100644 --- a/spec/lib/diaspora_federation/federation/sender_spec.rb +++ b/spec/lib/diaspora_federation/federation/sender_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Federation::Sender do let(:sender_id) { Fabricate.sequence(:diaspora_id) } diff --git a/spec/lib/diaspora_federation/http_client_spec.rb b/spec/lib/diaspora_federation/http_client_spec.rb index 00efe91..5a4c5a7 100644 --- a/spec/lib/diaspora_federation/http_client_spec.rb +++ b/spec/lib/diaspora_federation/http_client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe HttpClient do describe ".get" do diff --git a/spec/lib/diaspora_federation/parsers/base_parser_spec.rb b/spec/lib/diaspora_federation/parsers/base_parser_spec.rb index 1fdf683..17a3c17 100644 --- a/spec/lib/diaspora_federation/parsers/base_parser_spec.rb +++ b/spec/lib/diaspora_federation/parsers/base_parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Parsers::BaseParser do describe ".parse" do diff --git a/spec/lib/diaspora_federation/parsers/json_parser_spec.rb b/spec/lib/diaspora_federation/parsers/json_parser_spec.rb index 0758395..71beff5 100644 --- a/spec/lib/diaspora_federation/parsers/json_parser_spec.rb +++ b/spec/lib/diaspora_federation/parsers/json_parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Parsers::JsonParser do describe ".parse" do @@ -6,12 +8,12 @@ module DiasporaFederation it "raises error when the entity class doesn't match the entity_type property" do expect { - json_parser.parse(JSON.parse(<<-JSON -{ - "entity_type": "unknown_entity", - "entity_data": {} -} -JSON + json_parser.parse(JSON.parse(<<~JSON + { + "entity_type": "unknown_entity", + "entity_data": {} + } + JSON )) }.to raise_error DiasporaFederation::Parsers::BaseParser::InvalidRootNode, "'unknown_entity' can't be parsed by #{entity_class}" @@ -27,38 +29,38 @@ JSON it "returns a hash for the correct JSON input" do now = change_time(Time.now.utc) - json = <<-JSON -{ - "entity_type": "test_complex_entity", - "entity_data": { - "test1": "abc", - "test2": false, - "test3": "def", - "test4": 123, - "test5": "#{now.iso8601}", - "test6": { - "entity_type": "test_entity", - "entity_data": { - "test": "nested" - } - }, - "multi": [ - { - "entity_type": "other_entity", - "entity_data": { - "asdf": "01" - } - }, - { - "entity_type": "other_entity", - "entity_data": { - "asdf": "02" - } - } - ] - } -} -JSON + json = <<~JSON + { + "entity_type": "test_complex_entity", + "entity_data": { + "test1": "abc", + "test2": false, + "test3": "def", + "test4": 123, + "test5": "#{now.iso8601}", + "test6": { + "entity_type": "test_entity", + "entity_data": { + "test": "nested" + } + }, + "multi": [ + { + "entity_type": "other_entity", + "entity_data": { + "asdf": "01" + } + }, + { + "entity_type": "other_entity", + "entity_data": { + "asdf": "02" + } + } + ] + } + } + JSON hash = json_parser.parse(JSON.parse(json)).first expect(hash).to be_a(Hash) expect(hash[:test1]).to eq("abc") @@ -75,17 +77,17 @@ JSON end it "doesn't drop extra properties" do - json = <<-JSON.strip -{ - "entity_type": "test_default_entity", - "entity_data": { - "test1": "abc", - "test2": false, - "test3": "def", - "test_new": "new_value" - } -} -JSON + json = <<~JSON.strip + { + "entity_type": "test_default_entity", + "entity_data": { + "test1": "abc", + "test2": false, + "test3": "def", + "test_new": "new_value" + } + } + JSON parsed = Parsers::JsonParser.new(Entities::TestDefaultEntity).parse(JSON.parse(json)) expect(parsed[0]["test_new"]).to eq("new_value") diff --git a/spec/lib/diaspora_federation/parsers/relayable_json_parser_spec.rb b/spec/lib/diaspora_federation/parsers/relayable_json_parser_spec.rb index bab94ff..f878b49 100644 --- a/spec/lib/diaspora_federation/parsers/relayable_json_parser_spec.rb +++ b/spec/lib/diaspora_federation/parsers/relayable_json_parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Parsers::RelayableJsonParser do describe ".parse" do @@ -8,17 +10,17 @@ module DiasporaFederation '{"entity_type": "some_relayable", "entity_data": {}}' it "returns property order as a second argument" do - json = JSON.parse <<-JSON -{ - "entity_type": "some_relayable", - "property_order": ["property", "guid", "author"], - "entity_data": { - "author": "id@example.tld", - "guid": "im a guid", - "property": "value" - } -} -JSON + json = JSON.parse <<~JSON + { + "entity_type": "some_relayable", + "property_order": ["property", "guid", "author"], + "entity_data": { + "author": "id@example.tld", + "guid": "im a guid", + "property": "value" + } + } + JSON parsed_data = json_parser.parse(json) expect(parsed_data[0]).to be_a(Hash) expect(parsed_data[0][:guid]).to eq("im a guid") diff --git a/spec/lib/diaspora_federation/parsers/relayable_xml_parser_spec.rb b/spec/lib/diaspora_federation/parsers/relayable_xml_parser_spec.rb index d3f524e..5c465a0 100644 --- a/spec/lib/diaspora_federation/parsers/relayable_xml_parser_spec.rb +++ b/spec/lib/diaspora_federation/parsers/relayable_xml_parser_spec.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + module DiasporaFederation describe Parsers::RelayableXmlParser do describe ".parse" do let(:entity_class) { Entities::SomeRelayable } let(:xml_parser) { Parsers::RelayableXmlParser.new(entity_class) } it "passes order of the XML elements as a second argument in the returned list" do - xml_object = Nokogiri::XML(<<-XML).root - - im a guid - value - id@example.tld - -XML + xml_object = Nokogiri::XML(<<~XML).root + + im a guid + value + id@example.tld + + XML parsed_data = xml_parser.parse(xml_object) expect(parsed_data[0]).to be_a(Hash) diff --git a/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb b/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb index fdcf4b6..da3a661 100644 --- a/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb +++ b/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Parsers::XmlParser do describe ".parse" do @@ -11,11 +13,11 @@ module DiasporaFederation end it "raises an error when the entity class doesn't match the root node" do - xml = <<-XML - - asdf - -XML + xml = <<~XML + + asdf + + XML expect { xml_parser.parse(Nokogiri::XML(xml).root) @@ -32,12 +34,12 @@ XML end it "uses xml_name for parsing" do - xml = <<-XML.strip - - asdf - qwer - -XML + xml = <<~XML.strip + + asdf + qwer + + XML parsed = Parsers::XmlParser.new(Entities::TestEntityWithXmlName).parse(Nokogiri::XML(xml).root) @@ -46,12 +48,12 @@ XML end it "allows name for parsing even when property has a xml_name" do - xml = <<-XML.strip - - asdf - qwer - -XML + xml = <<~XML.strip + + asdf + qwer + + XML parsed = Parsers::XmlParser.new(Entities::TestEntityWithXmlName).parse(Nokogiri::XML(xml).root) @@ -60,13 +62,13 @@ XML end it "parses the string to the correct type" do - xml = <<-XML.strip - - asdf - qwer - true - -XML + xml = <<~XML.strip + + asdf + qwer + true + + XML parsed = Parsers::XmlParser.new(Entities::TestDefaultEntity).parse(Nokogiri::XML(xml).root) @@ -76,11 +78,11 @@ XML end it "parses boolean fields with false value" do - xml = <<-XML.strip - - false - -XML + xml = <<~XML.strip + + false + + XML parsed = Parsers::XmlParser.new(Entities::TestEntityWithBoolean).parse(Nokogiri::XML(xml).root) expect(parsed[0][:test]).to eq(false) @@ -88,11 +90,11 @@ XML it "parses boolean fields with a randomly matching pattern as nil" do %w[ttFFFtt yesFFDSFSDy noDFDSFFDFn fXf LLyes].each do |weird_value| - xml = <<-XML.strip - - #{weird_value} - -XML + xml = <<~XML.strip + + #{weird_value} + + XML parsed = Parsers::XmlParser.new(Entities::TestEntityWithBoolean).parse( Nokogiri::XML(xml).root @@ -103,11 +105,11 @@ XML it "parses integer fields with a randomly matching pattern as nil" do %w[1,2,3 foobar two].each do |weird_value| - xml = <<-XML.strip - - #{weird_value} - -XML + xml = <<~XML.strip + + #{weird_value} + + XML parsed = Parsers::XmlParser.new(Entities::TestEntityWithInteger).parse( Nokogiri::XML(xml).root @@ -118,11 +120,11 @@ XML it "parses timestamp fields with a randomly matching pattern as nil" do %w[foobar yesterday now 1.2.foo].each do |weird_value| - xml = <<-XML.strip - - #{weird_value} - -XML + xml = <<~XML.strip + + #{weird_value} + + XML parsed = Parsers::XmlParser.new(Entities::TestEntityWithTimestamp).parse( Nokogiri::XML(xml).root @@ -152,14 +154,14 @@ XML end it "doesn't drop extra properties" do - xml = <<-XML.strip - - asdf - qwer - true - new_value - -XML + xml = <<~XML.strip + + asdf + qwer + true + new_value + + XML parsed = Parsers::XmlParser.new(Entities::TestDefaultEntity).parse(Nokogiri::XML(xml).root) expect(parsed[0]["test_new"]).to eq("new_value") diff --git a/spec/lib/diaspora_federation/properties_dsl_spec.rb b/spec/lib/diaspora_federation/properties_dsl_spec.rb index d7ce682..f5ff9ee 100644 --- a/spec/lib/diaspora_federation/properties_dsl_spec.rb +++ b/spec/lib/diaspora_federation/properties_dsl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe PropertiesDSL do subject(:dsl) { Class.new.extend(PropertiesDSL) } diff --git a/spec/lib/diaspora_federation/salmon/aes_spec.rb b/spec/lib/diaspora_federation/salmon/aes_spec.rb index cd0db9e..8fa5af0 100644 --- a/spec/lib/diaspora_federation/salmon/aes_spec.rb +++ b/spec/lib/diaspora_federation/salmon/aes_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Salmon::AES do let(:data) { "test data string" } diff --git a/spec/lib/diaspora_federation/salmon/encrypted_magic_envelope_spec.rb b/spec/lib/diaspora_federation/salmon/encrypted_magic_envelope_spec.rb index 7b5f264..de6d97a 100644 --- a/spec/lib/diaspora_federation/salmon/encrypted_magic_envelope_spec.rb +++ b/spec/lib/diaspora_federation/salmon/encrypted_magic_envelope_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Salmon::EncryptedMagicEnvelope do let(:sender_id) { Fabricate.sequence(:diaspora_id) } diff --git a/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb b/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb index 43349f0..348dcfb 100644 --- a/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb +++ b/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Salmon::EncryptedSlap do let(:sender) { "user_test@diaspora.example.tld" } @@ -25,21 +27,21 @@ module DiasporaFederation end it "verifies the existence of 'encrypted_header'" do - faulty_xml = < -
-XML + faulty_xml = <<~XML + + + XML expect { Salmon::EncryptedSlap.from_xml(faulty_xml, recipient_key) }.to raise_error Salmon::MissingHeader end it "verifies the existence of a magic envelope" do - faulty_xml = < - -
-XML + faulty_xml = <<~XML + + + + XML expect(Salmon::EncryptedSlap).to receive(:header_data).and_return(aes_key: "", iv: "", author_id: "") expect { Salmon::EncryptedSlap.from_xml(faulty_xml, recipient_key) diff --git a/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb b/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb index 01d28e5..b3f1b27 100644 --- a/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb +++ b/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Salmon::MagicEnvelope do let(:sender) { Fabricate.sequence(:diaspora_id) } diff --git a/spec/lib/diaspora_federation/salmon/slap_spec.rb b/spec/lib/diaspora_federation/salmon/slap_spec.rb index 465f827..a79729d 100644 --- a/spec/lib/diaspora_federation/salmon/slap_spec.rb +++ b/spec/lib/diaspora_federation/salmon/slap_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Salmon::Slap do let(:sender) { "test_user@pod.somedomain.tld" } @@ -24,24 +26,24 @@ module DiasporaFederation end it "verifies the existence of an author_id" do - faulty_xml = < -
- -XML + faulty_xml = <<~XML + +
+ + XML expect { Salmon::Slap.from_xml(faulty_xml) }.to raise_error Salmon::MissingAuthor end it "verifies the existence of a magic envelope" do - faulty_xml = <<-XML - -
- #{sender} -
-
-XML + faulty_xml = <<~XML + +
+ #{sender} +
+
+ XML expect { Salmon::Slap.from_xml(faulty_xml) }.to raise_error Salmon::MissingMagicEnvelope diff --git a/spec/lib/diaspora_federation/salmon/xml_payload_spec.rb b/spec/lib/diaspora_federation/salmon/xml_payload_spec.rb index c254580..180949b 100644 --- a/spec/lib/diaspora_federation/salmon/xml_payload_spec.rb +++ b/spec/lib/diaspora_federation/salmon/xml_payload_spec.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + module DiasporaFederation describe Salmon::XmlPayload do let(:entity) { Entities::TestEntity.new(test: "asdf") } - let(:entity_xml) { <<-XML.strip } - - - - asdf - - - -XML + let(:entity_xml) { <<~XML.strip } + + + + asdf + + + + XML describe ".unpack" do context "sanity" do @@ -41,11 +43,11 @@ XML end it "allows unwrapped entities" do - xml = <<-XML - - asdf - -XML + xml = <<~XML + + asdf + + XML entity = Salmon::XmlPayload.unpack(Nokogiri::XML(xml).root) diff --git a/spec/lib/diaspora_federation/schemas_spec.rb b/spec/lib/diaspora_federation/schemas_spec.rb index 4ac5107..f41c1a1 100644 --- a/spec/lib/diaspora_federation/schemas_spec.rb +++ b/spec/lib/diaspora_federation/schemas_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "diaspora_federation/schemas" module DiasporaFederation diff --git a/spec/lib/diaspora_federation/validators/account_deletion_validator_spec.rb b/spec/lib/diaspora_federation/validators/account_deletion_validator_spec.rb index 2c76af6..78c5463 100644 --- a/spec/lib/diaspora_federation/validators/account_deletion_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/account_deletion_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::AccountDeletionValidator do let(:entity) { :account_deletion_entity } diff --git a/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb b/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb index e8c4ea5..77e0f0b 100644 --- a/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::AccountMigrationValidator do let(:entity) { :account_migration_entity } diff --git a/spec/lib/diaspora_federation/validators/comment_validator_spec.rb b/spec/lib/diaspora_federation/validators/comment_validator_spec.rb index 5a0b0c5..34c3529 100644 --- a/spec/lib/diaspora_federation/validators/comment_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/comment_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::CommentValidator do let(:entity) { :comment_entity } diff --git a/spec/lib/diaspora_federation/validators/contact_validator_spec.rb b/spec/lib/diaspora_federation/validators/contact_validator_spec.rb index 1e5b926..171415e 100644 --- a/spec/lib/diaspora_federation/validators/contact_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/contact_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::ContactValidator do let(:entity) { :contact_entity } diff --git a/spec/lib/diaspora_federation/validators/conversation_validator_spec.rb b/spec/lib/diaspora_federation/validators/conversation_validator_spec.rb index d5f93a9..4a9f3da 100644 --- a/spec/lib/diaspora_federation/validators/conversation_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/conversation_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::ConversationValidator do let(:entity) { :conversation_entity } diff --git a/spec/lib/diaspora_federation/validators/embed_validator_spec.rb b/spec/lib/diaspora_federation/validators/embed_validator_spec.rb index d6045b3..d9639dc 100644 --- a/spec/lib/diaspora_federation/validators/embed_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/embed_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::EmbedValidator do let(:entity) { :embed_entity } diff --git a/spec/lib/diaspora_federation/validators/event_participation_validator_spec.rb b/spec/lib/diaspora_federation/validators/event_participation_validator_spec.rb index f7e1358..288f6ba 100644 --- a/spec/lib/diaspora_federation/validators/event_participation_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/event_participation_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::EventParticipationValidator do let(:entity) { :event_participation_entity } diff --git a/spec/lib/diaspora_federation/validators/event_validator_spec.rb b/spec/lib/diaspora_federation/validators/event_validator_spec.rb index c516a95..64efe53 100644 --- a/spec/lib/diaspora_federation/validators/event_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/event_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::EventValidator do let(:entity) { :event_entity } diff --git a/spec/lib/diaspora_federation/validators/h_card_validator_spec.rb b/spec/lib/diaspora_federation/validators/h_card_validator_spec.rb index ac70097..30f89dc 100644 --- a/spec/lib/diaspora_federation/validators/h_card_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/h_card_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::HCardValidator do let(:entity) { :h_card } diff --git a/spec/lib/diaspora_federation/validators/like_validator_spec.rb b/spec/lib/diaspora_federation/validators/like_validator_spec.rb index 34888d6..6529245 100644 --- a/spec/lib/diaspora_federation/validators/like_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/like_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::LikeValidator do let(:entity) { :like_entity } diff --git a/spec/lib/diaspora_federation/validators/location_validator_spec.rb b/spec/lib/diaspora_federation/validators/location_validator_spec.rb index 1b60840..ffe81da 100644 --- a/spec/lib/diaspora_federation/validators/location_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/location_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::LocationValidator do let(:entity) { :location_entity } diff --git a/spec/lib/diaspora_federation/validators/message_validator_spec.rb b/spec/lib/diaspora_federation/validators/message_validator_spec.rb index 0889cbb..571fd96 100644 --- a/spec/lib/diaspora_federation/validators/message_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/message_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::MessageValidator do let(:entity) { :message_entity } diff --git a/spec/lib/diaspora_federation/validators/optional_aware_validator_spec.rb b/spec/lib/diaspora_federation/validators/optional_aware_validator_spec.rb index 049ee49..047af2b 100644 --- a/spec/lib/diaspora_federation/validators/optional_aware_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/optional_aware_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::OptionalAwareValidator do def entity_stub(additional_data={}) diff --git a/spec/lib/diaspora_federation/validators/participation_validator_spec.rb b/spec/lib/diaspora_federation/validators/participation_validator_spec.rb index 7ffdcfc..7983cea 100644 --- a/spec/lib/diaspora_federation/validators/participation_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/participation_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::ParticipationValidator do let(:entity) { :participation_entity } diff --git a/spec/lib/diaspora_federation/validators/person_validator_spec.rb b/spec/lib/diaspora_federation/validators/person_validator_spec.rb index 6b7d61d..e8c195f 100644 --- a/spec/lib/diaspora_federation/validators/person_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/person_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::PersonValidator do let(:entity) { :person_entity } diff --git a/spec/lib/diaspora_federation/validators/photo_validator_spec.rb b/spec/lib/diaspora_federation/validators/photo_validator_spec.rb index 342ebac..e55cfec 100644 --- a/spec/lib/diaspora_federation/validators/photo_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/photo_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::PhotoValidator do let(:entity) { :photo_entity } diff --git a/spec/lib/diaspora_federation/validators/poll_answer_validator_spec.rb b/spec/lib/diaspora_federation/validators/poll_answer_validator_spec.rb index be1d1e5..f849017 100644 --- a/spec/lib/diaspora_federation/validators/poll_answer_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/poll_answer_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::PollAnswerValidator do let(:entity) { :poll_answer_entity } diff --git a/spec/lib/diaspora_federation/validators/poll_participation_validator_spec.rb b/spec/lib/diaspora_federation/validators/poll_participation_validator_spec.rb index 51215d8..95581ef 100644 --- a/spec/lib/diaspora_federation/validators/poll_participation_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/poll_participation_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::PollParticipationValidator do let(:entity) { :poll_participation_entity } diff --git a/spec/lib/diaspora_federation/validators/poll_validator_spec.rb b/spec/lib/diaspora_federation/validators/poll_validator_spec.rb index 2b26b55..d1fd0b7 100644 --- a/spec/lib/diaspora_federation/validators/poll_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/poll_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::PollValidator do let(:entity) { :poll_entity } diff --git a/spec/lib/diaspora_federation/validators/profile_validator_spec.rb b/spec/lib/diaspora_federation/validators/profile_validator_spec.rb index c9c4e7c..79c5106 100644 --- a/spec/lib/diaspora_federation/validators/profile_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/profile_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::ProfileValidator do let(:entity) { :profile_entity } diff --git a/spec/lib/diaspora_federation/validators/related_entity_validator_spec.rb b/spec/lib/diaspora_federation/validators/related_entity_validator_spec.rb index 56bf669..654b875 100644 --- a/spec/lib/diaspora_federation/validators/related_entity_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/related_entity_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::RelatedEntityValidator do let(:entity) { :related_entity } diff --git a/spec/lib/diaspora_federation/validators/reshare_validator_spec.rb b/spec/lib/diaspora_federation/validators/reshare_validator_spec.rb index 6909ed6..6aaad65 100644 --- a/spec/lib/diaspora_federation/validators/reshare_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/reshare_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::ReshareValidator do let(:entity) { :reshare_entity } diff --git a/spec/lib/diaspora_federation/validators/retraction_validator_spec.rb b/spec/lib/diaspora_federation/validators/retraction_validator_spec.rb index b19294c..917b8d6 100644 --- a/spec/lib/diaspora_federation/validators/retraction_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/retraction_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::RetractionValidator do let(:entity) { :retraction_entity } diff --git a/spec/lib/diaspora_federation/validators/rules/birthday_spec.rb b/spec/lib/diaspora_federation/validators/rules/birthday_spec.rb index 8ed274d..cdee654 100644 --- a/spec/lib/diaspora_federation/validators/rules/birthday_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/birthday_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::Birthday do it "will not accept parameters" do validator = Validation::Validator.new({}) diff --git a/spec/lib/diaspora_federation/validators/rules/boolean_spec.rb b/spec/lib/diaspora_federation/validators/rules/boolean_spec.rb index cf95e1b..5151739 100644 --- a/spec/lib/diaspora_federation/validators/rules/boolean_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/boolean_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::Boolean do it "will not accept parameters" do validator = Validation::Validator.new({}) diff --git a/spec/lib/diaspora_federation/validators/rules/diaspora_id_list_spec.rb b/spec/lib/diaspora_federation/validators/rules/diaspora_id_list_spec.rb index d6ad026..1030d37 100644 --- a/spec/lib/diaspora_federation/validators/rules/diaspora_id_list_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/diaspora_id_list_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::DiasporaIdList do let(:id_str) { Array.new(3) { Fabricate.sequence(:diaspora_id) }.join(";") } diff --git a/spec/lib/diaspora_federation/validators/rules/diaspora_id_spec.rb b/spec/lib/diaspora_federation/validators/rules/diaspora_id_spec.rb index a796530..d824d9f 100644 --- a/spec/lib/diaspora_federation/validators/rules/diaspora_id_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/diaspora_id_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::DiasporaId do it "will not accept parameters" do validator = Validation::Validator.new({}) diff --git a/spec/lib/diaspora_federation/validators/rules/guid_spec.rb b/spec/lib/diaspora_federation/validators/rules/guid_spec.rb index 3a71404..779bc1d 100644 --- a/spec/lib/diaspora_federation/validators/rules/guid_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/guid_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::Guid do it "will not accept parameters" do validator = Validation::Validator.new({}) diff --git a/spec/lib/diaspora_federation/validators/rules/not_nil_spec.rb b/spec/lib/diaspora_federation/validators/rules/not_nil_spec.rb index 62709c9..7c10359 100644 --- a/spec/lib/diaspora_federation/validators/rules/not_nil_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/not_nil_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::NotNil do it "will not accept parameters" do validator = Validation::Validator.new({}) diff --git a/spec/lib/diaspora_federation/validators/rules/public_key_spec.rb b/spec/lib/diaspora_federation/validators/rules/public_key_spec.rb index ed3b1b6..1691fe6 100644 --- a/spec/lib/diaspora_federation/validators/rules/public_key_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/public_key_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::PublicKey do it "will not accept parameters" do validator = Validation::Validator.new({}) diff --git a/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb b/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb index 52e8720..b7fb86a 100644 --- a/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Validation::Rule::TagCount do it "requires a parameter" do validator = Validation::Validator.new({}) diff --git a/spec/lib/diaspora_federation/validators/status_message_validator_spec.rb b/spec/lib/diaspora_federation/validators/status_message_validator_spec.rb index 0f8bd4b..26f9bfc 100644 --- a/spec/lib/diaspora_federation/validators/status_message_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/status_message_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::StatusMessageValidator do let(:entity) { :status_message_entity } diff --git a/spec/lib/diaspora_federation/validators/web_finger_validator_spec.rb b/spec/lib/diaspora_federation/validators/web_finger_validator_spec.rb index 8aaf77b..a7aac23 100644 --- a/spec/lib/diaspora_federation/validators/web_finger_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/web_finger_validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe Validators::WebFingerValidator do let(:entity) { :webfinger } diff --git a/spec/lib/diaspora_federation_spec.rb b/spec/lib/diaspora_federation_spec.rb index 4451309..e95fe6e 100644 --- a/spec/lib/diaspora_federation_spec.rb +++ b/spec/lib/diaspora_federation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe DiasporaFederation do context "validate_config" do diff --git a/spec/routing/fetch_routing_spec.rb b/spec/routing/fetch_routing_spec.rb index e8c50fe..6dfdb28 100644 --- a/spec/routing/fetch_routing_spec.rb +++ b/spec/routing/fetch_routing_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe ReceiveController, type: :routing do routes { DiasporaFederation::Engine.routes } diff --git a/spec/routing/receive_routing_spec.rb b/spec/routing/receive_routing_spec.rb index 87a53b9..a0afc20 100644 --- a/spec/routing/receive_routing_spec.rb +++ b/spec/routing/receive_routing_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe ReceiveController, type: :routing do routes { DiasporaFederation::Engine.routes } diff --git a/spec/routing/webfinger_routing_spec.rb b/spec/routing/webfinger_routing_spec.rb index 11f845a..9b1f33b 100644 --- a/spec/routing/webfinger_routing_spec.rb +++ b/spec/routing/webfinger_routing_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiasporaFederation describe ReceiveController, type: :routing do routes { DiasporaFederation::Engine.routes } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b4f4ce2..f20a729 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + unless ENV["NO_COVERAGE"] == "true" require "simplecov" require "simplecov-rcov" @@ -52,9 +54,7 @@ RSpec.configure do |config| expect_config.syntax = :expect end - if defined?(::Rails) - config.filter_run_excluding rails: (::Rails::VERSION::MAJOR == 5 ? 4 : 5) - else + unless defined?(::Rails) config.exclude_pattern = "**/controllers/**/*_spec.rb, **/routing/**/*_spec.rb" config.filter_run_excluding rails: true end diff --git a/spec/support/fixture_builder.rb b/spec/support/fixture_builder.rb index 0e536d5..df473cc 100644 --- a/spec/support/fixture_builder.rb +++ b/spec/support/fixture_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # set default users as initial database for each test RSpec.configure do |config| config.before(:suite) do diff --git a/spec/support/helper_methods.rb b/spec/support/helper_methods.rb index 12a6f18..b2bb3a6 100644 --- a/spec/support/helper_methods.rb +++ b/spec/support/helper_methods.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # default users def alice @alice ||= Person.find_by(diaspora_id: "alice@localhost:3000") diff --git a/spec/support/legacy_helper.rb b/spec/support/legacy_helper.rb index 384f43b..d938530 100644 --- a/spec/support/legacy_helper.rb +++ b/spec/support/legacy_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file only exists to generate legacy XMLs to test that we can still parse it. def generate_legacy_salmon_slap(entity, sender, sender_privkey) diff --git a/spec/support/shared_entity_specs.rb b/spec/support/shared_entity_specs.rb index a62eaf2..4c7ad42 100644 --- a/spec/support/shared_entity_specs.rb +++ b/spec/support/shared_entity_specs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def entity_hash_from(hash) hash.delete(:parent_author_signature) hash.map {|key, value| diff --git a/spec/support/shared_magic_envelope_specs.rb b/spec/support/shared_magic_envelope_specs.rb index cbfcde3..41ba7fc 100644 --- a/spec/support/shared_magic_envelope_specs.rb +++ b/spec/support/shared_magic_envelope_specs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_examples "a MagicEnvelope instance" do before do allow(DiasporaFederation.callbacks).to receive(:trigger).with( diff --git a/spec/support/shared_parser_specs.rb b/spec/support/shared_parser_specs.rb index f5cb26c..96e67f3 100644 --- a/spec/support/shared_parser_specs.rb +++ b/spec/support/shared_parser_specs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_examples ".parse parse error" do |reason, json| it "raises error when #{reason}" do expect { diff --git a/spec/support/shared_signable_specs.rb b/spec/support/shared_signable_specs.rb index 8e5140d..3a0619c 100644 --- a/spec/support/shared_signable_specs.rb +++ b/spec/support/shared_signable_specs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_examples "a signable" do let(:private_key) { OpenSSL::PKey::RSA.generate(1024) } let(:test_signature) { sign_with_key(private_key, test_string) } diff --git a/spec/support/shared_validator_specs.rb b/spec/support/shared_validator_specs.rb index 862148f..e8d240d 100644 --- a/spec/support/shared_validator_specs.rb +++ b/spec/support/shared_validator_specs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def entity_stub(entity, data={}) entity_class = Fabricate.schematic(entity).options[:class_name] allow_any_instance_of(entity_class).to receive(:freeze) diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index 08cc98f..dbf84da 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/test/dummy/app/models/entity.rb b/test/dummy/app/models/entity.rb index 41135ed..3cbf562 100644 --- a/test/dummy/app/models/entity.rb +++ b/test/dummy/app/models/entity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Entity attr_accessor :author, :guid attr_reader :entity_type diff --git a/test/dummy/app/models/person.rb b/test/dummy/app/models/person.rb index cd96c6a..75bb515 100644 --- a/test/dummy/app/models/person.rb +++ b/test/dummy/app/models/person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Person attr_accessor :diaspora_id, :url, :guid, :serialized_public_key, :serialized_private_key @@ -34,6 +36,7 @@ class Person def find_by(opts) return database[:diaspora_id][opts[:diaspora_id]] if opts[:diaspora_id] + database[:guid][opts[:guid]] end diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index 5191e69..0739660 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/test/dummy/config.ru b/test/dummy/config.ru index 193e5fe..097cb7b 100644 --- a/test/dummy/config.ru +++ b/test/dummy/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require ::File.expand_path("../config/environment", __FILE__) diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 7b71468..dccc66d 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,28 +1,35 @@ +# frozen_string_literal: true + require_relative "boot" +require "rails" +# Pick the frameworks you want: +# require "active_model/railtie" +# require "active_job/railtie" +# require "active_record/railtie" +# require "active_storage/engine" require "action_controller/railtie" +# require "action_mailer/railtie" +# require "action_mailbox/engine" +# require "action_text/engine" +require "action_view/railtie" +# require "action_cable/engine" +# require "sprockets/railtie" +require "rails/test_unit/railtie" +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) require "diaspora_federation/rails" module Dummy class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.0 + # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - - # Version of your assets, change this if you want to expire all your assets - # config.assets.version = "1.0" - - # autoload files from test/dummy/lib - config.autoload_once_paths += %W[#{config.root}/lib] + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. end end diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index bb5714c..55bd95c 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb index f970ac2..7df99e8 100644 --- a/test/dummy/config/environment.rb +++ b/test/dummy/config/environment.rb @@ -1,5 +1,7 @@ -# Load the rails application +# frozen_string_literal: true + +# Load the Rails application. require_relative "application" -# Initialize the rails application +# Initialize the Rails application. Rails.application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 2d78bb2..d1a500a 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -9,36 +11,35 @@ Rails.application.configure do # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true - # Don't care if the mailer can't send. - # config.action_mailer.raise_delivery_errors = false + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp", "caching-dev.txt").exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise an error on page load if there are pending migrations. - # config.active_record.migration_error = :page_load - - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - # config.assets.debug = true - - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - # config.assets.digest = true - - # Adds additional error checking when serving assets at runtime. - # Checks for improperly declared sprockets dependencies. - # Raises helpful error messages. - # config.assets.raise_runtime_errors = true - - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # Set the logging destination(s) config.log_to = %w[stdout file] diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index da40eee..f7d9dab 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -14,28 +16,16 @@ Rails.application.configure do config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like - # NGINX, varnish or squid. - # config.action_dispatch.rack_cache = true + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = false + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? - # Compress JavaScripts and CSS. - # config.assets.js_compressor = :uglifier - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - # config.assets.compile = false - - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - # config.assets.digest = true - - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache @@ -55,20 +45,14 @@ Rails.application.configure do config.show_log_configuration = false # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "dummy_production" # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). @@ -80,6 +64,34 @@ Rails.application.configure do # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new - # Do not dump schema after migrations. - # config.active_record.dump_schema_after_migration = false + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index e7fbf43..bae3b39 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -1,29 +1,30 @@ +# frozen_string_literal: true + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + config.cache_classes = false # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static file server for tests with Cache-Control for performance. - if Rails::VERSION::MAJOR == 5 - config.public_file_server.enable = true - config.public_file_server.headers = {"Cache-Control" => "public, max-age=3600"} - else - config.serve_static_files = true - config.static_cache_control = "public, max-age=3600" - end + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{1.hour.to_i}" + } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false @@ -31,17 +32,9 @@ Rails.application.configure do # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - # config.action_mailer.delivery_method = :test - - # Randomize the order test cases are executed. - # config.active_support.test_order = :random - # Print deprecation notices to the stderr. - # config.active_support.deprecation = :stderr + config.active_support.deprecation = :stderr - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true end diff --git a/test/dummy/config/initializers/cookies_serializer.rb b/test/dummy/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..20a704a --- /dev/null +++ b/test/dummy/config/initializers/cookies_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/test/dummy/config/initializers/diaspora_federation.rb b/test/dummy/config/initializers/diaspora_federation.rb index 430b5e8..09eed96 100644 --- a/test/dummy/config/initializers/diaspora_federation.rb +++ b/test/dummy/config/initializers/diaspora_federation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "diaspora_federation" ca_file = if File.file?("/etc/ssl/certs/ca-certificates.crt") diff --git a/test/dummy/config/initializers/faraday.rb b/test/dummy/config/initializers/faraday.rb index 027a3fa..856578c 100644 --- a/test/dummy/config/initializers/faraday.rb +++ b/test/dummy/config/initializers/faraday.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Use net_http in test, that's better supported by webmock unless Rails.env.test? require "typhoeus/adapters/faraday" diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb index 4a994e1..7a4f47b 100644 --- a/test/dummy/config/initializers/filter_parameter_logging.rb +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/test/dummy/config/initializers/session_store.rb b/test/dummy/config/initializers/session_store.rb index 7ee20e3..606745f 100644 --- a/test/dummy/config/initializers/session_store.rb +++ b/test/dummy/config/initializers/session_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: "_dummy_session" diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb index a7b1b91..e7148a3 100644 --- a/test/dummy/config/initializers/wrap_parameters.rb +++ b/test/dummy/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which @@ -5,10 +7,5 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) -end - -# To enable root element in JSON for ActiveRecord objects. -ActiveSupport.on_load(:active_record) do - self.include_root_in_json = true + wrap_parameters format: [:json] end diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 4dccc36..cabecec 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do mount DiasporaFederation::Engine => "/" diff --git a/test/gemfiles/no-rails.Gemfile b/test/gemfiles/no-rails.Gemfile index 564f1c4..cd31967 100644 --- a/test/gemfiles/no-rails.Gemfile +++ b/test/gemfiles/no-rails.Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" # Declare your gem's dependencies in diaspora_federation.gemspec. @@ -17,16 +19,16 @@ end group :test do # rspec formatter - gem "fuubar", "2.3.2", require: false + gem "fuubar", "2.4.1", require: false gem "nyan-cat-formatter", require: false # test coverage - gem "simplecov", "0.16.1", require: false + gem "simplecov", "0.17.1", require: false gem "simplecov-rcov", "0.2.3", require: false # test helpers gem "json-schema-rspec", "0.0.4" - gem "rspec-collection_matchers", "~> 1.1.2" + gem "rspec-collection_matchers", "~> 1.2.0" gem "rspec-json_expectations", "~> 2.1" gem "webmock", "~> 3.0" end @@ -35,7 +37,5 @@ group :development, :test do gem "rake" # unit tests - gem "rspec", "~> 3.8.0" + gem "rspec", "~> 3.9.0" end - - gem "fabrication", "< 2.17.0" diff --git a/test/gemfiles/no-rails.Gemfile.lock b/test/gemfiles/no-rails.Gemfile.lock index 79926f1..3666cdf 100644 --- a/test/gemfiles/no-rails.Gemfile.lock +++ b/test/gemfiles/no-rails.Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: ../.. specs: diaspora_federation (0.2.6) - faraday (>= 0.9.0, < 0.16.0) + faraday (>= 0.9.0, < 0.18.0) faraday_middleware (>= 0.10.0, < 0.14.0) nokogiri (~> 1.6, >= 1.6.8) typhoeus (~> 1.0) @@ -16,59 +16,59 @@ PATH GEM remote: https://rubygems.org/ specs: - addressable (2.6.0) - public_suffix (>= 2.0.2, < 4.0) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) crack (0.4.3) safe_yaml (~> 1.0.0) diff-lcs (1.3) - docile (1.3.1) + docile (1.3.2) ethon (0.12.0) ffi (>= 1.3.0) - fabrication (2.16.3) - faraday (0.15.4) + fabrication (2.20.2) + faraday (0.17.0) multipart-post (>= 1.2, < 3) faraday_middleware (0.13.1) faraday (>= 0.7.4, < 1.0) - ffi (1.10.0) - fuubar (2.3.2) + ffi (1.11.1) + fuubar (2.4.1) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) - hashdiff (0.3.8) + hashdiff (1.0.0) json (2.2.0) json-schema (2.8.1) addressable (>= 2.4) json-schema-rspec (0.0.4) json-schema (~> 2.5) rspec - macaddr (1.7.1) - systemu (~> 2.6.2) + macaddr (1.7.2) + systemu (~> 2.6.5) mini_portile2 (2.4.0) - multipart-post (2.0.0) - nokogiri (1.9.1) + multipart-post (2.1.1) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) nyan-cat-formatter (0.12.0) rspec (>= 2.99, >= 2.14.2, < 4) - public_suffix (3.0.3) - rake (12.3.2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-collection_matchers (1.1.3) + public_suffix (4.0.1) + rake (13.0.0) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-collection_matchers (1.2.0) rspec-expectations (>= 2.99.0.beta1) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-json_expectations (2.1.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.9.0) + rspec-json_expectations (2.2.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - ruby-progressbar (1.10.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) + ruby-progressbar (1.10.1) safe_yaml (1.0.5) - simplecov (0.16.1) + simplecov (0.17.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) @@ -81,10 +81,10 @@ GEM uuid (2.3.9) macaddr (~> 1.0) valid (1.2.0) - webmock (3.5.1) + webmock (3.7.6) addressable (>= 2.3.6) crack (>= 0.3.2) - hashdiff + hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS ruby @@ -93,17 +93,16 @@ DEPENDENCIES diaspora_federation! diaspora_federation-json_schema! diaspora_federation-test! - fabrication (< 2.17.0) - fuubar (= 2.3.2) + fuubar (= 2.4.1) json-schema-rspec (= 0.0.4) nyan-cat-formatter rake - rspec (~> 3.8.0) - rspec-collection_matchers (~> 1.1.2) + rspec (~> 3.9.0) + rspec-collection_matchers (~> 1.2.0) rspec-json_expectations (~> 2.1) - simplecov (= 0.16.1) + simplecov (= 0.17.1) simplecov-rcov (= 0.2.3) webmock (~> 3.0) BUNDLED WITH - 1.17.3 + 2.0.2 diff --git a/test/gemfiles/rails4.Gemfile b/test/gemfiles/rails4.Gemfile deleted file mode 100644 index 8de5931..0000000 --- a/test/gemfiles/rails4.Gemfile +++ /dev/null @@ -1,44 +0,0 @@ -source "https://rubygems.org" - -# Declare your gem's dependencies in diaspora_federation.gemspec. -# Bundler will treat runtime dependencies like base dependencies, and -# development dependencies will be added by default to the :development group. -gemspec name: "diaspora_federation", path: "../../" - -Dir["diaspora_federation-*.gemspec"].each do |gemspec| - plugin = gemspec.scan(/diaspora_federation-(.*)\.gemspec/).flatten.first - gemspec(name: "diaspora_federation-#{plugin}", development_group: plugin, path: "../../") -end - -# Declare any dependencies that are still in development here instead of in -# your gemspec. These might include edge Rails or gems from your path or -# Git. Remember to move these dependencies to your gemspec before releasing -# your gem to rubygems.org. - -group :test do - # rspec formatter - gem "fuubar", "2.3.2", require: false - gem "nyan-cat-formatter", require: false - - # test coverage - gem "simplecov", "0.16.1", require: false - gem "simplecov-rcov", "0.2.3", require: false - - # test helpers - gem "json-schema-rspec", "0.0.4" - gem "rspec-collection_matchers", "~> 1.1.2" - gem "rspec-json_expectations", "~> 2.1" - gem "webmock", "~> 3.0" -end - -group :development, :test do - gem "rake" - - # unit tests - gem "rspec", "~> 3.8.0" - gem "rspec-rails", "~> 3.8.0" -end - - gem "fabrication", "< 2.17.0" - -gem "actionpack", "4.2.8" diff --git a/test/gemfiles/rails4.Gemfile.lock b/test/gemfiles/rails4.Gemfile.lock deleted file mode 100644 index 917f535..0000000 --- a/test/gemfiles/rails4.Gemfile.lock +++ /dev/null @@ -1,171 +0,0 @@ -PATH - remote: ../.. - specs: - diaspora_federation (0.2.6) - faraday (>= 0.9.0, < 0.16.0) - faraday_middleware (>= 0.10.0, < 0.14.0) - nokogiri (~> 1.6, >= 1.6.8) - typhoeus (~> 1.0) - valid (~> 1.0) - diaspora_federation-json_schema (0.2.6) - diaspora_federation-rails (0.2.6) - actionpack (>= 4.2, < 6) - diaspora_federation (= 0.2.6) - diaspora_federation-test (0.2.6) - diaspora_federation (= 0.2.6) - fabrication (~> 2.16) - uuid (~> 2.3, >= 2.3.8) - -GEM - remote: https://rubygems.org/ - specs: - actionpack (4.2.8) - actionview (= 4.2.8) - activesupport (= 4.2.8) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.8) - activesupport (= 4.2.8) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activesupport (4.2.8) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - addressable (2.6.0) - public_suffix (>= 2.0.2, < 4.0) - builder (3.2.3) - concurrent-ruby (1.1.5) - crack (0.4.3) - safe_yaml (~> 1.0.0) - crass (1.0.4) - diff-lcs (1.3) - docile (1.3.1) - erubis (2.7.0) - ethon (0.12.0) - ffi (>= 1.3.0) - fabrication (2.16.3) - faraday (0.15.4) - multipart-post (>= 1.2, < 3) - faraday_middleware (0.13.1) - faraday (>= 0.7.4, < 1.0) - ffi (1.10.0) - fuubar (2.3.2) - rspec-core (~> 3.0) - ruby-progressbar (~> 1.4) - hashdiff (0.3.8) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - json (2.2.0) - json-schema (2.8.1) - addressable (>= 2.4) - json-schema-rspec (0.0.4) - json-schema (~> 2.5) - rspec - loofah (2.2.3) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - macaddr (1.7.1) - systemu (~> 2.6.2) - mini_portile2 (2.4.0) - minitest (5.11.3) - multipart-post (2.0.0) - nokogiri (1.9.1) - mini_portile2 (~> 2.4.0) - nyan-cat-formatter (0.12.0) - rspec (>= 2.99, >= 2.14.2, < 4) - public_suffix (3.0.3) - rack (1.6.11) - rack-test (0.6.3) - rack (>= 1.0) - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (4.2.8) - actionpack (= 4.2.8) - activesupport (= 4.2.8) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-collection_matchers (1.1.3) - rspec-expectations (>= 2.99.0.beta1) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-json_expectations (2.1.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - ruby-progressbar (1.10.0) - safe_yaml (1.0.5) - simplecov (0.16.1) - docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - simplecov-rcov (0.2.3) - simplecov (>= 0.4.1) - systemu (2.6.5) - thor (0.20.3) - thread_safe (0.3.6) - typhoeus (1.3.1) - ethon (>= 0.9.0) - tzinfo (1.2.5) - thread_safe (~> 0.1) - uuid (2.3.9) - macaddr (~> 1.0) - valid (1.2.0) - webmock (3.5.1) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff - -PLATFORMS - ruby - -DEPENDENCIES - actionpack (= 4.2.8) - diaspora_federation! - diaspora_federation-json_schema! - diaspora_federation-rails! - diaspora_federation-test! - fabrication (< 2.17.0) - fuubar (= 2.3.2) - json-schema-rspec (= 0.0.4) - nyan-cat-formatter - rake - rspec (~> 3.8.0) - rspec-collection_matchers (~> 1.1.2) - rspec-json_expectations (~> 2.1) - rspec-rails (~> 3.8.0) - simplecov (= 0.16.1) - simplecov-rcov (= 0.2.3) - webmock (~> 3.0) - -BUNDLED WITH - 1.17.3