From 42fc30e54c9de04c28f4138c11360ac9abeff7a8 Mon Sep 17 00:00:00 2001 From: Moncef Belyamani Date: Wed, 19 Sep 2018 15:53:14 -0400 Subject: [PATCH] LG-651 Allow newrelic_rpm to be updated **Why**: The `newrelic_rpm` gem added a call to `SecureRandom.hex(8)` on 6/13/18: https://github.com/newrelic/rpm/commit/60ef61c512a29107de5015b1d574efc4566d08f6 Some of our tests stub calls to `SecureRandom`, and because we have New Relic tracers in an initializer, the newly-added call to `SecureRandom` in the gem caused the tests to fail because they are not expecting that additional call. RSpec tells us to stub the call with a default value first in this case. --- Gemfile.lock | 2 +- spec/services/encryption/password_verifier_spec.rb | 5 +++++ spec/services/encryption/user_access_key_spec.rb | 9 +++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 84ec516c697..0fc9ea0a6ef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -353,7 +353,7 @@ GEM net-sftp (2.1.2) net-ssh (>= 2.6.5) net-ssh (4.1.0) - newrelic_rpm (5.2.0.345) + newrelic_rpm (5.4.0.347) nio4r (2.3.1) nokogiri (1.8.4) mini_portile2 (~> 2.3.0) diff --git a/spec/services/encryption/password_verifier_spec.rb b/spec/services/encryption/password_verifier_spec.rb index fa93fbcb490..e62bcd53aa9 100644 --- a/spec/services/encryption/password_verifier_spec.rb +++ b/spec/services/encryption/password_verifier_spec.rb @@ -4,6 +4,11 @@ describe '.digest' do it 'creates a digest from the password' do salt = '1' * 64 # 32 hex encoded bytes is 64 characters + # The newrelic_rpm gem added a call to `SecureRandom.hex(8)` in + # abstract_segment.rb on 6/13/18. Our New Relic tracers in + # config/initializers/new_relic_tracers.rb trigger this call, which + # is why we stub with a default value first. + allow(SecureRandom).to receive(:hex) { salt } allow(SecureRandom).to receive(:hex).once.with(32).and_return(salt) digest = described_class.digest('saltypickles') diff --git a/spec/services/encryption/user_access_key_spec.rb b/spec/services/encryption/user_access_key_spec.rb index 8a3f0a05c11..5a5f264ba26 100644 --- a/spec/services/encryption/user_access_key_spec.rb +++ b/spec/services/encryption/user_access_key_spec.rb @@ -21,6 +21,11 @@ before do allow(FeatureManagement).to receive(:use_kms?).and_return(true) + # The newrelic_rpm gem added a call to `SecureRandom.hex(8)` in + # abstract_segment.rb on 6/13/18. Our New Relic tracers in + # config/initializers/new_relic_tracers.rb trigger this call, which + # is why we stub with a default value first. + allow(SecureRandom).to receive(:random_bytes) { random_r } allow(SecureRandom).to receive(:random_bytes).with(32).and_return(random_r) stub_aws_kms_client(random_r, encrypted_random_r) end @@ -78,7 +83,7 @@ it 'assigns random_r and calculates the cek, encryption_key, and encrypted_password' do subject.build - expect(SecureRandom).to have_received(:random_bytes).once + expect(SecureRandom).to have_received(:random_bytes).with(32).once expect(subject.random_r).to eq(random_r) expect(subject.encryption_key).to eq(encryption_key) expect(subject.cek).to eq(cek) @@ -90,7 +95,7 @@ it 'derives random_r from the encryption key and sets the cek and encrypted password' do subject.unlock(encryption_key) - expect(SecureRandom).to_not have_received(:random_bytes) + expect(SecureRandom).to_not have_received(:random_bytes).with(32) expect(subject.random_r).to eq(random_r) expect(subject.encryption_key).to eq(encryption_key) expect(subject.cek).to eq(cek)