Commit 0355488d authored by Rubén Dávila Santos's avatar Rubén Dávila Santos

Merge branch 'normalise-license-md5' into 'master'

Normalise license MD5 values

See merge request !2205
parents 5514552c 39318708
......@@ -135,6 +135,12 @@ class License < ActiveRecord::Base
self.data = file.read
end
def md5
normalized_data = self.data.gsub("\r\n", "\n").gsub(/\n+$/, '') + "\n"
Digest::MD5.hexdigest(normalized_data)
end
def license
return nil unless self.data
......
......@@ -82,7 +82,7 @@ module Gitlab
if license
usage_data[:edition] = license_edition(license.plan)
usage_data[:license_md5] = Digest::MD5.hexdigest(license.data)
usage_data[:license_md5] = license.md5
usage_data[:historical_max_users] = ::HistoricalData.max_historical_user_count
usage_data[:licensee] = license.licensee
usage_data[:license_user_count] = license.restricted_user_count
......
......@@ -315,6 +315,26 @@ describe License do
end
end
describe "#md5" do
it "returns the same MD5 for licenses with carriage returns and those without" do
other_license = build(:license, data: license.data.gsub("\n", "\r\n"))
expect(other_license.md5).to eq(license.md5)
end
it "returns the same MD5 for licenses with trailing newlines and those without" do
other_license = build(:license, data: license.data.chomp)
expect(other_license.md5).to eq(license.md5)
end
it "returns the same MD5 for licenses with multiple trailing newlines and those with a single trailing newline" do
other_license = build(:license, data: "#{license.data}\n\n\n")
expect(other_license.md5).to eq(license.md5)
end
end
describe "#license" do
context "when no data is provided" do
before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment