FIX: add protection for scss removal during upgrade

In some cases plugins would remove scss files or change them, but CSS
was still calculated based off stale data in old instance cache
This commit is contained in:
Sam 2018-05-31 17:02:27 +10:00
parent be28154d3b
commit 5086fdc76d
2 changed files with 36 additions and 1 deletions

View File

@ -256,7 +256,18 @@ class Stylesheet::Manager
raise "attempting to look up theme digest for invalid field"
end
Digest::SHA1.hexdigest(scss.to_s + color_scheme_digest.to_s + settings_digest)
Digest::SHA1.hexdigest(scss.to_s + color_scheme_digest.to_s + settings_digest + plugins_digest)
end
# this protects us from situations where new versions of a plugin removed a file
# old instances may still be serving CSS and not aware of the change
# so we could end up poisoning the cache with a bad file that can not be removed
def plugins_digest
assets = []
assets += DiscoursePluginRegistry.stylesheets.to_a
assets += DiscoursePluginRegistry.mobile_stylesheets.to_a
assets += DiscoursePluginRegistry.desktop_stylesheets.to_a
Digest::SHA1.hexdigest(assets.sort.join)
end
def settings_digest

View File

@ -65,6 +65,30 @@ describe Stylesheet::Manager do
expect(new_link).to include("/stylesheets/desktop_theme_#{theme.id}_")
end
describe 'digest' do
after do
DiscoursePluginRegistry.stylesheets.delete "fake_file"
end
it 'can correctly account for plugins in digest' do
theme = Theme.create!(
name: 'parent',
user_id: -1
)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
digest1 = manager.digest
DiscoursePluginRegistry.stylesheets.add "fake_file"
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
digest2 = manager.digest
expect(digest1).not_to eq(digest2)
end
end
describe 'color_scheme_digest' do
it "changes with category background image" do
theme = Theme.new(