prefab-cloud-ruby 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,11 @@ class TestLocalConfigParser < Minitest::Test
6
6
  FILE_NAME = 'example-config.yaml'
7
7
  DEFAULT_MATCH = 'default'
8
8
 
9
+ def setup
10
+ super
11
+ @mock_resolver = MockResolver.new
12
+ end
13
+
9
14
  def test_parse_int_config
10
15
  key = :sample_int
11
16
  parsed = Prefab::LocalConfigParser.parse(key, 123, {}, FILE_NAME)[key]
@@ -34,7 +39,7 @@ class TestLocalConfigParser < Minitest::Test
34
39
  assert_equal 1, config.rows[0].values.size
35
40
 
36
41
  value_row = config.rows[0].values[0]
37
- assert_equal 'all-features', Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, key, {}).unwrap
42
+ assert_equal 'all-features', Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, key, {}, @mock_resolver).unwrap
38
43
  end
39
44
 
40
45
  def test_flag_in_user_key
@@ -53,13 +58,73 @@ class TestLocalConfigParser < Minitest::Test
53
58
  assert_equal 1, config.rows[0].values[0].criteria.size
54
59
 
55
60
  value_row = config.rows[0].values[0]
56
- assert_equal true, Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, key, {}).unwrap
61
+ assert_equal true, Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, key, {}, @mock_resolver).unwrap
57
62
 
58
63
  assert_equal 'user.key', value_row.criteria[0].property_name
59
64
  assert_equal :PROP_IS_ONE_OF, value_row.criteria[0].operator
60
65
  assert_equal %w[abc123 xyz987], value_row.criteria[0].value_to_match.string_list.values
61
66
  end
62
67
 
68
+ def test_provided_values
69
+ with_env('LOOKUP_ENV', 'from env') do
70
+ key = :test_provided
71
+ value = stringify_keys({type: 'provided', source: 'ENV_VAR', lookup: 'LOOKUP_ENV'})
72
+ parsed = Prefab::LocalConfigParser.parse(key, value, {}, FILE_NAME)[key]
73
+ config = parsed[:config]
74
+
75
+ assert_equal FILE_NAME, parsed[:source]
76
+ assert_equal 'LOOKUP_ENV', parsed[:match]
77
+ assert_equal :CONFIG, config.config_type
78
+ assert_equal key.to_s, config.key
79
+ assert_equal 1, config.rows.size
80
+ assert_equal 1, config.rows[0].values.size
81
+
82
+ value_row = config.rows[0].values[0]
83
+ provided = value_row.value.provided
84
+ assert_equal :ENV_VAR, provided.source
85
+ assert_equal 'LOOKUP_ENV', provided.lookup
86
+ assert_equal 'from env', Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, config, {}, @mock_resolver).unwrap
87
+ reportable_value = Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, config, {}, @mock_resolver).reportable_value
88
+ assert_equal 'from env', reportable_value
89
+ end
90
+ end
91
+
92
+ def test_confidential_provided_values
93
+ with_env('LOOKUP_ENV', 'from env') do
94
+ key = :test_provided
95
+ value = stringify_keys({type: 'provided', source: 'ENV_VAR', lookup: 'LOOKUP_ENV', confidential: true})
96
+ parsed = Prefab::LocalConfigParser.parse(key, value, {}, FILE_NAME)[key]
97
+ config = parsed[:config]
98
+
99
+ value_row = config.rows[0].values[0]
100
+ provided = value_row.value.provided
101
+ assert_equal :ENV_VAR, provided.source
102
+ assert_equal 'LOOKUP_ENV', provided.lookup
103
+ assert_equal 'from env', Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, config, {}, @mock_resolver).unwrap
104
+ reportable_value = Prefab::ConfigValueUnwrapper.deepest_value(value_row.value, config, {}, @mock_resolver).reportable_value
105
+ assert reportable_value.start_with? Prefab::ConfigValueUnwrapper::CONFIDENTIAL_PREFIX
106
+ end
107
+ end
108
+
109
+ def test_confidential_values
110
+ key = :test_confidential
111
+ value = stringify_keys({value: 'a confidential string', confidential: true})
112
+ parsed = Prefab::LocalConfigParser.parse(key, value, {}, FILE_NAME)[key]
113
+ config = parsed[:config]
114
+
115
+ assert_equal FILE_NAME, parsed[:source]
116
+ assert_equal :CONFIG, config.config_type
117
+ assert_equal key.to_s, config.key
118
+ assert_equal 1, config.rows.size
119
+ assert_equal 1, config.rows[0].values.size
120
+
121
+ value_row = config.rows[0].values[0]
122
+ config_value = value_row.value
123
+ assert_equal 'a confidential string', Prefab::ConfigValueUnwrapper.deepest_value(config_value, key, {}, @mock_resolver).unwrap
124
+ reportable_value = Prefab::ConfigValueUnwrapper.deepest_value(config_value, key, {}, @mock_resolver).reportable_value
125
+ assert reportable_value.start_with? Prefab::ConfigValueUnwrapper::CONFIDENTIAL_PREFIX
126
+ end
127
+
63
128
  private
64
129
 
65
130
  def stringify_keys(hash)
@@ -73,4 +138,10 @@ class TestLocalConfigParser < Minitest::Test
73
138
  end
74
139
  result
75
140
  end
141
+
142
+ class MockResolver
143
+ def get(key)
144
+ raise "unexpected key"
145
+ end
146
+ end
76
147
  end
data/test/test_logger.rb CHANGED
@@ -87,22 +87,22 @@ class TestLogger < Minitest::Test
87
87
 
88
88
  def test_log_internal
89
89
  prefab, io = captured_logger
90
- prefab.log.log_internal(::Logger::WARN, 'test message', 'test.path')
90
+ prefab.log.log_internal(::Logger::WARN, 'test message', 'cloud.prefab.client.test.path')
91
91
  assert_logged io, 'WARN', "cloud.prefab.client.test.path", "test message"
92
92
  end
93
93
 
94
94
  def test_log_internal_unknown
95
95
  prefab, io = captured_logger
96
- prefab.log.log_internal(::Logger::UNKNOWN, 'test message', 'test.path')
96
+ prefab.log.log_internal(::Logger::UNKNOWN, 'test message', 'cloud.prefab.client.test.path')
97
97
  assert_logged io, 'ANY', "cloud.prefab.client.test.path", "test message"
98
98
  end
99
99
 
100
100
  def test_log_internal_silencing
101
101
  prefab, io = captured_logger
102
102
  prefab.log.silence do
103
- prefab.log.log_internal(::Logger::WARN, 'should not log', 'test.path')
103
+ prefab.log.log_internal(::Logger::WARN, 'should not log', 'cloud.prefab.client.test.path')
104
104
  end
105
- prefab.log.log_internal(::Logger::WARN, 'should log', 'test.path')
105
+ prefab.log.log_internal(::Logger::WARN, 'should log', 'cloud.prefab.client.test.path')
106
106
  assert_logged io, 'WARN', "cloud.prefab.client.test.path", "should log"
107
107
  refute_logged io, 'should not log'
108
108
  end
@@ -457,7 +457,7 @@ class TestLogger < Minitest::Test
457
457
  def test_structured_internal_logging
458
458
  prefab, io = captured_logger
459
459
 
460
- prefab.log.log_internal(::Logger::WARN, 'test', 'test.path', user: "michael")
460
+ prefab.log.log_internal(::Logger::WARN, 'test', 'cloud.prefab.client.test.path', user: "michael")
461
461
 
462
462
  assert_logged io, 'WARN', 'cloud.prefab.client.test.path', "test user=michael"
463
463
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-01 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: activesupport
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '4'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '4'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: benchmark-ips
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -207,7 +221,9 @@ files:
207
221
  - lib/prefab/context_shape.rb
208
222
  - lib/prefab/context_shape_aggregator.rb
209
223
  - lib/prefab/criteria_evaluator.rb
224
+ - lib/prefab/encryption.rb
210
225
  - lib/prefab/error.rb
226
+ - lib/prefab/errors/env_var_parse_error.rb
211
227
  - lib/prefab/errors/initialization_timeout_error.rb
212
228
  - lib/prefab/errors/invalid_api_key_error.rb
213
229
  - lib/prefab/errors/missing_default_error.rb
@@ -220,6 +236,7 @@ files:
220
236
  - lib/prefab/internal_logger.rb
221
237
  - lib/prefab/local_config_parser.rb
222
238
  - lib/prefab/log_path_aggregator.rb
239
+ - lib/prefab/log_subscribers/action_controller_subscriber.rb
223
240
  - lib/prefab/logger_client.rb
224
241
  - lib/prefab/murmer3.rb
225
242
  - lib/prefab/options.rb
@@ -228,6 +245,7 @@ files:
228
245
  - lib/prefab/rate_limit_cache.rb
229
246
  - lib/prefab/resolved_config_presenter.rb
230
247
  - lib/prefab/sse_logger.rb
248
+ - lib/prefab/static_logger.rb
231
249
  - lib/prefab/time_helpers.rb
232
250
  - lib/prefab/weighted_value_resolver.rb
233
251
  - lib/prefab/yaml_config_parser.rb
@@ -241,6 +259,7 @@ files:
241
259
  - test/support/mock_base_client.rb
242
260
  - test/support/mock_config_client.rb
243
261
  - test/support/mock_config_loader.rb
262
+ - test/test_action_controller.rb
244
263
  - test/test_client.rb
245
264
  - test/test_config_client.rb
246
265
  - test/test_config_loader.rb
@@ -251,6 +270,7 @@ files:
251
270
  - test/test_context_shape.rb
252
271
  - test/test_context_shape_aggregator.rb
253
272
  - test/test_criteria_evaluator.rb
273
+ - test/test_encryption.rb
254
274
  - test/test_evaluation_summary_aggregator.rb
255
275
  - test/test_example_contexts_aggregator.rb
256
276
  - test/test_exponential_backoff.rb