Skip to content

Commit

Permalink
Test with Active Record 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 30, 2022
1 parent 7242443 commit c2d825c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -2,12 +2,22 @@ name: build
on: [push, pull_request]
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- ruby: 3.1
gemfile: Gemfile
- ruby: 3.2.0-preview2
gemfile: gemfiles/activerecord71.gemfile
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: |
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
Expand Down
13 changes: 13 additions & 0 deletions gemfiles/activerecord71.gemfile
@@ -0,0 +1,13 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake"
gem "minitest", ">= 5"
gem "sqlite3"
gem "activerecord", github: "rails/rails"

gem "aws-sdk-kms"
gem "google-cloud-kms"
gem "vault"
gem "nokogiri" # for aws-sdk
4 changes: 2 additions & 2 deletions lib/active_kms/log_subscriber.rb
Expand Up @@ -4,14 +4,14 @@ def decrypt(event)
return unless logger.debug?

name = "Decrypt Data Key (#{event.duration.round(1)}ms)"
debug " #{color(name, YELLOW, true)}"
debug " #{color(name, YELLOW, bold: true)}"
end

def encrypt(event)
return unless logger.debug?

name = "Encrypt Data Key (#{event.duration.round(1)}ms)"
debug " #{color(name, YELLOW, true)}"
debug " #{color(name, YELLOW, bold: true)}"
end
end
end
3 changes: 2 additions & 1 deletion test/key_provider_test.rb
Expand Up @@ -8,7 +8,8 @@ def setup
def test_works
# should ideally be encrypt: 1 and no decrypt
# https://github.com/rails/rails/issues/42388
assert_operations encrypt: 3, decrypt: 1 do
encrypt = ActiveRecord::VERSION::STRING.to_f >= 7.1 ? 1 : 3
assert_operations encrypt: encrypt, decrypt: 1 do
User.create!(email: "test@example.org")
end

Expand Down
17 changes: 10 additions & 7 deletions test/test_helper.rb
Expand Up @@ -39,13 +39,16 @@ class User < ActiveRecord::Base
raise "Invalid key provider"
end

ActiveRecord::Encryption.configure(
key_provider: key_provider,
# https://github.com/rails/rails/issues/42385
primary_key: "secret",
key_derivation_salt: "secret",
deterministic_key: nil
)
encryption_options = {
key_provider: key_provider
}
# https://github.com/rails/rails/issues/42385
if ActiveRecord::VERSION::STRING.to_f < 7.1
encryption_options[:primary_key] = "secret"
encryption_options[:key_derivation_salt] = "secret"
encryption_options[:deterministic_key] = nil
end
ActiveRecord::Encryption.configure(**encryption_options)

$events = Hash.new(0)
ActiveSupport::Notifications.subscribe(/active_kms/) do |name, _start, _finish, _id, _payload|
Expand Down

0 comments on commit c2d825c

Please sign in to comment.