Skip to content

Commit a51973a

Browse files
committed
Disable encryption for PostgreSQL
This will need to wait for Rails to support binary encrypted columns - see rails/rails#52650.
1 parent 6925096 commit a51973a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ end
3434
configs.each do |config|
3535
namespace :test do
3636
task config do
37+
if config.to_s.start_with?("encrypted") && ENV["TARGET_DB"] == "postgres"
38+
puts "Skipping encrypted tests on PostgreSQL as binary encrypted columns are not supported by Rails yet"
39+
return
40+
end
41+
3742
if config == :default
3843
sh("bin/rails test")
3944
else

lib/solid_cache/engine.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ class Engine < ::Rails::Engine
3535
config.after_initialize do
3636
Rails.cache.setup! if Rails.cache.is_a?(Store)
3737
end
38+
39+
config.after_initialize do
40+
if SolidCache.configuration.encrypt? && SolidCache::Record.connection.adapter_name == "PostgreSQL"
41+
raise \
42+
"Cannot enable encryption for Solid Cache: Active Record Encryption does not currently support " \
43+
"encrypting binary columns on PostgreSQL"
44+
end
45+
end
3846
end
3947
end

test/unit/encryption_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ class SolidCache::EncryptionTest < ActiveSupport::TestCase
4040

4141
private
4242
def raw_first_value
43-
SolidCache::Entry.connection.select_all("select * from solid_cache_entries order by id desc limit 1").first["value"]
43+
raw = SolidCache::Entry.connection.select_all("select * from solid_cache_entries order by id desc limit 1").first["value"]
44+
45+
if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
46+
ActiveRecord::Base.connection.unescape_bytea(raw)
47+
else
48+
raw
49+
end
4450
end
4551

4652
def first_value

0 commit comments

Comments
 (0)