From be58cb5b4c3fc818092e597d09f0610c32bf2fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 14 Dec 2023 10:49:21 +0100 Subject: [PATCH] Adds ENV vars for configuring the BB server (#310) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add env vars for bb settings * documentation * fix rubocop * Update bulletin_board/server/spec/commands/create_election_spec.rb Co-authored-by: Andrés Pereira de Lucena * update rubocop * update schema * update schema * add log level env * rubocop --------- Co-authored-by: Andrés Pereira de Lucena --- bulletin_board/js-client/src/types.d.ts | 2 +- bulletin_board/ruby-client/Gemfile | 13 +++-- bulletin_board/ruby-client/Gemfile.lock | 45 ++++++++++------ .../decidim-bulletin_board.gemspec | 6 +-- .../bulletin_board/graphql/bb_schema.json | 4 +- .../lib/decidim/bulletin_board/jwk_utils.rb | 2 +- .../ruby-client/spec/support/command_stub.rb | 2 +- bulletin_board/server/.rubocop.yml | 10 ++++ bulletin_board/server/Gemfile | 8 +-- bulletin_board/server/Gemfile.lock | 52 ++++++++++++------- bulletin_board/server/README.md | 2 +- .../sandbox/generate_load_test_stats.rb | 2 +- .../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/election_type.rb | 4 +- .../server/app/graphql/types/mutation_type.rb | 12 ++--- .../server/app/graphql/types/query_type.rb | 34 ++++++------ .../server/app/helpers/application_helper.rb | 2 +- .../app/jobs/sandbox/generate_votes_job.rb | 2 +- .../server/config/environments/production.rb | 4 +- bulletin_board/server/config/settings.yml | 4 +- .../spec/commands/create_election_spec.rb | 22 +++++++- .../spec/requests/documentation_spec.rb | 4 +- .../server/spec/tasks/add_authority_spec.rb | 2 + ...enerate_identification_private_key_spec.rb | 2 + .../pages/environment_variables.adoc | 9 ++++ .../manual/operations/automated-tests.adoc | 2 +- 34 files changed, 170 insertions(+), 99 deletions(-) diff --git a/bulletin_board/js-client/src/types.d.ts b/bulletin_board/js-client/src/types.d.ts index 41c6c60b..cd685e7a 100644 --- a/bulletin_board/js-client/src/types.d.ts +++ b/bulletin_board/js-client/src/types.d.ts @@ -206,8 +206,8 @@ export type QueryElectionArgs = { export type QueryLogEntryArgs = { - electionUniqueId: Scalars['String']; contentHash: Scalars['String']; + electionUniqueId: Scalars['String']; }; diff --git a/bulletin_board/ruby-client/Gemfile b/bulletin_board/ruby-client/Gemfile index a8fd6082..8dac6a24 100644 --- a/bulletin_board/ruby-client/Gemfile +++ b/bulletin_board/ruby-client/Gemfile @@ -8,6 +8,13 @@ gemspec # Graphql version 2.1 breaks graphql-client compatibility See https://github.com/github/graphql-client/pull/310 gem "graphql", "~> 2.0.0" -gem "rubocop", "~> 1.28.0" -gem "rubocop-faker", "~> 1.1.0" -gem "rubocop-rspec", "~> 2.10" +gem "rubocop", "~> 1.57.0" +gem "rubocop-faker", "~> 1.1" +gem "rubocop-rspec", "~> 2.20" + +group :development, :test do + gem "rake", "~> 13.0" + gem "rspec", "~> 3.7" + gem "webmock", "~> 3.6" + gem "wisper-rspec", "~> 1.1.0" +end diff --git a/bulletin_board/ruby-client/Gemfile.lock b/bulletin_board/ruby-client/Gemfile.lock index 39994ec0..8fcc115d 100644 --- a/bulletin_board/ruby-client/Gemfile.lock +++ b/bulletin_board/ruby-client/Gemfile.lock @@ -128,7 +128,9 @@ GEM hashdiff (1.0.1) i18n (1.12.0) concurrent-ruby (~> 1.0) + json (2.7.1) jwt (2.5.0) + language_server-protocol (3.17.0.3) loofah (2.21.3) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -160,9 +162,10 @@ GEM racc (~> 1.4) nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) - parallel (1.22.1) - parser (3.1.2.1) + parallel (1.23.0) + parser (3.2.2.4) ast (~> 2.4.1) + racc public_suffix (5.0.0) racc (1.7.1) rack (2.2.8) @@ -198,7 +201,7 @@ GEM zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.5.0) + regexp_parser (2.8.3) rexml (3.2.5) rspec (3.11.0) rspec-core (~> 3.11.0) @@ -213,29 +216,37 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-support (3.11.0) - rubocop (1.28.2) + rubocop (1.57.2) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.17.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.21.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.19.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.24.0) + rubocop (~> 1.33) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) - rubocop-rspec (2.11.1) - rubocop (~> 1.19) - ruby-progressbar (1.11.0) + rubocop-rspec (2.25.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) thor (1.2.2) timeout (0.4.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.2.0) + unicode-display_width (2.5.0) webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) @@ -257,9 +268,9 @@ DEPENDENCIES graphql (~> 2.0.0) rake (~> 13.0) rspec (~> 3.7) - rubocop (~> 1.28.0) - rubocop-faker (~> 1.1.0) - rubocop-rspec (~> 2.10) + rubocop (~> 1.57.0) + rubocop-faker (~> 1.1) + rubocop-rspec (~> 2.20) 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 3c2421dc..f29ba7d9 100644 --- a/bulletin_board/ruby-client/decidim-bulletin_board.gemspec +++ b/bulletin_board/ruby-client/decidim-bulletin_board.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z` .split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - .concat(["app/assets/javascripts/decidim/bulletin_board/decidim-bulletin_board.js"]) + .push("app/assets/javascripts/decidim/bulletin_board/decidim-bulletin_board.js") end s.bindir = "exe" s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) } @@ -31,9 +31,5 @@ Gem::Specification.new do |s| s.add_dependency "jwt", "~> 2.5.0" s.add_dependency "wisper", "~> 2.0.0" - s.add_development_dependency "rake", "~> 13.0" - 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/graphql/bb_schema.json b/bulletin_board/ruby-client/lib/decidim/bulletin_board/graphql/bb_schema.json index 346b2f06..f18c95ad 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/graphql/bb_schema.json +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/graphql/bb_schema.json @@ -1445,7 +1445,7 @@ "description": "Returns the log entry with the given content hash for the given election", "args": [ { - "name": "electionUniqueId", + "name": "contentHash", "description": null, "type": { "kind": "NON_NULL", @@ -1459,7 +1459,7 @@ "defaultValue": null }, { - "name": "contentHash", + "name": "electionUniqueId", "description": null, "type": { "kind": "NON_NULL", diff --git a/bulletin_board/ruby-client/lib/decidim/bulletin_board/jwk_utils.rb b/bulletin_board/ruby-client/lib/decidim/bulletin_board/jwk_utils.rb index 5c42328b..8799e6f8 100644 --- a/bulletin_board/ruby-client/lib/decidim/bulletin_board/jwk_utils.rb +++ b/bulletin_board/ruby-client/lib/decidim/bulletin_board/jwk_utils.rb @@ -10,7 +10,7 @@ def self.thumbprint(json) end def self.private_key?(json) - (json.keys & JWK_PRIVATE_FIELDS).any? + json.keys.intersect?(JWK_PRIVATE_FIELDS) end def self.import_private_key(json) diff --git a/bulletin_board/ruby-client/spec/support/command_stub.rb b/bulletin_board/ruby-client/spec/support/command_stub.rb index 701d2d10..e26cf161 100644 --- a/bulletin_board/ruby-client/spec/support/command_stub.rb +++ b/bulletin_board/ruby-client/spec/support/command_stub.rb @@ -11,7 +11,7 @@ def stub_command(clazz, called_method, event_to_publish, *published_event_args) end # rubocop:disable Lint/EmptyBlock - define_method(:configure) { |*_args|; } + define_method(:configure) { |*_args| } # rubocop:enable Lint/EmptyBlock end) end diff --git a/bulletin_board/server/.rubocop.yml b/bulletin_board/server/.rubocop.yml index 43c44b45..d45968a3 100644 --- a/bulletin_board/server/.rubocop.yml +++ b/bulletin_board/server/.rubocop.yml @@ -3,6 +3,11 @@ inherit_from: - https://raw.githubusercontent.com/decidim/decidim/develop/decidim-dev/config/rubocop/rspec.yml - https://raw.githubusercontent.com/decidim/decidim/develop/decidim-dev/config/rubocop/rails.yml +require: + - rubocop-factory_bot + # TODO: Uncomment the following line when all the app/graphql/types have a description in their fields + # - rubocop-graphql + AllCops: Include: - "**/*.rb" @@ -20,3 +25,8 @@ Style/OpenStructUse: Rails/HasManyOrHasOneDependent: Enabled: false + +FactoryBot/FactoryAssociationWithStrategy: + Enabled: false + + diff --git a/bulletin_board/server/Gemfile b/bulletin_board/server/Gemfile index f4e0c72a..ab223752 100644 --- a/bulletin_board/server/Gemfile +++ b/bulletin_board/server/Gemfile @@ -66,11 +66,11 @@ group :development, :test do gem "net-smtp", "~> 0.3.1" gem "pry-rails" gem "rspec-rails", "~> 4.1" - gem "rubocop", "~> 1.28.0" - gem "rubocop-faker", "~> 1.1.0" + gem "rubocop", "~> 1.57.0" + gem "rubocop-faker", "~> 1.1" gem "rubocop-graphql", "~> 0.14.4" - gem "rubocop-rails", "~> 2.14" - gem "rubocop-rspec", "~> 2.10" + gem "rubocop-rails", "~> 2.22" + gem "rubocop-rspec", "~> 2.20" end group :development do diff --git a/bulletin_board/server/Gemfile.lock b/bulletin_board/server/Gemfile.lock index 5741ea74..9d1cca3b 100644 --- a/bulletin_board/server/Gemfile.lock +++ b/bulletin_board/server/Gemfile.lock @@ -191,8 +191,10 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + json (2.7.1) jsonl (0.1.5) jwt (2.5.0) + language_server-protocol (3.17.0.3) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -225,9 +227,10 @@ GEM racc (~> 1.4) nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) - parallel (1.22.1) - parser (3.1.2.1) + parallel (1.23.0) + parser (3.2.2.4) ast (~> 2.4.1) + racc pg (1.4.3) pry (0.14.1) coderay (~> 1.1) @@ -286,7 +289,7 @@ GEM wisper (>= 1.6.1) redcarpet (3.5.1) redis (4.8.1) - regexp_parser (2.5.0) + regexp_parser (2.8.3) rexml (3.2.5) rspec (3.11.0) rspec-core (~> 3.11.0) @@ -312,29 +315,38 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0) - rubocop (1.28.2) + rubocop (1.57.2) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.17.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.21.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.19.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.24.0) + rubocop (~> 1.33) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) rubocop-graphql (0.14.4) rubocop (>= 0.87, < 2) - rubocop-rails (2.15.1) + rubocop-rails (2.22.2) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-rspec (2.11.1) - rubocop (~> 1.19) - ruby-progressbar (1.11.0) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rspec (2.25.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -385,7 +397,7 @@ GEM turbolinks-source (5.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.2.0) + unicode-display_width (2.5.0) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) @@ -445,11 +457,11 @@ DEPENDENCIES redis (~> 4.0) rspec-graphql_matchers rspec-rails (~> 4.1) - rubocop (~> 1.28.0) - rubocop-faker (~> 1.1.0) + rubocop (~> 1.57.0) + rubocop-faker (~> 1.1) rubocop-graphql (~> 0.14.4) - rubocop-rails (~> 2.14) - rubocop-rspec (~> 2.10) + rubocop-rails (~> 2.22) + rubocop-rspec (~> 2.20) sass-rails (>= 6) sidekiq (~> 6.0) simplecov diff --git a/bulletin_board/server/README.md b/bulletin_board/server/README.md index e6f359e6..ba046b57 100644 --- a/bulletin_board/server/README.md +++ b/bulletin_board/server/README.md @@ -2,7 +2,7 @@ The Bulletin Board is a service composed by an Encryption Engine and an Append-Only Log. External queries to the Encryption Engine are allowed through an API. -- Ruby version: 2.6 +- Ruby version: 3.1 - Rails version: 6 - Python version: 3.8.2 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 9f8555b8..9466c895 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 @@ -82,7 +82,7 @@ def pertinent_pending_messages end def clear_existing_file - File.delete(STATS_OUTPUT_FILE_PATH) if File.exist?(STATS_OUTPUT_FILE_PATH) + FileUtils.rm_f(STATS_OUTPUT_FILE_PATH) end def write_stats_to_file(stats) 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 2132fa07..982064b2 100644 --- a/bulletin_board/server/app/graphql/mutations/end_vote_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/end_vote_mutation.rb @@ -5,8 +5,8 @@ class EndVoteMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) authority = find_authority(message_id) 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 517e6166..667dfdf1 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 @@ -5,8 +5,8 @@ class ProcessKeyCeremonyStepMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) trustee = find_trustee(message_id) 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 7adf2e1d..4525aa3e 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 @@ -5,8 +5,8 @@ class ProcessTallyStepMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) trustee = find_trustee(message_id) 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 242fe1b2..d602edf5 100644 --- a/bulletin_board/server/app/graphql/mutations/publish_results_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/publish_results_mutation.rb @@ -5,8 +5,8 @@ class PublishResultsMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) authority = find_authority(message_id) 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 51c03bc2..7b44ef8a 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 @@ -5,8 +5,8 @@ class ReportMissingTrusteeMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) authority = find_authority(message_id) 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 4fe00741..1d2b1c6b 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 @@ -5,8 +5,8 @@ class StartKeyCeremonyMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) authority = find_authority(message_id) 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 abb75a89..d392799f 100644 --- a/bulletin_board/server/app/graphql/mutations/start_tally_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/start_tally_mutation.rb @@ -5,8 +5,8 @@ class StartTallyMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) authority = find_authority(message_id) 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 3f7ea14a..05689549 100644 --- a/bulletin_board/server/app/graphql/mutations/start_vote_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/start_vote_mutation.rb @@ -5,8 +5,8 @@ class StartVoteMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) authority = find_authority(message_id) diff --git a/bulletin_board/server/app/graphql/mutations/vote_mutation.rb b/bulletin_board/server/app/graphql/mutations/vote_mutation.rb index 1ac94201..ebb076e9 100644 --- a/bulletin_board/server/app/graphql/mutations/vote_mutation.rb +++ b/bulletin_board/server/app/graphql/mutations/vote_mutation.rb @@ -5,8 +5,8 @@ class VoteMutation < BaseMutation argument :message_id, String, required: true argument :signed_data, String, required: true - field :pending_message, Types::PendingMessageType, null: true field :error, String, null: true + field :pending_message, Types::PendingMessageType, null: true def resolve(message_id:, signed_data:) authority = find_authority(message_id) diff --git a/bulletin_board/server/app/graphql/types/election_type.rb b/bulletin_board/server/app/graphql/types/election_type.rb index 006de5e4..b9a4f786 100644 --- a/bulletin_board/server/app/graphql/types/election_type.rb +++ b/bulletin_board/server/app/graphql/types/election_type.rb @@ -2,10 +2,10 @@ module Types class ElectionType < Types::BaseObject + field :authority, Types::ClientType, null: false field :id, ID, null: false, method: :unique_id - field :title, GraphQL::Types::JSON, null: false field :status, String, null: false - field :authority, Types::ClientType, null: false + field :title, GraphQL::Types::JSON, null: false field :trustees, [Types::ClientType], null: false, description: "Returns the list of trustees for this election" field :log_entries, [Types::LogEntryType], null: false, description: "Returns the list of log entries for this election in the bulletin board" do diff --git a/bulletin_board/server/app/graphql/types/mutation_type.rb b/bulletin_board/server/app/graphql/types/mutation_type.rb index 667bf742..56c4bd99 100644 --- a/bulletin_board/server/app/graphql/types/mutation_type.rb +++ b/bulletin_board/server/app/graphql/types/mutation_type.rb @@ -3,15 +3,15 @@ module Types class MutationType < Types::BaseObject field :create_election, mutation: Mutations::CreateElectionMutation - field :start_key_ceremony, mutation: Mutations::StartKeyCeremonyMutation - field :process_key_ceremony_step, mutation: Mutations::ProcessKeyCeremonyStepMutation - field :start_vote, mutation: Mutations::StartVoteMutation - field :vote, mutation: Mutations::VoteMutation field :end_vote, mutation: Mutations::EndVoteMutation - field :start_tally, mutation: Mutations::StartTallyMutation + field :process_key_ceremony_step, mutation: Mutations::ProcessKeyCeremonyStepMutation field :process_tally_step, mutation: Mutations::ProcessTallyStepMutation - field :report_missing_trustee, mutation: Mutations::ReportMissingTrusteeMutation field :publish_results, mutation: Mutations::PublishResultsMutation + field :report_missing_trustee, mutation: Mutations::ReportMissingTrusteeMutation field :reset_test_database, mutation: Mutations::ResetTestDatabaseMutation + field :start_key_ceremony, mutation: Mutations::StartKeyCeremonyMutation + field :start_tally, mutation: Mutations::StartTallyMutation + field :start_vote, mutation: Mutations::StartVoteMutation + field :vote, mutation: Mutations::VoteMutation 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 36061d1b..1f3f2dab 100644 --- a/bulletin_board/server/app/graphql/types/query_type.rb +++ b/bulletin_board/server/app/graphql/types/query_type.rb @@ -7,28 +7,16 @@ class QueryType < Types::BaseObject null: false, description: "Returns the information for this bulletin board instance" - def me - BulletinBoard - end - field :authorities, [Types::ClientType], null: false, description: "Returns a list of authorities in the bulletin board" - def authorities - Authority.all - end - field :elections, [Types::ElectionType], null: false, description: "Returns a list of elections in the bulletin board" - def elections - Election.all - end - field :election, Types::ElectionType, null: true, @@ -36,10 +24,6 @@ def elections argument :unique_id, String, required: true end - def election(unique_id:) - Election.find_by(unique_id:) - end - field :pending_message, Types::PendingMessageType, null: true, @@ -60,12 +44,28 @@ def resolve(_parent, args, _context) Types::LogEntryType, null: true, description: "Returns the log entry with the given content hash for the given election" do - argument :election_unique_id, String, required: true argument :content_hash, String, required: true + argument :election_unique_id, String, required: true def resolve(_parent, args, _context) LogEntry.find_by(election: Election.find_by(unique_id: args[:election_unique_id]), content_hash: args[:content_hash]) end end + + def me + BulletinBoard + end + + def authorities + Authority.all + end + + def elections + Election.all + end + + def election(unique_id:) + Election.find_by(unique_id:) + end end end diff --git a/bulletin_board/server/app/helpers/application_helper.rb b/bulletin_board/server/app/helpers/application_helper.rb index 0e94b723..7ce5aa9a 100644 --- a/bulletin_board/server/app/helpers/application_helper.rb +++ b/bulletin_board/server/app/helpers/application_helper.rb @@ -4,7 +4,7 @@ module ApplicationHelper def render_doc(file) - md_render File.read(Rails.root.join("docs", "#{file}.md")) + md_render Rails.root.join("docs", "#{file}.md").read end def md_render(text) 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 77d36628..c6f809ab 100644 --- a/bulletin_board/server/app/jobs/sandbox/generate_votes_job.rb +++ b/bulletin_board/server/app/jobs/sandbox/generate_votes_job.rb @@ -47,7 +47,7 @@ def perform(number_of_votes, election_id, file_path, client_settings = {}) private def remove_existing_file - File.delete(file_path) if File.exist?(file_path) + FileUtils.rm_f(file_path) end def random_plaintext_ballot diff --git a/bulletin_board/server/config/environments/production.rb b/bulletin_board/server/config/environments/production.rb index 0e0c4a33..e0adb24b 100644 --- a/bulletin_board/server/config/environments/production.rb +++ b/bulletin_board/server/config/environments/production.rb @@ -50,7 +50,7 @@ # Use the lowest log level to ensure availability of diagnostic information # when problems arise. - config.log_level = :info + config.log_level = %w(debug info warn error fatal).include?(ENV["RAILS_LOG_LEVEL"]) ? ENV["RAILS_LOG_LEVEL"] : :info # Prepend all log lines with the following tags. config.log_tags = [:request_id] @@ -77,7 +77,7 @@ config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new + config.log_formatter = Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' diff --git a/bulletin_board/server/config/settings.yml b/bulletin_board/server/config/settings.yml index 73618c5b..778476ef 100644 --- a/bulletin_board/server/config/settings.yml +++ b/bulletin_board/server/config/settings.yml @@ -1,7 +1,7 @@ default: &default - iat_expiration_minutes: 60 + iat_expiration_minutes: <%= ENV.fetch("IAT_EXPIRATION_MINUTES", 60).to_i %> create_election: - hours_before: 2 + hours_before: <%= ENV.fetch("HOURS_BEFORE_CREATE_ELECTION", 1).to_i %> development: <<: *default diff --git a/bulletin_board/server/spec/commands/create_election_spec.rb b/bulletin_board/server/spec/commands/create_election_spec.rb index a7969ce5..7de233de 100644 --- a/bulletin_board/server/spec/commands/create_election_spec.rb +++ b/bulletin_board/server/spec/commands/create_election_spec.rb @@ -87,7 +87,27 @@ it_behaves_like "create election fails" it "broadcasts invalid" do - expect { subject }.to broadcast(:invalid, "Election should start at least in 2 hours from now.") + expect { subject }.to broadcast(:invalid, "Election should start at least in 1 hours from now.") + end + + context "when the `hours before` the election creation is set" do + let(:hours_before) { 2 } + + before do + allow(Rails.configuration.settings).to receive(:create_election).and_return({ hours_before: }) + end + + it "broadcasts invalid" do + expect { subject }.to broadcast(:invalid, "Election should start at least in 2 hours from now.") + end + + context "and is zero" do + let(:hours_before) { 0 } + + it "broadcasts ok" do + expect { subject }.to broadcast(:ok) + end + end end end diff --git a/bulletin_board/server/spec/requests/documentation_spec.rb b/bulletin_board/server/spec/requests/documentation_spec.rb index 44780aea..d3e66be0 100644 --- a/bulletin_board/server/spec/requests/documentation_spec.rb +++ b/bulletin_board/server/spec/requests/documentation_spec.rb @@ -2,7 +2,8 @@ require "rails_helper" -RSpec.describe "Documentation page", type: :request do +# rubocop:disable RSpec/DescribeClass +RSpec.describe "Documentation page" do subject { get "/api/docs" } it "returns the documentation home page" do @@ -15,3 +16,4 @@ expect(response.body).to include("window.renderDocumentation(\"/api\")") end end +# rubocop:enable RSpec/DescribeClass diff --git a/bulletin_board/server/spec/tasks/add_authority_spec.rb b/bulletin_board/server/spec/tasks/add_authority_spec.rb index 59a5c06d..d9ff4cac 100644 --- a/bulletin_board/server/spec/tasks/add_authority_spec.rb +++ b/bulletin_board/server/spec/tasks/add_authority_spec.rb @@ -2,6 +2,7 @@ require "rails_helper" +# rubocop:disable RSpec/NoExpectationExample RSpec.describe "client:add_authority", type: :task do subject { task.execute(name:, public_key:) } @@ -48,3 +49,4 @@ end end end +# rubocop:enable RSpec/NoExpectationExample diff --git a/bulletin_board/server/spec/tasks/generate_identification_private_key_spec.rb b/bulletin_board/server/spec/tasks/generate_identification_private_key_spec.rb index c2245dfa..2ad11e72 100644 --- a/bulletin_board/server/spec/tasks/generate_identification_private_key_spec.rb +++ b/bulletin_board/server/spec/tasks/generate_identification_private_key_spec.rb @@ -2,6 +2,7 @@ require "rails_helper" +# rubocop:disable RSpec/NoExpectationExample RSpec.describe "client:generate_identification_private_key", type: :task do subject { task.execute } @@ -25,3 +26,4 @@ end end end +# rubocop:enable RSpec/NoExpectationExample diff --git a/docs/modules/configure/pages/environment_variables.adoc b/docs/modules/configure/pages/environment_variables.adoc index c3b6d037..290dde8f 100644 --- a/docs/modules/configure/pages/environment_variables.adoc +++ b/docs/modules/configure/pages/environment_variables.adoc @@ -21,6 +21,15 @@ We try to let most of the things defined through Environment Variables, as https |SECRET_KEY_BASE |Secret key base for the Application. It's specially important that this is kept secret from the outside word; do NOT publish it on GitHub/GitLab/BitBucket. +|RAILS_LOG_LEVEL +|Log level for the application. Defaults to `info` (possible values are `debug`, `info`, `warn`, `error` and `fatal`). + +|IAT_EXPIRATION_MINUTES +|Expiration time for the JWT tokens, in minutes. Defaults to 60 minutes. + +|HOURS_BEFORE_CREATE_ELECTION +|Number of hours before the election starts that the election can be created. Defaults to 1 hour. + |SEED |Used to force seed test data on production environments, if `true`. diff --git a/docs/modules/develop/pages/manual/operations/automated-tests.adoc b/docs/modules/develop/pages/manual/operations/automated-tests.adoc index 9a010473..c40df3ae 100644 --- a/docs/modules/develop/pages/manual/operations/automated-tests.adoc +++ b/docs/modules/develop/pages/manual/operations/automated-tests.adoc @@ -34,7 +34,7 @@ We divide the test phase in 4 steps: Make sure you set the `SANDBOX` environment variable to any value to activate it; * The web server and the background worker server shall run in separate machines in order for web traffic and background jobs not to affect each other; * Use Sidekiq as queue adapter; -* In `bulletin_board/server/config/settings.yml`, set `iat_expiration_minutes` to few hours/days. +* In `bulletin_board/server/config/settings.yml`, set `iat_expiration_minutes` to few hours/days (or use the ENV variable `IAT_EXPIRATION_MINUTES`). This is the amount of time a vote is considered valid from its emission - since the vote generation phase could take a few hours, you don't want it to be too low and have the Bulletin Board to reject the votes when you start the load test. [#generate-votes]