我有一个带有加密属性的模型的Rails 7.0.3应用程序。我有一个RSpec测试来测试模型的行为。我有一个运行GitHub的RSpec操作工作流设置。但是:每一次针对特定提交的第一次运行都会失败,每一次运行都会成功地执行。作为
错误:
ActiveRecord::Encryption::Errors::Configuration:
key_derivation_salt is not configured. Please configure it via credential active_record_encryption.key_derivation_salt or by setting config.active_record.encryption.key_derivation_saltGitHub操作配置(为了简洁起见,忽略了一些不必要的细节):
name: CI
on: [push]
jobs:
rspec:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ".ruby-version"
- name: Bundle Install
run: |
gem install bundler -v $(grep 'BUNDLED WITH' -A1 Gemfile.lock | tail -n 1 )
bundle config set --local path 'vendor/bundle'
bundle install --jobs 4 --retry 3
- env:
RAILS_MASTER_KEY: "${{ secrets.RAILS_MASTER_KEY }}"
run: RAILS_ENV=test bundle exec rspec我在回购配置中有秘密设置:

必要的加密配置存储在test.enc.yml中。
active_record_encryption:
primary_key: u▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉
deterministic_key: 4▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉
key_derivation_salt: R▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉我真的不喜欢使用RSpec retry/rerun的一些味道来修复它。我真的很想解决根本的问题。有人知道吗?
发布于 2022-07-08 10:23:04
在测试环境中加载credentials看起来更像是一个问题。今天我偶然发现了类似的错误,但我不想通过RAILS_MASTER_KEY测试环境。我所做的是将这段代码添加到config/environments/test.rb文件中:
config.active_record.encryption.primary_key = 'test'
config.active_record.encryption.deterministic_key = 'test'
config.active_record.encryption.key_derivation_salt = 'test'除非在测试环境中不需要外部安全的DB,否则这将为您完成任务。
https://stackoverflow.com/questions/72481748
复制相似问题