summaryrefslogtreecommitdiff
path: root/spec/initializers
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-11-22 16:17:08 +0000
committerNick Thomas <nick@gitlab.com>2018-11-27 18:24:18 +0000
commit6ddefe7cada5268469561c70a8557cf1545684b2 (patch)
tree3f54240e3472da4c4f6004ae19da20f78ba476f3 /spec/initializers
parent0afce35d65aa433d221e41632c6d8095ab68c39f (diff)
downloadgitlab-ce-6ddefe7cada5268469561c70a8557cf1545684b2.tar.gz
Correctly handle data-loss scenarios when encrypting columns
If the EncryptColumns background migration runs in a sidekiq with a stale view of the database schema, or when the purported destination columns don't actually exist, data loss can result. Attempt to work around these issues by reloading schema information before running the migration, and raising errors if the model reports that any of its source or destination columns are missing.
Diffstat (limited to 'spec/initializers')
-rw-r--r--spec/initializers/attr_encrypted_no_db_connection_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/initializers/attr_encrypted_no_db_connection_spec.rb b/spec/initializers/attr_encrypted_no_db_connection_spec.rb
new file mode 100644
index 00000000000..2da9f1cbd96
--- /dev/null
+++ b/spec/initializers/attr_encrypted_no_db_connection_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe 'GitLab monkey-patches to AttrEncrypted' do
+ describe '#attribute_instance_methods_as_symbols_available?' do
+ it 'returns false' do
+ expect(ActiveRecord::Base.__send__(:attribute_instance_methods_as_symbols_available?)).to be_falsy
+ end
+
+ it 'does not define virtual attributes' do
+ klass = Class.new(ActiveRecord::Base) do
+ # We need some sort of table to work on
+ self.table_name = 'projects'
+
+ attr_encrypted :foo
+ end
+
+ instance = klass.new
+
+ aggregate_failures do
+ %w[
+ encrypted_foo encrypted_foo=
+ encrypted_foo_iv encrypted_foo_iv=
+ encrypted_foo_salt encrypted_foo_salt=
+ ].each do |method_name|
+ expect(instance).not_to respond_to(method_name)
+ end
+ end
+ end
+ end
+end