mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract encrypted models to their own files
We are not encrypting attributes when loading models with the table missing. This way we make sure we only load the encrypted models when necessary during the encryption tests and prevent the problem of missing encrypted attributes due to having cached the class without them encrypted.
This commit is contained in:
parent
406fab468e
commit
81afcabd19
21 changed files with 74 additions and 61 deletions
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/post"
|
||||
require "models/post_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::ConcurrencyTest < ActiveRecord::TestCase
|
||||
setup do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/book"
|
||||
require "models/book_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::ConfigurableTest < ActiveRecord::TestCase
|
||||
test "can access context properties with top level getters" do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/book"
|
||||
require "models/post"
|
||||
require "models/book_encrypted"
|
||||
require "models/post_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::ContextsTest < ActiveRecord::TestCase
|
||||
fixtures :posts
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/author"
|
||||
require "models/book"
|
||||
require "models/post"
|
||||
require "models/author_encrypted"
|
||||
require "models/book_encrypted"
|
||||
require "models/post_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::EncryptableRecordApiTest < ActiveRecord::TestCase
|
||||
fixtures :posts
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/author"
|
||||
require "models/book"
|
||||
require "models/post"
|
||||
require "models/traffic_light"
|
||||
require "models/author_encrypted"
|
||||
require "models/book_encrypted"
|
||||
require "models/post_encrypted"
|
||||
require "models/traffic_light_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::EncryptableRecordTest < ActiveRecord::TestCase
|
||||
fixtures :books, :posts
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/book"
|
||||
require "models/book_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::EncryptableFixtureTest < ActiveRecord::TestCase
|
||||
fixtures :encrypted_books, :encrypted_book_that_ignores_cases
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/author"
|
||||
require "models/author_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::EncryptionSchemesTest < ActiveRecord::TestCase
|
||||
test "can decrypt encrypted_value encrypted with a different encryption scheme" do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/book"
|
||||
require "models/book_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::ExtendedDeterministicQueriesTest < ActiveRecord::TestCase
|
||||
setup do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/author"
|
||||
require "models/post"
|
||||
require "models/author_encrypted"
|
||||
require "models/post_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::MassEncryptionTest < ActiveRecord::TestCase
|
||||
setup do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/book"
|
||||
require "models/post"
|
||||
require "models/book_encrypted"
|
||||
require "models/post_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::EncryptionPerformanceTest < ActiveRecord::TestCase
|
||||
fixtures :encrypted_books, :posts
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/book"
|
||||
require "models/book_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::EvenlopeEncryptionPerformanceTest < ActiveRecord::TestCase
|
||||
fixtures :encrypted_books
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/book"
|
||||
require "models/book_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::ExtendedDeterministicQueriesPerformanceTest < ActiveRecord::TestCase
|
||||
# TODO: Is this failing only with SQLite/in memory adapter?
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/encryption/helper"
|
||||
require "models/post"
|
||||
require "models/post_encrypted"
|
||||
|
||||
class ActiveRecord::Encryption::UnencryptedAttributesTest < ActiveRecord::TestCase
|
||||
test "when :support_unencrypted_data is off, it works with unencrypted attributes normally" do
|
||||
|
|
|
@ -258,9 +258,3 @@ class AuthorFavoriteWithScope < ActiveRecord::Base
|
|||
belongs_to :author
|
||||
belongs_to :favorite_author, class_name: "Author"
|
||||
end
|
||||
|
||||
class EncryptedAuthor < Author
|
||||
self.table_name = "authors"
|
||||
|
||||
encrypts :name, key: "my very own key", previous: { deterministic: true }
|
||||
end
|
||||
|
|
9
activerecord/test/models/author_encrypted.rb
Normal file
9
activerecord/test/models/author_encrypted.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "models/author"
|
||||
|
||||
class EncryptedAuthor < Author
|
||||
self.table_name = "authors"
|
||||
|
||||
encrypts :name, key: "my very own key", previous: { deterministic: true }
|
||||
end
|
|
@ -33,21 +33,3 @@ class PublishedBook < ActiveRecord::Base
|
|||
|
||||
validates_uniqueness_of :isbn
|
||||
end
|
||||
|
||||
class EncryptedBook < Book
|
||||
self.table_name = "books"
|
||||
|
||||
encrypts :name, deterministic: true
|
||||
end
|
||||
|
||||
class EncryptedBookWithDowncaseName < Book
|
||||
self.table_name = "books"
|
||||
|
||||
encrypts :name, deterministic: true, downcase: true
|
||||
end
|
||||
|
||||
class EncryptedBookThatIgnoresCase < Book
|
||||
self.table_name = "books"
|
||||
|
||||
encrypts :name, deterministic: true, ignore_case: true
|
||||
end
|
||||
|
|
21
activerecord/test/models/book_encrypted.rb
Normal file
21
activerecord/test/models/book_encrypted.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "models/book"
|
||||
|
||||
class EncryptedBook < Book
|
||||
self.table_name = "books"
|
||||
|
||||
encrypts :name, deterministic: true
|
||||
end
|
||||
|
||||
class EncryptedBookWithDowncaseName < Book
|
||||
self.table_name = "books"
|
||||
|
||||
encrypts :name, deterministic: true, downcase: true
|
||||
end
|
||||
|
||||
class EncryptedBookThatIgnoresCase < Book
|
||||
self.table_name = "books"
|
||||
|
||||
encrypts :name, deterministic: true, ignore_case: true
|
||||
end
|
|
@ -377,15 +377,3 @@ class Postesque < ActiveRecord::Base
|
|||
belongs_to :author_with_address, class_name: "Author", foreign_key: :author_id
|
||||
belongs_to :author_with_the_letter_a, class_name: "Author", foreign_key: :author_id
|
||||
end
|
||||
|
||||
class EncryptedPost < Post
|
||||
self.table_name = "posts"
|
||||
|
||||
# We want to modify the key for testing purposes
|
||||
class MutableDerivedSecretKeyProvider < ActiveRecord::Encryption::DerivedSecretKeyProvider
|
||||
attr_accessor :key
|
||||
end
|
||||
|
||||
encrypts :title
|
||||
encrypts :body, key_provider: MutableDerivedSecretKeyProvider.new("my post body secret!")
|
||||
end
|
||||
|
|
15
activerecord/test/models/post_encrypted.rb
Normal file
15
activerecord/test/models/post_encrypted.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "models/post"
|
||||
|
||||
class EncryptedPost < Post
|
||||
self.table_name = "posts"
|
||||
|
||||
# We want to modify the key for testing purposes
|
||||
class MutableDerivedSecretKeyProvider < ActiveRecord::Encryption::DerivedSecretKeyProvider
|
||||
attr_accessor :key
|
||||
end
|
||||
|
||||
encrypts :title
|
||||
encrypts :body, key_provider: MutableDerivedSecretKeyProvider.new("my post body secret!")
|
||||
end
|
|
@ -4,7 +4,3 @@ class TrafficLight < ActiveRecord::Base
|
|||
serialize :state, Array
|
||||
serialize :long_state, Array
|
||||
end
|
||||
|
||||
class EncryptedTrafficLight < TrafficLight
|
||||
encrypts :state
|
||||
end
|
||||
|
|
8
activerecord/test/models/traffic_light_encrypted.rb
Normal file
8
activerecord/test/models/traffic_light_encrypted.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
|
||||
require "models/traffic_light"
|
||||
|
||||
class EncryptedTrafficLight < TrafficLight
|
||||
encrypts :state
|
||||
end
|
Loading…
Reference in a new issue