From efa669273bc8aa56ecfced4d63ab0f9af4649273 Mon Sep 17 00:00:00 2001 From: Andrew Cain Date: Thu, 25 Jul 2024 15:36:48 +1000 Subject: [PATCH] fix: ensure tii signing secret is sent as a base64 string --- .../turn_it_in/tii_action_register_webhook.rb | 2 +- test/sidekiq/tii_webhooks_job_test.rb | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/models/turn_it_in/tii_action_register_webhook.rb b/app/models/turn_it_in/tii_action_register_webhook.rb index 2cd008c8f..9a78c813a 100644 --- a/app/models/turn_it_in/tii_action_register_webhook.rb +++ b/app/models/turn_it_in/tii_action_register_webhook.rb @@ -44,7 +44,7 @@ def need_to_register_webhook? def register_webhook data = TCAClient::WebhookWithSecret.new( - signing_secret: ENV.fetch('TCA_SIGNING_KEY', nil), + signing_secret: Base64.encode64(ENV.fetch('TCA_SIGNING_KEY', nil)), url: TurnItIn.webhook_url, event_types: %w[ SIMILARITY_COMPLETE diff --git a/test/sidekiq/tii_webhooks_job_test.rb b/test/sidekiq/tii_webhooks_job_test.rb index 615177b3a..23aeaae0d 100644 --- a/test/sidekiq/tii_webhooks_job_test.rb +++ b/test/sidekiq/tii_webhooks_job_test.rb @@ -35,22 +35,22 @@ def test_register_webhooks headers: {}) # and will register the webhooks - register_webhooks_stub = stub_request(:post, "https://#{ENV['TCA_HOST']}/api/v1/webhooks"). - with(tii_headers). - with( - body: TCAClient::WebhookWithSecret.new( - signing_secret: ENV.fetch('TCA_SIGNING_KEY', nil), - url: TurnItIn.webhook_url, - event_types: [ - 'SIMILARITY_COMPLETE', - 'SUBMISSION_COMPLETE', - 'SIMILARITY_UPDATED', - 'PDF_STATUS', - 'GROUP_ATTACHMENT_COMPLETE' - ] - ).to_json, - ). - to_return(status: 200, body: "", headers: {}) + register_webhooks_stub = stub_request(:post, "https://#{ENV['TCA_HOST']}/api/v1/webhooks") + .with(tii_headers) + .with( + body: TCAClient::WebhookWithSecret.new( + signing_secret: Base64.encode64(ENV.fetch('TCA_SIGNING_KEY', nil)), + url: TurnItIn.webhook_url, + event_types: [ + 'SIMILARITY_COMPLETE', + 'SUBMISSION_COMPLETE', + 'SIMILARITY_UPDATED', + 'PDF_STATUS', + 'GROUP_ATTACHMENT_COMPLETE' + ] + ).to_json + ) + .to_return(status: 200, body: "", headers: {}) job = TiiRegisterWebHookJob.new job.perform