Add license encryption key for testing purposes
There's only one encryption key for licenses at the moment. In order to encrypt licenses that were created for testing purposes, a new encryption key is introduced.
This commit is contained in:
parent
d9cc615bc1
commit
755a42599b
9
.test_license_encryption_key.pub
Normal file
9
.test_license_encryption_key.pub
Normal file
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtgemxR8RUJXi3p7G/dkh
|
||||
Yuln1L4lA6GtQsT83X0yTVDbLVsI2C6bepsRjGiLV0R/9JGvTojORx+9F/ZQAiEC
|
||||
g6QXWasAOSmrzr4EjADG6cWcCnOju8hX9yib1HUIBxl+jHkmXP3NPuwyb8p2G149
|
||||
EG1o4apEqE5RtqV/Xyx/u57xTYYZShJ/c7o4iA8xvt6IAKFPFKpQwb5hv4KvUZBP
|
||||
h0xG2qvOjDu430fK8JclPlXHqPjXDkXOZyLd4FvRStdEQU3RVXvUQfuGt/tOMS7J
|
||||
nPQ94fr/xdaEbcEtIlr32+tcgsMWyhqtDCPUWJT1aRPviUgaJKLoVs8tRKwYMV9+
|
||||
1wIDAQAB
|
||||
-----END PUBLIC KEY-----
|
|
@ -1,7 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
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)
|
||||
Gitlab::License.encryption_key = public_key
|
||||
rescue
|
||||
|
|
|
@ -286,7 +286,8 @@ def trial_ends_on
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
|
5
ee/changelogs/unreleased/use_testing_license_key.yml
Normal file
5
ee/changelogs/unreleased/use_testing_license_key.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Add license encryption key for testing purposes
|
||||
merge_request: 42475
|
||||
author:
|
||||
type: added
|
|
@ -849,8 +849,18 @@ def build_license_with_add_ons(add_ons, plan: nil)
|
|||
described_class.delete_all
|
||||
end
|
||||
|
||||
let_it_be(:today) { Date.current }
|
||||
|
||||
it 'does not include the undecryptable license' do
|
||||
undecryptable_license = create(:license, created_at: today)
|
||||
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
|
||||
today = Date.current
|
||||
now = Time.current
|
||||
|
||||
past_license = create(:license, created_at: now - 1.month, data: build(:gitlab_license, starts_at: today - 1.month, expires_at: today + 11.months).export)
|
||||
|
|
Loading…
Reference in a new issue