Commit 755a4259 authored by Corinna Wiesner's avatar Corinna Wiesner

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.
parent d9cc615b
-----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
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 @@ class License < ApplicationRecord
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
......
---
title: Add license encryption key for testing purposes
merge_request: 42475
author:
type: added
......@@ -849,8 +849,18 @@ RSpec.describe License do
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)
......
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