webvalve 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +13 -3
- data/lib/webvalve.rb +3 -18
- data/lib/webvalve/fake_service_config.rb +10 -7
- data/lib/webvalve/manager.rb +73 -7
- data/lib/webvalve/version.rb +1 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/log/test.log +16 -0
- data/spec/examples.txt +61 -32
- data/spec/webvalve/fake_service_config_spec.rb +27 -91
- data/spec/webvalve/manager_spec.rb +527 -39
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 467554297c4382a3f12ce68e32c1b9fed9b2d69afa2b97fb46d3f98be5437dc7
|
4
|
+
data.tar.gz: cb6a4ee0e1a8db1cb37c78737a9d3822b8a4da3e864217612599174b6687e8ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44fd3a16ea1499de33242bbb8a37dcff77e1af8b7a70ea220fda9c29fce8505f19fc2739f48fdb9f47471fe4f5057ed8ffa8d6918949d8e6d6491160b3e79c1d
|
7
|
+
data.tar.gz: ad0bdc05029b4fdb3e58428186841bcfc6bbeba9e7f21e2df8ab4e4fd2ded9fba0af2aa592b8d1fe0752b141b30d5c8020fd7b57efe65620033a942f9eb9bd98
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,15 @@ and this project aims to adhere to [Semantic Versioning](http://semver.org/spec/
|
|
9
9
|
### Added
|
10
10
|
### Removed
|
11
11
|
|
12
|
+
## [0.11.0] - 2019-09-23
|
13
|
+
### Changed
|
14
|
+
- rework configuration so that WebValve has 3 operating modes: off,
|
15
|
+
on+allowing, and on+intercepting. support toggling the latter two
|
16
|
+
modes with
|
17
|
+
`WEBVALVED_ENABLED=1`+`WEBVALVE_SERVICE_ENABLED_DEFAULT=1` and
|
18
|
+
`WEBVALVED_ENABLED=1`+`WEBVALVE_SERVICE_ENABLED_DEFAULT=0`.
|
19
|
+
(https://github.com/Betterment/webvalve/pull/34)
|
20
|
+
|
12
21
|
## [0.10.0] - 2019-09-23
|
13
22
|
### Changed
|
14
23
|
- `Webvalve.register` no longer accepts classes; you must provide class names as strings. Fixes a Rails 6 deprecation warning. (https://github.com/Betterment/webvalve/pull/35)
|
data/README.md
CHANGED
@@ -227,12 +227,22 @@ not registered.
|
|
227
227
|
|
228
228
|
## Frequently Asked Questions
|
229
229
|
|
230
|
-
> Can I use WebValve in environments like staging and
|
230
|
+
> Can I use WebValve in environments like staging, demo, and production?
|
231
231
|
|
232
232
|
Yes! By default WebValve is only enabled in test and development
|
233
233
|
environments; however, it can be enabled in other environments by
|
234
|
-
setting `WEBVALVE_ENABLED=true
|
235
|
-
cheap, one-off environments for
|
234
|
+
setting `WEBVALVE_ENABLED=true` (actually, any of 1/t/true will work).
|
235
|
+
This can be useful for spinning up cheap, one-off environments for
|
236
|
+
user-testing or demos. When WebValve is enabled in any environment other
|
237
|
+
than development/test it will default services to enabled rather than
|
238
|
+
disabled, allowing all traffic to pass-thru. This ensures that
|
239
|
+
production-like environments are run integrated by default. You can
|
240
|
+
change this behavior by setting `WEBVALVE_SERVICE_ENABLED_DEFAULT=false`
|
241
|
+
(any of 0/f/false will work). This will default to the same experience
|
242
|
+
as local development, defaulting services to disabled, intercepting all
|
243
|
+
traffic. In either of these modes, you can use the
|
244
|
+
`$SERVICE_ENABLED=true/false` to toggle a specific service into the
|
245
|
+
desired state.
|
236
246
|
|
237
247
|
> Can I use WebValve without Rails?
|
238
248
|
|
data/lib/webvalve.rb
CHANGED
@@ -3,9 +3,6 @@ require 'active_support'
|
|
3
3
|
require 'active_support/core_ext'
|
4
4
|
|
5
5
|
module WebValve
|
6
|
-
ALWAYS_ENABLED_ENVS = %w(development test).freeze
|
7
|
-
ENABLED_VALUES = %w(1 t true).freeze
|
8
|
-
|
9
6
|
class << self
|
10
7
|
# @!method setup
|
11
8
|
# @see WebValve::Manager#setup
|
@@ -15,23 +12,11 @@ module WebValve
|
|
15
12
|
# @see WebValve::Manager#allow_url
|
16
13
|
# @!method reset
|
17
14
|
# @see WebValve::Manager#reset
|
18
|
-
|
15
|
+
# @!method enabled?
|
16
|
+
# @see WebValve::Manager#enabled?
|
17
|
+
delegate :setup, :register, :allow_url, :reset, :enabled?, to: :manager
|
19
18
|
attr_writer :logger
|
20
19
|
|
21
|
-
def enabled?
|
22
|
-
if env.in?(ALWAYS_ENABLED_ENVS)
|
23
|
-
if ENV.key? 'WEBVALVE_ENABLED'
|
24
|
-
logger.warn(<<~MESSAGE)
|
25
|
-
WARNING: Ignoring WEBVALVE_ENABLED environment variable setting (#{ENV['WEBVALVE_ENABLED']})
|
26
|
-
WebValve is always enabled in development and test environments.
|
27
|
-
MESSAGE
|
28
|
-
end
|
29
|
-
true
|
30
|
-
else
|
31
|
-
ENABLED_VALUES.include?(ENV['WEBVALVE_ENABLED'])
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
20
|
def config_paths
|
36
21
|
@config_paths ||= Set.new
|
37
22
|
end
|
@@ -7,9 +7,12 @@ module WebValve
|
|
7
7
|
@custom_service_url = url
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
10
|
+
def explicitly_enabled?
|
11
|
+
value_from_env.present? && WebValve::ENABLED_VALUES.include?(value_from_env.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def explicitly_disabled?
|
15
|
+
value_from_env.present? && WebValve::DISABLED_VALUES.include?(value_from_env.to_s)
|
13
16
|
end
|
14
17
|
|
15
18
|
def service_url
|
@@ -24,6 +27,10 @@ module WebValve
|
|
24
27
|
|
25
28
|
attr_reader :custom_service_url
|
26
29
|
|
30
|
+
def value_from_env
|
31
|
+
ENV["#{service_name.to_s.upcase}_ENABLED"]
|
32
|
+
end
|
33
|
+
|
27
34
|
def missing_url_message
|
28
35
|
<<~MESSAGE
|
29
36
|
There is no URL defined for #{service_class_name}.
|
@@ -36,10 +43,6 @@ module WebValve
|
|
36
43
|
url.to_s.sub(%r(\Ahttp(s)?://[^@/]+@), 'http\1://')
|
37
44
|
end
|
38
45
|
|
39
|
-
def service_enabled_in_env?
|
40
|
-
WebValve::ENABLED_VALUES.include?(ENV["#{service_name.to_s.upcase}_ENABLED"])
|
41
|
-
end
|
42
|
-
|
43
46
|
def default_service_url
|
44
47
|
ENV["#{service_name.to_s.upcase}_API_URL"]
|
45
48
|
end
|
data/lib/webvalve/manager.rb
CHANGED
@@ -3,6 +3,10 @@ require 'singleton'
|
|
3
3
|
require 'set'
|
4
4
|
|
5
5
|
module WebValve
|
6
|
+
ALWAYS_ENABLED_ENVS = %w(development test).freeze
|
7
|
+
ENABLED_VALUES = %w(1 t true).freeze
|
8
|
+
DISABLED_VALUES = %w(0 f false).freeze
|
9
|
+
|
6
10
|
# @api private
|
7
11
|
class Manager
|
8
12
|
include Singleton
|
@@ -19,16 +23,46 @@ module WebValve
|
|
19
23
|
end
|
20
24
|
|
21
25
|
def setup
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
return unless enabled?
|
27
|
+
|
28
|
+
if intercepting?
|
29
|
+
fake_service_configs.each do |config|
|
30
|
+
if !WebValve.env.test? && config.explicitly_enabled?
|
31
|
+
allowlist_service config
|
32
|
+
else
|
33
|
+
webmock_service config
|
34
|
+
end
|
35
|
+
end
|
36
|
+
WebMock.disable_net_connect! webmock_disable_options
|
37
|
+
WebMock.enable!
|
38
|
+
end
|
39
|
+
|
40
|
+
if allowing?
|
41
|
+
fake_service_configs.each do |config|
|
42
|
+
if config.explicitly_disabled?
|
43
|
+
webmock_service config
|
44
|
+
end
|
45
|
+
end
|
46
|
+
if fake_service_configs.any?(&:explicitly_disabled?)
|
47
|
+
WebMock.allow_net_connect!
|
48
|
+
WebMock.enable!
|
27
49
|
end
|
28
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
def enabled?
|
55
|
+
in_always_intercepting_env? || explicitly_enabled?
|
56
|
+
end
|
57
|
+
|
58
|
+
# @api private
|
59
|
+
def intercepting?
|
60
|
+
in_always_intercepting_env? || (explicitly_enabled? && !services_enabled_by_default?)
|
61
|
+
end
|
29
62
|
|
30
|
-
|
31
|
-
|
63
|
+
# @api private
|
64
|
+
def allowing?
|
65
|
+
!in_always_intercepting_env? && explicitly_enabled? && services_enabled_by_default?
|
32
66
|
end
|
33
67
|
|
34
68
|
# @api private
|
@@ -49,6 +83,38 @@ module WebValve
|
|
49
83
|
|
50
84
|
private
|
51
85
|
|
86
|
+
def explicitly_enabled?
|
87
|
+
ENABLED_VALUES.include?(ENV['WEBVALVE_ENABLED'])
|
88
|
+
end
|
89
|
+
|
90
|
+
def services_enabled_by_default?
|
91
|
+
if WebValve.env.in?(ALWAYS_ENABLED_ENVS)
|
92
|
+
if ENV.key? 'WEBVALVE_SERVICE_ENABLED_DEFAULT'
|
93
|
+
WebValve.logger.warn(<<~MESSAGE)
|
94
|
+
WARNING: Ignoring WEBVALVE_SERVICE_ENABLED_DEFAULT environment variable setting (#{ENV['WEBVALVE_SERVICE_ENABLED_DEFAULT']})
|
95
|
+
WebValve is always enabled in intercepting mode in development and test environments.
|
96
|
+
MESSAGE
|
97
|
+
end
|
98
|
+
false
|
99
|
+
else
|
100
|
+
ENABLED_VALUES.include?(ENV.fetch('WEBVALVE_SERVICE_ENABLED_DEFAULT', '1'))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def in_always_intercepting_env?
|
105
|
+
if WebValve.env.in?(ALWAYS_ENABLED_ENVS)
|
106
|
+
if ENV.key? 'WEBVALVE_ENABLED'
|
107
|
+
WebValve.logger.warn(<<~MESSAGE)
|
108
|
+
WARNING: Ignoring WEBVALVE_ENABLED environment variable setting (#{ENV['WEBVALVE_ENABLED']})
|
109
|
+
WebValve is always enabled in development and test environments.
|
110
|
+
MESSAGE
|
111
|
+
end
|
112
|
+
true
|
113
|
+
else
|
114
|
+
false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
52
118
|
def webmock_disable_options
|
53
119
|
{ allow_localhost: true }.tap do |opts|
|
54
120
|
opts[:allow] = allowlisted_url_regexps unless WebValve.env.test?
|
data/lib/webvalve/version.rb
CHANGED
data/spec/dummy/log/test.log
CHANGED
@@ -6,3 +6,19 @@
|
|
6
6
|
[1m[33mWebValve Request Captured (19.5ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
7
7
|
[1m[33mWebValve Request Captured (0.4ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
8
8
|
[1m[33mWebValve Request Captured (1.8ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
9
|
+
[1m[33mWebValve Request Captured (5.2ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
10
|
+
[1m[33mWebValve Request Captured (0.3ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
11
|
+
[1m[33mWebValve Request Captured (0.3ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
12
|
+
[1m[33mWebValve Request Captured (2.9ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
13
|
+
[1m[33mWebValve Request Captured (7.0ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
14
|
+
[1m[33mWebValve Request Captured (0.3ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
15
|
+
[1m[33mWebValve Request Captured (2.7ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
16
|
+
[1m[33mWebValve Request Captured (0.4ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
17
|
+
[1m[33mWebValve Request Captured (0.5ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
18
|
+
[1m[33mWebValve Request Captured (4.3ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
19
|
+
[1m[33mWebValve Request Captured (2.1ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
20
|
+
[1m[33mWebValve Request Captured (0.3ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
21
|
+
[1m[33mWebValve Request Captured (1.7ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
22
|
+
[1m[33mWebValve Request Captured (0.4ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
23
|
+
[1m[33mWebValve Request Captured (4.2ms)[0m [1m[1mdummy.dev GET /widgets [200][0m
|
24
|
+
[1m[33mWebValve Request Captured (0.3ms)[0m [1m[1mdummy.dev GET /foos [][0m
|
data/spec/examples.txt
CHANGED
@@ -1,32 +1,61 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/webvalve/fake_service_config_spec.rb[1:1:1
|
4
|
-
./spec/webvalve/fake_service_config_spec.rb[1:1:
|
5
|
-
./spec/webvalve/fake_service_config_spec.rb[1:
|
6
|
-
./spec/webvalve/fake_service_config_spec.rb[1:
|
7
|
-
./spec/webvalve/fake_service_config_spec.rb[1:1
|
8
|
-
./spec/webvalve/fake_service_config_spec.rb[1:
|
9
|
-
./spec/webvalve/fake_service_config_spec.rb[1:
|
10
|
-
./spec/webvalve/
|
11
|
-
./spec/webvalve/
|
12
|
-
./spec/webvalve/
|
13
|
-
./spec/webvalve/
|
14
|
-
./spec/webvalve/
|
15
|
-
./spec/webvalve/
|
16
|
-
./spec/webvalve/
|
17
|
-
./spec/webvalve/
|
18
|
-
./spec/webvalve/manager_spec.rb[1:1]
|
19
|
-
./spec/webvalve/manager_spec.rb[1:2:
|
20
|
-
./spec/webvalve/manager_spec.rb[1:3
|
21
|
-
./spec/webvalve/manager_spec.rb[1:4
|
22
|
-
./spec/webvalve/manager_spec.rb[1:5:
|
23
|
-
./spec/webvalve/manager_spec.rb[1:5:2]
|
24
|
-
./spec/webvalve/manager_spec.rb[1:5:3]
|
25
|
-
./spec/webvalve/manager_spec.rb[1:5:
|
26
|
-
./spec/webvalve/manager_spec.rb[1:5:
|
27
|
-
./spec/webvalve/manager_spec.rb[1:5:
|
28
|
-
./spec/webvalve/manager_spec.rb[1:5:
|
29
|
-
./spec/
|
30
|
-
./spec/
|
31
|
-
./spec/
|
32
|
-
./spec/
|
1
|
+
example_id | status | run_time |
|
2
|
+
-------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/webvalve/fake_service_config_spec.rb[1:1:1] | passed | 0.00032 seconds |
|
4
|
+
./spec/webvalve/fake_service_config_spec.rb[1:1:2] | passed | 0.00406 seconds |
|
5
|
+
./spec/webvalve/fake_service_config_spec.rb[1:2:1] | passed | 0.00014 seconds |
|
6
|
+
./spec/webvalve/fake_service_config_spec.rb[1:2:2] | passed | 0.00015 seconds |
|
7
|
+
./spec/webvalve/fake_service_config_spec.rb[1:3:1] | passed | 0.00215 seconds |
|
8
|
+
./spec/webvalve/fake_service_config_spec.rb[1:3:2] | passed | 0.00019 seconds |
|
9
|
+
./spec/webvalve/fake_service_config_spec.rb[1:3:3] | passed | 0.00013 seconds |
|
10
|
+
./spec/webvalve/fake_service_spec.rb[1:1] | passed | 0.01281 seconds |
|
11
|
+
./spec/webvalve/fake_service_spec.rb[1:2:1] | passed | 0.02669 seconds |
|
12
|
+
./spec/webvalve/fake_service_spec.rb[1:2:2] | passed | 0.03046 seconds |
|
13
|
+
./spec/webvalve/manager_spec.rb[1:1] | passed | 0.0002 seconds |
|
14
|
+
./spec/webvalve/manager_spec.rb[1:2:1] | passed | 0.00387 seconds |
|
15
|
+
./spec/webvalve/manager_spec.rb[1:3:1] | passed | 0.00026 seconds |
|
16
|
+
./spec/webvalve/manager_spec.rb[1:4:1] | passed | 0.00015 seconds |
|
17
|
+
./spec/webvalve/manager_spec.rb[1:5:1:1] | passed | 0.00027 seconds |
|
18
|
+
./spec/webvalve/manager_spec.rb[1:5:2:1] | passed | 0.00027 seconds |
|
19
|
+
./spec/webvalve/manager_spec.rb[1:5:2:2] | passed | 0.00036 seconds |
|
20
|
+
./spec/webvalve/manager_spec.rb[1:5:2:3] | passed | 0.00681 seconds |
|
21
|
+
./spec/webvalve/manager_spec.rb[1:5:2:4] | passed | 0.00042 seconds |
|
22
|
+
./spec/webvalve/manager_spec.rb[1:5:2:5] | passed | 0.01559 seconds |
|
23
|
+
./spec/webvalve/manager_spec.rb[1:5:2:6] | passed | 0.00192 seconds |
|
24
|
+
./spec/webvalve/manager_spec.rb[1:5:3:1:1] | passed | 0.00026 seconds |
|
25
|
+
./spec/webvalve/manager_spec.rb[1:5:3:2:1] | passed | 0.00053 seconds |
|
26
|
+
./spec/webvalve/manager_spec.rb[1:5:3:2:2] | passed | 0.00066 seconds |
|
27
|
+
./spec/webvalve/manager_spec.rb[1:5:3:2:3] | passed | 0.0004 seconds |
|
28
|
+
./spec/webvalve/manager_spec.rb[1:5:4:1] | passed | 0.00036 seconds |
|
29
|
+
./spec/webvalve/manager_spec.rb[1:5:4:2] | passed | 0.0007 seconds |
|
30
|
+
./spec/webvalve/manager_spec.rb[1:6:1:1] | passed | 0.0002 seconds |
|
31
|
+
./spec/webvalve/manager_spec.rb[1:6:1:2] | passed | 0.00149 seconds |
|
32
|
+
./spec/webvalve/manager_spec.rb[1:6:2:1] | passed | 0.00014 seconds |
|
33
|
+
./spec/webvalve/manager_spec.rb[1:6:2:2] | passed | 0.00109 seconds |
|
34
|
+
./spec/webvalve/manager_spec.rb[1:6:2:3] | passed | 0.00037 seconds |
|
35
|
+
./spec/webvalve/manager_spec.rb[1:6:3:1] | passed | 0.00013 seconds |
|
36
|
+
./spec/webvalve/manager_spec.rb[1:6:3:2] | passed | 0.00012 seconds |
|
37
|
+
./spec/webvalve/manager_spec.rb[1:6:3:3] | passed | 0.0001 seconds |
|
38
|
+
./spec/webvalve/manager_spec.rb[1:6:3:4] | passed | 0.00011 seconds |
|
39
|
+
./spec/webvalve/manager_spec.rb[1:6:3:5] | passed | 0.00011 seconds |
|
40
|
+
./spec/webvalve/manager_spec.rb[1:7:1:1] | passed | 0.00011 seconds |
|
41
|
+
./spec/webvalve/manager_spec.rb[1:7:1:2] | passed | 0.00045 seconds |
|
42
|
+
./spec/webvalve/manager_spec.rb[1:7:2:1] | passed | 0.00011 seconds |
|
43
|
+
./spec/webvalve/manager_spec.rb[1:7:2:2] | passed | 0.00031 seconds |
|
44
|
+
./spec/webvalve/manager_spec.rb[1:7:2:3] | passed | 0.0001 seconds |
|
45
|
+
./spec/webvalve/manager_spec.rb[1:7:3:1] | passed | 0.00013 seconds |
|
46
|
+
./spec/webvalve/manager_spec.rb[1:7:3:2] | passed | 0.00012 seconds |
|
47
|
+
./spec/webvalve/manager_spec.rb[1:7:3:3] | passed | 0.00016 seconds |
|
48
|
+
./spec/webvalve/manager_spec.rb[1:7:3:4] | passed | 0.00016 seconds |
|
49
|
+
./spec/webvalve/manager_spec.rb[1:7:3:5] | passed | 0.00011 seconds |
|
50
|
+
./spec/webvalve/manager_spec.rb[1:8:1:1] | passed | 0.00008 seconds |
|
51
|
+
./spec/webvalve/manager_spec.rb[1:8:1:2] | passed | 0.00028 seconds |
|
52
|
+
./spec/webvalve/manager_spec.rb[1:8:2:1] | passed | 0.0001 seconds |
|
53
|
+
./spec/webvalve/manager_spec.rb[1:8:2:2] | passed | 0.00034 seconds |
|
54
|
+
./spec/webvalve/manager_spec.rb[1:8:3:1] | passed | 0.0001 seconds |
|
55
|
+
./spec/webvalve/manager_spec.rb[1:8:3:2] | passed | 0.00009 seconds |
|
56
|
+
./spec/webvalve/manager_spec.rb[1:8:3:3] | passed | 0.00008 seconds |
|
57
|
+
./spec/webvalve/manager_spec.rb[1:8:3:4] | passed | 0.00007 seconds |
|
58
|
+
./spec/webvalve_spec.rb[1:1] | passed | 0.0001 seconds |
|
59
|
+
./spec/webvalve_spec.rb[1:2] | passed | 0.00326 seconds |
|
60
|
+
./spec/webvalve_spec.rb[1:3] | passed | 0.00021 seconds |
|
61
|
+
./spec/webvalve_spec.rb[1:4] | passed | 0.00042 seconds |
|
@@ -19,114 +19,50 @@ RSpec.describe WebValve::FakeServiceConfig do
|
|
19
19
|
|
20
20
|
subject { described_class.new service_class_name: fake_service.name }
|
21
21
|
|
22
|
-
describe '.
|
23
|
-
|
24
|
-
|
25
|
-
with_rails_env 'test' do
|
26
|
-
ex.run
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'returns true when DUMMY_ENABLED is unset' do
|
31
|
-
expect(subject.should_intercept?).to eq true
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'returns true regardless of DUMMY_ENABLED value' do
|
35
|
-
with_env 'DUMMY_ENABLED' => '1' do
|
36
|
-
expect(subject.should_intercept?).to eq true
|
37
|
-
end
|
38
|
-
|
39
|
-
with_env 'DUMMY_ENABLED' => '0' do
|
40
|
-
expect(subject.should_intercept?).to eq true
|
41
|
-
end
|
42
|
-
end
|
22
|
+
describe '.explicitly_enabled?' do
|
23
|
+
it 'returns false when DUMMY_ENABLED is unset' do
|
24
|
+
expect(subject.explicitly_enabled?).to eq false
|
43
25
|
end
|
44
26
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
ex.run
|
49
|
-
end
|
27
|
+
it 'returns true when DUMMY_ENABLED is truthy' do
|
28
|
+
with_env 'DUMMY_ENABLED' => '1' do
|
29
|
+
expect(subject.explicitly_enabled?).to eq true
|
50
30
|
end
|
51
31
|
|
52
|
-
|
53
|
-
expect(subject.
|
32
|
+
with_env 'DUMMY_ENABLED' => 't' do
|
33
|
+
expect(subject.explicitly_enabled?).to eq true
|
54
34
|
end
|
55
35
|
|
56
|
-
|
57
|
-
|
58
|
-
expect(subject.should_intercept?).to eq false
|
59
|
-
end
|
60
|
-
|
61
|
-
with_env 'DUMMY_ENABLED' => 't' do
|
62
|
-
expect(subject.should_intercept?).to eq false
|
63
|
-
end
|
64
|
-
|
65
|
-
with_env 'DUMMY_ENABLED' => 'true' do
|
66
|
-
expect(subject.should_intercept?).to eq false
|
67
|
-
end
|
36
|
+
with_env 'DUMMY_ENABLED' => 'true' do
|
37
|
+
expect(subject.explicitly_enabled?).to eq true
|
68
38
|
end
|
69
39
|
|
70
|
-
|
71
|
-
|
72
|
-
expect(subject.should_intercept?).to eq true
|
73
|
-
end
|
74
|
-
|
75
|
-
with_env 'DUMMY_ENABLED' => 'f' do
|
76
|
-
expect(subject.should_intercept?).to eq true
|
77
|
-
end
|
78
|
-
|
79
|
-
with_env 'DUMMY_ENABLED' => 'false' do
|
80
|
-
expect(subject.should_intercept?).to eq true
|
81
|
-
end
|
82
|
-
|
83
|
-
with_env 'DUMMY_ENABLED' => 'not true or false' do
|
84
|
-
expect(subject.should_intercept?).to eq true
|
85
|
-
end
|
40
|
+
with_env 'DUMMY_ENABLED' => 'not true or false' do
|
41
|
+
expect(subject.explicitly_enabled?).to eq false
|
86
42
|
end
|
87
43
|
end
|
44
|
+
end
|
88
45
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
46
|
+
describe '.explicitly_disabled?' do
|
47
|
+
it 'returns false when DUMMY_ENABLED is unset' do
|
48
|
+
expect(subject.explicitly_disabled?).to eq false
|
49
|
+
end
|
95
50
|
|
96
|
-
|
97
|
-
|
51
|
+
it 'returns true when DUMMY_ENABLED is falsey' do
|
52
|
+
with_env 'DUMMY_ENABLED' => '0' do
|
53
|
+
expect(subject.explicitly_disabled?).to eq true
|
98
54
|
end
|
99
55
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
56
|
+
with_env 'DUMMY_ENABLED' => 'f' do
|
57
|
+
expect(subject.explicitly_disabled?).to eq true
|
58
|
+
end
|
104
59
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
60
|
+
with_env 'DUMMY_ENABLED' => 'false' do
|
61
|
+
expect(subject.explicitly_disabled?).to eq true
|
108
62
|
end
|
109
63
|
|
110
|
-
|
111
|
-
|
112
|
-
with_env 'WEBVALVE_ENABLED' => '1' do
|
113
|
-
ex.run
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'returns true' do
|
118
|
-
expect(subject.should_intercept?).to eq true
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'respects DUMMY_ENABLED flag' do
|
122
|
-
with_env 'DUMMY_ENABLED' => '1' do
|
123
|
-
expect(subject.should_intercept?).to eq false
|
124
|
-
end
|
125
|
-
|
126
|
-
with_env 'DUMMY_ENABLED' => '0' do
|
127
|
-
expect(subject.should_intercept?).to eq true
|
128
|
-
end
|
129
|
-
end
|
64
|
+
with_env 'DUMMY_ENABLED' => 'not true or false' do
|
65
|
+
expect(subject.explicitly_disabled?).to eq false
|
130
66
|
end
|
131
67
|
end
|
132
68
|
end
|
@@ -32,44 +32,67 @@ RSpec.describe WebValve::Manager do
|
|
32
32
|
it 'stores the url' do
|
33
33
|
fake = class_double(WebValve::FakeService, name: "FooService")
|
34
34
|
|
35
|
-
subject.register fake.name, url: 'http://
|
36
|
-
expect(subject.fake_service_configs.first.service_url).to eq 'http://
|
35
|
+
subject.register fake.name, url: 'http://foo.dev'
|
36
|
+
expect(subject.fake_service_configs.first.service_url).to eq 'http://foo.dev'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe '#setup' do
|
41
|
-
|
42
|
-
|
41
|
+
context 'when WebValve is disabled' do
|
42
|
+
around do |ex|
|
43
|
+
with_rails_env 'production' do
|
44
|
+
# unset
|
45
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
46
|
+
ex.run
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
43
50
|
|
44
|
-
|
51
|
+
it 'does not setup webmock' do
|
52
|
+
allow(WebMock).to receive(:allow_net_connect!)
|
53
|
+
allow(WebMock).to receive(:enable!)
|
45
54
|
|
46
|
-
|
55
|
+
subject.setup
|
56
|
+
|
57
|
+
expect(WebMock).not_to have_received(:allow_net_connect!)
|
58
|
+
expect(WebMock).not_to have_received(:enable!)
|
59
|
+
end
|
47
60
|
end
|
48
61
|
|
49
|
-
|
50
|
-
|
62
|
+
context 'when WebValve is on and intercepting traffic' do
|
63
|
+
around do |ex|
|
64
|
+
with_rails_env 'production' do
|
65
|
+
with_env 'WEBVALVE_ENABLED' => '1', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => '0' do
|
66
|
+
ex.run
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
51
70
|
|
52
|
-
|
71
|
+
it 'enables webmock' do
|
72
|
+
allow(WebMock).to receive(:enable!)
|
53
73
|
|
54
|
-
|
55
|
-
end
|
74
|
+
subject.setup
|
56
75
|
|
57
|
-
|
58
|
-
|
76
|
+
expect(WebMock).to have_received(:enable!)
|
77
|
+
end
|
59
78
|
|
60
|
-
|
79
|
+
it 'disables network connections' do
|
80
|
+
allow(WebMock).to receive(:disable_net_connect!)
|
61
81
|
|
62
|
-
|
63
|
-
end
|
82
|
+
subject.setup
|
64
83
|
|
65
|
-
|
66
|
-
around do |example|
|
67
|
-
with_rails_env 'test' do
|
68
|
-
example.run
|
69
|
-
end
|
84
|
+
expect(WebMock).to have_received(:disable_net_connect!)
|
70
85
|
end
|
71
86
|
|
72
|
-
it '
|
87
|
+
it 'allows localhost connections' do
|
88
|
+
allow(WebMock).to receive(:disable_net_connect!)
|
89
|
+
|
90
|
+
subject.setup
|
91
|
+
|
92
|
+
expect(WebMock).to have_received(:disable_net_connect!).with(hash_including(allow_localhost: true))
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'allowlists configured urls in webmock' do
|
73
96
|
allow(WebMock).to receive(:disable_net_connect!)
|
74
97
|
results = [%r{\Ahttp://foo\.dev}, %r{\Ahttp://bar\.dev}]
|
75
98
|
|
@@ -78,19 +101,112 @@ RSpec.describe WebValve::Manager do
|
|
78
101
|
|
79
102
|
subject.setup
|
80
103
|
|
81
|
-
expect(WebMock).
|
104
|
+
expect(WebMock).to have_received(:disable_net_connect!)
|
82
105
|
.with(hash_including(allow: results))
|
83
106
|
end
|
107
|
+
|
108
|
+
it 'mocks registered fakes that are not enabled in ENV' do
|
109
|
+
disabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
|
110
|
+
web_mock_stubble = double(to_rack: true)
|
111
|
+
allow(WebMock).to receive(:stub_request).and_return(web_mock_stubble)
|
112
|
+
|
113
|
+
with_env 'SOMETHING_API_URL' => 'http://something.dev' do
|
114
|
+
subject.register disabled_service.name
|
115
|
+
subject.setup
|
116
|
+
end
|
117
|
+
|
118
|
+
expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://something\.dev})
|
119
|
+
expect(web_mock_stubble).to have_received(:to_rack)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'allowlists registered fakes that are enabled in ENV' do
|
123
|
+
enabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
|
124
|
+
|
125
|
+
with_env 'SOMETHING_ENABLED' => '1', 'SOMETHING_API_URL' => 'http://something.dev' do
|
126
|
+
subject.register enabled_service.name
|
127
|
+
subject.setup
|
128
|
+
end
|
129
|
+
|
130
|
+
expect(subject.allowlisted_urls).to include 'http://something.dev'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when WebValve is on and allowing traffic' do
|
135
|
+
around do |ex|
|
136
|
+
with_rails_env 'production' do
|
137
|
+
with_env 'WEBVALVE_ENABLED' => '1', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => '1' do
|
138
|
+
ex.run
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when there are no services disabled' do
|
144
|
+
it 'does not setup webmock' do
|
145
|
+
allow(WebMock).to receive(:allow_net_connect!)
|
146
|
+
allow(WebMock).to receive(:enable!)
|
147
|
+
|
148
|
+
subject.setup
|
149
|
+
|
150
|
+
expect(WebMock).not_to have_received(:allow_net_connect!)
|
151
|
+
expect(WebMock).not_to have_received(:enable!)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when there are explicitly disabled fake services to stub' do
|
156
|
+
it 'allows network connections and enables webmock' do
|
157
|
+
allow(WebMock).to receive(:allow_net_connect!)
|
158
|
+
allow(WebMock).to receive(:enable!)
|
159
|
+
|
160
|
+
enabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
|
161
|
+
|
162
|
+
with_env 'SOMETHING_ENABLED' => '0', 'SOMETHING_API_URL' => 'http://something.dev' do
|
163
|
+
subject.register enabled_service.name
|
164
|
+
subject.setup
|
165
|
+
end
|
166
|
+
|
167
|
+
expect(WebMock).to have_received(:allow_net_connect!)
|
168
|
+
expect(WebMock).to have_received(:enable!)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'mocks registered fakes that are explicitly disabled in ENV' do
|
172
|
+
disabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
|
173
|
+
other_service = class_double(WebValve::FakeService, name: 'FakeOther')
|
174
|
+
|
175
|
+
web_mock_stubble = double(to_rack: true)
|
176
|
+
allow(WebMock).to receive(:stub_request).and_return(web_mock_stubble)
|
177
|
+
|
178
|
+
with_env 'SOMETHING_API_URL' => 'http://something.dev', 'SOMETHING_ENABLED' => '0', 'OTHER_API_URL' => 'http://other.dev' do
|
179
|
+
subject.register disabled_service.name
|
180
|
+
subject.register other_service.name
|
181
|
+
subject.setup
|
182
|
+
end
|
183
|
+
|
184
|
+
expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://something\.dev})
|
185
|
+
expect(WebMock).not_to have_received(:stub_request).with(:any, %r{\Ahttp://other\.dev})
|
186
|
+
expect(web_mock_stubble).to have_received(:to_rack).once
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'does not allowlist registered fakes because the network is enabled' do
|
190
|
+
some_service = class_double(WebValve::FakeService, name: 'FakeSomething')
|
191
|
+
|
192
|
+
with_env 'SOMETHING_API_URL' => 'http://something.dev' do
|
193
|
+
subject.register some_service.name
|
194
|
+
subject.setup
|
195
|
+
end
|
196
|
+
|
197
|
+
expect(subject.allowlisted_urls).not_to include 'http://something.dev'
|
198
|
+
end
|
199
|
+
end
|
84
200
|
end
|
85
201
|
|
86
|
-
context 'in
|
202
|
+
context 'in test environment' do
|
87
203
|
around do |example|
|
88
|
-
with_rails_env '
|
204
|
+
with_rails_env 'test' do
|
89
205
|
example.run
|
90
206
|
end
|
91
207
|
end
|
92
208
|
|
93
|
-
it '
|
209
|
+
it 'does not allowlist configured urls in webmock' do
|
94
210
|
allow(WebMock).to receive(:disable_net_connect!)
|
95
211
|
results = [%r{\Ahttp://foo\.dev}, %r{\Ahttp://bar\.dev}]
|
96
212
|
|
@@ -99,33 +215,405 @@ RSpec.describe WebValve::Manager do
|
|
99
215
|
|
100
216
|
subject.setup
|
101
217
|
|
102
|
-
expect(WebMock).
|
218
|
+
expect(WebMock).not_to have_received(:disable_net_connect!)
|
103
219
|
.with(hash_including(allow: results))
|
104
220
|
end
|
105
221
|
|
106
|
-
it '
|
107
|
-
|
222
|
+
it 'fakes all services regardless of ENV settings' do
|
223
|
+
enabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
|
224
|
+
disabled_service = class_double(WebValve::FakeService, name: 'FakeSomethingElse')
|
225
|
+
other_service = class_double(WebValve::FakeService, name: 'FakeOther')
|
226
|
+
|
108
227
|
web_mock_stubble = double(to_rack: true)
|
109
228
|
allow(WebMock).to receive(:stub_request).and_return(web_mock_stubble)
|
110
229
|
|
111
|
-
with_env '
|
112
|
-
subject.register disabled_service.name
|
230
|
+
with_env 'SOMETHING_ENABLED' => '1', 'SOMETHING_ELSE_ENABLED' => '0', 'OTHER_ENABLED' => nil do
|
231
|
+
subject.register disabled_service.name, url: 'http://something.dev'
|
232
|
+
subject.register enabled_service.name, url: 'http://something-else.dev'
|
233
|
+
subject.register other_service.name, url: 'http://other.dev'
|
113
234
|
subject.setup
|
114
235
|
end
|
115
236
|
|
116
|
-
expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://
|
117
|
-
expect(
|
237
|
+
expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://something\.dev})
|
238
|
+
expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://something\-else\.dev})
|
239
|
+
expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://other\.dev})
|
240
|
+
expect(web_mock_stubble).to have_received(:to_rack).exactly(3).times
|
118
241
|
end
|
242
|
+
end
|
243
|
+
end
|
119
244
|
|
120
|
-
|
121
|
-
|
245
|
+
describe '.intercepting?' do
|
246
|
+
context 'in test env' do
|
247
|
+
around do |ex|
|
248
|
+
with_rails_env 'test' do
|
249
|
+
ex.run
|
250
|
+
end
|
251
|
+
end
|
122
252
|
|
123
|
-
|
124
|
-
|
125
|
-
|
253
|
+
it 'returns true when WEBVALVE_ENABLED is unset' do
|
254
|
+
expect(subject.intercepting?).to eq true
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'returns true regardless of WEBVALVE_ENABLED value' do
|
258
|
+
allow(WebValve.logger).to receive(:warn)
|
259
|
+
|
260
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
261
|
+
expect(subject.intercepting?).to eq true
|
262
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
263
|
+
end
|
264
|
+
|
265
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
266
|
+
expect(subject.intercepting?).to eq true
|
267
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context 'in development env' do
|
273
|
+
around do |ex|
|
274
|
+
with_rails_env 'development' do
|
275
|
+
ex.run
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'returns true when WEBVALVE_ENABLED is unset' do
|
280
|
+
expect(subject.intercepting?).to eq true
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'returns true regardless of WEBVALVE_ENABLED value' do
|
284
|
+
allow(WebValve.logger).to receive(:warn)
|
285
|
+
|
286
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
287
|
+
expect(subject.intercepting?).to eq true
|
288
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
289
|
+
end
|
290
|
+
|
291
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
292
|
+
expect(subject.intercepting?).to eq true
|
293
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'returns true when WEBVALVE_ENABLED is unset' do
|
298
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
299
|
+
expect(subject.intercepting?).to eq true
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context 'in production enviroment' do
|
305
|
+
around do |ex|
|
306
|
+
with_rails_env 'production' do
|
307
|
+
ex.run
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'return false when WEBVALVE_ENABLED is unset' do
|
312
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
313
|
+
expect(subject.intercepting?).to eq false
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'returns true when WEBVALVE_ENABLED is truthy and WEBVALVE_SERVICE_ENABLED_DEFAULT is set and falsey' do
|
318
|
+
with_env 'WEBVALVE_ENABLED' => '1', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => '0' do
|
319
|
+
expect(subject.intercepting?).to eq true
|
320
|
+
end
|
321
|
+
|
322
|
+
with_env 'WEBVALVE_ENABLED' => 't', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 'f' do
|
323
|
+
expect(subject.intercepting?).to eq true
|
324
|
+
end
|
325
|
+
|
326
|
+
with_env 'WEBVALVE_ENABLED' => 'true', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 'false' do
|
327
|
+
expect(subject.intercepting?).to eq true
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'returns false when WEBVALVE_ENABLED is truthy and WEBVALVE_SERVICE_ENABLED_DEFAULT is set and truthy' do
|
332
|
+
with_env 'WEBVALVE_ENABLED' => '1', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => '1' do
|
333
|
+
expect(subject.intercepting?).to eq false
|
334
|
+
end
|
335
|
+
|
336
|
+
with_env 'WEBVALVE_ENABLED' => 't', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 't' do
|
337
|
+
expect(subject.intercepting?).to eq false
|
338
|
+
end
|
339
|
+
|
340
|
+
with_env 'WEBVALVE_ENABLED' => 'true', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 'true' do
|
341
|
+
expect(subject.intercepting?).to eq false
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'returns false when WEBVALVE_ENABLED is truthy but WEBVALVE_SERVICE_ENABLED_DEFAULT is unset' do
|
346
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
347
|
+
expect(subject.intercepting?).to eq false
|
348
|
+
end
|
349
|
+
|
350
|
+
with_env 'WEBVALVE_ENABLED' => 't' do
|
351
|
+
expect(subject.intercepting?).to eq false
|
352
|
+
end
|
353
|
+
|
354
|
+
with_env 'WEBVALVE_ENABLED' => 'true' do
|
355
|
+
expect(subject.intercepting?).to eq false
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'returns false when WEBVALVE_ENABLED is not truthy' do
|
360
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
361
|
+
expect(subject.intercepting?).to eq false
|
362
|
+
end
|
363
|
+
|
364
|
+
with_env 'WEBVALVE_ENABLED' => 'f' do
|
365
|
+
expect(subject.intercepting?).to eq false
|
366
|
+
end
|
367
|
+
|
368
|
+
with_env 'WEBVALVE_ENABLED' => 'false' do
|
369
|
+
expect(subject.intercepting?).to eq false
|
370
|
+
end
|
371
|
+
|
372
|
+
with_env 'WEBVALVE_ENABLED' => 'not true or false' do
|
373
|
+
expect(subject.intercepting?).to eq false
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
describe '.allowing?' do
|
380
|
+
context 'in test env' do
|
381
|
+
around do |ex|
|
382
|
+
with_rails_env 'test' do
|
383
|
+
ex.run
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'returns false when WEBVALVE_ENABLED is unset' do
|
388
|
+
expect(subject.allowing?).to eq false
|
389
|
+
end
|
390
|
+
|
391
|
+
it 'returns false regardless of WEBVALVE_ENABLED value' do
|
392
|
+
allow(WebValve.logger).to receive(:warn)
|
393
|
+
|
394
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
395
|
+
expect(subject.allowing?).to eq false
|
396
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
397
|
+
end
|
398
|
+
|
399
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
400
|
+
expect(subject.allowing?).to eq false
|
401
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'in development env' do
|
407
|
+
around do |ex|
|
408
|
+
with_rails_env 'development' do
|
409
|
+
ex.run
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'returns false when WEBVALVE_ENABLED is unset' do
|
414
|
+
expect(subject.allowing?).to eq false
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'returns false regardless of WEBVALVE_ENABLED value' do
|
418
|
+
allow(WebValve.logger).to receive(:warn)
|
419
|
+
|
420
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
421
|
+
expect(subject.allowing?).to eq false
|
422
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
423
|
+
end
|
424
|
+
|
425
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
426
|
+
expect(subject.allowing?).to eq false
|
427
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
it 'returns false when WEBVALVE_ENABLED is unset' do
|
432
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
433
|
+
expect(subject.allowing?).to eq false
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
context 'in production enviroment' do
|
439
|
+
around do |ex|
|
440
|
+
with_rails_env 'production' do
|
441
|
+
ex.run
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
it 'returns false when WEBVALVE_ENABLED is unset' do
|
446
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
447
|
+
expect(subject.allowing?).to eq false
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
|
452
|
+
it 'returns true when WEBVALVE_ENABLED is truthy and WEBVALVE_SERVICE_ENABLED_DEFAULT is unset' do
|
453
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
454
|
+
expect(subject.allowing?).to eq true
|
455
|
+
end
|
456
|
+
|
457
|
+
with_env 'WEBVALVE_ENABLED' => 't' do
|
458
|
+
expect(subject.allowing?).to eq true
|
459
|
+
end
|
460
|
+
|
461
|
+
with_env 'WEBVALVE_ENABLED' => 'true' do
|
462
|
+
expect(subject.allowing?).to eq true
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
it 'returns true when WEBVALVE_ENABLED is truthy and WEBVALVE_SERVICE_ENABLED_DEFAULT is truthy' do
|
467
|
+
with_env 'WEBVALVE_ENABLED' => '1', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => '1' do
|
468
|
+
expect(subject.allowing?).to eq true
|
469
|
+
end
|
470
|
+
|
471
|
+
with_env 'WEBVALVE_ENABLED' => 't', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 't' do
|
472
|
+
expect(subject.allowing?).to eq true
|
473
|
+
end
|
474
|
+
|
475
|
+
with_env 'WEBVALVE_ENABLED' => 'true', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 'true' do
|
476
|
+
expect(subject.allowing?).to eq true
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
it 'returns false when WEBVALVE_ENABLED is truthy and WEBVALVE_SERVICE_ENABLED_DEFAULT is set and falsey' do
|
481
|
+
with_env 'WEBVALVE_ENABLED' => '1', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => '0' do
|
482
|
+
expect(subject.allowing?).to eq false
|
483
|
+
end
|
484
|
+
|
485
|
+
with_env 'WEBVALVE_ENABLED' => 't', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 'f' do
|
486
|
+
expect(subject.allowing?).to eq false
|
487
|
+
end
|
488
|
+
|
489
|
+
with_env 'WEBVALVE_ENABLED' => 'true', 'WEBVALVE_SERVICE_ENABLED_DEFAULT' => 'false' do
|
490
|
+
expect(subject.allowing?).to eq false
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
it 'returns false when WEBVALVE_ENABLED is falsey' do
|
495
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
496
|
+
expect(subject.allowing?).to eq false
|
497
|
+
end
|
498
|
+
|
499
|
+
with_env 'WEBVALVE_ENABLED' => 'f' do
|
500
|
+
expect(subject.allowing?).to eq false
|
501
|
+
end
|
502
|
+
|
503
|
+
with_env 'WEBVALVE_ENABLED' => 'false' do
|
504
|
+
expect(subject.allowing?).to eq false
|
126
505
|
end
|
127
506
|
|
128
|
-
|
507
|
+
with_env 'WEBVALVE_ENABLED' => 'not true or false' do
|
508
|
+
expect(subject.allowing?).to eq false
|
509
|
+
end
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
describe '.enabled?' do
|
515
|
+
context 'in test env' do
|
516
|
+
around do |ex|
|
517
|
+
with_rails_env 'test' do
|
518
|
+
ex.run
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
it 'returns true when WEBVALVE_ENABLED is unset' do
|
523
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
524
|
+
expect(subject.enabled?).to eq true
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
it 'returns true regardless of WEBVALVE_ENABLED value' do
|
529
|
+
allow(WebValve.logger).to receive(:warn)
|
530
|
+
|
531
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
532
|
+
expect(subject.enabled?).to eq true
|
533
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
534
|
+
end
|
535
|
+
|
536
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
537
|
+
expect(subject.enabled?).to eq true
|
538
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
context 'in development env' do
|
544
|
+
around do |ex|
|
545
|
+
with_rails_env 'development' do
|
546
|
+
ex.run
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
it 'returns true when WEBVALVE_ENABLED is unset' do
|
551
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
552
|
+
expect(subject.enabled?).to eq true
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
556
|
+
it 'returns true regardless of WEBVALVE_ENABLED value' do
|
557
|
+
allow(WebValve.logger).to receive(:warn)
|
558
|
+
|
559
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
560
|
+
expect(subject.enabled?).to eq true
|
561
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
562
|
+
end
|
563
|
+
|
564
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
565
|
+
expect(subject.enabled?).to eq true
|
566
|
+
expect(WebValve.logger).to have_received(:warn).at_least(1)
|
567
|
+
end
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
context 'in production enviroment' do
|
572
|
+
around do |ex|
|
573
|
+
with_rails_env 'production' do
|
574
|
+
ex.run
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
it 'returns false when WEBVALVE_ENABLED is unset' do
|
579
|
+
with_env 'WEBVALVE_ENABLED' => nil do
|
580
|
+
expect(subject.enabled?).to eq false
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
|
585
|
+
it 'returns false when WEBVALVE_ENABLED is falsey' do
|
586
|
+
with_env 'WEBVALVE_ENABLED' => '0' do
|
587
|
+
expect(subject.enabled?).to eq false
|
588
|
+
end
|
589
|
+
|
590
|
+
with_env 'WEBVALVE_ENABLED' => 'f' do
|
591
|
+
expect(subject.enabled?).to eq false
|
592
|
+
end
|
593
|
+
|
594
|
+
with_env 'WEBVALVE_ENABLED' => 'false' do
|
595
|
+
expect(subject.enabled?).to eq false
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
it 'returns true when WEBVALVE_ENABLED is truthy' do
|
600
|
+
with_env 'WEBVALVE_ENABLED' => '1' do
|
601
|
+
expect(subject.enabled?).to eq true
|
602
|
+
end
|
603
|
+
|
604
|
+
with_env 'WEBVALVE_ENABLED' => 't' do
|
605
|
+
expect(subject.enabled?).to eq true
|
606
|
+
end
|
607
|
+
|
608
|
+
with_env 'WEBVALVE_ENABLED' => 'true' do
|
609
|
+
expect(subject.enabled?).to eq true
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
it 'returns false when WEBVALVE_ENABLED is an invalid value' do
|
614
|
+
with_env 'WEBVALVE_ENABLED' => 'not true or false' do
|
615
|
+
expect(subject.enabled?).to eq false
|
616
|
+
end
|
129
617
|
end
|
130
618
|
end
|
131
619
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webvalve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- lib/webvalve/version.rb
|
163
163
|
- spec/dummy/README.rdoc
|
164
164
|
- spec/dummy/Rakefile
|
165
|
+
- spec/dummy/app/assets/config/manifest.js
|
165
166
|
- spec/dummy/app/assets/javascripts/application.js
|
166
167
|
- spec/dummy/app/assets/stylesheets/application.css
|
167
168
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -229,6 +230,7 @@ test_files:
|
|
229
230
|
- spec/spec_helper.rb
|
230
231
|
- spec/dummy/app/controllers/application_controller.rb
|
231
232
|
- spec/dummy/app/views/layouts/application.html.erb
|
233
|
+
- spec/dummy/app/assets/config/manifest.js
|
232
234
|
- spec/dummy/app/assets/javascripts/application.js
|
233
235
|
- spec/dummy/app/assets/stylesheets/application.css
|
234
236
|
- spec/dummy/app/helpers/application_helper.rb
|