From b40ca87b2a89d8c78aa618600b995f31d0664dd7 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 31 Jan 2022 16:34:33 +0100 Subject: [PATCH] Maintenance: Improve handling of XSS timeouts in tests. --- spec/models/concerns/has_xss_sanitized_note_examples.rb | 5 +++++ spec/models/ticket/article_spec.rb | 5 +++++ test/unit/html_sanitizer_test.rb | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/spec/models/concerns/has_xss_sanitized_note_examples.rb b/spec/models/concerns/has_xss_sanitized_note_examples.rb index a88a19bd9..051f01e8b 100644 --- a/spec/models/concerns/has_xss_sanitized_note_examples.rb +++ b/spec/models/concerns/has_xss_sanitized_note_examples.rb @@ -5,6 +5,11 @@ RSpec.shared_examples 'HasXssSanitizedNote' do |model_factory:| context 'with injected JS' do subject { create(model_factory, note: 'test 123 some text') } + before do + # XSS processing may run into a timeout on slow CI systems, so turn the timeout off for the test. + stub_const("#{HtmlSanitizer}::PROCESSING_TIMEOUT", nil) + end + it 'strips out some other text diff --git a/test/unit/html_sanitizer_test.rb b/test/unit/html_sanitizer_test.rb index 8d6ff934b..1542cedbc 100644 --- a/test/unit/html_sanitizer_test.rb +++ b/test/unit/html_sanitizer_test.rb @@ -4,6 +4,11 @@ require 'test_helper' class HtmlSanitizerTest < 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, nil) + test 'xss' do assert_equal(HtmlSanitizer.strict('123'), '123') assert_equal(HtmlSanitizer.strict(''), '') @@ -153,4 +158,6 @@ test 123 assert_equal(HtmlSanitizer.strict('test'), 'test') end + + HtmlSanitizer.const_set(:PROCESSING_TIMEOUT, processing_timeout) end