Project

General

Profile

Patch #35217 » 0001-replaces-uses-of-Digest-MD5-and-Digest-SHA1-with-AS-.patch

Jens Krämer, 2021-05-07 05:01

View differences:

app/controllers/repositories_controller.rb
User.current.preference.save
end
@cache_key = "repositories/diff/#{@repository.id}/" +
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
ActiveSupport::Digest.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
unless read_fragment(@cache_key)
@diff = @repository.diff(@path, @rev, @rev_to)
(show_error_not_found; return) unless @diff
app/models/attachment.rb
end
# Copies the temporary file to its final location
# and computes its MD5 hash
# and computes its hash
def files_to_final_location
if @temp_file
self.disk_directory = target_directory
......
if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50
ascii = filename
else
ascii = Digest::MD5.hexdigest(filename)
ascii = ActiveSupport::Digest.hexdigest(filename)
# keep the extension if any
ascii << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
end
app/views/repositories/_dir_list_content.html.erb
<% @entries.each do |entry| %>
<% tr_id = Digest::MD5.hexdigest(entry.path)
<% tr_id = ActiveSupport::Digest.hexdigest(entry.path)
depth = params[:depth].to_i %>
<% ent_path = Redmine::CodesetUtil.replace_invalid_utf8(entry.path) %>
<% ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name) %>
lib/plugins/open_id_authentication/lib/open_id_authentication/mem_cache_store.rb
# frozen_string_literal: false
require 'digest/sha1'
require 'openid/store/interface'
module OpenIdAuthentication
......
end
def digest(text)
Digest::SHA1.hexdigest(text)
ActiveSupport::Digest.hexdigest(text)
end
end
end
lib/redmine/wiki_formatting.rb
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'digest/md5'
module Redmine
module WikiFormatting
class StaleSectionError < StandardError; end
......
# Returns a cache key for the given text +format+, +text+, +object+ and +attribute+ or nil if no caching should be done
def cache_key_for(format, text, object, attribute)
if object && attribute && !object.new_record? && format.present?
"formatted_text/#{format}/#{object.class.model_name.cache_key}/#{object.id}-#{attribute}-#{Digest::MD5.hexdigest text}"
"formatted_text/#{format}/#{object.class.model_name.cache_key}/#{object.id}-#{attribute}-#{ActiveSupport::Digest.hexdigest text}"
end
end
lib/redmine/wiki_formatting/markdown/formatter.rb
def get_section(index)
section = extract_sections(index)[1]
hash = Digest::MD5.hexdigest(section)
hash = ActiveSupport::Digest.hexdigest(section)
return section, hash
end
def update_section(index, update, hash=nil)
t = extract_sections(index)
if hash.present? && hash != Digest::MD5.hexdigest(t[1])
if hash.present? && hash != ActiveSupport::Digest.hexdigest(t[1])
raise Redmine::WikiFormatting::StaleSectionError
end
lib/redmine/wiki_formatting/textile/formatter.rb
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../redcloth3', __FILE__)
require 'digest/md5'
module Redmine
module WikiFormatting
......
def get_section(index)
section = extract_sections(index)[1]
hash = Digest::MD5.hexdigest(section)
hash = ActiveSupport::Digest.hexdigest(section)
return section, hash
end
def update_section(index, update, hash=nil)
t = extract_sections(index)
if hash.present? && hash != Digest::MD5.hexdigest(t[1])
if hash.present? && hash != ActiveSupport::Digest.hexdigest(t[1])
raise Redmine::WikiFormatting::StaleSectionError
end
test/functional/wiki_controller_test.rb
:version => 3
},
:section => 2,
:section_hash => Digest::MD5.hexdigest("wrong hash")
:section_hash => ActiveSupport::Digest.hexdigest("wrong hash")
}
end
end
test/helpers/avatars_helper_test.rb
end
def test_avatar_with_user
assert_include Digest::MD5.hexdigest('jsmith@somenet.foo'), avatar(User.find_by_mail('jsmith@somenet.foo'))
assert_include ActiveSupport::Digest.hexdigest('jsmith@somenet.foo'), avatar(User.find_by_mail('jsmith@somenet.foo'))
end
def test_avatar_with_email_string
assert_include Digest::MD5.hexdigest('jsmith@somenet.foo'), avatar('jsmith <jsmith@somenet.foo>')
assert_include ActiveSupport::Digest.hexdigest('jsmith@somenet.foo'), avatar('jsmith <jsmith@somenet.foo>')
end
def test_avatar_with_anonymous_user
test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb
assert_kind_of Array, result
assert_equal 2, result.size
assert_equal expected, result.first, "section content did not match"
assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
assert_equal ActiveSupport::Digest.hexdigest(expected), result.last, "section hash did not match"
end
end
test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
require 'digest/md5'
class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
def setup
......
assert_equal(
[STR_WITHOUT_PRE[0], replacement, STR_WITHOUT_PRE[2..4]].flatten.join("\n\n"),
@formatter.new(TEXT_WITHOUT_PRE).
update_section(2, replacement, Digest::MD5.hexdigest(STR_WITHOUT_PRE[1]))
update_section(2, replacement, ActiveSupport::Digest.hexdigest(STR_WITHOUT_PRE[1]))
)
end
def test_update_section_with_wrong_hash_should_raise_an_error
assert_raise Redmine::WikiFormatting::StaleSectionError do
@formatter.new(TEXT_WITHOUT_PRE).update_section(2, "New text", Digest::MD5.hexdigest("Old text"))
@formatter.new(TEXT_WITHOUT_PRE).update_section(2, "New text", ActiveSupport::Digest.hexdigest("Old text"))
end
end
......
assert_kind_of Array, result
assert_equal 2, result.size
assert_equal expected, result.first, "section content did not match"
assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
assert_equal ActiveSupport::Digest.hexdigest(expected), result.last, "section hash did not match"
end
end
    (1-1/1)