From 98e9956d848bf0e3565d84526bf754ac49fab78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Fri, 26 Aug 2022 22:56:16 +0200 Subject: [PATCH] Fix GitHub build (#286) * Try fixing verification * Fix github build * Install pipenv * Revert "Try fixing verification" This reverts commit e16c15ce98a155ef9545e95f3895b689c8b72785. * Bump rubocop related gem versions * Fix automatic rubocop offences * Fix Rails/TransactionExitStatement offence * Fix Style/MapToHash offence * Fix Rails/CompactBlank offence * Fix Style/RedundantArgument offence * Add rubocop-graphql recommended library * Change branch to new one in workflow configuration * Add missing index from schema * Reintroduces the exit statemenent on transactions for process_message * Update rubocop at ruby-client and fix the violations * Fix rubocop violations at the server * Update the rubocop gems at the ruby-adapter * Update rubocop at the electionguard ruby-adapter * Fix the rubocop dependency issue at the bulletin board server * Add the net-* gems to the server development and test groups * Fix rspec expectation Co-authored-by: Txus Bach Co-authored-by: Antti Hukkanen --- .github/workflows/server-workflow.yml | 10 +++- bulletin_board/ruby-client/Gemfile | 4 +- bulletin_board/ruby-client/Gemfile.lock | 43 ++++++++------- .../decidim-bulletin_board.gemspec | 1 + .../authority/create_election.rb | 20 +++---- .../bulletin_board/authority/end_vote.rb | 2 +- .../authority/get_election_results.rb | 2 +- .../authority/publish_results.rb | 2 +- .../authority/report_missing_trustee.rb | 4 +- .../authority/start_key_ceremony.rb | 2 +- .../bulletin_board/authority/start_tally.rb | 2 +- .../bulletin_board/authority/start_vote.rb | 2 +- .../lib/decidim/bulletin_board/command.rb | 2 +- .../bulletin_board/graphql/file_adapter.rb | 2 +- .../decidim/bulletin_board/voter/cast_vote.rb | 2 +- .../bulletin_board/voter/in_person_vote.rb | 4 +- .../authority/create_election_spec.rb | 44 +++++++-------- .../decidim/bulletin_board/client_spec.rb | 2 + .../decidim/bulletin_board/jwk_utils_spec.rb | 30 +++++------ .../ruby-client/spec/shared/client_context.rb | 20 +++---- .../ruby-client/spec/support/command_stub.rb | 2 + bulletin_board/server/Gemfile | 10 ++-- bulletin_board/server/Gemfile.lock | 50 ++++++++++++----- .../server/app/channels/graphql_channel.rb | 8 +-- .../commands/concerns/log_entry_command.rb | 12 ++--- .../server/app/commands/create_election.rb | 10 ++-- .../server/app/commands/end_vote.rb | 10 ++-- .../server/app/commands/enqueue_message.rb | 10 ++-- .../app/commands/process_key_ceremony_step.rb | 10 ++-- .../server/app/commands/process_tally_step.rb | 10 ++-- .../server/app/commands/publish_results.rb | 10 ++-- .../app/commands/report_missing_trustee.rb | 10 ++-- .../sandbox/generate_load_test_stats.rb | 10 ++-- .../server/app/commands/start_key_ceremony.rb | 12 ++--- .../server/app/commands/start_tally.rb | 10 ++-- .../server/app/commands/start_vote.rb | 10 ++-- .../app/controllers/graphql_controller.rb | 2 +- .../sandbox/elections_controller.rb | 18 +++---- .../graphql/decidim_bulletin_board_schema.rb | 2 +- .../app/graphql/mutations/base_mutation.rb | 4 +- .../mutations/create_election_mutation.rb | 4 +- .../graphql/mutations/end_vote_mutation.rb | 2 +- .../process_key_ceremony_step_mutation.rb | 2 +- .../mutations/process_tally_step_mutation.rb | 2 +- .../mutations/publish_results_mutation.rb | 2 +- .../report_missing_trustee_mutation.rb | 2 +- .../mutations/start_key_ceremony_mutation.rb | 2 +- .../graphql/mutations/start_tally_mutation.rb | 2 +- .../graphql/mutations/start_vote_mutation.rb | 2 +- .../app/graphql/mutations/vote_mutation.rb | 2 +- .../server/app/graphql/types/query_type.rb | 2 +- .../app/jobs/sandbox/generate_votes_job.rb | 6 +-- bulletin_board/server/app/models/log_entry.rb | 2 +- .../app/queries/election_casted_votes.rb | 2 +- .../app/queries/election_in_person_votes.rb | 2 +- .../server/app/queries/election_voter_vote.rb | 2 +- .../app/services/concerns/redis_provider.rb | 6 +-- .../voting_scheme/dummy/bulletin_board.rb | 10 ++-- .../app/services/voting_scheme/dummy/voter.rb | 2 +- bulletin_board/server/bin/bundle | 10 ++-- bulletin_board/server/bin/webpack | 2 +- bulletin_board/server/bin/webpack-dev-server | 2 +- .../server/config/initializers/sidekiq.rb | 2 +- bulletin_board/server/config/routes.rb | 2 +- .../app_commands/scenarios/election.rb | 2 +- .../server/cypress/cypress_helper.rb | 2 +- ...2_add_unique_id_to_client_and_elections.rb | 3 ++ ...7160752_add_content_hash_to_log_entries.rb | 3 +- bulletin_board/server/db/schema.rb | 1 + bulletin_board/server/db/seeds.rb | 54 +++++++++---------- .../lib/tasks/client/add_authority.rake | 4 +- bulletin_board/server/lib/test/elections.rb | 8 +-- .../server/spec/commands/end_vote_spec.rb | 4 +- .../spec/commands/enqueue_message_spec.rb | 2 +- .../process_key_ceremony_step_spec.rb | 6 +-- .../spec/commands/process_tally_step_spec.rb | 6 +-- .../spec/commands/publish_results_spec.rb | 4 +- .../commands/report_missing_trustee_spec.rb | 4 +- .../commands/shared/log_entry_validations.rb | 2 +- .../spec/commands/start_key_ceremony_spec.rb | 4 +- .../server/spec/commands/start_tally_spec.rb | 4 +- .../server/spec/commands/start_vote_spec.rb | 4 +- .../server/spec/commands/vote_spec.rb | 14 ++--- .../server/spec/factories/electionguard.rb | 20 +++---- .../server/spec/factories/messages.rb | 40 +++++++------- .../server/spec/factories/models.rb | 14 ++--- .../server/spec/jobs/end_vote_job_spec.rb | 4 +- .../process_key_ceremony_step_job_spec.rb | 4 +- .../spec/jobs/process_tally_step_job_spec.rb | 4 +- .../spec/jobs/publish_results_job_spec.rb | 4 +- .../jobs/report_missing_trustee_job_spec.rb | 4 +- .../spec/jobs/start_key_ceremony_job_spec.rb | 6 +-- .../server/spec/jobs/start_tally_job_spec.rb | 4 +- .../server/spec/jobs/start_vote_job_spec.rb | 4 +- .../server/spec/jobs/vote_job_spec.rb | 6 +-- .../server/spec/models/bulletin_board_spec.rb | 2 +- .../server/spec/models/log_entry_spec.rb | 6 +-- .../create_election_mutation_spec.rb | 6 +-- .../spec/mutations/end_vote_mutation_spec.rb | 6 +-- ...process_key_ceremony_step_mutation_spec.rb | 6 +-- .../process_tally_step_mutation_spec.rb | 6 +-- .../publish_results_mutation_spec.rb | 6 +-- .../mutations/report_missing_trustee_spec.rb | 6 +-- .../start_key_ceremony_mutation_spec.rb | 6 +-- .../mutations/start_tally_mutation_spec.rb | 6 +-- .../mutations/start_vote_mutation_spec.rb | 6 +-- .../spec/mutations/vote_mutation_spec.rb | 6 +-- .../queries/get_election_log_entries_spec.rb | 8 +-- .../server/spec/queries/get_election_spec.rb | 2 +- .../server/spec/queries/get_log_entry_spec.rb | 2 +- .../spec/queries/get_pending_message_spec.rb | 6 +-- .../services/concerns/redis_provider_spec.rb | 4 +- .../server/spec/services/valid_votes_spec.rb | 6 +-- .../electionguard/bulletin_board_spec.rb | 4 +- .../spec/support/electionguard_test_data.rb | 4 +- .../server/spec/tasks/add_authority_spec.rb | 8 +-- voting_schemes/dummy/ruby-adapter/Gemfile | 4 +- .../dummy/ruby-adapter/Gemfile.lock | 33 ++++++------ .../electionguard/ruby-adapter/Gemfile | 4 +- .../electionguard/ruby-adapter/Gemfile.lock | 21 ++++---- 120 files changed, 476 insertions(+), 437 deletions(-) diff --git a/.github/workflows/server-workflow.yml b/.github/workflows/server-workflow.yml index 5084ca5b..a0e7c910 100644 --- a/.github/workflows/server-workflow.yml +++ b/.github/workflows/server-workflow.yml @@ -9,6 +9,7 @@ on: branches: - develop - main + - fix/github-ci env: CI: "true" @@ -26,12 +27,17 @@ jobs: fetch-depth: 1 - name: Copy local electionguard run: cp -r /code/voting_schemes/electionguard/electionguard-python voting_schemes/electionguard + + - name: Install pipenv + run: | + python3 -m pip install --upgrade pipenv wheel + - name: Upgrade setuptools for the virtual environment working-directory: ./voting_schemes/electionguard/python-wrapper run: | - pipenv run echo "Initialize" + python3 -m pipenv run echo "Initialize" curl -sS https://bootstrap.pypa.io/get-pip.py | $(pipenv --py) - pipenv run python -m pip install --upgrade setuptools + python3 -m pipenv run python -m pip install --upgrade setuptools - name: Cache python wrapper uses: actions/cache@v3 env: diff --git a/bulletin_board/ruby-client/Gemfile b/bulletin_board/ruby-client/Gemfile index 84bff130..c0b76600 100644 --- a/bulletin_board/ruby-client/Gemfile +++ b/bulletin_board/ruby-client/Gemfile @@ -5,6 +5,6 @@ source "https://rubygems.org" # Specify your gem's dependencies in decidim-bulletin_board.gemspec gemspec -gem "rubocop", "~> 0.92.0" +gem "rubocop", "~> 1.28.0" gem "rubocop-faker", "~> 1.1.0" -gem "rubocop-rspec", "~> 1.44.1" +gem "rubocop-rspec", "~> 2.10" diff --git a/bulletin_board/ruby-client/Gemfile.lock b/bulletin_board/ruby-client/Gemfile.lock index 50bcc6a5..97b4b09b 100644 --- a/bulletin_board/ruby-client/Gemfile.lock +++ b/bulletin_board/ruby-client/Gemfile.lock @@ -70,8 +70,8 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) builder (3.2.4) byebug (11.1.3) @@ -81,7 +81,7 @@ GEM crass (1.0.6) diff-lcs (1.5.0) erubi (1.11.0) - faker (2.20.0) + faker (2.22.0) i18n (>= 1.8.11, < 2) faraday (1.10.2) faraday-em_http (~> 1.0) @@ -119,7 +119,7 @@ GEM activesupport (>= 3.0) graphql hashdiff (1.0.1) - i18n (1.10.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) jwt (2.5.0) loofah (2.18.0) @@ -141,10 +141,10 @@ GEM racc (~> 1.4) nokogiri (1.13.8-x86_64-linux) racc (~> 1.4) - parallel (1.22.0) - parser (3.1.1.0) + parallel (1.22.1) + parser (3.1.2.1) ast (~> 2.4.1) - public_suffix (4.0.6) + public_suffix (5.0.0) racc (1.6.0) rack (2.2.4) rack-test (2.0.2) @@ -177,7 +177,7 @@ GEM thor (~> 1.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.2.1) + regexp_parser (2.5.0) rexml (3.2.5) rspec (3.11.0) rspec-core (~> 3.11.0) @@ -188,27 +188,26 @@ GEM rspec-expectations (3.11.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) - rspec-mocks (3.11.0) + rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-support (3.11.0) - rubocop (0.92.0) + rubocop (1.28.2) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.5.0) + rubocop-ast (>= 1.17.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.16.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.21.0) parser (>= 3.1.1.0) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) - rubocop-rspec (1.44.1) - rubocop (~> 0.87) - rubocop-ast (>= 0.7.1) + rubocop-rspec (2.11.1) + rubocop (~> 1.19) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) sprockets (4.1.1) @@ -221,8 +220,8 @@ GEM thor (1.2.1) tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (1.8.0) - webmock (3.14.0) + unicode-display_width (2.2.0) + webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -242,9 +241,9 @@ DEPENDENCIES decidim-bulletin_board! rake (~> 13.0) rspec (~> 3.7) - rubocop (~> 0.92.0) + rubocop (~> 1.28.0) rubocop-faker (~> 1.1.0) - rubocop-rspec (~> 1.44.1) + rubocop-rspec (~> 2.10) webmock (~> 3.6) wisper-rspec (~> 1.1.0) diff --git a/bulletin_board/ruby-client/decidim-bulletin_board.gemspec b/bulletin_board/ruby-client/decidim-bulletin_board.gemspec index 829b7451..b0b86b7c 100644 --- a/bulletin_board/ruby-client/decidim-bulletin_board.gemspec +++ b/bulletin_board/ruby-client/decidim-bulletin_board.gemspec @@ -35,4 +35,5 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec", "~> 3.7" s.add_development_dependency "webmock", "~> 3.6" s.add_development_dependency "wisper-rspec", "~> 1.1.0" + s.metadata["rubygems_mfa_required"] = "true" end diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/create_election.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/create_election.rb index d7da97ce..77e58591 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/create_election.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/create_election.rb @@ -18,7 +18,7 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, + message_id:, signed_data: sign_message(message_id, message) } @@ -46,18 +46,18 @@ def call def message { - scheme: scheme, - bulletin_board: bulletin_board, - authority: authority, - trustees: trustees, - polling_stations: polling_stations, + scheme:, + bulletin_board:, + authority:, + trustees:, + polling_stations:, description: { name: text(election_data[:title]), start_date: election_data[:start_date].strftime("%FT%T%:z"), end_date: election_data[:end_date].strftime("%FT%T%:z"), - candidates: candidates, - contests: contests, - ballot_styles: ballot_styles + candidates:, + contests:, + ballot_styles: } } end @@ -149,7 +149,7 @@ def default_text(field) def text(field) { - text: field.map { |locale, value| { language: locale.to_s, value: value } } + text: field.map { |locale, value| { language: locale.to_s, value: } } } end diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/end_vote.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/end_vote.rb index 15b6fdc1..21f11e4f 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/end_vote.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/end_vote.rb @@ -26,7 +26,7 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, + message_id:, signed_data: sign_message(message_id, {}) } diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/get_election_results.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/get_election_results.rb index b8031b5f..3817b0a6 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/get_election_results.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/get_election_results.rb @@ -44,7 +44,7 @@ def call @election = response.data.election @signed_data = election.log_entries.first.signed_data - broadcast(:ok, { election_results: decoded_data["results"], verifiable_results: verifiable_results }) + broadcast(:ok, { election_results: decoded_data["results"], verifiable_results: }) rescue Graphlient::Errors::ServerError broadcast(:error, "Sorry, something went wrong") end diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/publish_results.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/publish_results.rb index 7fa9e323..378a83c4 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/publish_results.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/publish_results.rb @@ -26,7 +26,7 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, + message_id:, signed_data: sign_message(message_id, {}) } diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/report_missing_trustee.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/report_missing_trustee.rb index 12e0b844..ff9824f9 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/report_missing_trustee.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/report_missing_trustee.rb @@ -28,8 +28,8 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, - signed_data: sign_message(message_id, { trustee_id: trustee_id }) + message_id:, + signed_data: sign_message(message_id, { trustee_id: }) } response = graphql.query do diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_key_ceremony.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_key_ceremony.rb index 8376705d..cd1b1cba 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_key_ceremony.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_key_ceremony.rb @@ -26,7 +26,7 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, + message_id:, signed_data: sign_message(message_id, {}) } diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_tally.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_tally.rb index d6dd5395..fcfca107 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_tally.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_tally.rb @@ -26,7 +26,7 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, + message_id:, signed_data: sign_message(message_id, {}) } diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_vote.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_vote.rb index e0e03d95..f51e5496 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_vote.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/authority/start_vote.rb @@ -26,7 +26,7 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, + message_id:, signed_data: sign_message(message_id, {}) } diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/command.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/command.rb index a54ae9ff..fc23b72b 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/command.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/command.rb @@ -20,7 +20,7 @@ def sign_message(message_id, message) def complete_message(message_id, message) message.merge({ iat: Time.now.to_i, - message_id: message_id + message_id: }) end diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/graphql/file_adapter.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/graphql/file_adapter.rb index 50a735d1..c357308b 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/graphql/file_adapter.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/graphql/file_adapter.rb @@ -8,7 +8,7 @@ module Graphql class FileAdapter attr_reader :file_name - def initialize(file_name, _options = {}, &_block) + def initialize(file_name, _options = {}, &) @file_name = file_name end diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/cast_vote.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/cast_vote.rb index 690e416c..f292766a 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/cast_vote.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/cast_vote.rb @@ -30,7 +30,7 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, + message_id:, signed_data: sign_message(message_id, { content: encrypted_vote }) } diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/in_person_vote.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/in_person_vote.rb index cf70f734..2828e596 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/in_person_vote.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/voter/in_person_vote.rb @@ -30,8 +30,8 @@ def message_id def call # arguments used inside the graphql operation args = { - message_id: message_id, - signed_data: sign_message(message_id, { polling_station_id: polling_station_id }) + message_id:, + signed_data: sign_message(message_id, { polling_station_id: }) } begin diff --git a/bulletin_board/ruby-client/spec/decidim/bulletin_board/authority/create_election_spec.rb b/bulletin_board/ruby-client/spec/decidim/bulletin_board/authority/create_election_spec.rb index 6809813c..178cdbbd 100644 --- a/bulletin_board/ruby-client/spec/decidim/bulletin_board/authority/create_election_spec.rb +++ b/bulletin_board/ruby-client/spec/decidim/bulletin_board/authority/create_election_spec.rb @@ -27,8 +27,8 @@ module Authority ], default_locale: "en", title: { - "en": "An election", - "es": "Una elección" + en: "An election", + es: "Una elección" }, start_date: Time.new(2023, 4, 5, 6, 7, 8, "+03:00"), end_date: Time.new(2023, 4, 7, 6, 5, 4, "+03:00"), @@ -38,12 +38,12 @@ module Authority slug: "question-1", max_selections: 1, title: { - "en": "A question", - "es": "Una pregunta" + en: "A question", + es: "Una pregunta" }, description: { - "en": "A question description", - "es": "Una descripción de pregunta" + en: "A question description", + es: "Una descripción de pregunta" }, answers: [ { @@ -58,12 +58,12 @@ module Authority slug: "question-2", max_selections: 2, title: { - "en": "Another question", - "es": "Otra pregunta" + en: "Another question", + es: "Otra pregunta" }, description: { - "en": "Another question description", - "es": "Otra descripción de pregunta" + en: "Another question description", + es: "Otra descripción de pregunta" }, answers: [ { @@ -79,36 +79,38 @@ module Authority { slug: "answer-1", title: { - "en": "An answer", - "es": "Una respuesta" + en: "An answer", + es: "Una respuesta" } }, { slug: "answer-2", title: { - "en": "Another answer", - "es": "Otra respuesta" + en: "Another answer", + es: "Otra respuesta" } }, { slug: "answer-3", title: { - "en": "An answer for another question", - "es": "Una respuesta para otra pregunta" + en: "An answer for another question", + es: "Una respuesta para otra pregunta" } }, { slug: "answer-4", title: { - "en": "Another answer for another question", - "es": "Otra respuesta para otra pregunta" + en: "Another answer for another question", + es: "Otra respuesta para otra pregunta" } } ], ballot_styles: { - "ballot_style_1": ["question-1"], - "ballot_style_2": ["question-2"], - "ballot_style_3": ["question-1", "question-2"] + # rubocop:disable Naming/VariableNumber + ballot_style_1: ["question-1"], + ballot_style_2: ["question-2"], + ballot_style_3: ["question-1", "question-2"] + # rubocop:enable Naming/VariableNumber } } end diff --git a/bulletin_board/ruby-client/spec/decidim/bulletin_board/client_spec.rb b/bulletin_board/ruby-client/spec/decidim/bulletin_board/client_spec.rb index 4ee67d0e..afc0c05e 100644 --- a/bulletin_board/ruby-client/spec/decidim/bulletin_board/client_spec.rb +++ b/bulletin_board/ruby-client/spec/decidim/bulletin_board/client_spec.rb @@ -76,7 +76,9 @@ module BulletinBoard let(:election_id) { "test.1" } let(:voter_id) { "voter.1" } let(:encrypted_vote) do + # rubocop:disable Naming/VariableNumber { question_1: "aNsWeR 1" }.to_json + # rubocop:enable Naming/VariableNumber end let(:result) { [:ok, double(status: "enqueued")] } diff --git a/bulletin_board/ruby-client/spec/decidim/bulletin_board/jwk_utils_spec.rb b/bulletin_board/ruby-client/spec/decidim/bulletin_board/jwk_utils_spec.rb index e61cc1e5..cf7eb0b5 100644 --- a/bulletin_board/ruby-client/spec/decidim/bulletin_board/jwk_utils_spec.rb +++ b/bulletin_board/ruby-client/spec/decidim/bulletin_board/jwk_utils_spec.rb @@ -4,24 +4,24 @@ RSpec.describe Decidim::BulletinBoard::JwkUtils do PUBLIC_KEY = { - "kty": "RSA", - "n": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", - "e": "AQAB", - "alg": "RS256", - "kid": "2011-04-29" + kty: "RSA", + n: "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", + e: "AQAB", + alg: "RS256", + kid: "2011-04-29" }.freeze PRIVATE_KEY = { - "p": "7w3nfUDi7KZs5NkllDNy3Te77ngZFpiLvLykf0hO8BQ5G58ce9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BfyDnlOIaxUXOtPYve11IQ" }.freeze subject { described_class } diff --git a/bulletin_board/ruby-client/spec/shared/client_context.rb b/bulletin_board/ruby-client/spec/shared/client_context.rb index ba7d532c..7daab070 100644 --- a/bulletin_board/ruby-client/spec/shared/client_context.rb +++ b/bulletin_board/ruby-client/spec/shared/client_context.rb @@ -16,27 +16,27 @@ let(:config) do double( - bulletin_board_server: bulletin_board_server, - bulletin_board_public_key: bulletin_board_public_key, + bulletin_board_server:, + bulletin_board_public_key:, - authority_api_key: authority_api_key, - authority_name: authority_name, - authority_private_key: authority_private_key, + authority_api_key:, + authority_name:, + authority_private_key:, - scheme_name: scheme_name, - number_of_trustees: number_of_trustees, - quorum: quorum + scheme_name:, + number_of_trustees:, + quorum: ) end let(:bulletin_board_server) { "https://bb.example.org" } let(:bulletin_board_public_key) do - { "kty": "RSA", "n": "zMXsZpYPKkDlSmezX898y7zNOaJ7ENIN4kj4UhQ95Vm4HlgTpIs2VMMsO0eqynMaOR_G1mXdqbpbaJtXijBe4V8323QwGm6WVAa71E7pDXa5g6-uo5f8GePitN0YER9y2yNQN4uTaNzJiWV2uLBUYfMdj3SIif31YwLULHAOj3B_oleFK8coE_Qr3NzATcYBmsqE8AR4NljxTO6KDmP1SLdf5GBOBhOAIFbnL_Kpj2xkm7MS3hjMVKpiRhqA1UgX5oKZ8ixBv46fNJF0pBsHi3fHNjK9oZzgdx_AI-YFpdE_40-8bh_g9sWzxacqOM2-MdQLHbvRPEVltO3E8tr6I5YWrylcP7l9VD8OJeqjq2qFYHnGYdmLoD2XuXmI9EuBvSb9H4-qcartxZSIQCimKib_fxZvgrG1FSRRhK6YpvIdGv4-G2zfCCRsC4XD80TYI2bf-oYCoy7eU3_eVHFMV2yg4p1Wnuw2Vgq0edPL_bKaV9JvGx7F-U5juxNN0WZR9LzbPl4ReejzN95lyHgbj0nTH_u3bSpZmgJrQF-PwdnPcG46deVjJgUeosrlC4lQxVrRz0GL58BuFunnz2uYDBDrcJCiG60EbdkAFHjOcXU4wrUWATin7je_aqdBXhSnkTafcJAMvL7Y2Ld7vDge8nLqjAVlAi5am3rN0kqKT6M", "e": "AQAB", "kid": "a8e86f02ca27e1861bfc49e2a9a4614ca9068f8efdb6d42d19d3aab0eb2a31be" } + { kty: "RSA", n: "zMXsZpYPKkDlSmezX898y7zNOaJ7ENIN4kj4UhQ95Vm4HlgTpIs2VMMsO0eqynMaOR_G1mXdqbpbaJtXijBe4V8323QwGm6WVAa71E7pDXa5g6-uo5f8GePitN0YER9y2yNQN4uTaNzJiWV2uLBUYfMdj3SIif31YwLULHAOj3B_oleFK8coE_Qr3NzATcYBmsqE8AR4NljxTO6KDmP1SLdf5GBOBhOAIFbnL_Kpj2xkm7MS3hjMVKpiRhqA1UgX5oKZ8ixBv46fNJF0pBsHi3fHNjK9oZzgdx_AI-YFpdE_40-8bh_g9sWzxacqOM2-MdQLHbvRPEVltO3E8tr6I5YWrylcP7l9VD8OJeqjq2qFYHnGYdmLoD2XuXmI9EuBvSb9H4-qcartxZSIQCimKib_fxZvgrG1FSRRhK6YpvIdGv4-G2zfCCRsC4XD80TYI2bf-oYCoy7eU3_eVHFMV2yg4p1Wnuw2Vgq0edPL_bKaV9JvGx7F-U5juxNN0WZR9LzbPl4ReejzN95lyHgbj0nTH_u3bSpZmgJrQF-PwdnPcG46deVjJgUeosrlC4lQxVrRz0GL58BuFunnz2uYDBDrcJCiG60EbdkAFHjOcXU4wrUWATin7je_aqdBXhSnkTafcJAMvL7Y2Ld7vDge8nLqjAVlAi5am3rN0kqKT6M", e: "AQAB", kid: "a8e86f02ca27e1861bfc49e2a9a4614ca9068f8efdb6d42d19d3aab0eb2a31be" } end let(:authority_api_key) { Random.urlsafe_base64(30) } let(:authority_name) { "Decidim Test Authority" } let(:authority_private_key) do - { "kty": "RSA", "n": "pNgMt8lnPDD3TlWYGhRiV1oZkPQmnLdiUzwyb_-35qKD9k-HU86xo0uSgoOUWkBtnvFscq8zNDPAGAlZVokaN_z9ksZblSce0LEl8l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3GWodKKSZggpnCLDd4H-1fXlbDYCXSJpoikAdZ1nFgXnnrUDdKRaAajnwpIYtIvXVewSQYR-BULzunUtIRZt8hx_6FRzhRha9gH_TtPTeYZ_vISuz0Y2rhUpx1Q2kaLlR9M8PUxm47l0xvX3LMKN6h6oWxFtn7wq0qwZ-Bjv24mOrOAQ", dq: "nXGD10hURrwk9W7hxP0sjB2Rdnr06iv3THs4JWFL16_h32bZO1BSWoho_chbgYlMmtFXGFFIWVLxAcAI2gWC_MA4cbmapvIMW2LNh1vgxJW5v95_NuGUlECeEEwcAu1-_b7z5XBCmAy3nLem9sbb_5wv0hMpPH0VRvbnZeBO3SBIkO0lddYCqU-8wN9HqkyoexQleSUnAm1O0iy4GIHT2aEmdNaRaKy2EhmNiTZdZeseZueOvyGPtTVONp2ofacMdcN0z39jr22qo9DWtdusd7nVPOpqkllEF6GrGUeHBnGD92n4YjDuxRnqefu8fXxUFrcLav0p8CNSv9ek291woQ", qi: "w6hfKEBLLHRWPkjajgxZyyetj-UFfVkILRT0plOllJ2JV8whcOXRXbiXH2r8zqMeyMFrrMwmuvv4TVQaruKB0ZQOG7Tz5Lw0RZEREOLnBwc3vSi_iLd-jBz01LdExTpqsAHMkaMQR9x62J8DE1ZNxVdn3ELYKik0f1L2r_WErzhvT1uq69HAybUp6WHcFYH0PSqHg4LOneXAdU1_g-ji2Zn9dlA_2oYGQ5S6JXPV7v2IVbEFpxyVD1lPbFT0iKhyZZevictjgD_JGHveIVqsq5w0Csyz08h0oEW9hYEq-4bquMxSf18gjldoS5uQPD7FUECgL8bxsCdc4hP6UEKYGw" } end let(:scheme_name) { "test" } let(:number_of_trustees) { 2 } diff --git a/bulletin_board/ruby-client/spec/support/command_stub.rb b/bulletin_board/ruby-client/spec/support/command_stub.rb index 5689cabd..701d2d10 100644 --- a/bulletin_board/ruby-client/spec/support/command_stub.rb +++ b/bulletin_board/ruby-client/spec/support/command_stub.rb @@ -10,6 +10,8 @@ def stub_command(clazz, called_method, event_to_publish, *published_event_args) "a.message+id" end + # rubocop:disable Lint/EmptyBlock define_method(:configure) { |*_args|; } + # rubocop:enable Lint/EmptyBlock end) end diff --git a/bulletin_board/server/Gemfile b/bulletin_board/server/Gemfile index bc69bab2..e3ad6925 100644 --- a/bulletin_board/server/Gemfile +++ b/bulletin_board/server/Gemfile @@ -58,12 +58,16 @@ group :development, :test do gem "byebug", platforms: [:mri, :mingw, :x64_mingw] gem "cypress-on-rails", "~> 1.0" gem "graphlient", "~> 0.5.0" + gem "net-imap", "~> 0.2.3" + gem "net-pop", "~> 0.1.1" + gem "net-smtp", "~> 0.3.1" gem "pry-rails" gem "rspec-rails", "~> 4.1" - gem "rubocop", "~> 0.92.0" + gem "rubocop", "~> 1.28.0" gem "rubocop-faker", "~> 1.1.0" - gem "rubocop-rails", "~> 2.9.1" - gem "rubocop-rspec", "~> 1.44.1" + gem "rubocop-graphql", "~> 0.14.4" + gem "rubocop-rails", "~> 2.14" + gem "rubocop-rspec", "~> 2.10" end group :development do diff --git a/bulletin_board/server/Gemfile.lock b/bulletin_board/server/Gemfile.lock index 69c7d031..8e771095 100644 --- a/bulletin_board/server/Gemfile.lock +++ b/bulletin_board/server/Gemfile.lock @@ -127,6 +127,7 @@ GEM descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) diff-lcs (1.5.0) + digest (3.1.0) docile (1.4.0) equalizer (0.0.11) erubi (1.11.0) @@ -207,6 +208,20 @@ GEM minitest (5.16.3) msgpack (1.5.6) multipart-post (2.2.3) + net-imap (0.2.3) + digest + net-protocol + strscan + net-pop (0.1.1) + digest + net-protocol + timeout + net-protocol (0.1.3) + timeout + net-smtp (0.3.1) + digest + net-protocol + timeout nio4r (2.5.8) nokogiri (1.13.8) mini_portile2 (~> 2.8.0) @@ -300,27 +315,28 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0) - rubocop (0.92.0) + rubocop (1.28.2) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.5.0) + rubocop-ast (>= 1.17.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) + unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.21.0) parser (>= 3.1.1.0) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) - rubocop-rails (2.9.1) + rubocop-graphql (0.14.4) + rubocop (>= 0.87, < 2) + rubocop-rails (2.15.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.90.0, < 2.0) - rubocop-rspec (1.44.1) - rubocop (~> 0.87) - rubocop-ast (>= 0.7.1) + rubocop (>= 1.7.0, < 2.0) + rubocop-rspec (2.11.1) + rubocop (~> 1.19) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) sass-rails (6.0.0) @@ -362,15 +378,17 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + strscan (3.0.4) thor (1.2.1) thread_safe (0.3.6) tilt (2.0.11) + timeout (0.3.0) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (1.8.0) + unicode-display_width (2.2.0) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) @@ -417,6 +435,9 @@ DEPENDENCIES jsonl jwt listen (~> 3.2) + net-imap (~> 0.2.3) + net-pop (~> 0.1.1) + net-smtp (~> 0.3.1) pg (>= 0.18, < 2.0) pry-rails puma (~> 5.3) @@ -428,10 +449,11 @@ DEPENDENCIES redis (~> 4.0) rspec-graphql_matchers rspec-rails (~> 4.1) - rubocop (~> 0.92.0) + rubocop (~> 1.28.0) rubocop-faker (~> 1.1.0) - rubocop-rails (~> 2.9.1) - rubocop-rspec (~> 1.44.1) + rubocop-graphql (~> 0.14.4) + rubocop-rails (~> 2.14) + rubocop-rspec (~> 2.10) sass-rails (>= 6) sidekiq (~> 6.0) simplecov diff --git a/bulletin_board/server/app/channels/graphql_channel.rb b/bulletin_board/server/app/channels/graphql_channel.rb index f7f1ef80..066bd957 100644 --- a/bulletin_board/server/app/channels/graphql_channel.rb +++ b/bulletin_board/server/app/channels/graphql_channel.rb @@ -18,10 +18,10 @@ def execute(data) } result = DecidimBulletinBoardSchema.execute( - query: query, - context: context, - variables: variables, - operation_name: operation_name + query:, + context:, + variables:, + operation_name: ) payload = { diff --git a/bulletin_board/server/app/commands/concerns/log_entry_command.rb b/bulletin_board/server/app/commands/concerns/log_entry_command.rb index eea4ddad..b543f712 100644 --- a/bulletin_board/server/app/commands/concerns/log_entry_command.rb +++ b/bulletin_board/server/app/commands/concerns/log_entry_command.rb @@ -16,9 +16,9 @@ module LogEntryCommand def log_entry @log_entry ||= LogEntry.new( - message_id: message_id, - signed_data: signed_data, - client: client + message_id:, + signed_data:, + client: ) end @@ -84,9 +84,9 @@ def create_response_log_entries! ) LogEntry.create!( - election: election, - message_id: message_id, - signed_data: BulletinBoard.sign(response_message.merge(message_id: message_id, iat: Time.current.to_i)), + election:, + message_id:, + signed_data: BulletinBoard.sign(response_message.merge(message_id:, iat: Time.current.to_i)), bulletin_board: true ) end diff --git a/bulletin_board/server/app/commands/create_election.rb b/bulletin_board/server/app/commands/create_election.rb index 63d8be97..7f59e688 100644 --- a/bulletin_board/server/app/commands/create_election.rb +++ b/bulletin_board/server/app/commands/create_election.rb @@ -49,16 +49,16 @@ def call def election @election ||= log_entry.election = Election.new( unique_id: message_identifier.election_id, - title: title, + title:, status: :created, - authority: authority, + authority:, log_entries: [log_entry] ) end def create_trustees trustees.each do |trustee| - find_or_create_trustee(trustee).election_trustees.create!(election: election) + find_or_create_trustee(trustee).election_trustees.create!(election:) end end @@ -80,9 +80,9 @@ def trustees end def title - @title ||= decoded_data.dig(:description, :name, :text).map do |text| + @title ||= decoded_data.dig(:description, :name, :text).to_h do |text| [text["language"], text["value"]] - end.to_h + end end def start_date diff --git a/bulletin_board/server/app/commands/end_vote.rb b/bulletin_board/server/app/commands/end_vote.rb index d7606e89..58326f47 100644 --- a/bulletin_board/server/app/commands/end_vote.rb +++ b/bulletin_board/server/app/commands/end_vote.rb @@ -24,13 +24,13 @@ def initialize(authority, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("end_vote") + return broadcast(:invalid, error) unless + valid_step?(election.vote?) && + valid_client?(authority.authority? && election.authority == authority) && + valid_author?(message_identifier.from_authority?) election.with_lock do - return broadcast(:invalid, error) unless - valid_step?(election.vote?) && - valid_client?(authority.authority? && election.authority == authority) && - valid_author?(message_identifier.from_authority?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement election.log_entries << log_entry log_entry.save! diff --git a/bulletin_board/server/app/commands/enqueue_message.rb b/bulletin_board/server/app/commands/enqueue_message.rb index 88a45643..e2b8a839 100644 --- a/bulletin_board/server/app/commands/enqueue_message.rb +++ b/bulletin_board/server/app/commands/enqueue_message.rb @@ -44,15 +44,15 @@ def valid? end def pending_messages? - PendingMessage.enqueued.exists?(client: client, election: election, message_id: message_id) + PendingMessage.enqueued.exists?(client:, election:, message_id:) end def create_pending_message! @pending_message = PendingMessage.create!( - client: client, - election: election, - message_id: message_id, - signed_data: signed_data, + client:, + election:, + message_id:, + signed_data:, status: :enqueued ) end diff --git a/bulletin_board/server/app/commands/process_key_ceremony_step.rb b/bulletin_board/server/app/commands/process_key_ceremony_step.rb index cfc81746..e9a4910e 100644 --- a/bulletin_board/server/app/commands/process_key_ceremony_step.rb +++ b/bulletin_board/server/app/commands/process_key_ceremony_step.rb @@ -25,13 +25,13 @@ def initialize(trustee, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("key_ceremony") + return broadcast(:invalid, error) unless + valid_client?(client.trustee? && election.trustees.member?(trustee)) && + valid_author?(message_identifier.from_trustee?) && + valid_step?(election.key_ceremony?) election.with_lock do - return broadcast(:invalid, error) unless - valid_client?(client.trustee? && election.trustees.member?(trustee)) && - valid_author?(message_identifier.from_trustee?) && - valid_step?(election.key_ceremony?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement log_entry.election = election log_entry.save! diff --git a/bulletin_board/server/app/commands/process_tally_step.rb b/bulletin_board/server/app/commands/process_tally_step.rb index ba20d527..f21db065 100644 --- a/bulletin_board/server/app/commands/process_tally_step.rb +++ b/bulletin_board/server/app/commands/process_tally_step.rb @@ -24,13 +24,13 @@ def initialize(trustee, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("tally") + return broadcast(:invalid, error) unless + valid_client?(client.trustee? && election.trustees.member?(client)) && + valid_author?(message_identifier.from_trustee?) && + valid_step?(election.tally_started?) election.with_lock do - return broadcast(:invalid, error) unless - valid_client?(client.trustee? && election.trustees.member?(client)) && - valid_author?(message_identifier.from_trustee?) && - valid_step?(election.tally_started?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement log_entry.election = election log_entry.save! diff --git a/bulletin_board/server/app/commands/publish_results.rb b/bulletin_board/server/app/commands/publish_results.rb index ddb0ee37..75b69a98 100644 --- a/bulletin_board/server/app/commands/publish_results.rb +++ b/bulletin_board/server/app/commands/publish_results.rb @@ -24,13 +24,13 @@ def initialize(authority, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("publish_results") + return broadcast(:invalid, error) unless + valid_step?(election.tally_ended?) && + valid_client?(authority.authority? && election.authority == authority) && + valid_author?(message_identifier.from_authority?) election.with_lock do - return broadcast(:invalid, error) unless - valid_step?(election.tally_ended?) && - valid_client?(authority.authority? && election.authority == authority) && - valid_author?(message_identifier.from_authority?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement log_entry.election = election log_entry.save! diff --git a/bulletin_board/server/app/commands/report_missing_trustee.rb b/bulletin_board/server/app/commands/report_missing_trustee.rb index 5a999873..8a722127 100644 --- a/bulletin_board/server/app/commands/report_missing_trustee.rb +++ b/bulletin_board/server/app/commands/report_missing_trustee.rb @@ -24,13 +24,13 @@ def initialize(authority, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("tally", "missing_trustee") + return broadcast(:invalid, error) unless + valid_client?(authority.authority? && election.authority == authority) && + valid_author?(message_identifier.from_authority?) && + valid_step?(election.tally_started?) election.with_lock do - return broadcast(:invalid, error) unless - valid_client?(authority.authority? && election.authority == authority) && - valid_author?(message_identifier.from_authority?) && - valid_step?(election.tally_started?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement log_entry.election = election log_entry.save! diff --git a/bulletin_board/server/app/commands/sandbox/generate_load_test_stats.rb b/bulletin_board/server/app/commands/sandbox/generate_load_test_stats.rb index bbce060c..9f8555b8 100644 --- a/bulletin_board/server/app/commands/sandbox/generate_load_test_stats.rb +++ b/bulletin_board/server/app/commands/sandbox/generate_load_test_stats.rb @@ -49,12 +49,12 @@ def votes_stats def aggregate_stats { - votes_number: votes_number, - accepted_votes_number: accepted_votes_number, + votes_number:, + accepted_votes_number:, accepted_votes_percentage: accepted_votes_number * 100 / votes_number, - total_processing_time: total_processing_time, + total_processing_time:, avg_processing_time: total_processing_time / votes_number, - total_running_time: total_running_time + total_running_time: } end @@ -76,7 +76,7 @@ def total_processing_time def pertinent_pending_messages @pertinent_pending_messages ||= PendingMessage - .where(election_id: election_id) + .where(election_id:) .where("created_at >= :date", date: earliest_vote_time) .where("created_at <= :date", date: latest_vote_time) end diff --git a/bulletin_board/server/app/commands/start_key_ceremony.rb b/bulletin_board/server/app/commands/start_key_ceremony.rb index 108e07f6..e78c5761 100644 --- a/bulletin_board/server/app/commands/start_key_ceremony.rb +++ b/bulletin_board/server/app/commands/start_key_ceremony.rb @@ -24,13 +24,13 @@ def initialize(authority, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("start_key_ceremony") + return broadcast(:invalid, error) unless + valid_client?(authority.authority? && election.authority == authority) && + valid_author?(message_identifier.from_authority?) && + valid_step?(election.created?) election.with_lock do - return broadcast(:invalid, error) unless - valid_client?(authority.authority? && election.authority == authority) && - valid_author?(message_identifier.from_authority?) && - valid_step?(election.created?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement log_entry.election = election log_entry.save! @@ -50,7 +50,7 @@ def create_response_log_entries! @response_log_entries = response_messages.map do |response_message| LogEntry.create!( - election: election, + election:, message_id: response_message["message_id"], signed_data: BulletinBoard.sign(response_message), bulletin_board: true diff --git a/bulletin_board/server/app/commands/start_tally.rb b/bulletin_board/server/app/commands/start_tally.rb index 1b6442a5..53cfcf8b 100644 --- a/bulletin_board/server/app/commands/start_tally.rb +++ b/bulletin_board/server/app/commands/start_tally.rb @@ -24,13 +24,13 @@ def initialize(authority, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("start_tally") + return broadcast(:invalid, error) unless + valid_client?(authority.authority? && election.authority == authority) && + valid_author?(message_identifier.from_authority?) && + valid_step?(election.vote_ended?) election.with_lock do - return broadcast(:invalid, error) unless - valid_client?(authority.authority? && election.authority == authority) && - valid_author?(message_identifier.from_authority?) && - valid_step?(election.vote_ended?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement log_entry.election = election log_entry.save! diff --git a/bulletin_board/server/app/commands/start_vote.rb b/bulletin_board/server/app/commands/start_vote.rb index 746314c5..5e4b5bf1 100644 --- a/bulletin_board/server/app/commands/start_vote.rb +++ b/bulletin_board/server/app/commands/start_vote.rb @@ -24,13 +24,13 @@ def initialize(authority, message_id, signed_data) def call return broadcast(:invalid, error) unless valid_log_entry?("start_vote") + return broadcast(:invalid, error) unless + valid_step?(election.key_ceremony_ended?) && + valid_client?(authority.authority? && election.authority == authority) && + valid_author?(message_identifier.from_authority?) election.with_lock do - return broadcast(:invalid, error) unless - valid_step?(election.key_ceremony_ended?) && - valid_client?(authority.authority? && election.authority == authority) && - valid_author?(message_identifier.from_authority?) && - process_message + return broadcast(:invalid, error) unless process_message # rubocop:disable Rails/TransactionExitStatement log_entry.election = election log_entry.save! diff --git a/bulletin_board/server/app/controllers/graphql_controller.rb b/bulletin_board/server/app/controllers/graphql_controller.rb index 96ee8a7d..a225776f 100644 --- a/bulletin_board/server/app/controllers/graphql_controller.rb +++ b/bulletin_board/server/app/controllers/graphql_controller.rb @@ -19,7 +19,7 @@ def execute trustee_unique_id: request.headers["TrusteeUniqueId"] || headers["TrusteeUniqueId"] } - result = DecidimBulletinBoardSchema.execute(query, variables: variables, context: context, operation_name: operation_name) + result = DecidimBulletinBoardSchema.execute(query, variables:, context:, operation_name:) render json: result rescue StandardError => e raise e unless Rails.env.development? diff --git a/bulletin_board/server/app/controllers/sandbox/elections_controller.rb b/bulletin_board/server/app/controllers/sandbox/elections_controller.rb index a01976c7..76247b07 100644 --- a/bulletin_board/server/app/controllers/sandbox/elections_controller.rb +++ b/bulletin_board/server/app/controllers/sandbox/elections_controller.rb @@ -109,13 +109,13 @@ def results def election_data @election_data ||= params.require(:election).permit(:default_locale, title: {}).to_h.merge( - trustees: trustees, - start_date: start_date, - end_date: end_date, - polling_stations: polling_stations, - questions: questions, - answers: answers, - ballot_styles: ballot_styles + trustees:, + start_date:, + end_date:, + polling_stations:, + questions:, + answers:, + ballot_styles: ) end @@ -138,7 +138,7 @@ def trustees end def polling_stations - @polling_stations ||= params[:election][:polling_stations].reject(&:blank?) + @polling_stations ||= params[:election][:polling_stations].compact_blank end def questions @@ -254,7 +254,7 @@ def bulk_votes_file_update_time(election) end def generated_votes_number(election) - `wc -l "#{bulk_votes_file_path(election)}"`.strip.split(" ")[0].to_i + `wc -l "#{bulk_votes_file_path(election)}"`.strip.split[0].to_i end end end diff --git a/bulletin_board/server/app/graphql/decidim_bulletin_board_schema.rb b/bulletin_board/server/app/graphql/decidim_bulletin_board_schema.rb index 7f22edab..169002cb 100644 --- a/bulletin_board/server/app/graphql/decidim_bulletin_board_schema.rb +++ b/bulletin_board/server/app/graphql/decidim_bulletin_board_schema.rb @@ -5,6 +5,6 @@ class DecidimBulletinBoardSchema < GraphQL::Schema query(Types::QueryType) use GraphQL::Guard.new( policy_object: Policies::VisibilityPolicy, - not_authorized: ->(_type, _field) { nil } + not_authorized: ->(_type, _field) {} ) end diff --git a/bulletin_board/server/app/graphql/mutations/base_mutation.rb b/bulletin_board/server/app/graphql/mutations/base_mutation.rb index 330ac2a8..9465e99b 100644 --- a/bulletin_board/server/app/graphql/mutations/base_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/base_mutation.rb @@ -4,8 +4,8 @@ module Mutations class BaseMutation < GraphQL::Schema::Mutation def find_authority(message_id) message_identifier = Decidim::BulletinBoard::MessageIdentifier.new(message_id) - message_identifier.from_authority? && Authority.find_by(unique_id: message_identifier.author_id, api_key: context[:api_key]) || - message_identifier.from_voter? && Authority.find_by(api_key: context[:api_key]) + (message_identifier.from_authority? && Authority.find_by(unique_id: message_identifier.author_id, api_key: context[:api_key])) || + (message_identifier.from_voter? && Authority.find_by(api_key: context[:api_key])) end def find_trustee(message_id) diff --git a/bulletin_board/server/app/graphql/mutations/create_election_mutation.rb b/bulletin_board/server/app/graphql/mutations/create_election_mutation.rb index 7827e029..e0ec737e 100644 --- a/bulletin_board/server/app/graphql/mutations/create_election_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/create_election_mutation.rb @@ -17,10 +17,10 @@ def resolve(message_id:, signed_data:) CreateElection.call(authority, message_id, signed_data) do on(:ok) do |election| - result = { election: election } + result = { election: } end on(:invalid) do |error| - result = { error: error } + result = { error: } end end diff --git a/bulletin_board/server/app/graphql/mutations/end_vote_mutation.rb b/bulletin_board/server/app/graphql/mutations/end_vote_mutation.rb index ce3f0e4f..2132fa07 100644 --- a/bulletin_board/server/app/graphql/mutations/end_vote_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/end_vote_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(authority, message_id, signed_data, EndVoteJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/process_key_ceremony_step_mutation.rb b/bulletin_board/server/app/graphql/mutations/process_key_ceremony_step_mutation.rb index 34c2af4a..517e6166 100644 --- a/bulletin_board/server/app/graphql/mutations/process_key_ceremony_step_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/process_key_ceremony_step_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(trustee, message_id, signed_data, ProcessKeyCeremonyStepJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/process_tally_step_mutation.rb b/bulletin_board/server/app/graphql/mutations/process_tally_step_mutation.rb index 1758305e..7adf2e1d 100644 --- a/bulletin_board/server/app/graphql/mutations/process_tally_step_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/process_tally_step_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(trustee, message_id, signed_data, ProcessTallyStepJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/publish_results_mutation.rb b/bulletin_board/server/app/graphql/mutations/publish_results_mutation.rb index 14f795e9..242fe1b2 100644 --- a/bulletin_board/server/app/graphql/mutations/publish_results_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/publish_results_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(authority, message_id, signed_data, PublishResultsJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/report_missing_trustee_mutation.rb b/bulletin_board/server/app/graphql/mutations/report_missing_trustee_mutation.rb index 1ecb884b..51c03bc2 100644 --- a/bulletin_board/server/app/graphql/mutations/report_missing_trustee_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/report_missing_trustee_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(authority, message_id, signed_data, ReportMissingTrusteeJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/start_key_ceremony_mutation.rb b/bulletin_board/server/app/graphql/mutations/start_key_ceremony_mutation.rb index a8f2731d..4fe00741 100644 --- a/bulletin_board/server/app/graphql/mutations/start_key_ceremony_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/start_key_ceremony_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(authority, message_id, signed_data, StartKeyCeremonyJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/start_tally_mutation.rb b/bulletin_board/server/app/graphql/mutations/start_tally_mutation.rb index 0d2d64fa..abb75a89 100644 --- a/bulletin_board/server/app/graphql/mutations/start_tally_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/start_tally_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(authority, message_id, signed_data, StartTallyJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/start_vote_mutation.rb b/bulletin_board/server/app/graphql/mutations/start_vote_mutation.rb index e87aebe8..3f7ea14a 100644 --- a/bulletin_board/server/app/graphql/mutations/start_vote_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/start_vote_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(authority, message_id, signed_data, StartVoteJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/mutations/vote_mutation.rb b/bulletin_board/server/app/graphql/mutations/vote_mutation.rb index c47bf5ea..1ac94201 100644 --- a/bulletin_board/server/app/graphql/mutations/vote_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/vote_mutation.rb @@ -17,7 +17,7 @@ def resolve(message_id:, signed_data:) EnqueueMessage.call(authority, message_id, signed_data, VoteJob) do on(:ok) do |pending_message| - result = { pending_message: pending_message } + result = { pending_message: } end end diff --git a/bulletin_board/server/app/graphql/types/query_type.rb b/bulletin_board/server/app/graphql/types/query_type.rb index 69d181ca..36061d1b 100644 --- a/bulletin_board/server/app/graphql/types/query_type.rb +++ b/bulletin_board/server/app/graphql/types/query_type.rb @@ -37,7 +37,7 @@ def elections end def election(unique_id:) - Election.find_by(unique_id: unique_id) + Election.find_by(unique_id:) end field :pending_message, diff --git a/bulletin_board/server/app/jobs/sandbox/generate_votes_job.rb b/bulletin_board/server/app/jobs/sandbox/generate_votes_job.rb index dc540845..77d36628 100644 --- a/bulletin_board/server/app/jobs/sandbox/generate_votes_job.rb +++ b/bulletin_board/server/app/jobs/sandbox/generate_votes_job.rb @@ -51,13 +51,13 @@ def remove_existing_file end def random_plaintext_ballot - election.manifest[:description][:contests].map do |contest| + election.manifest[:description][:contests].to_h do |contest| [ contest[:object_id], contest[:ballot_selections].sample(Random.rand(contest[:number_elected] + 1)) .map { |ballot_selection| ballot_selection[:object_id] } ] - end.to_h + end end def election @@ -69,7 +69,7 @@ def client end def log_entry_for(message_type) - election.log_entries.where(message_type: message_type).last + election.log_entries.where(message_type:).last end end end diff --git a/bulletin_board/server/app/models/log_entry.rb b/bulletin_board/server/app/models/log_entry.rb index 0fc83878..678facd3 100644 --- a/bulletin_board/server/app/models/log_entry.rb +++ b/bulletin_board/server/app/models/log_entry.rb @@ -31,7 +31,7 @@ def content def previous_hash return election.unique_id if message_identifier.type == "create_election" - LogEntry.where(election: election).order(id: :desc).pick(:chained_hash) || + LogEntry.where(election:).order(id: :desc).pick(:chained_hash) || raise("No previous hash for #{election.unique_id}") end end diff --git a/bulletin_board/server/app/queries/election_casted_votes.rb b/bulletin_board/server/app/queries/election_casted_votes.rb index 7811d083..c97514d4 100644 --- a/bulletin_board/server/app/queries/election_casted_votes.rb +++ b/bulletin_board/server/app/queries/election_casted_votes.rb @@ -12,7 +12,7 @@ def self.for(election) def query LogEntry.includes(:client).where( - election: election, + election:, message_type: "vote", message_subtype: "cast" ) diff --git a/bulletin_board/server/app/queries/election_in_person_votes.rb b/bulletin_board/server/app/queries/election_in_person_votes.rb index c531edcb..89df986d 100644 --- a/bulletin_board/server/app/queries/election_in_person_votes.rb +++ b/bulletin_board/server/app/queries/election_in_person_votes.rb @@ -12,7 +12,7 @@ def self.for(election) def query LogEntry.where( - election: election, + election:, message_type: "vote", message_subtype: "in_person" ) diff --git a/bulletin_board/server/app/queries/election_voter_vote.rb b/bulletin_board/server/app/queries/election_voter_vote.rb index 7381ea7e..4b1b8423 100644 --- a/bulletin_board/server/app/queries/election_voter_vote.rb +++ b/bulletin_board/server/app/queries/election_voter_vote.rb @@ -13,7 +13,7 @@ def self.for(election, voter_id) def query LogEntry.where( - election: election, + election:, author_unique_id: voter_id ) end diff --git a/bulletin_board/server/app/services/concerns/redis_provider.rb b/bulletin_board/server/app/services/concerns/redis_provider.rb index f5c9fe9e..8dbdeae5 100644 --- a/bulletin_board/server/app/services/concerns/redis_provider.rb +++ b/bulletin_board/server/app/services/concerns/redis_provider.rb @@ -5,9 +5,9 @@ module RedisProvider def redis @redis ||= - if !Rails.env.production? || ENV["SANDBOX"] - redis_host = ENV["REDIS_HOST"] || "localhost" - redis_port = ENV["REDIS_PORT"] || 6379 + if !Rails.env.production? || ENV.fetch("SANDBOX", nil) + redis_host = ENV.fetch("REDIS_HOST", "localhost") + redis_port = ENV.fetch("REDIS_PORT", 6379) Redis.new(host: redis_host, port: redis_port, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) else Redis.new diff --git a/bulletin_board/server/app/services/voting_scheme/dummy/bulletin_board.rb b/bulletin_board/server/app/services/voting_scheme/dummy/bulletin_board.rb index dcced974..addc7e78 100644 --- a/bulletin_board/server/app/services/voting_scheme/dummy/bulletin_board.rb +++ b/bulletin_board/server/app/services/voting_scheme/dummy/bulletin_board.rb @@ -152,7 +152,7 @@ def join_compensations state[:joint_compensations].each do |question, answers| answers.each do |answer, value| state[:joint_shares][question][answer] *= - (value**(1.0 / state[:compensations].count) * state[:joint_election_key]).round + ((value**(1.0 / state[:compensations].count)) * state[:joint_election_key]).round end end end @@ -169,17 +169,17 @@ def join_shares end def build_questions_struct(initial_value) - election.manifest[:description][:contests].map do |contest| + election.manifest[:description][:contests].to_h do |contest| [ contest[:object_id], - contest[:ballot_selections].map do |ballot_selection| + contest[:ballot_selections].to_h do |ballot_selection| [ ballot_selection[:object_id], initial_value ] - end.to_h + end ] - end.to_h + end end end end diff --git a/bulletin_board/server/app/services/voting_scheme/dummy/voter.rb b/bulletin_board/server/app/services/voting_scheme/dummy/voter.rb index deb115f1..181557fe 100644 --- a/bulletin_board/server/app/services/voting_scheme/dummy/voter.rb +++ b/bulletin_board/server/app/services/voting_scheme/dummy/voter.rb @@ -19,7 +19,7 @@ def encrypt(vote) plaintext = vote[contest[:object_id]].present? && vote[contest[:object_id]].include?(ballot_selection[:object_id]) ? 1 : 0 { object_id: ballot_selection[:object_id], - ciphertext: plaintext + (rand * 500).floor * joint_election_key + ciphertext: plaintext + ((rand * 500).floor * joint_election_key) } end } diff --git a/bulletin_board/server/bin/bundle b/bulletin_board/server/bin/bundle index 56bb728d..cdd44a7e 100755 --- a/bulletin_board/server/bin/bundle +++ b/bulletin_board/server/bin/bundle @@ -18,7 +18,7 @@ m = Module.new do end def env_var_version - ENV["BUNDLER_VERSION"] + ENV.fetch("BUNDLER_VERSION", nil) end def cli_arg_version @@ -38,7 +38,7 @@ m = Module.new do end def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] + gemfile = ENV.fetch("BUNDLE_GEMFILE", nil) return gemfile if gemfile && !gemfile.empty? # rubocop:disable Rails/Present File.expand_path("../Gemfile", __dir__) @@ -63,10 +63,8 @@ m = Module.new do end def bundler_version - @bundler_version ||= begin - env_var_version || cli_arg_version || - lockfile_version || "#{Gem::Requirement.default}.a" - end + @bundler_version ||= env_var_version || cli_arg_version || + lockfile_version || "#{Gem::Requirement.default}.a" end def load_bundler! diff --git a/bulletin_board/server/bin/webpack b/bulletin_board/server/bin/webpack index 49a066b7..9af82483 100755 --- a/bulletin_board/server/bin/webpack +++ b/bulletin_board/server/bin/webpack @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" +ENV["RAILS_ENV"] ||= ENV.fetch("RACK_ENV", "development") ENV["NODE_ENV"] ||= "development" require "pathname" diff --git a/bulletin_board/server/bin/webpack-dev-server b/bulletin_board/server/bin/webpack-dev-server index 6a06d251..592934f6 100755 --- a/bulletin_board/server/bin/webpack-dev-server +++ b/bulletin_board/server/bin/webpack-dev-server @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" +ENV["RAILS_ENV"] ||= ENV.fetch("RACK_ENV", "development") ENV["NODE_ENV"] ||= "development" require "pathname" diff --git a/bulletin_board/server/config/initializers/sidekiq.rb b/bulletin_board/server/config/initializers/sidekiq.rb index 7ccd4c22..e4418628 100644 --- a/bulletin_board/server/config/initializers/sidekiq.rb +++ b/bulletin_board/server/config/initializers/sidekiq.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if Rails.env.production? || ENV["SANDBOX"] +if Rails.env.production? || ENV.fetch("SANDBOX", nil) Sidekiq.configure_server do |config| config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } } end diff --git a/bulletin_board/server/config/routes.rb b/bulletin_board/server/config/routes.rb index 7c393d4b..e80cd628 100644 --- a/bulletin_board/server/config/routes.rb +++ b/bulletin_board/server/config/routes.rb @@ -11,7 +11,7 @@ root to: "pages#index" - if !Rails.env.production? || ENV["SANDBOX"] + if !Rails.env.production? || ENV.fetch("SANDBOX", nil) mount Sidekiq::Web => "/sidekiq" scope "/sandbox", module: :sandbox, as: :sandbox do resources :elections, only: [:new, :create, :index] do diff --git a/bulletin_board/server/cypress/app_commands/scenarios/election.rb b/bulletin_board/server/cypress/app_commands/scenarios/election.rb index af19c175..018afb5b 100644 --- a/bulletin_board/server/cypress/app_commands/scenarios/election.rb +++ b/bulletin_board/server/cypress/app_commands/scenarios/election.rb @@ -19,5 +19,5 @@ end { - trustees: trustees + trustees: } diff --git a/bulletin_board/server/cypress/cypress_helper.rb b/bulletin_board/server/cypress/cypress_helper.rb index a6422810..8d3833a8 100644 --- a/bulletin_board/server/cypress/cypress_helper.rb +++ b/bulletin_board/server/cypress/cypress_helper.rb @@ -27,7 +27,7 @@ CypressOnRails::SmartFactoryWrapper.configure( always_reload: !Rails.configuration.cache_classes, - factory: factory, + factory:, files: [ Rails.root.join("spec/factories.rb"), Rails.root.join("spec/factories/**/*.rb") diff --git a/bulletin_board/server/db/migrate/20201028151442_add_unique_id_to_client_and_elections.rb b/bulletin_board/server/db/migrate/20201028151442_add_unique_id_to_client_and_elections.rb index f1ac3b18..bed9b204 100644 --- a/bulletin_board/server/db/migrate/20201028151442_add_unique_id_to_client_and_elections.rb +++ b/bulletin_board/server/db/migrate/20201028151442_add_unique_id_to_client_and_elections.rb @@ -2,8 +2,11 @@ class AddUniqueIdToClientAndElections < ActiveRecord::Migration[6.1] class Election < ApplicationRecord; end + class Client < ApplicationRecord; end + class Authority < Client; end + class Trustee < Client; end def change diff --git a/bulletin_board/server/db/migrate/20201207160752_add_content_hash_to_log_entries.rb b/bulletin_board/server/db/migrate/20201207160752_add_content_hash_to_log_entries.rb index 155419b8..bc92bb16 100644 --- a/bulletin_board/server/db/migrate/20201207160752_add_content_hash_to_log_entries.rb +++ b/bulletin_board/server/db/migrate/20201207160752_add_content_hash_to_log_entries.rb @@ -2,6 +2,7 @@ class AddContentHashToLogEntries < ActiveRecord::Migration[6.1] def change - add_column :log_entries, :content_hash, :string, null: true, index: true + add_column :log_entries, :content_hash, :string, null: true + add_index :log_entries, :content_hash end end diff --git a/bulletin_board/server/db/schema.rb b/bulletin_board/server/db/schema.rb index 4f9a6311..403f83f9 100644 --- a/bulletin_board/server/db/schema.rb +++ b/bulletin_board/server/db/schema.rb @@ -96,6 +96,7 @@ t.string "message_subtype" t.index ["chained_hash"], name: "index_log_entries_on_chained_hash", unique: true t.index ["client_id"], name: "index_log_entries_on_client_id" + t.index ["content_hash"], name: "index_log_entries_on_content_hash" t.index ["election_id", "message_type", "message_subtype", "author_unique_id"], name: "index_log_entries_on_type_subtype_author" t.index ["election_id"], name: "index_log_entries_on_election_id" t.index ["iat"], name: "index_log_entries_on_iat" diff --git a/bulletin_board/server/db/seeds.rb b/bulletin_board/server/db/seeds.rb index 5d64205b..9eb5a0a2 100644 --- a/bulletin_board/server/db/seeds.rb +++ b/bulletin_board/server/db/seeds.rb @@ -7,92 +7,92 @@ def create_start_key_ceremony_log_entry(election) FactoryBot.create(:log_entry, - election: election, + election:, message: FactoryBot.build(:start_key_ceremony_message, - election: election)) + election:)) end def create_key_ceremony_log_entries(election) Trustee.first(3).zip(Test::PrivateKeys.trustees_private_keys, Test::Elections.trustees_election_keys).each do |trustee, private_key, election_key| FactoryBot.create(:log_entry, - election: election, + election:, client: trustee, - private_key: private_key, + private_key:, message: FactoryBot.build(:key_ceremony_message, election_public_key: election_key, - election: election, - trustee: trustee)) + election:, + trustee:)) end end def create_end_key_ceremony_log_entry(election) FactoryBot.create(:log_entry, :by_bulletin_board, - election: election, + election:, message: FactoryBot.build(:end_key_ceremony_message, - election: election)) + election:)) end def create_start_vote_log_entry(election) FactoryBot.create(:log_entry, - election: election, + election:, message: FactoryBot.build(:start_vote_message, - election: election)) + election:)) end def create_vote_log_entries(election, amount = 3) amount.times do - vote_message = FactoryBot.build(:vote_message, election: election) - FactoryBot.create(:pending_message, :accepted, election: election, message: vote_message) - FactoryBot.create(:log_entry, election: election, message: vote_message) + vote_message = FactoryBot.build(:vote_message, election:) + FactoryBot.create(:pending_message, :accepted, election:, message: vote_message) + FactoryBot.create(:log_entry, election:, message: vote_message) end end def create_end_vote_log_entry(election) FactoryBot.create(:log_entry, - election: election, + election:, message: FactoryBot.build(:end_vote_message, - election: election)) + election:)) end def create_start_tally_log_entries(election) FactoryBot.create(:log_entry, - election: election, + election:, message: FactoryBot.build(:start_tally_message, - election: election)) + election:)) FactoryBot.create(:log_entry, :by_bulletin_board, - election: election, + election:, message: FactoryBot.build(:tally_cast_message, - election: election)) + election:)) end def create_tally_log_entries(election) Trustee.first(3).zip(Test::PrivateKeys.trustees_private_keys, Test::Elections.trustees_election_keys).each do |trustee, private_key, election_key| FactoryBot.create(:log_entry, - election: election, + election:, client: trustee, - private_key: private_key, + private_key:, message: FactoryBot.build(:tally_share_message, election_public_key: election_key, - election: election, - trustee: trustee)) + election:, + trustee:)) end end def create_end_tally_log_entry(election) FactoryBot.create(:log_entry, :by_bulletin_board, - election: election, + election:, message: FactoryBot.build(:end_tally_message, - election: election)) + election:)) end def create_publish_results_log_entry(election) FactoryBot.create(:log_entry, - election: election, + election:, message: FactoryBot.build(:publish_results_message, - election: election)) + election:)) end Authority.create!( diff --git a/bulletin_board/server/lib/tasks/client/add_authority.rake b/bulletin_board/server/lib/tasks/client/add_authority.rake index 819480eb..71012f8b 100644 --- a/bulletin_board/server/lib/tasks/client/add_authority.rake +++ b/bulletin_board/server/lib/tasks/client/add_authority.rake @@ -16,7 +16,7 @@ namespace :client do next end - authority = Authority.new(name: name, public_key: public_key, public_key_thumbprint: public_key_thumbprint, api_key: generate_api_key) + authority = Authority.new(name:, public_key:, public_key_thumbprint:, api_key: generate_api_key) begin authority.save! puts "Authority '#{authority.name}' successfuly added!" @@ -37,7 +37,7 @@ namespace :client do jwk = JWT::JWK.import(jwk) - jwk.export.yield_self do |hash| + jwk.export.then do |hash| [hash, Decidim::BulletinBoard::JwkUtils.thumbprint(hash)] end end diff --git a/bulletin_board/server/lib/test/elections.rb b/bulletin_board/server/lib/test/elections.rb index 5eb0b1da..a75a2f0d 100644 --- a/bulletin_board/server/lib/test/elections.rb +++ b/bulletin_board/server/lib/test/elections.rb @@ -12,17 +12,17 @@ def joint_election_key end def build_cast(election) - election.manifest[:description][:contests].map do |contest| + election.manifest[:description][:contests].to_h do |contest| [ contest[:object_id], - contest[:ballot_selections].map do |ballot_selection| + contest[:ballot_selections].to_h do |ballot_selection| [ ballot_selection[:object_id], yield ] - end.to_h + end ] - end.to_h + end end end end diff --git a/bulletin_board/server/spec/commands/end_vote_spec.rb b/bulletin_board/server/spec/commands/end_vote_spec.rb index 545283fd..a515c9ac 100644 --- a/bulletin_board/server/spec/commands/end_vote_spec.rb +++ b/bulletin_board/server/spec/commands/end_vote_spec.rb @@ -12,7 +12,7 @@ let(:election_status) { :vote } let(:client) { Authority.first } let(:message_type) { :end_vote_message } - let(:message_params) { { election: election } } + let(:message_params) { { election: } } it "broadcasts ok" do expect { subject }.to broadcast(:ok, election) @@ -57,7 +57,7 @@ end context "when the client is not the election authority" do - let(:client) { create(:authority, private_key: private_key) } + let(:client) { create(:authority, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "ending the voting period fails" diff --git a/bulletin_board/server/spec/commands/enqueue_message_spec.rb b/bulletin_board/server/spec/commands/enqueue_message_spec.rb index da2079a1..1286398b 100644 --- a/bulletin_board/server/spec/commands/enqueue_message_spec.rb +++ b/bulletin_board/server/spec/commands/enqueue_message_spec.rb @@ -46,7 +46,7 @@ describe "broadcasting invalid" do context "with pending messages" do - let!(:pending_message) { create(:pending_message, :message_model, election: election, client: client, message_id: message_id) } + let!(:pending_message) { create(:pending_message, :message_model, election:, client:, message_id:) } it "is not valid" do expect { subject }.to broadcast(:invalid) diff --git a/bulletin_board/server/spec/commands/process_key_ceremony_step_spec.rb b/bulletin_board/server/spec/commands/process_key_ceremony_step_spec.rb index d60a05dc..75e42779 100644 --- a/bulletin_board/server/spec/commands/process_key_ceremony_step_spec.rb +++ b/bulletin_board/server/spec/commands/process_key_ceremony_step_spec.rb @@ -8,13 +8,13 @@ include_context "with a signed message" - let!(:election) { create(:election, :key_ceremony, trustees_done: trustees_done) } + let!(:election) { create(:election, :key_ceremony, trustees_done:) } let(:trustees_done) { [] } let(:trustee) { Trustee.first } let(:client) { trustee } let(:private_key) { Test::PrivateKeys.trustees_private_keys.first } let(:message_type) { :key_ceremony_message } - let(:message_params) { { election: election, trustee: trustee } } + let(:message_params) { { election:, trustee: } } it "broadcasts ok" do expect { subject }.to broadcast(:ok) @@ -95,7 +95,7 @@ end context "when the client is not an election trustee" do - let(:trustee) { create(:trustee, private_key: private_key) } + let(:trustee) { create(:trustee, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "key ceremony fails" diff --git a/bulletin_board/server/spec/commands/process_tally_step_spec.rb b/bulletin_board/server/spec/commands/process_tally_step_spec.rb index 7001d7a9..b4d535e7 100644 --- a/bulletin_board/server/spec/commands/process_tally_step_spec.rb +++ b/bulletin_board/server/spec/commands/process_tally_step_spec.rb @@ -8,13 +8,13 @@ include_context "with a signed message" - let!(:election) { create(:election, :tally_started, trustees_done: trustees_done) } + let!(:election) { create(:election, :tally_started, trustees_done:) } let(:trustees_done) { [] } let(:trustee) { Trustee.first } let(:client) { trustee } let(:private_key) { Test::PrivateKeys.trustees_private_keys.first } let(:message_type) { :tally_share_message } - let(:message_params) { { election: election, trustee: trustee } } + let(:message_params) { { election:, trustee: } } it "broadcasts ok" do expect { subject }.to broadcast(:ok) @@ -103,7 +103,7 @@ end context "when the client is not an election trustee" do - let(:trustee) { create(:trustee, private_key: private_key) } + let(:trustee) { create(:trustee, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "tally fails" diff --git a/bulletin_board/server/spec/commands/publish_results_spec.rb b/bulletin_board/server/spec/commands/publish_results_spec.rb index be3b847b..3f716d07 100644 --- a/bulletin_board/server/spec/commands/publish_results_spec.rb +++ b/bulletin_board/server/spec/commands/publish_results_spec.rb @@ -12,7 +12,7 @@ let(:election_status) { :tally_ended } let(:client) { Authority.first } let(:message_type) { :publish_results_message } - let(:message_params) { { election: election } } + let(:message_params) { { election: } } it "broadcasts ok" do expect { subject }.to broadcast(:ok, election) @@ -82,7 +82,7 @@ end context "when the client is not the election authority" do - let(:client) { create(:authority, private_key: private_key) } + let(:client) { create(:authority, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "publishing results fails" diff --git a/bulletin_board/server/spec/commands/report_missing_trustee_spec.rb b/bulletin_board/server/spec/commands/report_missing_trustee_spec.rb index 359994d6..64ba164b 100644 --- a/bulletin_board/server/spec/commands/report_missing_trustee_spec.rb +++ b/bulletin_board/server/spec/commands/report_missing_trustee_spec.rb @@ -12,7 +12,7 @@ let(:election_status) { :tally_started } let(:client) { Authority.first } let(:message_type) { :report_missing_trustee_message } - let(:message_params) { { election: election } } + let(:message_params) { { election: } } shared_examples "reporting the missing trustee fails" do it "doesn't create a log entry" do @@ -45,7 +45,7 @@ end context "when the client is not the election authority" do - let(:client) { create(:authority, private_key: private_key) } + let(:client) { create(:authority, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "reporting the missing trustee fails" diff --git a/bulletin_board/server/spec/commands/shared/log_entry_validations.rb b/bulletin_board/server/spec/commands/shared/log_entry_validations.rb index 1692c0e5..346d5989 100644 --- a/bulletin_board/server/spec/commands/shared/log_entry_validations.rb +++ b/bulletin_board/server/spec/commands/shared/log_entry_validations.rb @@ -26,7 +26,7 @@ it_behaves_like examples it "broadcasts invalid" do - expect { subject }.to broadcast(:invalid, "Signature verification raised") + expect { subject }.to broadcast(:invalid, "Signature verification failed") end end diff --git a/bulletin_board/server/spec/commands/start_key_ceremony_spec.rb b/bulletin_board/server/spec/commands/start_key_ceremony_spec.rb index 5bf11887..a47bbe9f 100644 --- a/bulletin_board/server/spec/commands/start_key_ceremony_spec.rb +++ b/bulletin_board/server/spec/commands/start_key_ceremony_spec.rb @@ -12,7 +12,7 @@ let(:election_status) { :created } let(:client) { Authority.first } let(:message_type) { :start_key_ceremony_message } - let(:message_params) { { election: election } } + let(:message_params) { { election: } } shared_examples "starting the key ceremony fails" do it "doesn't create a log entry" do @@ -53,7 +53,7 @@ end context "when the client is not the election authority" do - let(:client) { create(:authority, private_key: private_key) } + let(:client) { create(:authority, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "starting the key ceremony fails" diff --git a/bulletin_board/server/spec/commands/start_tally_spec.rb b/bulletin_board/server/spec/commands/start_tally_spec.rb index 743b64dc..1bb76d22 100644 --- a/bulletin_board/server/spec/commands/start_tally_spec.rb +++ b/bulletin_board/server/spec/commands/start_tally_spec.rb @@ -12,7 +12,7 @@ let(:election_status) { :vote_ended } let(:client) { Authority.first } let(:message_type) { :start_tally_message } - let(:message_params) { { election: election } } + let(:message_params) { { election: } } shared_examples "starting the tally fails" do it "doesn't create a log entry" do @@ -53,7 +53,7 @@ end context "when the client is not the election authority" do - let(:client) { create(:authority, private_key: private_key) } + let(:client) { create(:authority, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "starting the tally fails" diff --git a/bulletin_board/server/spec/commands/start_vote_spec.rb b/bulletin_board/server/spec/commands/start_vote_spec.rb index 9ceada5c..777daad4 100644 --- a/bulletin_board/server/spec/commands/start_vote_spec.rb +++ b/bulletin_board/server/spec/commands/start_vote_spec.rb @@ -12,7 +12,7 @@ let(:election_status) { :key_ceremony_ended } let(:client) { Authority.first } let(:message_type) { :start_vote_message } - let(:message_params) { { election: election } } + let(:message_params) { { election: } } it "broadcasts ok" do expect { subject }.to broadcast(:ok, election) @@ -57,7 +57,7 @@ end context "when the client is not the election authority" do - let(:client) { create(:authority, private_key: private_key) } + let(:client) { create(:authority, private_key:) } let(:private_key) { generate(:private_key) } it_behaves_like "starting the voting period fails" diff --git a/bulletin_board/server/spec/commands/vote_spec.rb b/bulletin_board/server/spec/commands/vote_spec.rb index a85f94eb..8275de47 100644 --- a/bulletin_board/server/spec/commands/vote_spec.rb +++ b/bulletin_board/server/spec/commands/vote_spec.rb @@ -12,7 +12,7 @@ let(:election_status) { :vote } let(:client) { Authority.first } let(:message_type) { :vote_message } - let(:message_params) { { election: election, voter_id: voter_id } } + let(:message_params) { { election:, voter_id: } } let(:voter_id) { generate(:voter_id) } it "broadcasts ok" do @@ -57,7 +57,7 @@ end context "when the client is not the election authority" do - let(:client) { create(:authority, private_key: private_key) } + let(:client) { create(:authority, private_key:) } let(:private_key) { generate(:private_key) } it "broadcasts invalid" do @@ -76,7 +76,7 @@ context "when the message author is not a voter" do let(:message_id) { "#{election.unique_id}.vote.cast+x.#{voter_id}" } - let(:extra_message_params) { { message_id: message_id } } + let(:extra_message_params) { { message_id: } } it "broadcasts invalid" do expect { subject }.to broadcast(:invalid, "Invalid message author") @@ -84,8 +84,8 @@ end context "when the voter has already voted in person" do - let!(:in_person_vote) { create(:log_entry, election: election, message: previous_message) } - let(:previous_message) { build(:in_person_vote_message, election: election, voter_id: voter_id) } + let!(:in_person_vote) { create(:log_entry, election:, message: previous_message) } + let(:previous_message) { build(:in_person_vote_message, election:, voter_id:) } it "broadcasts invalid" do expect { subject }.to broadcast(:invalid, "Can't cast a vote after voting in person.") @@ -105,8 +105,8 @@ end context "when the voter has already voted in person" do - let!(:in_person_vote) { create(:log_entry, election: election, message: previous_message) } - let(:previous_message) { build(:in_person_vote_message, election: election, voter_id: voter_id) } + let!(:in_person_vote) { create(:log_entry, election:, message: previous_message) } + let(:previous_message) { build(:in_person_vote_message, election:, voter_id:) } it "broadcasts invalid" do expect { subject }.to broadcast(:invalid, "Can't cast a vote after voting in person.") diff --git a/bulletin_board/server/spec/factories/electionguard.rb b/bulletin_board/server/spec/factories/electionguard.rb index b68d5503..9d91132b 100644 --- a/bulletin_board/server/spec/factories/electionguard.rb +++ b/bulletin_board/server/spec/factories/electionguard.rb @@ -19,7 +19,7 @@ factory :electionguard_election, class: "Election" do transient do authority_private_key { generate(:private_key) } - trustees_plus_keys { generate_list(:private_key, 3).zip(ELECTION_TRUSTEES_IDS).map { |private_key, id| [build(:trustee, unique_id: id, private_key: private_key), private_key] } } + trustees_plus_keys { generate_list(:private_key, 3).zip(ELECTION_TRUSTEES_IDS).map { |private_key, id| [build(:trustee, unique_id: id, private_key:), private_key] } } last_step { :end_key_ceremony } voting_scheme { :electionguard } end @@ -53,7 +53,7 @@ def create_election_step(election, evaluator) create_election_message["trustees"][order]["public_key"] = trustee.public_key end - election.log_entries << FactoryBot.build(:log_entry, election: election, client: election.authority, + election.log_entries << FactoryBot.build(:log_entry, election:, client: election.authority, private_key: evaluator.authority_private_key, message: create_election_message) end @@ -62,7 +62,7 @@ def start_key_ceremony_step(election, evaluator) start_key_ceremony_message["iat"] = Time.current.to_i start_key_ceremony_message["message_id"] = "#{election.unique_id}.start_key_ceremony+a.#{election.authority.slug}" - election.log_entries << FactoryBot.build(:log_entry, election: election, client: election.authority, + election.log_entries << FactoryBot.build(:log_entry, election:, client: election.authority, private_key: evaluator.authority_private_key, message: start_key_ceremony_message) end @@ -77,8 +77,8 @@ def trustee_election_keys_step(election, evaluator) trustee_public_key_message["iat"] = Time.current.to_i trustee_public_key_message["message_id"] = "#{election.unique_id}.key_ceremony.trustee_election_keys+t.#{trustee.slug}" - election.log_entries << FactoryBot.build(:log_entry, election: election, client: trustee, - private_key: private_key, message: trustee_public_key_message) + election.log_entries << FactoryBot.build(:log_entry, election:, client: trustee, + private_key:, message: trustee_public_key_message) end end @@ -92,8 +92,8 @@ def trustee_partial_election_keys_step(election, evaluator) trustee_partial_public_key_message["iat"] = Time.current.to_i trustee_partial_public_key_message["message_id"] = "#{election.unique_id}.key_ceremony.trustee_partial_election_keys+t.#{trustee.slug}" - election.log_entries << FactoryBot.build(:log_entry, election: election, client: trustee, - private_key: private_key, message: trustee_partial_public_key_message) + election.log_entries << FactoryBot.build(:log_entry, election:, client: trustee, + private_key:, message: trustee_partial_public_key_message) end end @@ -107,8 +107,8 @@ def trustee_verification_step(election, evaluator) trustee_verification_message["iat"] = Time.current.to_i trustee_verification_message["message_id"] = "#{election.unique_id}.key_ceremony.trustee_verification+t.#{trustee.slug}" - election.log_entries << FactoryBot.build(:log_entry, election: election, client: trustee, - private_key: private_key, message: trustee_verification_message) + election.log_entries << FactoryBot.build(:log_entry, election:, client: trustee, + private_key:, message: trustee_verification_message) end end @@ -117,6 +117,6 @@ def end_key_ceremony_step(election, _evaluator) end_key_ceremony_message["iat"] = Time.current.to_i end_key_ceremony_message["message_id"] = "#{election.unique_id}.end_key_ceremony+b.#{BulletinBoard.slug}" - election.log_entries << FactoryBot.build(:log_entry, election: election, bulletin_board: true, + election.log_entries << FactoryBot.build(:log_entry, election:, bulletin_board: true, signed_data: BulletinBoard.sign(end_key_ceremony_message), message: end_key_ceremony_message) end diff --git a/bulletin_board/server/spec/factories/messages.rb b/bulletin_board/server/spec/factories/messages.rb index cfdbd458..64d3afc8 100644 --- a/bulletin_board/server/spec/factories/messages.rb +++ b/bulletin_board/server/spec/factories/messages.rb @@ -55,9 +55,9 @@ def fix_reserved_names(attributes) scheme { build(:voting_scheme, name: voting_scheme) } bulletin_board { build(:json_bulletin_board) } authority { build(:json_authority, authority: authority_client) } - trustees { trustees_plus_keys.map { |trustee, private_key| build(:json_trustee, trustee: trustee, private_key: private_key) } } + trustees { trustees_plus_keys.map { |trustee, private_key| build(:json_trustee, trustee:, private_key:) } } polling_stations { [] } - description { build(:description, number_of_questions: number_of_questions, start_date: start_date, title: title) } + description { build(:description, number_of_questions:, start_date:, title:) } end factory :voting_scheme do @@ -143,7 +143,7 @@ def fix_reserved_names(attributes) value { Faker::Quotes::Shakespeare.as_you_like_it } end - text { build_list(:text_value, 1, value: value) } + text { build_list(:text_value, 1, value:) } end factory :text_value do @@ -185,7 +185,7 @@ def fix_reserved_names(attributes) "#{election.unique_id}.key_ceremony.trustee_election_keys+t.#{trustee.slug}" end end - content { build(:key_ceremony_message_content, *content_traits, election: election, trustee: trustee).to_json } + content { build(:key_ceremony_message_content, *content_traits, election:, trustee:).to_json } end factory :key_ceremony_message_content do @@ -213,7 +213,7 @@ def fix_reserved_names(attributes) end message_id { "#{election.unique_id}.end_key_ceremony+b.#{BulletinBoard.slug}" } - content { build(:joint_election_message_content, *content_traits, election: election).to_json } + content { build(:joint_election_message_content, *content_traits, election:).to_json } end factory :joint_election_message_content do @@ -240,7 +240,7 @@ def fix_reserved_names(attributes) end message_id { "#{election.unique_id}.vote.cast+v.#{voter_id}" } - content { build(:vote_message_content, *content_traits, election: election).to_json } + content { build(:vote_message_content, *content_traits, election:).to_json } end factory :vote_message_content do @@ -263,7 +263,7 @@ def fix_reserved_names(attributes) ballot_selections: contest[:ballot_selections].map do |ballot_selection| { object_id: ballot_selection[:object_id], - ciphertext: (selection.member?(ballot_selection) ? 1 : 0) + Random.random_number(500) * evaluator.joint_election_key + ciphertext: (selection.member?(ballot_selection) ? 1 : 0) + (Random.random_number(500) * evaluator.joint_election_key) } end } @@ -306,7 +306,7 @@ def fix_reserved_names(attributes) end message_id { "#{election.unique_id}.tally.cast+b.#{BulletinBoard.slug}" } - content { Test::Elections.build_cast(election) { Random.random_number(99) + Random.random_number(13) * joint_election_key }.to_json } + content { Test::Elections.build_cast(election) { Random.random_number(99) + (Random.random_number(13) * joint_election_key) }.to_json } end factory :tally_share_message, parent: :message do @@ -314,12 +314,12 @@ def fix_reserved_names(attributes) election { create(:election, :tally_started) } trustee { Trustee.first } joint_election_key { Test::Elections.joint_election_key } - tally_cast { Test::Elections.build_cast(election) { Random.random_number(99) + Random.random_number(13) * joint_election_key } } + tally_cast { Test::Elections.build_cast(election) { Random.random_number(99) + (Random.random_number(13) * joint_election_key) } } election_public_key { Test::Elections.trustees_election_keys.first } end message_id { "#{election.unique_id}.tally.share+t.#{trustee.slug}" } - content { build(:tally_share_message_content, *content_traits, election: election, trustee: trustee, tally_cast: tally_cast, election_public_key: election_public_key).to_json } + content { build(:tally_share_message_content, *content_traits, election:, trustee:, tally_cast:, election_public_key:).to_json } end factory :tally_share_message_content do @@ -327,7 +327,7 @@ def fix_reserved_names(attributes) election { create(:election, :tally_started) } trustee { Trustee.first } joint_election_key { Test::Elections.joint_election_key } - tally_cast { Test::Elections.build_cast(election) { Random.random_number(99) + Random.random_number(13) * joint_election_key } } + tally_cast { Test::Elections.build_cast(election) { Random.random_number(99) + (Random.random_number(13) * joint_election_key) } } election_public_key { Test::Elections.trustees_election_keys.first } end @@ -338,17 +338,17 @@ def fix_reserved_names(attributes) end after(:build) do |content, evaluator| - content[:contests] = evaluator.tally_cast.map do |question, answers| + content[:contests] = evaluator.tally_cast.to_h do |question, answers| [ question, - answers.map do |answer, votes_sum| + answers.to_h do |answer, votes_sum| [ answer, (votes_sum % evaluator.election_public_key) * evaluator.election_public_key ] - end.to_h + end ] - end.to_h + end end end @@ -368,23 +368,23 @@ def fix_reserved_names(attributes) election { create(:election, :tally_ended) } authority { Authority.first } joint_election_key { Test::Elections.joint_election_key } - tally_cast { Test::Elections.build_cast(election) { Random.random_number(99) + Random.random_number(13) * joint_election_key } } + tally_cast { Test::Elections.build_cast(election) { Random.random_number(99) + (Random.random_number(13) * joint_election_key) } } end message_id { "#{election.unique_id}.end_tally+b.#{BulletinBoard.slug}" } after(:build) do |message, evaluator| - message[:results] = evaluator.tally_cast.map do |question, answers| + message[:results] = evaluator.tally_cast.to_h do |question, answers| [ question, - answers.map do |answer, votes_sum| + answers.to_h do |answer, votes_sum| [ answer, votes_sum % evaluator.joint_election_key ] - end.to_h + end ] - end.to_h + end end end diff --git a/bulletin_board/server/spec/factories/models.rb b/bulletin_board/server/spec/factories/models.rb index 542f0051..bf86aea8 100644 --- a/bulletin_board/server/spec/factories/models.rb +++ b/bulletin_board/server/spec/factories/models.rb @@ -43,7 +43,7 @@ after(:build) do |election, evaluator| election.trustees << evaluator.trustees_plus_keys.map(&:first) - election.log_entries << build(:log_entry, election: election, private_key: evaluator.authority_private_key, + election.log_entries << build(:log_entry, election:, private_key: evaluator.authority_private_key, message: build(:create_election_message, election_id: election.unique_id, authority_client: election.authority, voting_scheme: evaluator.voting_scheme, @@ -91,7 +91,7 @@ election.voting_scheme_state = JSON.generate(quorum: 2, joint_election_key: Test::Elections.joint_election_key, trustees: evaluator.trustees_plus_keys.map(&:first).map(&:slug), - joint_shares: joint_shares, + joint_shares:, shares: evaluator.trustees_done.map(&:slug), compensations: [], joint_compensations: {}, missing: []) end @@ -101,10 +101,10 @@ status { :tally_ended } after(:build) do |election, evaluator| - joint_shares = Test::Elections.build_cast(election) { Random.random_number(99) + Random.random_number(13) * Test::Elections.joint_election_key } + joint_shares = Test::Elections.build_cast(election) { Random.random_number(99) + (Random.random_number(13) * Test::Elections.joint_election_key) } election.voting_scheme_state = JSON.generate(joint_election_key: Test::Elections.joint_election_key, trustees: evaluator.trustees_plus_keys.map(&:first).map(&:slug), - joint_shares: joint_shares, + joint_shares:, shares: evaluator.trustees_plus_keys.map(&:first).map(&:slug), compensations: [], joint_compensations: {}, missing: []) end @@ -117,7 +117,7 @@ after(:build) do |election, _evaluator| verifiable_results_path = File.expand_path("assets/verifiable-results.tar", __dir__) election.verifiable_results.attach(io: File.open(verifiable_results_path), filename: "verifiable-results.tar") - election.verifiable_results_hash = Digest::SHA256.base64digest(File.open(verifiable_results_path).read) + election.verifiable_results_hash = Digest::SHA256.base64digest(File.read(verifiable_results_path)) end end end @@ -148,14 +148,14 @@ trait :vote do transient do - message { build(:vote_message, election: election, voter_id: voter_id) } + message { build(:vote_message, election:, voter_id:) } voter_id { generate(:voter_id) } end end trait :in_person_vote do transient do - message { build(:in_person_vote_message, election: election, voter_id: voter_id) } + message { build(:in_person_vote_message, election:, voter_id:) } voter_id { generate(:voter_id) } end end diff --git a/bulletin_board/server/spec/jobs/end_vote_job_spec.rb b/bulletin_board/server/spec/jobs/end_vote_job_spec.rb index 06a6269a..e5ff728d 100644 --- a/bulletin_board/server/spec/jobs/end_vote_job_spec.rb +++ b/bulletin_board/server/spec/jobs/end_vote_job_spec.rb @@ -5,9 +5,9 @@ RSpec.describe EndVoteJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message) } + let!(:pending_message) { create(:pending_message, election:, message:) } let(:election) { create(:election, :vote) } - let(:message) { build(:end_vote_message, election: election) } + let(:message) { build(:end_vote_message, election:) } it "processes the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("accepted") diff --git a/bulletin_board/server/spec/jobs/process_key_ceremony_step_job_spec.rb b/bulletin_board/server/spec/jobs/process_key_ceremony_step_job_spec.rb index 0714866e..d8dbaa2e 100644 --- a/bulletin_board/server/spec/jobs/process_key_ceremony_step_job_spec.rb +++ b/bulletin_board/server/spec/jobs/process_key_ceremony_step_job_spec.rb @@ -5,11 +5,11 @@ RSpec.describe ProcessKeyCeremonyStepJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message, client: trustee, private_key: private_key) } + let!(:pending_message) { create(:pending_message, election:, message:, client: trustee, private_key:) } let(:election) { create(:election, :key_ceremony) } let(:trustee) { Trustee.first } let(:private_key) { Test::PrivateKeys.trustees_private_keys.first } - let(:message) { build(:key_ceremony_message, content_traits: content_traits, election: election) } + let(:message) { build(:key_ceremony_message, content_traits:, election:) } let(:content_traits) { [] } it "processes the message" do diff --git a/bulletin_board/server/spec/jobs/process_tally_step_job_spec.rb b/bulletin_board/server/spec/jobs/process_tally_step_job_spec.rb index 20668ddc..f1b8e900 100644 --- a/bulletin_board/server/spec/jobs/process_tally_step_job_spec.rb +++ b/bulletin_board/server/spec/jobs/process_tally_step_job_spec.rb @@ -5,11 +5,11 @@ RSpec.describe ProcessTallyStepJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message, client: trustee, private_key: private_key) } + let!(:pending_message) { create(:pending_message, election:, message:, client: trustee, private_key:) } let(:election) { create(:election, :tally_started) } let(:trustee) { Trustee.first } let(:private_key) { Test::PrivateKeys.trustees_private_keys.first } - let(:message) { build(:tally_share_message, content_traits: content_traits, election: election, trustee: trustee) } + let(:message) { build(:tally_share_message, content_traits:, election:, trustee:) } let(:content_traits) { [] } it "processes the message" do diff --git a/bulletin_board/server/spec/jobs/publish_results_job_spec.rb b/bulletin_board/server/spec/jobs/publish_results_job_spec.rb index b0135dfe..6de9e165 100644 --- a/bulletin_board/server/spec/jobs/publish_results_job_spec.rb +++ b/bulletin_board/server/spec/jobs/publish_results_job_spec.rb @@ -5,9 +5,9 @@ RSpec.describe PublishResultsJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message) } + let!(:pending_message) { create(:pending_message, election:, message:) } let(:election) { create(:election, :tally_ended) } - let(:message) { build(:publish_results_message, election: election) } + let(:message) { build(:publish_results_message, election:) } it "processes the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("accepted") diff --git a/bulletin_board/server/spec/jobs/report_missing_trustee_job_spec.rb b/bulletin_board/server/spec/jobs/report_missing_trustee_job_spec.rb index bb49e7cc..ab7058c1 100644 --- a/bulletin_board/server/spec/jobs/report_missing_trustee_job_spec.rb +++ b/bulletin_board/server/spec/jobs/report_missing_trustee_job_spec.rb @@ -5,9 +5,9 @@ RSpec.describe ReportMissingTrusteeJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message) } + let!(:pending_message) { create(:pending_message, election:, message:) } let(:election) { create(:election, :tally_started) } - let(:message) { build(:report_missing_trustee_message, election: election) } + let(:message) { build(:report_missing_trustee_message, election:) } it "processes the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("accepted") diff --git a/bulletin_board/server/spec/jobs/start_key_ceremony_job_spec.rb b/bulletin_board/server/spec/jobs/start_key_ceremony_job_spec.rb index 7b63d9cd..a5b6de8b 100644 --- a/bulletin_board/server/spec/jobs/start_key_ceremony_job_spec.rb +++ b/bulletin_board/server/spec/jobs/start_key_ceremony_job_spec.rb @@ -5,16 +5,16 @@ RSpec.describe StartKeyCeremonyJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message) } + let!(:pending_message) { create(:pending_message, election:, message:) } let(:election) { create(:election) } - let(:message) { build(:start_key_ceremony_message, election: election) } + let(:message) { build(:start_key_ceremony_message, election:) } it "processes the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("accepted") end context "when the message was already processed" do - let!(:pending_message) { create(:pending_message, election: election, message: message, status: :accepted) } + let!(:pending_message) { create(:pending_message, election:, message:, status: :accepted) } it "doesn't change the message status" do expect { subject }.not_to(change { PendingMessage.last.status }) diff --git a/bulletin_board/server/spec/jobs/start_tally_job_spec.rb b/bulletin_board/server/spec/jobs/start_tally_job_spec.rb index eb4df2f7..20291398 100644 --- a/bulletin_board/server/spec/jobs/start_tally_job_spec.rb +++ b/bulletin_board/server/spec/jobs/start_tally_job_spec.rb @@ -5,9 +5,9 @@ RSpec.describe StartTallyJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message) } + let!(:pending_message) { create(:pending_message, election:, message:) } let(:election) { create(:election, :vote_ended) } - let(:message) { build(:start_tally_message, election: election) } + let(:message) { build(:start_tally_message, election:) } it "processes the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("accepted") diff --git a/bulletin_board/server/spec/jobs/start_vote_job_spec.rb b/bulletin_board/server/spec/jobs/start_vote_job_spec.rb index 94c45885..62df245f 100644 --- a/bulletin_board/server/spec/jobs/start_vote_job_spec.rb +++ b/bulletin_board/server/spec/jobs/start_vote_job_spec.rb @@ -5,9 +5,9 @@ RSpec.describe StartVoteJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message) } + let!(:pending_message) { create(:pending_message, election:, message:) } let(:election) { create(:election, :key_ceremony_ended) } - let(:message) { build(:start_vote_message, election: election) } + let(:message) { build(:start_vote_message, election:) } it "processes the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("accepted") diff --git a/bulletin_board/server/spec/jobs/vote_job_spec.rb b/bulletin_board/server/spec/jobs/vote_job_spec.rb index b6a0b945..33fbeee9 100644 --- a/bulletin_board/server/spec/jobs/vote_job_spec.rb +++ b/bulletin_board/server/spec/jobs/vote_job_spec.rb @@ -5,16 +5,16 @@ RSpec.describe VoteJob do subject { described_class.perform_now(pending_message.id) } - let!(:pending_message) { create(:pending_message, election: election, message: message) } + let!(:pending_message) { create(:pending_message, election:, message:) } let(:election) { create(:election, :vote) } - let(:message) { build(:vote_message, election: election) } + let(:message) { build(:vote_message, election:) } it "processes the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("accepted") end context "when the message is rejected" do - let(:message) { build(:vote_message, content_traits: [:invalid], election: election) } + let(:message) { build(:vote_message, content_traits: [:invalid], election:) } it "rejects the message" do expect { subject }.to change { PendingMessage.last.status }.from("enqueued").to("rejected") diff --git a/bulletin_board/server/spec/models/bulletin_board_spec.rb b/bulletin_board/server/spec/models/bulletin_board_spec.rb index 8ef5ebfb..0bf4d5b7 100644 --- a/bulletin_board/server/spec/models/bulletin_board_spec.rb +++ b/bulletin_board/server/spec/models/bulletin_board_spec.rb @@ -64,6 +64,6 @@ end it "is configered when private key is present" do - expect(subject.configured?).to eq(true) + expect(subject.configured?).to be(true) end end diff --git a/bulletin_board/server/spec/models/log_entry_spec.rb b/bulletin_board/server/spec/models/log_entry_spec.rb index a1e2d1df..3eed6046 100644 --- a/bulletin_board/server/spec/models/log_entry_spec.rb +++ b/bulletin_board/server/spec/models/log_entry_spec.rb @@ -6,7 +6,7 @@ subject { log_entry } let(:election) { create(:election) } - let(:log_entry) { build(:log_entry, election: election, message: message) } + let(:log_entry) { build(:log_entry, election:, message:) } let(:iat) { Time.current.to_i } let(:message_type) { "type" } let(:message) do @@ -15,7 +15,7 @@ content: "the message content", data: 123, more_data: true, - iat: iat + iat: }.with_indifferent_access end @@ -55,7 +55,7 @@ end context "when the election has cached log_entries" do - let(:last_log_entry) { create(:log_entry, election: election, message: message) } + let(:last_log_entry) { create(:log_entry, election:, message:) } before do election.log_entries diff --git a/bulletin_board/server/spec/mutations/create_election_mutation_spec.rb b/bulletin_board/server/spec/mutations/create_election_mutation_spec.rb index 436e5e2f..4a34e640 100644 --- a/bulletin_board/server/spec/mutations/create_election_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/create_election_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe CreateElectionMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -24,7 +24,7 @@ module Mutations GQL end let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } let(:payload) { build(:create_election_message) } let(:message_id) { payload["message_id"] } @@ -42,7 +42,7 @@ module Mutations election: { id: be_present, status: "created", - title: payload[:description][:name][:text].map { |title| [title[:language].to_sym, title[:value]] }.to_h, + title: payload[:description][:name][:text].to_h { |title| [title[:language].to_sym, title[:value]] }, authority: { id: authority.unique_id } diff --git a/bulletin_board/server/spec/mutations/end_vote_mutation_spec.rb b/bulletin_board/server/spec/mutations/end_vote_mutation_spec.rb index 3195c79e..bf2e1319 100644 --- a/bulletin_board/server/spec/mutations/end_vote_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/end_vote_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe EndVoteMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -29,9 +29,9 @@ module Mutations let!(:election) { create(:election, :vote) } let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } - let(:payload) { build(:end_vote_message, election: election) } + let(:payload) { build(:end_vote_message, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do diff --git a/bulletin_board/server/spec/mutations/process_key_ceremony_step_mutation_spec.rb b/bulletin_board/server/spec/mutations/process_key_ceremony_step_mutation_spec.rb index 4ded548f..d2980cc9 100644 --- a/bulletin_board/server/spec/mutations/process_key_ceremony_step_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/process_key_ceremony_step_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe ProcessKeyCeremonyStepMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } } } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } } } let(:query) do <<~GQL @@ -30,7 +30,7 @@ module Mutations let!(:election) { create(:election) } let(:trustee) { Trustee.first } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.trustees_private_keys.first.keypair, "RS256") } - let(:payload) { build(:key_ceremony_message, trustee: trustee, election: election) } + let(:payload) { build(:key_ceremony_message, trustee:, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do @@ -64,7 +64,7 @@ module Mutations end context "when the trustee is not authorized" do - let(:trustee) { build(:trustee, private_key: private_key) } + let(:trustee) { build(:trustee, private_key:) } let(:private_key) { generate(:private_key) } it "doesn't create a pending message" do diff --git a/bulletin_board/server/spec/mutations/process_tally_step_mutation_spec.rb b/bulletin_board/server/spec/mutations/process_tally_step_mutation_spec.rb index 3cd6c56f..8ae72c14 100644 --- a/bulletin_board/server/spec/mutations/process_tally_step_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/process_tally_step_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe ProcessTallyStepMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } } } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } } } let(:query) do <<~GQL @@ -30,7 +30,7 @@ module Mutations let!(:election) { create(:election, :tally_started) } let(:trustee) { Trustee.first } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.trustees_private_keys.first.keypair, "RS256") } - let(:payload) { build(:tally_share_message, trustee: trustee, election: election) } + let(:payload) { build(:tally_share_message, trustee:, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do @@ -64,7 +64,7 @@ module Mutations end context "when the trustee is not authorized" do - let(:trustee) { build(:trustee, private_key: private_key) } + let(:trustee) { build(:trustee, private_key:) } let(:private_key) { generate(:private_key) } it "doesn't create a pending message" do diff --git a/bulletin_board/server/spec/mutations/publish_results_mutation_spec.rb b/bulletin_board/server/spec/mutations/publish_results_mutation_spec.rb index c26938bf..6c548a5d 100644 --- a/bulletin_board/server/spec/mutations/publish_results_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/publish_results_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe PublishResultsMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -29,9 +29,9 @@ module Mutations let!(:election) { create(:election, :tally_ended) } let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } - let(:payload) { build(:publish_results_message, election: election) } + let(:payload) { build(:publish_results_message, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do diff --git a/bulletin_board/server/spec/mutations/report_missing_trustee_spec.rb b/bulletin_board/server/spec/mutations/report_missing_trustee_spec.rb index 713fb5b0..84f77739 100644 --- a/bulletin_board/server/spec/mutations/report_missing_trustee_spec.rb +++ b/bulletin_board/server/spec/mutations/report_missing_trustee_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe ReportMissingTrusteeMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -29,9 +29,9 @@ module Mutations let!(:election) { create(:election, :tally_started) } let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } - let(:payload) { build(:report_missing_trustee_message, election: election) } + let(:payload) { build(:report_missing_trustee_message, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do diff --git a/bulletin_board/server/spec/mutations/start_key_ceremony_mutation_spec.rb b/bulletin_board/server/spec/mutations/start_key_ceremony_mutation_spec.rb index 168f028a..a79cecc9 100644 --- a/bulletin_board/server/spec/mutations/start_key_ceremony_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/start_key_ceremony_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe StartKeyCeremonyMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -29,9 +29,9 @@ module Mutations let!(:election) { create(:election) } let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } - let(:payload) { build(:start_key_ceremony_message, election: election) } + let(:payload) { build(:start_key_ceremony_message, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do diff --git a/bulletin_board/server/spec/mutations/start_tally_mutation_spec.rb b/bulletin_board/server/spec/mutations/start_tally_mutation_spec.rb index db6e9d5d..2fa2aeb8 100644 --- a/bulletin_board/server/spec/mutations/start_tally_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/start_tally_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe StartTallyMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -29,9 +29,9 @@ module Mutations let!(:election) { create(:election, :vote_ended) } let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } - let(:payload) { build(:start_tally_message, election: election) } + let(:payload) { build(:start_tally_message, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do diff --git a/bulletin_board/server/spec/mutations/start_vote_mutation_spec.rb b/bulletin_board/server/spec/mutations/start_vote_mutation_spec.rb index ee86ba4a..a9ee79c8 100644 --- a/bulletin_board/server/spec/mutations/start_vote_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/start_vote_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe StartVoteMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -29,9 +29,9 @@ module Mutations let!(:election) { create(:election, :key_ceremony_ended) } let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } - let(:payload) { build(:start_vote_message, election: election) } + let(:payload) { build(:start_vote_message, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do diff --git a/bulletin_board/server/spec/mutations/vote_mutation_spec.rb b/bulletin_board/server/spec/mutations/vote_mutation_spec.rb index 899335ee..c3325c00 100644 --- a/bulletin_board/server/spec/mutations/vote_mutation_spec.rb +++ b/bulletin_board/server/spec/mutations/vote_mutation_spec.rb @@ -4,7 +4,7 @@ module Mutations RSpec.describe VoteMutation, type: :request do - subject { post "/api", params: { query: query, variables: { messageId: message_id, signedData: signed_data } }, headers: headers } + subject { post "/api", params: { query:, variables: { messageId: message_id, signedData: signed_data } }, headers: } let(:query) do <<~GQL @@ -29,9 +29,9 @@ module Mutations let!(:election) { create(:election, :vote) } let(:authority) { Authority.first } - let(:headers) { { "Authorization": authority.api_key } } + let(:headers) { { Authorization: authority.api_key } } let(:signed_data) { JWT.encode(payload.as_json, Test::PrivateKeys.authority_private_key.keypair, "RS256") } - let(:payload) { build(:vote_message, election: election) } + let(:payload) { build(:vote_message, election:) } let(:message_id) { payload["message_id"] } it "adds the message to the pending messages table" do diff --git a/bulletin_board/server/spec/queries/get_election_log_entries_spec.rb b/bulletin_board/server/spec/queries/get_election_log_entries_spec.rb index a3e3c14a..89a5362d 100644 --- a/bulletin_board/server/spec/queries/get_election_log_entries_spec.rb +++ b/bulletin_board/server/spec/queries/get_election_log_entries_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe "GetElectionLogEntries" do - subject { DecidimBulletinBoardSchema.execute(query, context: context) } + subject { DecidimBulletinBoardSchema.execute(query, context:) } let!(:election) { create(:election) } let(:context) { {} } @@ -53,9 +53,9 @@ describe "log entries with temporary hidden data" do let!(:election) { create(:election, :tally_started) } - let(:tally_cast) { create(:log_entry, :by_bulletin_board, election: election, message: build(:tally_cast_message, election: election)) } - let(:tally_share) { create(:log_entry, :by_trustee, election: election, message: build(:tally_share_message, election: election)) } - let(:end_tally) { create(:log_entry, :by_bulletin_board, election: election, message: build(:end_tally_message, election: election)) } + let(:tally_cast) { create(:log_entry, :by_bulletin_board, election:, message: build(:tally_cast_message, election:)) } + let(:tally_share) { create(:log_entry, :by_trustee, election:, message: build(:tally_share_message, election:)) } + let(:end_tally) { create(:log_entry, :by_bulletin_board, election:, message: build(:end_tally_message, election:)) } before { tally_cast && tally_share && end_tally } diff --git a/bulletin_board/server/spec/queries/get_election_spec.rb b/bulletin_board/server/spec/queries/get_election_spec.rb index da0686c2..a39db078 100644 --- a/bulletin_board/server/spec/queries/get_election_spec.rb +++ b/bulletin_board/server/spec/queries/get_election_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe "GetElection" do - subject { DecidimBulletinBoardSchema.execute(query, context: context) } + subject { DecidimBulletinBoardSchema.execute(query, context:) } let(:election) { create(:election) } let(:context) { {} } diff --git a/bulletin_board/server/spec/queries/get_log_entry_spec.rb b/bulletin_board/server/spec/queries/get_log_entry_spec.rb index 75e7673c..390e4a5e 100644 --- a/bulletin_board/server/spec/queries/get_log_entry_spec.rb +++ b/bulletin_board/server/spec/queries/get_log_entry_spec.rb @@ -21,7 +21,7 @@ } GQL end - let!(:log_entry) { create(:log_entry, election: election, message: build(:vote_message, election: election)) } + let!(:log_entry) { create(:log_entry, election:, message: build(:vote_message, election:)) } let(:election) { create(:election) } let(:election_unique_id) { election.unique_id } let(:content_hash) { log_entry.content_hash } diff --git a/bulletin_board/server/spec/queries/get_pending_message_spec.rb b/bulletin_board/server/spec/queries/get_pending_message_spec.rb index cf92b874..0a4b2b93 100644 --- a/bulletin_board/server/spec/queries/get_pending_message_spec.rb +++ b/bulletin_board/server/spec/queries/get_pending_message_spec.rb @@ -3,9 +3,9 @@ require "rails_helper" RSpec.describe "GetPendingMessage" do - subject { DecidimBulletinBoardSchema.execute(query, context: context) } + subject { DecidimBulletinBoardSchema.execute(query, context:) } - let!(:pending_message) { create(:pending_message, election: election, message: build(:vote_message, election: election)) } + let!(:pending_message) { create(:pending_message, election:, message: build(:vote_message, election:)) } let(:election) { create(:election) } let(:pending_message_id) { pending_message.id } let(:context) { {} } @@ -67,7 +67,7 @@ describe "pending messages with results data" do let!(:election) { create(:election, :tally_started) } - let!(:pending_message) { create(:pending_message, :by_trustee, election: election, message: build(:tally_share_message, election: election)) } + let!(:pending_message) { create(:pending_message, :by_trustee, election:, message: build(:tally_share_message, election:)) } it "hides the signed data" do expect(subject.deep_symbolize_keys).to include( diff --git a/bulletin_board/server/spec/services/concerns/redis_provider_spec.rb b/bulletin_board/server/spec/services/concerns/redis_provider_spec.rb index 7147b0ff..09ad6e0c 100644 --- a/bulletin_board/server/spec/services/concerns/redis_provider_spec.rb +++ b/bulletin_board/server/spec/services/concerns/redis_provider_spec.rb @@ -22,8 +22,8 @@ def access it "returns a Redis instance with the correct configurations" do expect(redis).to be_a(Redis) expect(options).to include( - host: ENV["REDIS_HOST"] || "localhost", - port: ENV["REDIS_PORT"] || 6379, + host: ENV.fetch("REDIS_HOST", "localhost"), + port: ENV.fetch("REDIS_PORT", 6379), ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } ) end diff --git a/bulletin_board/server/spec/services/valid_votes_spec.rb b/bulletin_board/server/spec/services/valid_votes_spec.rb index 2fff22b4..463d949c 100644 --- a/bulletin_board/server/spec/services/valid_votes_spec.rb +++ b/bulletin_board/server/spec/services/valid_votes_spec.rb @@ -6,7 +6,7 @@ subject(:instance) { described_class.new(election).to_a } let(:election) { create(:election, :vote) } - let(:some_votes) { create_list(:log_entry, 10, :vote, election: election) } + let(:some_votes) { create_list(:log_entry, 10, :vote, election:) } let(:create_votes) { some_votes } before { create_votes } @@ -14,14 +14,14 @@ it { expect(subject).to match_array(some_votes) } context "when there are duplicated votes" do - let(:replacement) { create(:log_entry, :vote, election: election, voter_id: some_votes.first.author_unique_id) } + let(:replacement) { create(:log_entry, :vote, election:, voter_id: some_votes.first.author_unique_id) } let(:create_votes) { some_votes && replacement } it { expect(subject).to match_array(some_votes.excluding(some_votes.first).append(replacement)) } end context "when there are in_person votes" do - let(:replacement) { create(:log_entry, :in_person_vote, election: election, voter_id: some_votes.first.author_unique_id) } + let(:replacement) { create(:log_entry, :in_person_vote, election:, voter_id: some_votes.first.author_unique_id) } let(:create_votes) { some_votes && replacement } it { expect(subject).to match_array(some_votes.excluding(some_votes.first)) } diff --git a/bulletin_board/server/spec/services/voting_scheme/electionguard/bulletin_board_spec.rb b/bulletin_board/server/spec/services/voting_scheme/electionguard/bulletin_board_spec.rb index 10d6b00d..32db1976 100644 --- a/bulletin_board/server/spec/services/voting_scheme/electionguard/bulletin_board_spec.rb +++ b/bulletin_board/server/spec/services/voting_scheme/electionguard/bulletin_board_spec.rb @@ -7,7 +7,7 @@ module Electionguard RSpec.describe BulletinBoard do subject(:instance) { described_class.new(election) } - let(:election) { build(:electionguard_election, last_step: last_step) } + let(:election) { build(:electionguard_election, last_step:) } describe "process_message" do subject do @@ -51,7 +51,7 @@ module Electionguard let(:dont_process_count) { 1 } it "returns the joint election key message" do - expect(JSON.parse(election.log_entries.last.decoded_data["content"])["election_joint_key"]["joint_public_key"]).not_to eq(nil) + expect(JSON.parse(election.log_entries.last.decoded_data["content"])["election_joint_key"]["joint_public_key"]).not_to be_nil end end end diff --git a/bulletin_board/server/spec/support/electionguard_test_data.rb b/bulletin_board/server/spec/support/electionguard_test_data.rb index ba674c00..efd6cde0 100644 --- a/bulletin_board/server/spec/support/electionguard_test_data.rb +++ b/bulletin_board/server/spec/support/electionguard_test_data.rb @@ -10,8 +10,8 @@ def initialize(enumerable) @enumerable = enumerable end - def each(&block) - @enumerable.each(&block) + def each(&) + @enumerable.each(&) end def of_type(type) diff --git a/bulletin_board/server/spec/tasks/add_authority_spec.rb b/bulletin_board/server/spec/tasks/add_authority_spec.rb index 19e7faac..59a5c06d 100644 --- a/bulletin_board/server/spec/tasks/add_authority_spec.rb +++ b/bulletin_board/server/spec/tasks/add_authority_spec.rb @@ -3,11 +3,11 @@ require "rails_helper" RSpec.describe "client:add_authority", type: :task do - subject { task.execute(name: name, public_key: public_key) } + subject { task.execute(name:, public_key:) } let(:name) { authority.name } let(:public_key) { private_key.export.map { |k, v| "#{k}=#{v}" }.join("&") } - let(:authority) { build(:authority, private_key: private_key) } + let(:authority) { build(:authority, private_key:) } let(:private_key) { generate(:private_key) } it "creates a new authority" do @@ -17,7 +17,7 @@ end context "when authority's public key already exists" do - let(:authority) { create(:authority, private_key: private_key) } + let(:authority) { create(:authority, private_key:) } let(:name) { "#{authority.name}2" } it "detects the existing public key" do @@ -28,7 +28,7 @@ end context "when authority's name already exists" do - let(:authority) { create(:authority, private_key: private_key) } + let(:authority) { create(:authority, private_key:) } let(:public_key) { private_key.export.map { |k, v| "#{k}=#{v}" }.join("&") } it "detects the existing name" do diff --git a/voting_schemes/dummy/ruby-adapter/Gemfile b/voting_schemes/dummy/ruby-adapter/Gemfile index 90f80806..7fc5b1b5 100644 --- a/voting_schemes/dummy/ruby-adapter/Gemfile +++ b/voting_schemes/dummy/ruby-adapter/Gemfile @@ -5,6 +5,6 @@ source "https://rubygems.org" # Specify your gem's dependencies in decidim-bulletin_board-dummy.gemspec gemspec -gem "rubocop", "~> 0.92.0" +gem "rubocop", "~> 1.28.0" gem "rubocop-faker", "~> 1.1.0" -gem "rubocop-rspec", "~> 1.44.1" +gem "rubocop-rspec", "~> 2.10" diff --git a/voting_schemes/dummy/ruby-adapter/Gemfile.lock b/voting_schemes/dummy/ruby-adapter/Gemfile.lock index 8da32f58..86d7e2e4 100644 --- a/voting_schemes/dummy/ruby-adapter/Gemfile.lock +++ b/voting_schemes/dummy/ruby-adapter/Gemfile.lock @@ -115,8 +115,8 @@ GEM racc (~> 1.4) nokogiri (1.13.8-x86_64-linux) racc (~> 1.4) - parallel (1.20.1) - parser (3.0.0.0) + parallel (1.22.1) + parser (3.1.2.1) ast (~> 2.4.1) racc (1.6.0) rack (2.2.4) @@ -148,9 +148,9 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) - rainbow (3.0.0) + rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.1.1) + regexp_parser (2.5.0) rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) @@ -165,30 +165,29 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.2) - rubocop (0.92.0) + rubocop (1.28.2) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.5.0) + rubocop-ast (>= 1.17.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.4.1) - parser (>= 2.7.1.5) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.21.0) + parser (>= 3.1.1.0) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) - rubocop-rspec (1.44.1) - rubocop (~> 0.87) - rubocop-ast (>= 0.7.1) + rubocop-rspec (2.11.1) + rubocop (~> 1.19) ruby-progressbar (1.11.0) strscan (3.0.4) thor (1.2.1) timeout (0.3.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (1.7.0) + unicode-display_width (2.2.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -201,9 +200,9 @@ PLATFORMS DEPENDENCIES rake (~> 13.0) rspec (~> 3.7) - rubocop (~> 0.92.0) + rubocop (~> 1.28.0) rubocop-faker (~> 1.1.0) - rubocop-rspec (~> 1.44.1) + rubocop-rspec (~> 2.10) voting_schemes-dummy! BUNDLED WITH diff --git a/voting_schemes/electionguard/ruby-adapter/Gemfile b/voting_schemes/electionguard/ruby-adapter/Gemfile index 90f80806..7fc5b1b5 100644 --- a/voting_schemes/electionguard/ruby-adapter/Gemfile +++ b/voting_schemes/electionguard/ruby-adapter/Gemfile @@ -5,6 +5,6 @@ source "https://rubygems.org" # Specify your gem's dependencies in decidim-bulletin_board-dummy.gemspec gemspec -gem "rubocop", "~> 0.92.0" +gem "rubocop", "~> 1.28.0" gem "rubocop-faker", "~> 1.1.0" -gem "rubocop-rspec", "~> 1.44.1" +gem "rubocop-rspec", "~> 2.10" diff --git a/voting_schemes/electionguard/ruby-adapter/Gemfile.lock b/voting_schemes/electionguard/ruby-adapter/Gemfile.lock index fd7960b8..17866c37 100644 --- a/voting_schemes/electionguard/ruby-adapter/Gemfile.lock +++ b/voting_schemes/electionguard/ruby-adapter/Gemfile.lock @@ -165,30 +165,29 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-support (3.11.0) - rubocop (0.92.0) + rubocop (1.28.2) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.5.0) + rubocop-ast (>= 1.17.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) + unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.21.0) parser (>= 3.1.1.0) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) - rubocop-rspec (1.44.1) - rubocop (~> 0.87) - rubocop-ast (>= 0.7.1) + rubocop-rspec (2.11.1) + rubocop (~> 1.19) ruby-progressbar (1.11.0) strscan (3.0.4) thor (1.2.1) timeout (0.3.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (1.8.0) + unicode-display_width (2.2.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -201,9 +200,9 @@ PLATFORMS DEPENDENCIES rake (~> 13.0) rspec (~> 3.7) - rubocop (~> 0.92.0) + rubocop (~> 1.28.0) rubocop-faker (~> 1.1.0) - rubocop-rspec (~> 1.44.1) + rubocop-rspec (~> 2.10) voting_schemes-electionguard! BUNDLED WITH