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 8b88cf2f0..e897eaabb 100644 --- a/app/models/turn_it_in/tii_action_register_webhook.rb +++ b/app/models/turn_it_in/tii_action_register_webhook.rb @@ -41,10 +41,11 @@ def need_to_register_webhook? end def register_webhook - raise "TCA_SIGNING_KEY is not set" if data.signing_secret.nil? + key = ENV.fetch('TCA_SIGNING_KEY', nil) + raise "TCA_SIGNING_KEY is not set" if key.nil? data = TCAClient::WebhookWithSecret.new( - signing_secret: Base64.encode64(ENV.fetch('TCA_SIGNING_KEY', nil)).tr("\n", ''), + signing_secret: Base64.encode64(key).tr("\n", ''), url: TurnItIn.webhook_url, event_types: %w[ SIMILARITY_COMPLETE diff --git a/test/models/task_test.rb b/test/models/task_test.rb index 9ad27e924..c20f32fb2 100644 --- a/test/models/task_test.rb +++ b/test/models/task_test.rb @@ -850,6 +850,7 @@ def test_accept_files_checks_they_all_exist task.task_status = TaskStatus.not_started task.save! + task.reload # Now... lets upload a submission with no files task.accept_submission user, [], user, self, nil, 'ready_for_feedback', nil @@ -860,7 +861,16 @@ def test_accept_files_checks_they_all_exist # Now... lets upload a submission with too many files begin - task.accept_submission user, [], user, self, nil, 'ready_for_feedback', nil + task.accept_submission user, + [ + { + id: 'file0', + name: 'Document 1', + type: 'document', + filename: 'file0.pdf', + "tempfile" => File.new(test_file_path('submissions/1.2P.pdf')) + } + ], user, self, nil, 'ready_for_feedback', nil assert false, 'Should have raised an error with too many files submitted' rescue StandardError => e assert_equal :not_started, task.status diff --git a/test/sidekiq/tii_webhooks_job_test.rb b/test/sidekiq/tii_webhooks_job_test.rb index 08fbe9dd4..2381029ca 100644 --- a/test/sidekiq/tii_webhooks_job_test.rb +++ b/test/sidekiq/tii_webhooks_job_test.rb @@ -5,6 +5,9 @@ class TiiWebhooksJobTest < ActiveSupport::TestCase include TestHelpers::TiiTestHelper def test_register_webhooks + setup_tii_eula + setup_tii_features_enabled + Doubtfire::Application.config.tii_register_webhook = true # Will ask for current webhooks @@ -32,14 +35,17 @@ def test_register_webhooks ] ) ].to_json, - headers: {}) + headers: {} + ) + + ENV['TCA_SIGNING_KEY'] = 'TESTING' # 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: Base64.encode64(ENV.fetch('TCA_SIGNING_KEY', nil)).tr("\n", '' ), + signing_secret: Base64.encode64(ENV.fetch('TCA_SIGNING_KEY', nil)).tr("\n", ''), url: TurnItIn.webhook_url, event_types: [ 'SIMILARITY_COMPLETE',