From 65bd4c7ce716bc8323780a08d48d72b8f7e567fd Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 7 Mar 2022 06:55:24 +0100 Subject: [PATCH] Maintenance: Fix HtmlSanitizer timeout stubbing in minitest. --- test/unit/html_sanitizer_test.rb | 14 +++++++++----- test/unit/ticket_trigger_test.rb | 16 +++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/test/unit/html_sanitizer_test.rb b/test/unit/html_sanitizer_test.rb index 1542cedbc..1fc6364c9 100644 --- a/test/unit/html_sanitizer_test.rb +++ b/test/unit/html_sanitizer_test.rb @@ -4,10 +4,16 @@ require 'test_helper' class HtmlSanitizerTest < ActiveSupport::TestCase - processing_timeout = HtmlSanitizer.const_get(:PROCESSING_TIMEOUT) + setup do + @processing_timeout = HtmlSanitizer.const_get(:PROCESSING_TIMEOUT) - # XSS processing may run into a timeout on slow CI systems, so turn the timeout off for the test. - HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, nil) + # XSS processing may run into a timeout on slow CI systems, so turn the timeout off for the test. + HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, nil) + end + + teardown do + HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, @processing_timeout) + end test 'xss' do assert_equal(HtmlSanitizer.strict('123'), '123') @@ -158,6 +164,4 @@ test 123 assert_equal(HtmlSanitizer.strict('test'), 'test') end - - HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, processing_timeout) end diff --git a/test/unit/ticket_trigger_test.rb b/test/unit/ticket_trigger_test.rb index 92086a41a..bdcd4efd9 100644 --- a/test/unit/ticket_trigger_test.rb +++ b/test/unit/ticket_trigger_test.rb @@ -4,13 +4,17 @@ require 'test_helper' class TicketTriggerTest < ActiveSupport::TestCase - processing_timeout = HtmlSanitizer.const_get(:PROCESSING_TIMEOUT) - - # XSS processing may run into a timeout on slow CI systems, so turn the timeout off for the test. - HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, 0.0001) - setup do Setting.set('ticket_trigger_recursive', true) + + @processing_timeout = HtmlSanitizer.const_get(:PROCESSING_TIMEOUT) + + # XSS processing may run into a timeout on slow CI systems, so turn the timeout off for the test. + HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, nil) + end + + teardown do + HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, @processing_timeout) end test '1 basic' do @@ -4688,6 +4692,4 @@ class TicketTriggerTest < ActiveSupport::TestCase assert_match('Thanks for your inquiry (Online-apotheke. Günstigster Preis. Ohne Rezepte)!', article1.subject) assert_equal(0, article1.attachments.count) end - - HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, processing_timeout) end