Commit 56994bf0 authored by Tiger Watson's avatar Tiger Watson

Merge branch 'vi-349313-fix-migration' into 'master'

Fix migration for cases with empty strings

See merge request gitlab-org/gitlab!77506
parents 337cbb5f 8d5405a6
...@@ -13,6 +13,8 @@ class EncryptStaticObjectsExternalStorageAuthToken < Gitlab::Database::Migration ...@@ -13,6 +13,8 @@ class EncryptStaticObjectsExternalStorageAuthToken < Gitlab::Database::Migration
ApplicationSetting.reset_column_information ApplicationSetting.reset_column_information
ApplicationSetting.encrypted_token_is_null.plaintext_token_is_not_null.find_each do |application_setting| ApplicationSetting.encrypted_token_is_null.plaintext_token_is_not_null.find_each do |application_setting|
next if application_setting.static_objects_external_storage_auth_token.empty?
token_encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(application_setting.static_objects_external_storage_auth_token) token_encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(application_setting.static_objects_external_storage_auth_token)
application_setting.update!(static_objects_external_storage_auth_token_encrypted: token_encrypted) application_setting.update!(static_objects_external_storage_auth_token_encrypted: token_encrypted)
end end
......
...@@ -53,4 +53,26 @@ RSpec.describe EncryptStaticObjectsExternalStorageAuthToken, :migration do ...@@ -53,4 +53,26 @@ RSpec.describe EncryptStaticObjectsExternalStorageAuthToken, :migration do
end end
end end
end end
context 'when static_objects_external_storage_auth_token is empty string' do
it 'does not break' do
settings = application_settings.create!
settings.update_column(:static_objects_external_storage_auth_token, '')
reversible_migration do |migration|
migration.before -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to eq('')
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_nil
}
migration.after -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to eq('')
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_nil
}
end
end
end
end end
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