From 010f59087dfe10d876b6e1e41544b39f3f7955c2 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Thu, 11 Apr 2024 12:24:21 +0200 Subject: [PATCH 1/4] Fix specs failing when run in docker - We mock the value of Setting.signal_server_phone_number, but were filtering out the value of ENV.fetch('SIGNAL_SERVER_PHONE_NUMBER', nil). Filtering out the env variables themselves is flaky because it depends on local .env variables, which is different locally, either with or without docker, and on different machines, like ci, or other teammates. This PR proposes to filter out the value of Setting.signal_server_phone_number, which would be the same as the request that is being received by vcr. --- spec/jobs/signal_adapter/receive_polling_job_spec.rb | 1 + spec/vcr_setup.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/jobs/signal_adapter/receive_polling_job_spec.rb b/spec/jobs/signal_adapter/receive_polling_job_spec.rb index c3a84d08f..2417ec1de 100644 --- a/spec/jobs/signal_adapter/receive_polling_job_spec.rb +++ b/spec/jobs/signal_adapter/receive_polling_job_spec.rb @@ -46,6 +46,7 @@ create(:request) allow(Setting).to receive(:signal_server_phone_number).and_return('SIGNAL_SERVER_PHONE_NUMBER') + allow(Setting).to receive(:signal_cli_rest_api_endpoint).and_return('http://localhost:8080') allow(job).to receive(:ping_monitoring_service).and_return(nil) end diff --git a/spec/vcr_setup.rb b/spec/vcr_setup.rb index fd72e83b7..3a9284e7d 100644 --- a/spec/vcr_setup.rb +++ b/spec/vcr_setup.rb @@ -10,7 +10,7 @@ c.filter_sensitive_data('*100EYES') { ENV.fetch('THREEMARB_API_IDENTITY', nil) } c.filter_sensitive_data('THREEMARB_API_SECRET') { ENV.fetch('THREEMARB_API_SECRET', nil) } c.filter_sensitive_data('THREEMARB_PRIVATE') { ENV.fetch('THREEMARB_PRIVATE', nil) } - c.filter_sensitive_data('SIGNAL_SERVER_PHONE_NUMBER') { ENV.fetch('SIGNAL_SERVER_PHONE_NUMBER', nil) } + c.filter_sensitive_data('SIGNAL_SERVER_PHONE_NUMBER') { Setting.signal_server_phone_number } c.configure_rspec_metadata! From a664e358bd1d0bd34f44f7e848a5bf6329917db9 Mon Sep 17 00:00:00 2001 From: Samuel Oey Date: Fri, 12 Apr 2024 14:42:53 +0200 Subject: [PATCH 2/4] fix: be nice to starters and don't have the only number that breaks the signal specs in the .env.template --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index de6a20730..cc46b4725 100644 --- a/.env.template +++ b/.env.template @@ -4,7 +4,7 @@ POSTGRES_USER= TELEGRAM_BOT_API_KEY=TOKEN TELEGRAM_BOT_USERNAME=NameOfYourBot -SIGNAL_SERVER_PHONE_NUMBER="+4912345789" +SIGNAL_SERVER_PHONE_NUMBER="+4987654321" EMAIL_FROM_ADDRESS=test@example.org From c848b42d63ec8c0e2c8ccf737bc3e41c6d49f914 Mon Sep 17 00:00:00 2001 From: Samuel Oey Date: Wed, 17 Apr 2024 14:16:17 +0200 Subject: [PATCH 3/4] refa: filter the setting data instead of the env data --- spec/vcr_setup.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/vcr_setup.rb b/spec/vcr_setup.rb index 3a9284e7d..f96d65e99 100644 --- a/spec/vcr_setup.rb +++ b/spec/vcr_setup.rb @@ -5,9 +5,9 @@ VCR.configure do |c| c.cassette_library_dir = 'vcr_cassettes' c.hook_into :webmock - c.filter_sensitive_data('TELEGRAM_BOT_API_KEY') { ENV.fetch('TELEGRAM_BOT_API_KEY', nil) } - c.filter_sensitive_data('TELEGRAM_BOT_USERNAME') { ENV.fetch('TELEGRAM_BOT_USERNAME', nil) } - c.filter_sensitive_data('*100EYES') { ENV.fetch('THREEMARB_API_IDENTITY', nil) } + c.filter_sensitive_data('TELEGRAM_BOT_API_KEY') { Setting.telegram_bot_api_key } + c.filter_sensitive_data('TELEGRAM_BOT_USERNAME') { Setting.telegram_bot_username } + c.filter_sensitive_data('*100EYES') { Setting.threemarb_api_identity } c.filter_sensitive_data('THREEMARB_API_SECRET') { ENV.fetch('THREEMARB_API_SECRET', nil) } c.filter_sensitive_data('THREEMARB_PRIVATE') { ENV.fetch('THREEMARB_PRIVATE', nil) } c.filter_sensitive_data('SIGNAL_SERVER_PHONE_NUMBER') { Setting.signal_server_phone_number } From 2f4b5ad8b2b1d31151a5384299a12a0bea1c261e Mon Sep 17 00:00:00 2001 From: Samuel Oey Date: Wed, 17 Apr 2024 14:18:30 +0200 Subject: [PATCH 4/4] refa: get rid of the unnecessary early return breaks execution --- app/adapters/signal_adapter/inbound.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/adapters/signal_adapter/inbound.rb b/app/adapters/signal_adapter/inbound.rb index 5454cd21d..f6128b293 100644 --- a/app/adapters/signal_adapter/inbound.rb +++ b/app/adapters/signal_adapter/inbound.rb @@ -56,7 +56,6 @@ def trigger(event, *args) def initialize_sender(signal_message) signal_phone_number = signal_message.dig(:envelope, :source) sender = Contributor.find_by(signal_phone_number: signal_phone_number) - return nil if signal_phone_number == Setting.signal_server_phone_number unless sender trigger(UNKNOWN_CONTRIBUTOR, signal_phone_number)