-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathsecret_key_finder_test.rb
121 lines (91 loc) · 2.5 KB
/
secret_key_finder_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# frozen_string_literal: true
require 'test_helper'
class Rails52Credentials
def credentials
OpenStruct.new(secret_key_base: 'credentials')
end
end
class Rails52Secrets
def credentials
OpenStruct.new(secret_key_base: nil)
end
def secrets
OpenStruct.new(secret_key_base: 'secrets')
end
end
class Rails52Config
def credentials
OpenStruct.new(secret_key_base: nil)
end
def secrets
OpenStruct.new(secret_key_base: nil)
end
def config
OpenStruct.new(secret_key_base: 'config')
end
end
class Rails52SecretKeyBase
def credentials
OpenStruct.new(secret_key_base: nil)
end
def secrets
OpenStruct.new(secret_key_base: nil)
end
def config
OpenStruct.new(secret_key_base: nil)
end
def secret_key_base
'secret_key_base'
end
end
class Rails41Secrets
def secrets
OpenStruct.new(secret_key_base: 'secrets')
end
def config
OpenStruct.new(secret_key_base: nil)
end
end
class Rails41Config
def secrets
OpenStruct.new(secret_key_base: nil)
end
def config
OpenStruct.new(secret_key_base: 'config')
end
end
class Rails40Config
def config
OpenStruct.new(secret_key_base: 'config')
end
end
class SecretKeyFinderTest < ActiveSupport::TestCase
test "rails 5.2 uses credentials when they're available" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52Credentials.new)
assert_equal 'credentials', secret_key_finder.find
end
test "rails 5.2 uses secrets when credentials are empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52Secrets.new)
assert_equal 'secrets', secret_key_finder.find
end
test "rails 5.2 uses config when secrets are empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52Config.new)
assert_equal 'config', secret_key_finder.find
end
test "rails 5.2 uses secret_key_base when config is empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52SecretKeyBase.new)
assert_equal 'secret_key_base', secret_key_finder.find
end
test "rails 4.1 uses secrets" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails41Secrets.new)
assert_equal 'secrets', secret_key_finder.find
end
test "rails 4.1 uses config when secrets are empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails41Config.new)
assert_equal 'config', secret_key_finder.find
end
test "rails 4.0 uses config" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails40Config.new)
assert_equal 'config', secret_key_finder.find
end
end