chamber 2.4.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -930
  3. data/Rakefile +6 -0
  4. data/lib/chamber.rb +11 -7
  5. data/lib/chamber/binary/heroku.rb +45 -25
  6. data/lib/chamber/binary/runner.rb +82 -44
  7. data/lib/chamber/binary/travis.rb +14 -8
  8. data/lib/chamber/commands/base.rb +1 -2
  9. data/lib/chamber/commands/comparable.rb +0 -1
  10. data/lib/chamber/commands/compare.rb +1 -1
  11. data/lib/chamber/commands/files.rb +0 -1
  12. data/lib/chamber/commands/heroku.rb +2 -3
  13. data/lib/chamber/commands/heroku/push.rb +1 -1
  14. data/lib/chamber/commands/initialize.rb +69 -12
  15. data/lib/chamber/commands/securable.rb +9 -4
  16. data/lib/chamber/commands/secure.rb +1 -1
  17. data/lib/chamber/commands/show.rb +20 -4
  18. data/lib/chamber/commands/travis.rb +0 -1
  19. data/lib/chamber/configuration.rb +5 -5
  20. data/lib/chamber/context_resolver.rb +12 -12
  21. data/lib/chamber/decryption_key.rb +51 -0
  22. data/lib/chamber/environmentable.rb +4 -1
  23. data/lib/chamber/errors/decryption_failure.rb +6 -0
  24. data/lib/chamber/file.rb +7 -8
  25. data/lib/chamber/file_set.rb +23 -22
  26. data/lib/chamber/filters/boolean_conversion_filter.rb +1 -2
  27. data/lib/chamber/filters/decryption_filter.rb +42 -25
  28. data/lib/chamber/filters/encryption_filter.rb +7 -5
  29. data/lib/chamber/filters/environment_filter.rb +7 -7
  30. data/lib/chamber/filters/failed_decryption_filter.rb +41 -0
  31. data/lib/chamber/filters/namespace_filter.rb +1 -1
  32. data/lib/chamber/filters/secure_filter.rb +3 -5
  33. data/lib/chamber/filters/translate_secure_keys_filter.rb +5 -24
  34. data/lib/chamber/namespace_set.rb +6 -6
  35. data/lib/chamber/rails.rb +1 -3
  36. data/lib/chamber/rails/railtie.rb +6 -3
  37. data/lib/chamber/settings.rb +34 -32
  38. data/lib/chamber/version.rb +1 -1
  39. data/spec/fixtures/settings.yml +1 -0
  40. data/spec/lib/chamber/commands/files_spec.rb +4 -2
  41. data/spec/lib/chamber/commands/secure_spec.rb +8 -5
  42. data/spec/lib/chamber/commands/show_spec.rb +18 -3
  43. data/spec/lib/chamber/context_resolver_spec.rb +38 -18
  44. data/spec/lib/chamber/file_set_spec.rb +73 -52
  45. data/spec/lib/chamber/file_spec.rb +37 -23
  46. data/spec/lib/chamber/filters/boolean_conversion_filter_spec.rb +35 -33
  47. data/spec/lib/chamber/filters/decryption_filter_spec.rb +142 -21
  48. data/spec/lib/chamber/filters/encryption_filter_spec.rb +51 -19
  49. data/spec/lib/chamber/filters/environment_filter_spec.rb +12 -6
  50. data/spec/lib/chamber/filters/failed_decryption_filter_spec.rb +53 -0
  51. data/spec/lib/chamber/filters/insecure_filter_spec.rb +38 -18
  52. data/spec/lib/chamber/filters/namespace_filter_spec.rb +38 -38
  53. data/spec/lib/chamber/filters/secure_filter_spec.rb +10 -10
  54. data/spec/lib/chamber/filters/translate_secure_keys_filter_spec.rb +9 -6
  55. data/spec/lib/chamber/namespace_set_spec.rb +7 -5
  56. data/spec/lib/chamber/settings_spec.rb +168 -79
  57. data/spec/lib/chamber_spec.rb +72 -71
  58. metadata +22 -21
  59. data/lib/chamber/errors/undecryptable_value_error.rb +0 -6
  60. data/templates/settings.yml +0 -14
@@ -5,9 +5,14 @@ module Chamber
5
5
  module Commands
6
6
  describe Show do
7
7
  let(:rootpath) { ::File.expand_path('./spec/fixtures') }
8
- let(:options) { { basepath: rootpath,
9
- rootpath: rootpath,
10
- namespaces: 'test' } }
8
+ let(:options) do
9
+ {
10
+ basepath: rootpath,
11
+ rootpath: rootpath,
12
+ namespaces: 'test',
13
+ decryption_key: './spec/spec_key',
14
+ }
15
+ end
11
16
 
12
17
  it 'can return values formatted as environment variables' do
13
18
  expect(Show.call(options.merge(as_env: true))).to eql(
@@ -18,15 +23,25 @@ ANOTHER_LEVEL_SETTING_ONE="1"
18
23
  ANOTHER_LEVEL_SETTING_TWO="2"
19
24
  MY_BOOLEAN="false"
20
25
  MY_DYNAMIC_SETTING="2"
26
+ MY_SECURE_SETTINGS="my_secure_value"
21
27
  MY_SETTING="my_value"
22
28
  HEREDOC
23
29
  )
24
30
  end
25
31
 
32
+ it 'can return values filtered by whether or not they are secure' do
33
+ expect(Show.call(options.merge(as_env: true, only_sensitive: true))).to eql(
34
+ <<-HEREDOC.chomp
35
+ MY_SECURE_SETTINGS="my_secure_value"
36
+ HEREDOC
37
+ )
38
+ end
39
+
26
40
  it 'can return values formatted as a hash' do
27
41
  expect(Show.call(options)).to eql(
28
42
  <<-HEREDOC.chomp
29
43
  {"my_setting"=>"my_value",
44
+ "my_secure_settings"=>"my_secure_value",
30
45
  "my_boolean"=>false,
31
46
  "my_dynamic_setting"=>2,
32
47
  "another_level"=>
@@ -9,24 +9,26 @@ describe ContextResolver do
9
9
  let(:rails_4_path) { ::File.expand_path('../../../rails-4-test', __FILE__) }
10
10
 
11
11
  it 'does not attempt to do any resolution if all valid options are passed in' do
12
- options = ContextResolver.resolve(basepath: 'my_path',
13
- namespaces: 'ns')
12
+ options = ContextResolver.resolve(basepath: 'my_path',
13
+ namespaces: 'ns')
14
14
 
15
15
  expect(options[:basepath].to_s).to eql 'my_path'
16
16
  expect(options[:namespaces]).to eql 'ns'
17
17
  end
18
18
 
19
- it 'does not attempt to do any resolution if files are passed in in place of a basepath' do
20
- options = ContextResolver.resolve(files: 'my_files',
21
- namespaces: 'ns')
19
+ it 'does not attempt to do any resolution if files are passed in in place of a ' \
20
+ 'basepath' do
21
+
22
+ options = ContextResolver.resolve(files: 'my_files',
23
+ namespaces: 'ns')
22
24
 
23
25
  expect(options[:files]).to eql 'my_files'
24
26
  expect(options[:namespaces]).to eql 'ns'
25
27
  end
26
28
 
27
29
  it 'defaults the basepath to the rootpath if none is explicitly set' do
28
- options = ContextResolver.resolve(rootpath: './app',
29
- namespaces: 'ns')
30
+ options = ContextResolver.resolve(rootpath: './app',
31
+ namespaces: 'ns')
30
32
 
31
33
  expect(options[:basepath].to_s).to eql './app'
32
34
  end
@@ -40,14 +42,13 @@ describe ContextResolver do
40
42
  it 'sets the default files if none are passed in' do
41
43
  options = ContextResolver.resolve(basepath: './app')
42
44
 
43
- expect(options[:files].map(&:to_s)).to eql [ './app/credentials*.yml',
44
- './app/settings*.yml',
45
- './app/settings' ]
45
+ expect(options[:files].map(&:to_s)).to eql ['./app/settings*.yml',
46
+ './app/settings']
46
47
  end
47
48
 
48
49
  it 'can handle if keys are passed as strings' do
49
- options = ContextResolver.resolve('files' => 'my_files',
50
- 'namespaces' => 'ns')
50
+ options = ContextResolver.resolve('files' => 'my_files',
51
+ 'namespaces' => 'ns')
51
52
 
52
53
  expect(options[:files]).to eql 'my_files'
53
54
  expect(options[:namespaces]).to eql 'ns'
@@ -69,9 +70,20 @@ describe ContextResolver do
69
70
  end
70
71
 
71
72
  it 'sets the decryption key to the default if not passed in' do
72
- options = ContextResolver.resolve(rootpath: rails_3_path)
73
+ options = ContextResolver.resolve(rootpath: rails_3_path)
74
+ key_contents = ::File.read(rails_3_path + '/.chamber.pem')
73
75
 
74
- expect(options[:decryption_key].to_s).to include 'rails-3-test/.chamber.pem'
76
+ expect(options[:decryption_key].to_s).to eql key_contents
77
+ end
78
+
79
+ it 'sets the decryption key to the value of the CHAMBER_KEY if available' do
80
+ ENV['CHAMBER_KEY'] = 'my key'
81
+
82
+ options = ContextResolver.resolve(rootpath: 'my_path')
83
+
84
+ expect(options[:decryption_key].to_s).to eql 'my key'
85
+
86
+ ENV['CHAMBER_KEY'] = nil
75
87
  end
76
88
 
77
89
  it 'does not set the encryption key if the keyfile does not exist' do
@@ -95,32 +107,40 @@ describe ContextResolver do
95
107
  end
96
108
 
97
109
  it 'sets the information to a Rails preset when the rootpath is a Rails app' do
110
+ allow(Socket).to receive(:gethostname).and_return 'my_host'
111
+
98
112
  options = ContextResolver.resolve(rootpath: rails_3_path,
99
113
  preset: 'rails')
100
114
 
101
115
  expect(options[:basepath].to_s).to include 'rails-3-test/config'
102
- expect(options[:namespaces]).to eql ['development']
116
+ expect(options[:namespaces]).to eql %w{development my_host}
103
117
  end
104
118
 
105
119
  it 'sets the basepath if inside a Rails 2 project' do
120
+ allow(Socket).to receive(:gethostname).and_return 'my_host'
121
+
106
122
  options = ContextResolver.resolve(rootpath: rails_2_path)
107
123
 
108
124
  expect(options[:basepath].to_s).to include 'rails-2-test/config'
109
- expect(options[:namespaces]).to eql ['development']
125
+ expect(options[:namespaces]).to eql %w{development my_host}
110
126
  end
111
127
 
112
128
  it 'sets the basepath if inside a Rails 3 project' do
129
+ allow(Socket).to receive(:gethostname).and_return 'my_host'
130
+
113
131
  options = ContextResolver.resolve(rootpath: rails_3_path)
114
132
 
115
133
  expect(options[:basepath].to_s).to include 'rails-3-test/config'
116
- expect(options[:namespaces]).to eql ['development']
134
+ expect(options[:namespaces]).to eql %w{development my_host}
117
135
  end
118
136
 
119
137
  it 'sets the basepath if inside a Rails 4 project' do
138
+ allow(Socket).to receive(:gethostname).and_return 'my_host'
139
+
120
140
  options = ContextResolver.resolve(rootpath: rails_4_path)
121
141
 
122
142
  expect(options[:basepath].to_s).to include 'rails-4-test/config'
123
- expect(options[:namespaces]).to eql ['development']
143
+ expect(options[:namespaces]).to eql %w{development my_host}
124
144
  end
125
145
  end
126
146
  end
@@ -2,12 +2,13 @@ require 'rspectacular'
2
2
  require 'chamber/file_set'
3
3
  require 'fileutils'
4
4
 
5
-
6
5
  module Chamber
7
6
  describe FileSet do
8
- before(:each) { FileUtils.mkdir '/tmp/settings' unless ::File.exist? '/tmp/settings'
9
- FileUtils.mkdir '/tmp/dash-set' unless ::File.exist? '/tmp/dash-set' }
10
- after(:each) { FileUtils.rm_rf '/tmp/settings' if ::File.exist? '/tmp/settings' }
7
+ before(:each) do
8
+ FileUtils.mkdir '/tmp/settings' unless ::File.exist? '/tmp/settings'
9
+ FileUtils.mkdir '/tmp/dash-set' unless ::File.exist? '/tmp/dash-set'
10
+ end
11
+ after(:each) { FileUtils.rm_rf '/tmp/settings' if ::File.exist? '/tmp/settings' }
11
12
 
12
13
  it 'can consider directories containing YAML files' do
13
14
  ::File.new('/tmp/settings/some_settings_file.yml', 'w+')
@@ -16,9 +17,9 @@ describe FileSet do
16
17
  file_set = FileSet.new files: '/tmp/settings'
17
18
 
18
19
  expect(file_set.filenames).to eql [
19
- '/tmp/settings/another_settings_file.yml',
20
- '/tmp/settings/some_settings_file.yml',
21
- ]
20
+ '/tmp/settings/another_settings_file.yml',
21
+ '/tmp/settings/some_settings_file.yml',
22
+ ]
22
23
 
23
24
  ::FileUtils.rm_rf('/tmp/settings')
24
25
  end
@@ -30,9 +31,23 @@ describe FileSet do
30
31
  file_set = FileSet.new files: '/tmp/settings/*.yml'
31
32
 
32
33
  expect(file_set.filenames).to eql [
33
- '/tmp/settings/another_settings_file.yml',
34
- '/tmp/settings/some_settings_file.yml',
35
- ]
34
+ '/tmp/settings/another_settings_file.yml',
35
+ '/tmp/settings/some_settings_file.yml',
36
+ ]
37
+
38
+ ::FileUtils.rm_rf('/tmp/settings')
39
+ end
40
+
41
+ it 'will process both *.yml and *.yml.erb files by default' do
42
+ ::File.new('/tmp/settings/some_settings_file.yml', 'w+')
43
+ ::File.new('/tmp/settings/another_settings_file.yml.erb', 'w+')
44
+
45
+ file_set = FileSet.new files: '/tmp/settings'
46
+
47
+ expect(file_set.filenames).to eql [
48
+ '/tmp/settings/another_settings_file.yml.erb',
49
+ '/tmp/settings/some_settings_file.yml',
50
+ ]
36
51
 
37
52
  ::FileUtils.rm_rf('/tmp/settings')
38
53
  end
@@ -44,8 +59,8 @@ describe FileSet do
44
59
  namespaces: ['blue']
45
60
 
46
61
  expect(file_set.filenames).to eql [
47
- '/tmp/settings/settings-blue.yml'
48
- ]
62
+ '/tmp/settings/settings-blue.yml',
63
+ ]
49
64
 
50
65
  ::FileUtils.rm_f('/tmp/settings/settings-blue.yml')
51
66
  end
@@ -61,15 +76,17 @@ describe FileSet do
61
76
  ::FileUtils.rm_f('/tmp/settings/settings-blue.yml')
62
77
  end
63
78
 
64
- it 'does not consider non-namespaced files which have dashes in their paths as namespaced' do
79
+ it 'does not consider non-namespaced files which have dashes in their paths as ' \
80
+ 'namespaced' do
81
+
65
82
  ::File.new('/tmp/dash-set/settings.yml', 'w+')
66
83
 
67
84
  file_set = FileSet.new files: '/tmp/dash-set/settings*.yml',
68
85
  namespaces: ['blue']
69
86
 
70
87
  expect(file_set.filenames).to eql [
71
- '/tmp/dash-set/settings.yml'
72
- ]
88
+ '/tmp/dash-set/settings.yml',
89
+ ]
73
90
 
74
91
  ::FileUtils.rm_r('/tmp/dash-set/settings.yml')
75
92
  end
@@ -78,13 +95,13 @@ describe FileSet do
78
95
  ::File.new('/tmp/settings.yml', 'w+')
79
96
 
80
97
  file_set = FileSet.new files: [
81
- '/tmp/settings.yml',
82
- '/tmp/settings.yml',
83
- ]
98
+ '/tmp/settings.yml',
99
+ '/tmp/settings.yml',
100
+ ]
84
101
 
85
102
  expect(file_set.filenames).to eql [
86
- '/tmp/settings.yml'
87
- ]
103
+ '/tmp/settings.yml',
104
+ ]
88
105
 
89
106
  ::FileUtils.rm_f('/tmp/settings.yml')
90
107
  end
@@ -94,14 +111,14 @@ describe FileSet do
94
111
  ::File.new('/tmp/settings/new_file.yml', 'w+')
95
112
 
96
113
  file_set = FileSet.new files: [
97
- '/tmp/settings.yml',
98
- '/tmp/settings/*.yml',
99
- ]
114
+ '/tmp/settings.yml',
115
+ '/tmp/settings/*.yml',
116
+ ]
100
117
 
101
118
  expect(file_set.filenames).to eql [
102
- '/tmp/settings.yml',
103
- '/tmp/settings/new_file.yml',
104
- ]
119
+ '/tmp/settings.yml',
120
+ '/tmp/settings/new_file.yml',
121
+ ]
105
122
 
106
123
  ::FileUtils.rm_rf('/tmp/settings*')
107
124
  end
@@ -112,8 +129,8 @@ describe FileSet do
112
129
  file_set = FileSet.new files: '/tmp/settings.yml'
113
130
 
114
131
  expect(file_set.filenames).to eql [
115
- '/tmp/settings.yml',
116
- ]
132
+ '/tmp/settings.yml',
133
+ ]
117
134
 
118
135
  ::FileUtils.rm_rf('/tmp/settings*')
119
136
  end
@@ -123,20 +140,20 @@ describe FileSet do
123
140
  ::File.new('/tmp/settings/settings-green.yml', 'w+')
124
141
 
125
142
  file_set = FileSet.new files: '/tmp/settings/settings*.yml',
126
- namespaces: ['blue', 'green']
143
+ namespaces: %w{blue green}
127
144
 
128
145
  expect(file_set.filenames).to eql [
129
- '/tmp/settings/settings-blue.yml',
130
- '/tmp/settings/settings-green.yml',
131
- ]
146
+ '/tmp/settings/settings-blue.yml',
147
+ '/tmp/settings/settings-green.yml',
148
+ ]
132
149
 
133
150
  file_set = FileSet.new files: '/tmp/settings/settings*.yml',
134
- namespaces: ['green', 'blue']
151
+ namespaces: %w{green blue}
135
152
 
136
153
  expect(file_set.filenames).to eql [
137
- '/tmp/settings/settings-green.yml',
138
- '/tmp/settings/settings-blue.yml',
139
- ]
154
+ '/tmp/settings/settings-green.yml',
155
+ '/tmp/settings/settings-blue.yml',
156
+ ]
140
157
 
141
158
  ::FileUtils.rm_f('/tmp/settings/settings*.yml')
142
159
  end
@@ -149,9 +166,9 @@ describe FileSet do
149
166
  namespaces: ['blue']
150
167
 
151
168
  expect(file_set.filenames).to eql [
152
- '/tmp/settings.yml',
153
- '/tmp/settings-blue.yml',
154
- ]
169
+ '/tmp/settings.yml',
170
+ '/tmp/settings-blue.yml',
171
+ ]
155
172
 
156
173
  ::FileUtils.rm_f('/tmp/settings*.yml')
157
174
  end
@@ -164,25 +181,27 @@ describe FileSet do
164
181
  namespaces: ['blue']
165
182
 
166
183
  expect(file_set.filenames).to eql [
167
- '/tmp/settings.yml',
168
- '/tmp/settings-blue.yml',
169
- ]
184
+ '/tmp/settings.yml',
185
+ '/tmp/settings-blue.yml',
186
+ ]
170
187
 
171
188
  ::FileUtils.rm_f('/tmp/settings*.yml')
172
189
  end
173
190
 
174
- it 'considers each glob independently, placing non-namespaced and namespaced versions of the globs files above those in subsequent globs' do
191
+ it 'considers each glob independently, placing non-namespaced and namespaced ' \
192
+ 'versions of the globs files above those in subsequent globs' do
193
+
175
194
  ::File.new('/tmp/settings/credentials-development.yml', 'w+')
176
195
  ::File.new('/tmp/settings/settings.yml', 'w+')
177
196
 
178
- file_set = FileSet.new files: ['/tmp/settings/credentials*.yml',
179
- '/tmp/settings/settings*.yml'],
197
+ file_set = FileSet.new files: ['/tmp/settings/credentials*.yml',
198
+ '/tmp/settings/settings*.yml'],
180
199
  namespaces: ['development']
181
200
 
182
201
  expect(file_set.filenames).to eql [
183
- '/tmp/settings/credentials-development.yml',
184
- '/tmp/settings/settings.yml',
185
- ]
202
+ '/tmp/settings/credentials-development.yml',
203
+ '/tmp/settings/settings.yml',
204
+ ]
186
205
 
187
206
  ::FileUtils.rm_rf('/tmp/settings')
188
207
  end
@@ -194,9 +213,9 @@ describe FileSet do
194
213
  file_set = FileSet.new files: '/tmp/settings/*.yml'
195
214
 
196
215
  expect(file_set.filenames).to eql [
197
- '/tmp/settings/another_settings_file.yml',
198
- '/tmp/settings/some_settings_file.yml',
199
- ]
216
+ '/tmp/settings/another_settings_file.yml',
217
+ '/tmp/settings/some_settings_file.yml',
218
+ ]
200
219
 
201
220
  ::FileUtils.rm_rf('/tmp/settings')
202
221
  end
@@ -213,7 +232,9 @@ describe FileSet do
213
232
  ::FileUtils.rm_f('/tmp/settings.yml')
214
233
  end
215
234
 
216
- it 'can convert settings without yielding to the block by using an intermediate settings object' do
235
+ it 'can convert settings without yielding to the block by using an intermediate ' \
236
+ 'settings object' do
237
+
217
238
  ::File.new('/tmp/settings.yml', 'w+')
218
239
 
219
240
  file_set = FileSet.new files: '/tmp/settings.yml'
@@ -4,6 +4,7 @@ require 'chamber/settings'
4
4
  require 'chamber/filters/encryption_filter'
5
5
  require 'tempfile'
6
6
 
7
+ # rubocop:disable Metrics/LineLength
7
8
  def create_tempfile_with_content(content)
8
9
  tempfile = Tempfile.new('settings')
9
10
  tempfile.puts content
@@ -14,7 +15,7 @@ end
14
15
  module Chamber
15
16
  describe File do
16
17
  it 'can convert file contents to settings' do
17
- tempfile = create_tempfile_with_content %Q({ test: settings })
18
+ tempfile = create_tempfile_with_content '{ test: settings }'
18
19
  settings_file = File.new path: tempfile.path
19
20
 
20
21
  allow(Settings).to receive(:new).
@@ -24,7 +25,7 @@ describe File do
24
25
 
25
26
  expect(file_settings).to eql :settings
26
27
  expect(Settings).to have_received(:new).
27
- with(settings: {'test' => 'settings'},
28
+ with(settings: { 'test' => 'settings' },
28
29
  namespaces: {},
29
30
  decryption_key: nil,
30
31
  encryption_key: nil)
@@ -48,42 +49,42 @@ describe File do
48
49
  end
49
50
 
50
51
  it 'throws an error when the file contents are malformed' do
51
- tempfile = create_tempfile_with_content %Q({ test : )
52
+ tempfile = create_tempfile_with_content '{ test : '
52
53
  settings_file = File.new path: tempfile.path
53
54
 
54
55
  expect { settings_file.to_settings }.to raise_error
55
56
  end
56
57
 
57
58
  it 'passes any namespaces through to the settings' do
58
- tempfile = create_tempfile_with_content %Q({ test: settings })
59
+ tempfile = create_tempfile_with_content '{ test: settings }'
59
60
  settings_file = File.new path: tempfile.path,
60
61
  namespaces: {
61
- environment: :development }
62
+ environment: :development }
62
63
 
63
64
  allow(Settings).to receive(:new)
64
65
 
65
66
  settings_file.to_settings
66
67
 
67
68
  expect(Settings).to have_received(:new).
68
- with( settings: {'test' => 'settings'},
69
- namespaces: {
70
- environment: :development },
71
- decryption_key: nil,
72
- encryption_key: nil)
69
+ with(settings: { 'test' => 'settings' },
70
+ namespaces: {
71
+ environment: :development },
72
+ decryption_key: nil,
73
+ encryption_key: nil)
73
74
  end
74
75
 
75
76
  it 'can handle files which contain ERB markup' do
76
- tempfile = create_tempfile_with_content %Q({ test: <%= 1 + 1 %> })
77
+ tempfile = create_tempfile_with_content '{ test: <%= 1 + 1 %> }'
77
78
  settings_file = File.new path: tempfile.path
78
79
 
79
80
  allow(Settings).to receive(:new)
80
81
 
81
82
  settings_file.to_settings
82
83
  expect(Settings).to have_received(:new).
83
- with( settings: {'test' => 2},
84
- namespaces: {},
85
- decryption_key: nil,
86
- encryption_key: nil)
84
+ with(settings: { 'test' => 2 },
85
+ namespaces: {},
86
+ decryption_key: nil,
87
+ encryption_key: nil)
87
88
  end
88
89
 
89
90
  it 'does not throw an error when attempting to convert a file which does not exist' do
@@ -127,10 +128,20 @@ HEREDOC
127
128
 
128
129
  settings_file.secure
129
130
 
130
- settings_file = File.new path: tempfile.path
131
-
132
- expect(settings_file.to_settings.send(:raw_data)['_secure_setting']).to match Filters::EncryptionFilter::BASE64_STRING_PATTERN
133
- expect(settings_file.to_settings.send(:raw_data)['_secure_other_setting']).to eql "g4ryOaWniDPht0x1pW10XWgtC7Bax2yQAM3+p9ZDMmBUKlVXgvCn8MvdvciX0126P7uuLylY7Pdbm8AnpjeaTvPOaDnDjPATkH1xpQG/HKBy+7zd67SMb3tJ3sxJNkYm6RrmydFHkDCghG37lvCnuZs1Jvd/mhpr/+thqKvtI+c/vzY+eFxM52lnoWWOgqwGCtUjb+PMbq+HjId6X8uRbpL1SpINA6WYJwvxTVK9XD/HYn67Fcqdova4dEHoqwzFfE+XVXM8uesE1DG3PFNhAzkT+mWXtBmo17i+K4wrOO06I13uDS3x+7LqoZz/Ez17SPXRJze4M/wyWfm43pnuVw=="
131
+ settings_file = File.new path: tempfile.path
132
+ raw_data = settings_file.to_settings.send(:raw_data)
133
+ secure_setting = raw_data['_secure_setting']
134
+ other_secure_setting = raw_data['_secure_other_setting']
135
+
136
+ expect(secure_setting).to match Filters::EncryptionFilter::BASE64_STRING_PATTERN
137
+ expect(other_secure_setting).to eql 'g4ryOaWniDPht0x1pW10XWgtC7Bax2yQAM3+p9ZDMmBU' \
138
+ 'KlVXgvCn8MvdvciX0126P7uuLylY7Pdbm8AnpjeaTvPO' \
139
+ 'aDnDjPATkH1xpQG/HKBy+7zd67SMb3tJ3sxJNkYm6Rrm' \
140
+ 'ydFHkDCghG37lvCnuZs1Jvd/mhpr/+thqKvtI+c/vzY+' \
141
+ 'eFxM52lnoWWOgqwGCtUjb+PMbq+HjId6X8uRbpL1SpIN' \
142
+ 'A6WYJwvxTVK9XD/HYn67Fcqdova4dEHoqwzFfE+XVXM8' \
143
+ 'uesE1DG3PFNhAzkT+mWXtBmo17i+K4wrOO06I13uDS3x' \
144
+ '+7LqoZz/Ez17SPXRJze4M/wyWfm43pnuVw=='
134
145
  end
135
146
 
136
147
  it 'does not rewrite the entire file but only the encrypted settings' do
@@ -153,8 +164,8 @@ HEREDOC
153
164
  settings_file.secure
154
165
 
155
166
  file_contents = ::File.read(tempfile.path)
156
- secure_setting_encoded = file_contents[/ _secure_setting: ([A-Za-z0-9\+\/]{342}==)$/, 1]
157
- secure_another_setting_encoded = file_contents[/ _secure_another_setting: ([A-Za-z0-9\+\/]{342}==)$/, 1]
167
+ secure_setting_encoded = file_contents[%r{ _secure_setting: ([A-Za-z0-9\+/]{342}==)$}, 1]
168
+ secure_another_setting_encoded = file_contents[%r{ _secure_another_setting: ([A-Za-z0-9\+/]{342}==)$}, 1]
158
169
 
159
170
  expect(::File.read(tempfile.path)).to eql <<-HEREDOC
160
171
  default:
@@ -170,7 +181,9 @@ other:
170
181
  HEREDOC
171
182
  end
172
183
 
173
- it 'when rewriting the file, can handle names and values with regex special characters' do
184
+ it 'when rewriting the file, can handle names and values with regex special ' \
185
+ 'characters' do
186
+
174
187
  tempfile = create_tempfile_with_content <<-HEREDOC
175
188
  stuff:
176
189
  _secure_another+_setting: "Thanks for +all the fish"
@@ -182,7 +195,7 @@ HEREDOC
182
195
  settings_file.secure
183
196
 
184
197
  file_contents = ::File.read(tempfile.path)
185
- secure_another_setting_encoded = file_contents[/ _secure_another\+_setting: ([A-Za-z0-9\+\/]{342}==)$/, 1]
198
+ secure_another_setting_encoded = file_contents[%r{ _secure_another\+_setting: ([A-Za-z0-9\+/]{342}==)$}, 1]
186
199
 
187
200
  expect(::File.read(tempfile.path)).to eql <<-HEREDOC
188
201
  stuff:
@@ -191,3 +204,4 @@ HEREDOC
191
204
  end
192
205
  end
193
206
  end
207
+ # rubocop:enable Metrics/LineLength