sitehub 0.5.0.alpha11 → 0.5.0.alpha12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -12
- data/lib/sitehub/candidate_routes.rb +18 -15
- data/lib/sitehub/candidate_routes/from_json.rb +4 -6
- data/lib/sitehub/constants.rb +1 -1
- data/lib/sitehub/core.rb +1 -1
- data/lib/sitehub/middleware/candidate_route_mappings.rb +2 -2
- data/lib/sitehub/version.rb +1 -1
- data/sitehub.gemspec +1 -1
- data/spec/integration/config_server_spec.rb +9 -9
- data/spec/sitehub/candidate_routes/from_json_spec.rb +42 -47
- data/spec/sitehub/candidate_routes_spec.rb +17 -19
- data/spec/sitehub/core_spec.rb +1 -2
- data/spec/sitehub/middleware/candidate_route_mappings_spec.rb +23 -20
- data/spec/support/{shared_examples → shared_contexts}/sitehub_json_context.rb +0 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5960551a37d7e1dcc81e5c1f1e785874e93e98ed
|
4
|
+
data.tar.gz: fce52d9ba323bd271d8164fef30ff61736bd698e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f61bbdaa2cb7bca2a6b4974cb0ea962b6076a7236c39b7e75e7f7959e98cbc463c18c97f06acf4216145aebeee7a139ccf0b730162fcc132654210f63ec8e816
|
7
|
+
data.tar.gz: e7d8c1ec72fae39c13fc47613d0558d478c74d7bb457bba43ca1c8ad70a4ed3cb3b811283d2f3eb4d5beada7b4ac7f2ee537f8a3329dfae97bbf0aa54f6d2e5e
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sitehub (0.5.0.
|
4
|
+
sitehub (0.5.0.alpha12)
|
5
5
|
activesupport
|
6
6
|
em-http-request
|
7
7
|
em-synchrony
|
8
8
|
faraday
|
9
|
-
rack
|
9
|
+
rack (~> 1.6.8)
|
10
10
|
rack-fiber_pool
|
11
11
|
rack-ssl-enforcer
|
12
12
|
thin
|
@@ -15,7 +15,7 @@ PATH
|
|
15
15
|
GEM
|
16
16
|
remote: https://rubygems.org/
|
17
17
|
specs:
|
18
|
-
activesupport (5.
|
18
|
+
activesupport (5.1.4)
|
19
19
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
20
|
i18n (~> 0.7)
|
21
21
|
minitest (~> 5.1)
|
@@ -33,11 +33,11 @@ GEM
|
|
33
33
|
simplecov (>= 0.7.1, < 1.0.0)
|
34
34
|
coercible (1.0.0)
|
35
35
|
descendants_tracker (~> 0.0.1)
|
36
|
-
concurrent-ruby (1.0.
|
36
|
+
concurrent-ruby (1.0.5)
|
37
37
|
cookiejar (0.3.3)
|
38
38
|
crack (0.4.3)
|
39
39
|
safe_yaml (~> 1.0.0)
|
40
|
-
daemons (1.2.
|
40
|
+
daemons (1.2.6)
|
41
41
|
descendants_tracker (0.0.4)
|
42
42
|
thread_safe (~> 0.3, >= 0.3.1)
|
43
43
|
diff-lcs (1.2.5)
|
@@ -50,10 +50,10 @@ GEM
|
|
50
50
|
http_parser.rb (>= 0.6.0)
|
51
51
|
em-socksify (0.3.1)
|
52
52
|
eventmachine (>= 1.0.0.beta.4)
|
53
|
-
em-synchrony (1.0.
|
53
|
+
em-synchrony (1.0.6)
|
54
54
|
eventmachine (>= 1.0.0.beta.1)
|
55
55
|
equalizer (0.0.11)
|
56
|
-
eventmachine (1.2.
|
56
|
+
eventmachine (1.2.5)
|
57
57
|
faraday (0.9.2)
|
58
58
|
multipart-post (>= 1.2, < 3)
|
59
59
|
geminabox (0.13.1)
|
@@ -65,19 +65,20 @@ GEM
|
|
65
65
|
hashdiff (0.3.0)
|
66
66
|
http_parser.rb (0.6.0)
|
67
67
|
httpclient (2.8.0)
|
68
|
-
i18n (0.
|
68
|
+
i18n (0.9.1)
|
69
|
+
concurrent-ruby (~> 1.0)
|
69
70
|
ice_nine (0.11.2)
|
70
71
|
json (1.8.3)
|
71
72
|
macaddr (1.7.1)
|
72
73
|
systemu (~> 2.6.2)
|
73
74
|
memory_profiler (0.9.6)
|
74
|
-
minitest (5.
|
75
|
+
minitest (5.10.3)
|
75
76
|
multipart-post (2.0.0)
|
76
77
|
nesty (1.0.2)
|
77
78
|
parser (2.3.1.2)
|
78
79
|
ast (~> 2.2)
|
79
80
|
powerpack (0.1.1)
|
80
|
-
rack (1.6.
|
81
|
+
rack (1.6.8)
|
81
82
|
rack-fiber_pool (0.9.3)
|
82
83
|
rack-protection (1.5.3)
|
83
84
|
rack
|
@@ -122,14 +123,14 @@ GEM
|
|
122
123
|
rack-protection (~> 1.4)
|
123
124
|
tilt (>= 1.3, < 3)
|
124
125
|
systemu (2.6.5)
|
125
|
-
thin (1.7.
|
126
|
+
thin (1.7.2)
|
126
127
|
daemons (~> 1.0, >= 1.0.9)
|
127
128
|
eventmachine (~> 1.0, >= 1.0.4)
|
128
129
|
rack (>= 1, < 3)
|
129
130
|
thread_safe (0.3.5)
|
130
131
|
tilt (2.0.5)
|
131
132
|
timecop (0.8.1)
|
132
|
-
tzinfo (1.2.
|
133
|
+
tzinfo (1.2.4)
|
133
134
|
thread_safe (~> 0.1)
|
134
135
|
unicode-display_width (1.0.5)
|
135
136
|
uuid (2.3.8)
|
@@ -14,6 +14,13 @@ require_relative 'forward_proxy'
|
|
14
14
|
require_relative 'downstream_client'
|
15
15
|
|
16
16
|
class SiteHub
|
17
|
+
class TrackingCookieDefinition
|
18
|
+
attr_reader :name, :path
|
19
|
+
def initialize(name, path = nil)
|
20
|
+
@name = name
|
21
|
+
@path = path
|
22
|
+
end
|
23
|
+
end
|
17
24
|
class CandidateRoutes
|
18
25
|
class InvalidDefinitionError < StandardError
|
19
26
|
end
|
@@ -55,11 +62,12 @@ class SiteHub
|
|
55
62
|
self
|
56
63
|
end
|
57
64
|
|
58
|
-
def candidates(
|
59
|
-
return @endpoints ||= Collection::RouteCollection.new unless
|
65
|
+
def candidates(clazz = nil)
|
66
|
+
return @endpoints ||= Collection::RouteCollection.new unless clazz
|
67
|
+
@endpoints ||= clazz.new
|
60
68
|
|
61
|
-
raise InvalidDefinitionError, ROUTES_WITH_SPLITS_MSG
|
62
|
-
@endpoints
|
69
|
+
raise InvalidDefinitionError, ROUTES_WITH_SPLITS_MSG unless @endpoints.is_a?(clazz)
|
70
|
+
@endpoints
|
63
71
|
end
|
64
72
|
|
65
73
|
def default(url:)
|
@@ -86,20 +94,18 @@ class SiteHub
|
|
86
94
|
end
|
87
95
|
|
88
96
|
# TODO: combine cookie name and path in to an : nobject
|
89
|
-
def initialize(id: nil,
|
97
|
+
def initialize(id: nil, version_cookie:, mapped_path:, rule: nil, &block)
|
90
98
|
@id = Identifier.new(id)
|
91
99
|
|
92
100
|
@mapped_path = sanitise_mapped_path(mapped_path)
|
93
|
-
|
94
|
-
|
101
|
+
sitehub_cookie_name(version_cookie.name)
|
102
|
+
sitehub_cookie_path(version_cookie.path)
|
95
103
|
|
96
104
|
rule(rule)
|
97
105
|
|
98
106
|
init(&block) if block_given?
|
99
107
|
end
|
100
108
|
|
101
|
-
|
102
|
-
|
103
109
|
def resolve(id: nil, env:)
|
104
110
|
id = Identifier.new(id)
|
105
111
|
if id.valid? && (route = candidates[id.root])
|
@@ -110,14 +116,12 @@ class SiteHub
|
|
110
116
|
end
|
111
117
|
|
112
118
|
def route(url: nil, label:, rule: nil, &block)
|
113
|
-
|
114
|
-
candidates(@routes)
|
119
|
+
candidates(Collection::RouteCollection)
|
115
120
|
add(label: label, rule: rule, url: url, &block)
|
116
121
|
end
|
117
122
|
|
118
123
|
def split(percentage:, url: nil, label:, &block)
|
119
|
-
|
120
|
-
candidates(@splits)
|
124
|
+
candidates(Collection::SplitRouteCollection)
|
121
125
|
add(label: label, percentage: percentage, url: url, &block)
|
122
126
|
end
|
123
127
|
|
@@ -175,8 +179,7 @@ class SiteHub
|
|
175
179
|
inherited_middleware = middlewares
|
176
180
|
|
177
181
|
self.class.new(id: id,
|
178
|
-
|
179
|
-
sitehub_cookie_path: sitehub_cookie_path,
|
182
|
+
version_cookie: TrackingCookieDefinition.new(sitehub_cookie_name, sitehub_cookie_path),
|
180
183
|
mapped_path: mapped_path,
|
181
184
|
rule: rule) do
|
182
185
|
middlewares.concat(inherited_middleware)
|
@@ -1,10 +1,9 @@
|
|
1
1
|
class SiteHub
|
2
2
|
class CandidateRoutes
|
3
|
-
|
4
3
|
module FromJson
|
5
4
|
extend CollectionMethods
|
6
5
|
|
7
|
-
def self.extended
|
6
|
+
def self.extended(clazz)
|
8
7
|
clazz.class_eval do
|
9
8
|
include InstanceMethods
|
10
9
|
end
|
@@ -14,8 +13,7 @@ class SiteHub
|
|
14
13
|
def from_hash(hash, sitehub_cookie_name, sitehub_cookie_path)
|
15
14
|
cookie_path = hash[:sitehub_cookie_path] || sitehub_cookie_path
|
16
15
|
cookie_name = hash[:sitehub_cookie_name] || sitehub_cookie_name
|
17
|
-
new(
|
18
|
-
sitehub_cookie_path: cookie_path,
|
16
|
+
new(version_cookie: TrackingCookieDefinition.new(cookie_name, cookie_path),
|
19
17
|
mapped_path: hash[:path]) do
|
20
18
|
handle_routes(hash, self)
|
21
19
|
default url: hash[:default] if hash[:default]
|
@@ -24,6 +22,7 @@ class SiteHub
|
|
24
22
|
|
25
23
|
module InstanceMethods
|
26
24
|
private
|
25
|
+
|
27
26
|
def handle_routes(hash, routes)
|
28
27
|
extract_splits(hash, routes)
|
29
28
|
extract_routes(hash, routes)
|
@@ -42,13 +41,12 @@ class SiteHub
|
|
42
41
|
cookie_name = split[:sitehub_cookie_name] || sitehub_cookie_name
|
43
42
|
|
44
43
|
if split[:splits] || split[:routes]
|
45
|
-
routes.split(percentage: percentage, label: label)
|
44
|
+
routes.split(percentage: percentage, label: label) { handle_routes(split, self) }
|
46
45
|
else
|
47
46
|
routes.split(percentage: percentage, label: label, url: split[:url])
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
51
|
-
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
data/lib/sitehub/constants.rb
CHANGED
@@ -7,7 +7,7 @@ class SiteHub
|
|
7
7
|
RESPONSE = 'sitehub.response'.freeze
|
8
8
|
ASYNC_CALLBACK = 'async.callback'.freeze
|
9
9
|
RECORDED_ROUTES_COOKIE = 'sitehub.recorded_route'.freeze
|
10
|
-
|
10
|
+
RECORDED_ROUTES_COOKIE_PATH = '/'.freeze
|
11
11
|
ERRORS = 'sitehub.errors'.freeze
|
12
12
|
TIME_STAMP_FORMAT = '%d/%b/%Y:%H:%M:%S %z'.freeze
|
13
13
|
EMPTY_STRING = ''.freeze
|
data/lib/sitehub/core.rb
CHANGED
@@ -19,7 +19,7 @@ class SiteHub
|
|
19
19
|
sitehub_cookie_path config[:sitehub_cookie_path] if config[:sitehub_cookie_path]
|
20
20
|
|
21
21
|
collection!(config, :proxies).each do |proxy|
|
22
|
-
mappings.add_route candidate_routes: CandidateRoutes.from_hash(proxy, sitehub_cookie_name, sitehub_cookie_path
|
22
|
+
mappings.add_route candidate_routes: CandidateRoutes.from_hash(proxy, sitehub_cookie_name, sitehub_cookie_path)
|
23
23
|
end
|
24
24
|
|
25
25
|
collection(config, :reverse_proxies).each do |proxy|
|
@@ -14,7 +14,7 @@ class SiteHub
|
|
14
14
|
include Equality
|
15
15
|
|
16
16
|
extend GetterSetterMethods
|
17
|
-
getter_setter :sitehub_cookie_path,
|
17
|
+
getter_setter :sitehub_cookie_path, RECORDED_ROUTES_COOKIE_PATH
|
18
18
|
getter_setter :sitehub_cookie_name, RECORDED_ROUTES_COOKIE
|
19
19
|
|
20
20
|
def initialize
|
@@ -36,7 +36,7 @@ class SiteHub
|
|
36
36
|
|
37
37
|
def add_route(url: nil, mapped_path: nil, candidate_routes: nil, &block)
|
38
38
|
unless candidate_routes
|
39
|
-
candidate_routes = CandidateRoutes.new(
|
39
|
+
candidate_routes = CandidateRoutes.new(version_cookie: TrackingCookieDefinition.new(sitehub_cookie_name),
|
40
40
|
mapped_path: mapped_path,
|
41
41
|
&block).tap do |builder|
|
42
42
|
builder.default(url: url) if url
|
data/lib/sitehub/version.rb
CHANGED
data/sitehub.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(spec)/*.rb})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'rack'
|
21
|
+
spec.add_dependency 'rack', '~> 1.6.8'
|
22
22
|
spec.add_dependency 'uuid'
|
23
23
|
spec.add_dependency 'em-http-request'
|
24
24
|
spec.add_dependency 'rack-ssl-enforcer'
|
@@ -4,14 +4,14 @@ describe 'config server' do
|
|
4
4
|
|
5
5
|
let(:config) do
|
6
6
|
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
proxies: [
|
8
|
+
{
|
9
|
+
sitehub_cookie_name: 'custom_name',
|
10
|
+
sitehub_cookie_path: '/custom/path',
|
11
|
+
path: '%r{/regex(.*)}',
|
12
|
+
default: DOWNSTREAM_URL
|
13
|
+
}
|
14
|
+
]
|
15
15
|
}
|
16
16
|
end
|
17
17
|
|
@@ -24,7 +24,7 @@ describe 'config server' do
|
|
24
24
|
|
25
25
|
let(:app) do
|
26
26
|
sitehub = sitehub do
|
27
|
-
config_server(CONFIG_SERVER_URL, caching_options: {expires_in: 1})
|
27
|
+
config_server(CONFIG_SERVER_URL, caching_options: { expires_in: 1 })
|
28
28
|
end
|
29
29
|
|
30
30
|
Async::Middleware.new(sitehub)
|
@@ -5,46 +5,42 @@ class SiteHub
|
|
5
5
|
include_context :sitehub_json
|
6
6
|
|
7
7
|
let(:described_class) { CandidateRoutes }
|
8
|
+
subject { described_class.from_hash(proxy_config, :top_level_cookie_name, :top_level_cookie_path) }
|
8
9
|
|
9
10
|
context 'cookie configuration' do
|
10
|
-
|
11
|
-
subject do
|
12
|
-
described_class.from_hash(proxy_config_hash, :top_level_cookie_name, :top_level_cookie_path)
|
13
|
-
end
|
14
|
-
|
15
11
|
let(:cookie_name) { 'custom_name' }
|
16
12
|
let(:cookie_path) { 'custom_path' }
|
17
13
|
|
18
14
|
context 'no config defined on proxy' do
|
19
|
-
|
20
|
-
let(:proxy_config_hash) do
|
15
|
+
let(:proxy_config) do
|
21
16
|
{
|
22
|
-
|
23
|
-
|
17
|
+
path: '/',
|
18
|
+
default: 'url'
|
24
19
|
}
|
25
20
|
end
|
26
21
|
|
27
22
|
it 'uses the config passed in to the method' do
|
28
|
-
|
29
|
-
|
23
|
+
expect(subject.default_route.sitehub_cookie_name).to eq(:top_level_cookie_name)
|
24
|
+
expect(subject.default_route.sitehub_cookie_path).to eq(:top_level_cookie_path)
|
30
25
|
end
|
31
26
|
end
|
32
|
-
context 'defined on proxy' do
|
33
27
|
|
34
|
-
|
28
|
+
context 'defined on proxy' do
|
29
|
+
let(:proxy_config) do
|
35
30
|
{
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
path: '/',
|
32
|
+
sitehub_cookie_name: cookie_name,
|
33
|
+
sitehub_cookie_path: cookie_path,
|
34
|
+
default: 'url'
|
40
35
|
}
|
41
36
|
end
|
37
|
+
|
42
38
|
it 'uses the configuration' do
|
43
39
|
expect(subject.default_route.sitehub_cookie_name).to eq(cookie_name)
|
44
40
|
expect(subject.default_route.sitehub_cookie_path).to eq(cookie_path)
|
45
41
|
end
|
46
42
|
|
47
|
-
#TODO - support cookie config within split
|
43
|
+
# TODO: - support cookie config within split
|
48
44
|
# context 'config defined on split' do
|
49
45
|
# let(:proxy_config_hash) do
|
50
46
|
# {
|
@@ -65,22 +61,19 @@ class SiteHub
|
|
65
61
|
# end
|
66
62
|
end
|
67
63
|
|
68
|
-
#TODO - support cookie config within split
|
64
|
+
# TODO: - support cookie config within split
|
69
65
|
context 'defined on route' do
|
70
66
|
it 'uses the configuration' do
|
71
|
-
|
72
67
|
end
|
73
68
|
end
|
74
69
|
end
|
75
70
|
|
76
|
-
|
77
71
|
context 'splits' do
|
78
|
-
|
79
|
-
|
80
|
-
end
|
72
|
+
let(:proxy_config) { split_proxy }
|
73
|
+
|
81
74
|
context 'sitehub_cookie_name' do
|
82
75
|
it 'sets it' do
|
83
|
-
expect(subject.sitehub_cookie_name).to eq(:
|
76
|
+
expect(subject.sitehub_cookie_name).to eq(:top_level_cookie_name)
|
84
77
|
end
|
85
78
|
end
|
86
79
|
|
@@ -93,8 +86,7 @@ class SiteHub
|
|
93
86
|
it 'returns core with splits' do
|
94
87
|
split_1 = split_1()
|
95
88
|
split_2 = split_2()
|
96
|
-
expected = described_class.new(
|
97
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
89
|
+
expected = described_class.new(version_cookie: TrackingCookieDefinition.new(:top_level_cookie_name, subject.sitehub_cookie_path),
|
98
90
|
mapped_path: subject.mapped_path) do
|
99
91
|
split percentage: split_1[:percentage], label: split_1[:label], url: split_1[:url]
|
100
92
|
split percentage: split_2[:percentage], label: split_2[:label], url: split_2[:url]
|
@@ -110,12 +102,11 @@ class SiteHub
|
|
110
102
|
end
|
111
103
|
|
112
104
|
context 'routes' do
|
113
|
-
|
114
|
-
|
115
|
-
end
|
105
|
+
let(:proxy_config) { routes_proxy }
|
106
|
+
|
116
107
|
context 'sitehub_cookie_name' do
|
117
108
|
it 'sets it' do
|
118
|
-
expect(subject.sitehub_cookie_name).to eq(:
|
109
|
+
expect(subject.sitehub_cookie_name).to eq(:top_level_cookie_name)
|
119
110
|
end
|
120
111
|
end
|
121
112
|
|
@@ -127,8 +118,7 @@ class SiteHub
|
|
127
118
|
|
128
119
|
it 'returns core with routes' do
|
129
120
|
route_1 = route_1()
|
130
|
-
expected = described_class.new(
|
131
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
121
|
+
expected = described_class.new(version_cookie: TrackingCookieDefinition.new(:top_level_cookie_name, subject.sitehub_cookie_path),
|
132
122
|
mapped_path: subject.mapped_path) do
|
133
123
|
route label: route_1[:label], url: route_1[:url]
|
134
124
|
end
|
@@ -144,16 +134,12 @@ class SiteHub
|
|
144
134
|
|
145
135
|
context 'nested routes' do
|
146
136
|
context 'routes inside a split' do
|
147
|
-
|
148
|
-
described_class.from_hash(nested_route_proxy, :expected, :top_level_cookie_path)
|
149
|
-
end
|
150
|
-
|
137
|
+
let(:proxy_config) { nested_route_proxy }
|
151
138
|
it 'creates them' do
|
152
139
|
route_1 = route_1()
|
153
140
|
nested_route = nested_route()
|
154
141
|
|
155
|
-
expected = described_class.new(
|
156
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
142
|
+
expected = described_class.new(version_cookie: TrackingCookieDefinition.new(:top_level_cookie_name, subject.sitehub_cookie_path),
|
157
143
|
mapped_path: subject.mapped_path) do
|
158
144
|
split(percentage: nested_route[:percentage], label: nested_route[:label]) do
|
159
145
|
route label: route_1[:label], url: route_1[:url]
|
@@ -164,17 +150,14 @@ class SiteHub
|
|
164
150
|
end
|
165
151
|
|
166
152
|
context 'splits in a split' do
|
167
|
-
|
168
|
-
described_class.from_hash(nested_split_proxy, :expected, :top_level_cookie_path)
|
169
|
-
end
|
153
|
+
let(:proxy_config) { nested_split_proxy }
|
170
154
|
|
171
155
|
it 'creates them' do
|
172
156
|
split_1 = split_1()
|
173
157
|
split_2 = split_2()
|
174
158
|
nested_split = nested_split()
|
175
159
|
|
176
|
-
expected = described_class.new(
|
177
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
160
|
+
expected = described_class.new(version_cookie: TrackingCookieDefinition.new(:top_level_cookie_name, subject.sitehub_cookie_path),
|
178
161
|
mapped_path: subject.mapped_path) do
|
179
162
|
split(percentage: nested_split[:percentage], label: nested_split[:label]) do
|
180
163
|
split percentage: split_1[:percentage], label: split_1[:label], url: split_1[:url]
|
@@ -187,11 +170,23 @@ class SiteHub
|
|
187
170
|
end
|
188
171
|
|
189
172
|
context 'default' do
|
190
|
-
|
191
|
-
|
173
|
+
let(:default_url) { 'url' }
|
174
|
+
let(:proxy_config_default) do
|
175
|
+
{
|
176
|
+
path: '/',
|
177
|
+
default: default_url
|
178
|
+
}
|
179
|
+
end
|
180
|
+
|
181
|
+
subject do
|
182
|
+
described_class.from_hash(proxy_config_default, :expected, :top_level_cookie_path)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'sets the default url' do
|
186
|
+
expect(subject.default_route.app.mapped_url).to eq(default_url)
|
192
187
|
end
|
193
188
|
end
|
194
189
|
end
|
195
190
|
end
|
196
191
|
end
|
197
|
-
end
|
192
|
+
end
|
@@ -5,9 +5,8 @@ class SiteHub
|
|
5
5
|
describe CandidateRoutes do
|
6
6
|
include_context :middleware_test
|
7
7
|
|
8
|
-
|
9
8
|
subject do
|
10
|
-
described_class.new(
|
9
|
+
described_class.new(version_cookie: TrackingCookieDefinition.new(:cookie_name),
|
11
10
|
mapped_path: '/path')
|
12
11
|
end
|
13
12
|
|
@@ -17,16 +16,15 @@ class SiteHub
|
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'returns the same intance everytime' do
|
20
|
-
collection = Collection::SplitRouteCollection
|
21
|
-
subject.candidates(collection)
|
19
|
+
collection = subject.candidates(Collection::SplitRouteCollection)
|
22
20
|
expect(subject.candidates).to be(collection)
|
23
21
|
end
|
24
22
|
|
25
23
|
context 'endpoints already set' do
|
26
24
|
context 'different object supplied' do
|
27
25
|
it 'raises an error' do
|
28
|
-
subject.candidates(Collection::SplitRouteCollection
|
29
|
-
expect { subject.candidates(Collection::RouteCollection
|
26
|
+
subject.candidates(Collection::SplitRouteCollection)
|
27
|
+
expect { subject.candidates(Collection::RouteCollection) }
|
30
28
|
.to raise_error(CandidateRoutes::InvalidDefinitionError)
|
31
29
|
end
|
32
30
|
end
|
@@ -48,7 +46,7 @@ class SiteHub
|
|
48
46
|
|
49
47
|
describe '#initialize' do
|
50
48
|
let(:named_parameters) do
|
51
|
-
{
|
49
|
+
{ version_cookie: TrackingCookieDefinition.new(:name),
|
52
50
|
mapped_path: '/path' }
|
53
51
|
end
|
54
52
|
|
@@ -83,7 +81,7 @@ class SiteHub
|
|
83
81
|
format(described_class::INVALID_PATH_MATCHER, '*', e.message)
|
84
82
|
end
|
85
83
|
|
86
|
-
expect { described_class.new(
|
84
|
+
expect { described_class.new(version_cookie: TrackingCookieDefinition.new(:cookie_name), mapped_path: '%r{*}') }
|
87
85
|
.to raise_error(described_class::InvalidPathMatcherError, expected_message)
|
88
86
|
end
|
89
87
|
end
|
@@ -161,7 +159,7 @@ class SiteHub
|
|
161
159
|
end
|
162
160
|
|
163
161
|
it 'accepts a percentage' do
|
164
|
-
subject.candidates(Collection::SplitRouteCollection
|
162
|
+
subject.candidates(Collection::SplitRouteCollection)
|
165
163
|
endpoint = subject.add url: :url, label: :current, percentage: 50
|
166
164
|
expect(endpoint.upper).to eq(50)
|
167
165
|
end
|
@@ -182,7 +180,7 @@ class SiteHub
|
|
182
180
|
|
183
181
|
expected_endpoints = CandidateRoutes.new(rule: rule,
|
184
182
|
id: :label1,
|
185
|
-
|
183
|
+
version_cookie: TrackingCookieDefinition.new(:cookie_name),
|
186
184
|
mapped_path: '/path',
|
187
185
|
&block).build
|
188
186
|
|
@@ -194,7 +192,7 @@ class SiteHub
|
|
194
192
|
context 'precentage and rule not supplied' do
|
195
193
|
context 'split required' do
|
196
194
|
it 'raise an error' do
|
197
|
-
subject.candidates(Collection::SplitRouteCollection
|
195
|
+
subject.candidates(Collection::SplitRouteCollection)
|
198
196
|
expected_message = described_class::PERCENTAGE_NOT_SPECIFIED_MSG
|
199
197
|
expect { subject.add(label: :label) {} }
|
200
198
|
.to raise_exception described_class::InvalidDefinitionError, expected_message
|
@@ -203,7 +201,7 @@ class SiteHub
|
|
203
201
|
|
204
202
|
context 'route required' do
|
205
203
|
it 'raise an error' do
|
206
|
-
subject.candidates(Collection::RouteCollection
|
204
|
+
subject.candidates(Collection::RouteCollection)
|
207
205
|
expected_message = described_class::RULE_NOT_SPECIFIED_MSG
|
208
206
|
expect { subject.add(label: :label) {} }
|
209
207
|
.to raise_exception described_class::InvalidDefinitionError, expected_message
|
@@ -224,7 +222,7 @@ class SiteHub
|
|
224
222
|
subject.add(rule: rule, label: :label, &block)
|
225
223
|
|
226
224
|
expected_endpoints = described_class.new(id: :label,
|
227
|
-
|
225
|
+
version_cookie: TrackingCookieDefinition.new(:cookie_name),
|
228
226
|
rule: rule,
|
229
227
|
mapped_path: subject.mapped_path,
|
230
228
|
&block).tap do |builder|
|
@@ -354,23 +352,23 @@ class SiteHub
|
|
354
352
|
|
355
353
|
context '#endpoints' do
|
356
354
|
context 'called with a collection' do
|
357
|
-
it 'sets endpoints to
|
358
|
-
subject.candidates(
|
359
|
-
expect(subject.candidates).to
|
355
|
+
it 'sets endpoints to a collection of that type' do
|
356
|
+
subject.candidates(Hash)
|
357
|
+
expect(subject.candidates).to be_a(Hash)
|
360
358
|
end
|
361
359
|
end
|
362
360
|
|
363
361
|
context 'already set with a different collection' do
|
364
362
|
it 'raise an error' do
|
365
|
-
subject.candidates(
|
366
|
-
expect { subject.candidates(
|
363
|
+
subject.candidates(Hash)
|
364
|
+
expect { subject.candidates(Array) }.to raise_exception described_class::InvalidDefinitionError
|
367
365
|
end
|
368
366
|
end
|
369
367
|
end
|
370
368
|
|
371
369
|
describe '#forward_proxy' do
|
372
370
|
subject do
|
373
|
-
described_class.new(
|
371
|
+
described_class.new(version_cookie: TrackingCookieDefinition.new(:cookie_name),
|
374
372
|
mapped_path: '/path')
|
375
373
|
end
|
376
374
|
|
data/spec/sitehub/core_spec.rb
CHANGED
@@ -45,7 +45,6 @@ class SiteHub
|
|
45
45
|
expect(core.mappings['/route_1'].sitehub_cookie_path).to eq(sitehub_json[:sitehub_cookie_path])
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
48
|
end
|
50
49
|
|
51
50
|
context 'reverse_proxies' do
|
@@ -84,7 +83,7 @@ class SiteHub
|
|
84
83
|
|
85
84
|
describe '#proxy' do
|
86
85
|
let(:expected_route) do
|
87
|
-
CandidateRoutes.new(
|
86
|
+
CandidateRoutes.new(version_cookie: TrackingCookieDefinition.new(RECORDED_ROUTES_COOKIE),
|
88
87
|
mapped_path: '/app')
|
89
88
|
end
|
90
89
|
|
@@ -19,25 +19,28 @@ class SiteHub
|
|
19
19
|
end.init
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
22
|
+
shared_examples 'getter setter' do |default: nil|
|
23
|
+
let(:method_name) { self.class.parent_groups[1].description.delete('#') }
|
24
|
+
if default
|
25
|
+
it 'defaults' do
|
26
|
+
expect(subject.public_send(method_name)).to eq(default)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'can be set' do
|
31
|
+
custom_value = 'value'
|
32
|
+
subject.public_send(method_name, custom_value)
|
33
|
+
expect(subject.public_send(method_name)).to eq(custom_value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#sitehub_cookie_path' do
|
38
|
+
it_behaves_like 'getter setter', default: RECORDED_ROUTES_COOKIE_PATH
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#sitehub_cookie_name' do
|
42
|
+
it_behaves_like 'getter setter', default: RECORDED_ROUTES_COOKIE
|
43
|
+
end
|
41
44
|
|
42
45
|
describe '#add_route' do
|
43
46
|
def route(app, id:)
|
@@ -50,7 +53,7 @@ class SiteHub
|
|
50
53
|
context 'candidate_routes as parameter' do
|
51
54
|
it 'sets it' do
|
52
55
|
another_mapping = '/mapping'
|
53
|
-
candidate_routes = CandidateRoutes.new(
|
56
|
+
candidate_routes = CandidateRoutes.new(version_cookie: TrackingCookieDefinition.new(:sitehub_cookie_name), mapped_path: another_mapping)
|
54
57
|
subject.add_route candidate_routes: candidate_routes
|
55
58
|
expect(subject[another_mapping]).to be(candidate_routes)
|
56
59
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitehub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0.
|
4
|
+
version: 0.5.0.alpha12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ladtech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.6.8
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.6.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: uuid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -448,10 +448,10 @@ files:
|
|
448
448
|
- spec/support/shared_contexts/module_spec_context.rb
|
449
449
|
- spec/support/shared_contexts/rack_request_context.rb
|
450
450
|
- spec/support/shared_contexts/rack_test_context.rb
|
451
|
+
- spec/support/shared_contexts/sitehub_json_context.rb
|
451
452
|
- spec/support/shared_examples.rb
|
452
453
|
- spec/support/shared_examples/memoized_helpers.rb
|
453
454
|
- spec/support/shared_examples/prohibited_http_header_filter.rb
|
454
|
-
- spec/support/shared_examples/sitehub_json_context.rb
|
455
455
|
- spec/support/silent_warnings.rb
|
456
456
|
- tasks/code_quality.rake
|
457
457
|
- tasks/gem_tasks.rake
|