From 99d7cfe20048b3d9b0d8348421a076c3c50cb7f5 Mon Sep 17 00:00:00 2001 From: Nikita Vasilevsky Date: Thu, 19 Dec 2024 12:56:54 +0000 Subject: [PATCH] [docs] Add `active_record_encryption.rb` bug report template --- CONTRIBUTING.md | 7 +++ .../active_record_encryption.rb | 53 +++++++++++++++++++ .../source/contributing_to_ruby_on_rails.md | 1 + 3 files changed, 61 insertions(+) create mode 100644 guides/bug_report_templates/active_record_encryption.rb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ba892a28d376c..7c9dd5c6a0e2e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,13 @@ * If possible, use the relevant bug report templates to create the issue. Simply copy the content of the appropriate template into a .rb file, make the necessary changes to demonstrate the issue, and **paste the content into the issue description**: * [**Active Record** (models, database) issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record.rb) + * [**Active Record Migrations** issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_migrations.rb) + * [**Active Record Encryption** issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_encryption.rb) + * [**Action View** (views, helpers) issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_view.rb) + * [**Active Job** issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_job.rb) + * [**Active Storage** issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_storage.rb) + * [**Action Mailer** issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailer.rb) + * [**Action Mailbox** issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailbox.rb) * [**Action Pack** (controllers, routing) issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_controller.rb) * [**Generic template** for other issues](https://github.com/rails/rails/blob/main/guides/bug_report_templates/generic.rb) diff --git a/guides/bug_report_templates/active_record_encryption.rb b/guides/bug_report_templates/active_record_encryption.rb new file mode 100644 index 0000000000000..f1280d266ca99 --- /dev/null +++ b/guides/bug_report_templates/active_record_encryption.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require "bundler/inline" + +gemfile(true) do + source "https://rubygems.org" + + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" + + gem "sqlite3" +end + +require "active_record/railtie" +require "minitest/autorun" + +# This connection will do for database-independent bug reports. +ENV["DATABASE_URL"] = "sqlite3::memory:" + +class TestApp < Rails::Application + config.load_defaults Rails::VERSION::STRING.to_f + config.eager_load = false + config.logger = Logger.new($stdout) + + config.active_record.encryption.primary_key = "primary_key" + config.active_record.encryption.deterministic_key = "deterministic_key" + config.active_record.encryption.key_derivation_salt = "key_derivation_salt" +end +Rails.application.initialize! + +ActiveRecord::Schema.define do + create_table :users, force: true do |t| + t.string :email + end +end + +class User < ActiveRecord::Base + encrypts :email +end + +class BugTest < ActiveSupport::TestCase + def test_encryption_stuff + post = User.create!(email: "test@example.com") + + encrypted_email = post.read_attribute_before_type_cast(:email) + + assert_not_equal "test@example.com", encrypted_email + assert_not_equal post.read_attribute(:email), encrypted_email + + assert_equal "test@example.com", post.email + end +end diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index 6aca596143618..3d89e47969284 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -41,6 +41,7 @@ Having a way to reproduce your issue will help people confirm, investigate, and * Template for Active Record (models, database) issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record.rb) * Template for testing Active Record (migration) issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_migrations.rb) +* Template for Active Record Encryption issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_encryption.rb) * Template for Action Pack (controllers, routing) issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_controller.rb) * Template for Action View (views, helpers) issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_view.rb) * Template for Active Job issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_job.rb)