|
1 | | -# require "minitest/mock" |
2 | | -# require_relative "../../test_helper" |
3 | | -# |
4 | | -# class Rails::AppEnv::CredentialsTest < ActiveSupport::TestCase |
5 | | -# test "Credentials#content_path returns 'config/credentials/{APP_ENV}.yml.enc' if the file exist" do |
6 | | -# Dir.mktmpdir do |tmp_dir| |
7 | | -# Rails.stub :root, Pathname(tmp_dir) do |
8 | | -# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do |
9 | | -# path = Rails.root.join("config/credentials/fake_foo.yml.enc") |
10 | | -# |
11 | | -# FileUtils.mkdir_p File.dirname(path) |
12 | | -# FileUtils.touch path |
13 | | -# |
14 | | -# assert_equal path, Rails::AppEnv::Credentials.content_path |
15 | | -# end |
16 | | -# end |
17 | | -# end |
18 | | -# end |
19 | | -# |
20 | | -# test "Credentials#content_path falls back to 'config/credentials.yml.enc' if the file does not exist" do |
21 | | -# Dir.mktmpdir do |tmp_dir| |
22 | | -# Rails.stub :root, Pathname(tmp_dir) do |
23 | | -# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do |
24 | | -# path = Rails.root.join("config/credentials.yml.enc") |
25 | | -# |
26 | | -# assert_equal path, Rails::AppEnv::Credentials.content_path |
27 | | -# end |
28 | | -# end |
29 | | -# end |
30 | | -# end |
31 | | -# |
32 | | -# test "Credentials#key_path returns 'config/credentials/{APP_ENV}.key' if the file exist" do |
33 | | -# Dir.mktmpdir do |tmp_dir| |
34 | | -# Rails.stub :root, Pathname(tmp_dir) do |
35 | | -# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do |
36 | | -# path = Rails.root.join("config/credentials/fake_foo.key") |
37 | | -# |
38 | | -# FileUtils.mkdir_p File.dirname(path) |
39 | | -# FileUtils.touch path |
40 | | -# |
41 | | -# assert_equal path, Rails::AppEnv::Credentials.key_path |
42 | | -# end |
43 | | -# end |
44 | | -# end |
45 | | -# end |
46 | | -# |
47 | | -# test "Credentials#key_path falls back to 'config/master.key' if the file does not exist" do |
48 | | -# Dir.mktmpdir do |tmp_dir| |
49 | | -# Rails.stub :root, Pathname(tmp_dir) do |
50 | | -# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do |
51 | | -# path = Rails.root.join("config/master.key") |
52 | | -# |
53 | | -# assert_equal path, Rails::AppEnv::Credentials.key_path |
54 | | -# end |
55 | | -# end |
56 | | -# end |
57 | | -# end |
58 | | -# end |
| 1 | +require "minitest/mock" |
| 2 | +require_relative "../../test_helper" |
| 3 | + |
| 4 | +class Rails::AppEnv::CredentialsTest < ActiveSupport::TestCase |
| 5 | + test "#configuration is a kind of ActiveSupport::Credentials" do |
| 6 | + assert_kind_of ActiveSupport::InheritableOptions, Rails::AppEnv::Credentials.configuration |
| 7 | + end |
| 8 | + |
| 9 | + test "#configuration.content_path is config/credentials/{Rails.app_env}.yml.enc" do |
| 10 | + Dir.mktmpdir do |tmp_dir| |
| 11 | + Rails.stub :root, Pathname(tmp_dir) do |
| 12 | + Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do |
| 13 | + path = Rails.root.join("config/credentials/foo.yml.enc") |
| 14 | + |
| 15 | + FileUtils.mkdir_p File.dirname(path) |
| 16 | + FileUtils.touch path |
| 17 | + |
| 18 | + assert_equal path, Rails::AppEnv::Credentials.configuration.content_path |
| 19 | + end |
| 20 | + end |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + test "#configuration.content_path falls back to config/credentials.yml.enc when config/credentials/{Rails.app_env}.yml.enc not exist" do |
| 25 | + Dir.mktmpdir do |tmp_dir| |
| 26 | + Rails.stub :root, Pathname(tmp_dir) do |
| 27 | + Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do |
| 28 | + path = Rails.root.join("config/credentials.yml.enc") |
| 29 | + |
| 30 | + assert_equal path, Rails::AppEnv::Credentials.configuration.content_path |
| 31 | + end |
| 32 | + end |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + test "#configuration.key_path is config/credentials/{APP_ENV}.key" do |
| 37 | + Dir.mktmpdir do |tmp_dir| |
| 38 | + Rails.stub :root, Pathname(tmp_dir) do |
| 39 | + Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do |
| 40 | + path = Rails.root.join("config/credentials/foo.key") |
| 41 | + |
| 42 | + FileUtils.mkdir_p File.dirname(path) |
| 43 | + FileUtils.touch path |
| 44 | + |
| 45 | + assert_equal path, Rails::AppEnv::Credentials.configuration.key_path |
| 46 | + end |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + test "#configuration.key_path falls back to config/master.key when config/credentials/{APP_ENV}.key not exist" do |
| 52 | + Dir.mktmpdir do |tmp_dir| |
| 53 | + Rails.stub :root, Pathname(tmp_dir) do |
| 54 | + Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do |
| 55 | + path = Rails.root.join("config/master.key") |
| 56 | + |
| 57 | + assert_equal path, Rails::AppEnv::Credentials.configuration.key_path |
| 58 | + end |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | +end |
0 commit comments