debian-mirror-gitlab/spec/migrations/generate_ci_jwt_signing_key_spec.rb

43 lines
1.2 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2021-09-04 01:27:46 +05:30
require_migration!
2021-01-29 00:20:46 +05:30
RSpec.describe GenerateCiJwtSigningKey do
let(:application_settings) do
Class.new(ActiveRecord::Base) do
self.table_name = 'application_settings'
attr_encrypted :ci_jwt_signing_key, {
mode: :per_attribute_iv,
2021-06-08 01:23:25 +05:30
key: Gitlab::Utils.ensure_utf8_size(Rails.application.secrets.db_key_base, bytes: 32.bytes),
2021-01-29 00:20:46 +05:30
algorithm: 'aes-256-gcm',
encode: true
}
end
end
it 'generates JWT signing key' do
application_settings.create!
reversible_migration do |migration|
migration.before -> {
settings = application_settings.first
expect(settings.ci_jwt_signing_key).to be_nil
expect(settings.encrypted_ci_jwt_signing_key).to be_nil
expect(settings.encrypted_ci_jwt_signing_key_iv).to be_nil
}
migration.after -> {
settings = application_settings.first
expect(settings.encrypted_ci_jwt_signing_key).to be_present
expect(settings.encrypted_ci_jwt_signing_key_iv).to be_present
expect { OpenSSL::PKey::RSA.new(settings.ci_jwt_signing_key) }.not_to raise_error
}
end
end
end