-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23351 from jrafanie/set-secret-token-globally-ear…
…lier-after-eager-load-hook Set secret_key_base early enough for rails processes
- Loading branch information
Showing
8 changed files
with
56 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
RSpec.describe Vmdb::Initializer do | ||
describe ".init_secret_token" do | ||
before do | ||
@token = Rails.application.secret_key_base | ||
end | ||
|
||
after do | ||
Rails.application.config.secret_key_base = @token | ||
Rails.application.secrets = nil | ||
end | ||
|
||
it "defaults to MiqDatabase session_secret_token" do | ||
MiqDatabase.seed | ||
Rails.application.config.secret_key_base = nil | ||
Rails.application.secrets = nil | ||
|
||
described_class.init_secret_token | ||
expect(Rails.application.secret_key_base).to eq(MiqDatabase.first.session_secret_token) | ||
expect(Rails.application.config.secret_key_base).to eq(MiqDatabase.first.session_secret_token) | ||
end | ||
|
||
it "uses random hex when MiqDatabase isn't seeded" do | ||
Rails.application.config.secret_key_base = nil | ||
Rails.application.secrets = nil | ||
|
||
described_class.init_secret_token | ||
expect(Rails.application.secret_key_base).to match(/^\h{128}$/) | ||
expect(Rails.application.config.secret_key_base).to match(/^\h{128}$/) | ||
end | ||
|
||
it "does not reset secrets when token already configured" do | ||
existing_value = SecureRandom.hex(64) | ||
Rails.application.config.secret_key_base = existing_value | ||
Rails.application.secrets = nil | ||
|
||
described_class.init_secret_token | ||
expect(Rails.application.secret_key_base).to eq(existing_value) | ||
expect(Rails.application.config.secret_key_base).to eq(existing_value) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters