Commit 3548b0bd authored by Stan Hu's avatar Stan Hu

Merge branch 'id-robust-license-method' into 'master'

Repository#license returns nil when license_key is not recognised

See merge request gitlab-org/gitlab!69878
parents a22c7bc5 2720e7d8
......@@ -627,7 +627,12 @@ class Repository
def license
return unless license_key
Licensee::License.new(license_key)
licensee_object = Licensee::License.new(license_key)
return if licensee_object.name.blank?
licensee_object
rescue Licensee::InvalidLicense
end
memoize_method :license
......
......@@ -1338,6 +1338,12 @@ RSpec.describe Repository do
expect(repository.license).to be_nil
end
it 'returns nil when license_key is not recognized' do
expect(repository).to receive(:license_key).twice.and_return('not-recognized')
expect(repository.license).to be_nil
end
it 'returns other when the content is not recognizable' do
license = Licensee::License.new('other')
repository.create_file(user, 'LICENSE', 'Gitlab B.V.',
......
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