Commit aec045de authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'use_testing_license_key' into 'master'

Add test encryption key

See merge request gitlab-org/gitlab!42475
parents 998f8f87 3e62d6ec
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtgemxR8RUJXi3p7G/dkh
Yuln1L4lA6GtQsT83X0yTVDbLVsI2C6bepsRjGiLV0R/9JGvTojORx+9F/ZQAiEC
g6QXWasAOSmrzr4EjADG6cWcCnOju8hX9yib1HUIBxl+jHkmXP3NPuwyb8p2G149
EG1o4apEqE5RtqV/Xyx/u57xTYYZShJ/c7o4iA8xvt6IAKFPFKpQwb5hv4KvUZBP
h0xG2qvOjDu430fK8JclPlXHqPjXDkXOZyLd4FvRStdEQU3RVXvUQfuGt/tOMS7J
nPQ94fr/xdaEbcEtIlr32+tcgsMWyhqtDCPUWJT1aRPviUgaJKLoVs8tRKwYMV9+
1wIDAQAB
-----END PUBLIC KEY-----
# frozen_string_literal: true # frozen_string_literal: true
Gitlab.ee do Gitlab.ee do
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub")) prefix = ENV['GITLAB_LICENSE_MODE'] == 'test' ? 'test_' : ''
public_key_file = File.read(Rails.root.join(".#{prefix}license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file) public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key Gitlab::License.encryption_key = public_key
rescue rescue
......
...@@ -286,7 +286,8 @@ class License < ApplicationRecord ...@@ -286,7 +286,8 @@ class License < ApplicationRecord
end end
def history def history
all.sort_by { |license| [license.starts_at, license.created_at, license.expires_at] }.reverse decryptable_licenses = all.select { |license| license.license.present? }
decryptable_licenses.sort_by { |license| [license.starts_at, license.created_at, license.expires_at] }.reverse
end end
private private
......
---
title: Add license encryption key for testing purposes
merge_request: 42475
author:
type: added
...@@ -849,6 +849,15 @@ RSpec.describe License do ...@@ -849,6 +849,15 @@ RSpec.describe License do
described_class.delete_all described_class.delete_all
end end
it 'does not include the undecryptable license' do
undecryptable_license = create(:license)
allow(undecryptable_license).to receive(:license).and_return(nil)
allow(License).to receive(:all).and_return([undecryptable_license])
expect(described_class.history.map(&:id)).to be_empty
end
it 'returns the licenses sorted by created_at, starts_at and expires_at descending' do it 'returns the licenses sorted by created_at, starts_at and expires_at descending' do
today = Date.current today = Date.current
now = Time.current now = Time.current
......
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