sitehub 0.5.0.alpha10 → 0.5.0.alpha11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/circle.yml +1 -1
- data/lib/sitehub/candidate_routes.rb +26 -29
- data/lib/sitehub/candidate_routes/from_json.rb +55 -0
- data/lib/sitehub/config_server.rb +1 -0
- data/lib/sitehub/constants.rb +1 -0
- data/lib/sitehub/core.rb +3 -1
- data/lib/sitehub/middleware/candidate_route_mappings.rb +7 -6
- data/lib/sitehub/version.rb +1 -1
- data/spec/integration/config_server_spec.rb +19 -7
- data/spec/sitehub/candidate_routes/from_json_spec.rb +197 -0
- data/spec/sitehub/candidate_routes_spec.rb +0 -148
- data/spec/sitehub/core_spec.rb +12 -6
- data/spec/sitehub/middleware/candidate_route_mappings_spec.rb +23 -8
- metadata +4 -3
- data/lib/sitehub/candidate_routes/class_methods.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 673473acf603cd4bb059ba39942acd23c298805a
|
4
|
+
data.tar.gz: d0ac444795bfd73878698d243f16718045b86e15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79508cdd923756cea548c2c62fd7f94ff27046d30961dfe81c30e0f401037939ab83539a8ac44e6720a5c6e31b767675426bf7292781b9d793867ee651bb4776
|
7
|
+
data.tar.gz: 768aef4bbde59e3378a98197f01e37ad901314375359dbeb324c60b53de91bf263414037f72027c909910f827856b89b116be3050efe0b3474cba4a69ef92625
|
data/Gemfile.lock
CHANGED
data/circle.yml
CHANGED
@@ -3,7 +3,7 @@ require 'sitehub/equality'
|
|
3
3
|
require 'sitehub/nil_route'
|
4
4
|
require 'sitehub/identifier'
|
5
5
|
require 'sitehub/getter_setter_methods'
|
6
|
-
require 'sitehub/candidate_routes/
|
6
|
+
require 'sitehub/candidate_routes/from_json'
|
7
7
|
|
8
8
|
require_relative 'collection/split_route_collection'
|
9
9
|
require_relative 'rules'
|
@@ -29,14 +29,11 @@ class SiteHub
|
|
29
29
|
IGNORING_URL_MSG = 'Block supplied, ignoring URL parameter'.freeze
|
30
30
|
URL_REQUIRED_MSG = 'URL must be supplied for splits and routes'.freeze
|
31
31
|
|
32
|
-
extend CollectionMethods,
|
33
|
-
include Rules, Equality, Middleware
|
32
|
+
extend CollectionMethods, FromJson, GetterSetterMethods
|
33
|
+
include Rules, Equality, Middleware, CollectionMethods
|
34
34
|
|
35
35
|
getter_setters :sitehub_cookie_path, :sitehub_cookie_name
|
36
|
-
attr_reader :id, :
|
37
|
-
attr_accessor :mapped_path
|
38
|
-
|
39
|
-
transient :calling_scope
|
36
|
+
attr_reader :id, :mapped_path
|
40
37
|
|
41
38
|
def add(label:, rule: nil, percentage: nil, url: nil, &block)
|
42
39
|
child_label = id.child_label(label)
|
@@ -88,30 +85,20 @@ class SiteHub
|
|
88
85
|
end
|
89
86
|
end
|
90
87
|
|
91
|
-
|
88
|
+
# TODO: combine cookie name and path in to an : nobject
|
89
|
+
def initialize(id: nil, sitehub_cookie_name:, sitehub_cookie_path: nil, mapped_path:, rule: nil, &block)
|
92
90
|
@id = Identifier.new(id)
|
93
|
-
@calling_scope = calling_scope
|
94
91
|
|
95
|
-
mapped_path =
|
96
|
-
@mapped_path = mapped_path
|
92
|
+
@mapped_path = sanitise_mapped_path(mapped_path)
|
97
93
|
@sitehub_cookie_name = sitehub_cookie_name
|
98
94
|
@sitehub_cookie_path = sitehub_cookie_path
|
99
|
-
@splits = Collection::SplitRouteCollection.new
|
100
|
-
@routes = Collection::RouteCollection.new
|
101
|
-
rule(rule)
|
102
95
|
|
103
|
-
|
96
|
+
rule(rule)
|
104
97
|
|
105
|
-
|
106
|
-
raise InvalidDefinitionError unless valid?
|
98
|
+
init(&block) if block_given?
|
107
99
|
end
|
108
100
|
|
109
|
-
|
110
|
-
super unless calling_scope
|
111
|
-
calling_scope.send(method, *args, &block)
|
112
|
-
rescue NoMethodError
|
113
|
-
super
|
114
|
-
end
|
101
|
+
|
115
102
|
|
116
103
|
def resolve(id: nil, env:)
|
117
104
|
id = Identifier.new(id)
|
@@ -123,19 +110,17 @@ class SiteHub
|
|
123
110
|
end
|
124
111
|
|
125
112
|
def route(url: nil, label:, rule: nil, &block)
|
113
|
+
@routes ||= Collection::RouteCollection.new
|
126
114
|
candidates(@routes)
|
127
115
|
add(label: label, rule: rule, url: url, &block)
|
128
116
|
end
|
129
117
|
|
130
118
|
def split(percentage:, url: nil, label:, &block)
|
119
|
+
@splits ||= Collection::SplitRouteCollection.new
|
131
120
|
candidates(@splits)
|
132
121
|
add(label: label, percentage: percentage, url: url, &block)
|
133
122
|
end
|
134
123
|
|
135
|
-
def splits?
|
136
|
-
candidates.is_a?(Collection::SplitRouteCollection)
|
137
|
-
end
|
138
|
-
|
139
124
|
def valid?
|
140
125
|
return true if default_route?
|
141
126
|
candidates.valid?
|
@@ -181,6 +166,11 @@ class SiteHub
|
|
181
166
|
splits? ? PERCENTAGE_NOT_SPECIFIED_MSG : RULE_NOT_SPECIFIED_MSG
|
182
167
|
end
|
183
168
|
|
169
|
+
def init(&block)
|
170
|
+
instance_eval(&block)
|
171
|
+
raise InvalidDefinitionError unless valid?
|
172
|
+
end
|
173
|
+
|
184
174
|
def new(id:, rule: nil, &block)
|
185
175
|
inherited_middleware = middlewares
|
186
176
|
|
@@ -188,11 +178,18 @@ class SiteHub
|
|
188
178
|
sitehub_cookie_name: sitehub_cookie_name,
|
189
179
|
sitehub_cookie_path: sitehub_cookie_path,
|
190
180
|
mapped_path: mapped_path,
|
191
|
-
rule: rule
|
192
|
-
calling_scope: calling_scope) do
|
181
|
+
rule: rule) do
|
193
182
|
middlewares.concat(inherited_middleware)
|
194
183
|
instance_eval(&block)
|
195
184
|
end
|
196
185
|
end
|
186
|
+
|
187
|
+
def sanitise_mapped_path(mapped_path)
|
188
|
+
string_containing_regexp?(mapped_path) ? string_to_regexp(mapped_path) : mapped_path
|
189
|
+
end
|
190
|
+
|
191
|
+
def splits?
|
192
|
+
candidates.is_a?(Collection::SplitRouteCollection)
|
193
|
+
end
|
197
194
|
end
|
198
195
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class SiteHub
|
2
|
+
class CandidateRoutes
|
3
|
+
|
4
|
+
module FromJson
|
5
|
+
extend CollectionMethods
|
6
|
+
|
7
|
+
def self.extended clazz
|
8
|
+
clazz.class_eval do
|
9
|
+
include InstanceMethods
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: support nested routes, i.e. support rule name being passed in
|
14
|
+
def from_hash(hash, sitehub_cookie_name, sitehub_cookie_path)
|
15
|
+
cookie_path = hash[:sitehub_cookie_path] || sitehub_cookie_path
|
16
|
+
cookie_name = hash[:sitehub_cookie_name] || sitehub_cookie_name
|
17
|
+
new(sitehub_cookie_name: cookie_name,
|
18
|
+
sitehub_cookie_path: cookie_path,
|
19
|
+
mapped_path: hash[:path]) do
|
20
|
+
handle_routes(hash, self)
|
21
|
+
default url: hash[:default] if hash[:default]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module InstanceMethods
|
26
|
+
private
|
27
|
+
def handle_routes(hash, routes)
|
28
|
+
extract_splits(hash, routes)
|
29
|
+
extract_routes(hash, routes)
|
30
|
+
end
|
31
|
+
|
32
|
+
def extract_routes(hash, routes)
|
33
|
+
collection(hash, :routes).each do |route|
|
34
|
+
routes.route(url: route[:url], label: route[:label])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def extract_splits(hash, routes)
|
39
|
+
collection(hash, :splits).each do |split|
|
40
|
+
label = split[:label]
|
41
|
+
percentage = split[:percentage]
|
42
|
+
cookie_name = split[:sitehub_cookie_name] || sitehub_cookie_name
|
43
|
+
|
44
|
+
if split[:splits] || split[:routes]
|
45
|
+
routes.split(percentage: percentage, label: label) { handle_routes(split, self) }
|
46
|
+
else
|
47
|
+
routes.split(percentage: percentage, label: label, url: split[:url])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/sitehub/constants.rb
CHANGED
@@ -7,6 +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
|
+
RECORDED_ROUTE_COOKIE_PATH = '/'.freeze
|
10
11
|
ERRORS = 'sitehub.errors'.freeze
|
11
12
|
TIME_STAMP_FORMAT = '%d/%b/%Y:%H:%M:%S %z'.freeze
|
12
13
|
EMPTY_STRING = ''.freeze
|
data/lib/sitehub/core.rb
CHANGED
@@ -16,9 +16,10 @@ class SiteHub
|
|
16
16
|
new do
|
17
17
|
extend CollectionMethods
|
18
18
|
sitehub_cookie_name config[:sitehub_cookie_name] if config[:sitehub_cookie_name]
|
19
|
+
sitehub_cookie_path config[:sitehub_cookie_path] if config[:sitehub_cookie_path]
|
19
20
|
|
20
21
|
collection!(config, :proxies).each do |proxy|
|
21
|
-
mappings.add_route
|
22
|
+
mappings.add_route candidate_routes: CandidateRoutes.from_hash(proxy, sitehub_cookie_name, sitehub_cookie_path )
|
22
23
|
end
|
23
24
|
|
24
25
|
collection(config, :reverse_proxies).each do |proxy|
|
@@ -33,6 +34,7 @@ class SiteHub
|
|
33
34
|
|
34
35
|
attr_reader :mappings, :reverse_proxies
|
35
36
|
def_delegator :mappings, :sitehub_cookie_name
|
37
|
+
def_delegator :mappings, :sitehub_cookie_path
|
36
38
|
|
37
39
|
def initialize(&block)
|
38
40
|
@reverse_proxies = {}
|
@@ -14,6 +14,7 @@ class SiteHub
|
|
14
14
|
include Equality
|
15
15
|
|
16
16
|
extend GetterSetterMethods
|
17
|
+
getter_setter :sitehub_cookie_path, RECORDED_ROUTE_COOKIE_PATH
|
17
18
|
getter_setter :sitehub_cookie_name, RECORDED_ROUTES_COOKIE
|
18
19
|
|
19
20
|
def initialize
|
@@ -33,16 +34,16 @@ class SiteHub
|
|
33
34
|
self
|
34
35
|
end
|
35
36
|
|
36
|
-
def add_route(url: nil, mapped_path: nil,
|
37
|
-
unless
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def add_route(url: nil, mapped_path: nil, candidate_routes: nil, &block)
|
38
|
+
unless candidate_routes
|
39
|
+
candidate_routes = CandidateRoutes.new(sitehub_cookie_name: sitehub_cookie_name,
|
40
|
+
mapped_path: mapped_path,
|
41
|
+
&block).tap do |builder|
|
41
42
|
builder.default(url: url) if url
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
self[
|
46
|
+
self[candidate_routes.mapped_path] = candidate_routes
|
46
47
|
end
|
47
48
|
|
48
49
|
def mapped_route(path:, request:)
|
data/lib/sitehub/version.rb
CHANGED
@@ -3,12 +3,16 @@ describe 'config server' do
|
|
3
3
|
include_context :sitehub_json
|
4
4
|
|
5
5
|
let(:config) do
|
6
|
-
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
{
|
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
|
+
}
|
12
16
|
end
|
13
17
|
|
14
18
|
let(:downstream_response) { 'downstream response' }
|
@@ -20,12 +24,20 @@ describe 'config server' do
|
|
20
24
|
|
21
25
|
let(:app) do
|
22
26
|
sitehub = sitehub do
|
23
|
-
config_server(CONFIG_SERVER_URL, caching_options: {
|
27
|
+
config_server(CONFIG_SERVER_URL, caching_options: {expires_in: 1})
|
24
28
|
end
|
25
29
|
|
26
30
|
Async::Middleware.new(sitehub)
|
27
31
|
end
|
28
32
|
|
33
|
+
context 'from_json' do
|
34
|
+
it 'reads cookie path from config' do
|
35
|
+
get('/regex123')
|
36
|
+
|
37
|
+
expect(app.last_response.cookies['custom_name'][:path]).to eq('/custom/path')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
29
41
|
it 'path as regex' do
|
30
42
|
get('/regex123')
|
31
43
|
|
@@ -0,0 +1,197 @@
|
|
1
|
+
class SiteHub
|
2
|
+
class CandidateRoutes
|
3
|
+
describe FromJson do
|
4
|
+
describe '::from_hash' do
|
5
|
+
include_context :sitehub_json
|
6
|
+
|
7
|
+
let(:described_class) { CandidateRoutes }
|
8
|
+
|
9
|
+
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
|
+
let(:cookie_name) { 'custom_name' }
|
16
|
+
let(:cookie_path) { 'custom_path' }
|
17
|
+
|
18
|
+
context 'no config defined on proxy' do
|
19
|
+
|
20
|
+
let(:proxy_config_hash) do
|
21
|
+
{
|
22
|
+
path: '/',
|
23
|
+
default: 'url'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'uses the config passed in to the method' do
|
28
|
+
expect(subject.default_route.sitehub_cookie_name).to eq(:top_level_cookie_name)
|
29
|
+
expect(subject.default_route.sitehub_cookie_path).to eq(:top_level_cookie_path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context 'defined on proxy' do
|
33
|
+
|
34
|
+
let(:proxy_config_hash) do
|
35
|
+
{
|
36
|
+
path: '/',
|
37
|
+
sitehub_cookie_name: cookie_name,
|
38
|
+
sitehub_cookie_path: cookie_path,
|
39
|
+
default: 'url'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
it 'uses the configuration' do
|
43
|
+
expect(subject.default_route.sitehub_cookie_name).to eq(cookie_name)
|
44
|
+
expect(subject.default_route.sitehub_cookie_path).to eq(cookie_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
#TODO - support cookie config within split
|
48
|
+
# context 'config defined on split' do
|
49
|
+
# let(:proxy_config_hash) do
|
50
|
+
# {
|
51
|
+
# path: '/',
|
52
|
+
# splits: [
|
53
|
+
# {sitehub_cookie_path: cookie_path,
|
54
|
+
# sitehub_cookie_name: cookie_name,
|
55
|
+
# percentage: 100,
|
56
|
+
# url: 'url',
|
57
|
+
# label: 'route_label'}
|
58
|
+
# ]
|
59
|
+
# }
|
60
|
+
# end
|
61
|
+
# it 'is overidden by the config on the route' do
|
62
|
+
# expect(subject.sitehub_cookie_name).to eq(cookie_name)
|
63
|
+
# expect(subject.sitehub_cookie_path).to eq(cookie_path)
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
end
|
67
|
+
|
68
|
+
#TODO - support cookie config within split
|
69
|
+
context 'defined on route' do
|
70
|
+
it 'uses the configuration' do
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
context 'splits' do
|
78
|
+
subject do
|
79
|
+
described_class.from_hash(split_proxy, :expected, :top_level_cookie_path)
|
80
|
+
end
|
81
|
+
context 'sitehub_cookie_name' do
|
82
|
+
it 'sets it' do
|
83
|
+
expect(subject.sitehub_cookie_name).to eq(:expected)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'sitehub_cookie_path' do
|
88
|
+
it 'sets it' do
|
89
|
+
expect(subject.sitehub_cookie_path).to eq(split_proxy[:sitehub_cookie_path])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns core with splits' do
|
94
|
+
split_1 = split_1()
|
95
|
+
split_2 = split_2()
|
96
|
+
expected = described_class.new(sitehub_cookie_name: :expected,
|
97
|
+
sitehub_cookie_path: subject.sitehub_cookie_path,
|
98
|
+
mapped_path: subject.mapped_path) do
|
99
|
+
split percentage: split_1[:percentage], label: split_1[:label], url: split_1[:url]
|
100
|
+
split percentage: split_2[:percentage], label: split_2[:label], url: split_2[:url]
|
101
|
+
end
|
102
|
+
expect(subject.candidates).to eq(expected.candidates)
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'default' do
|
106
|
+
it 'sets it' do
|
107
|
+
expect(subject.default_route.app.mapped_url).to eq(split_proxy[:default])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'routes' do
|
113
|
+
subject do
|
114
|
+
described_class.from_hash(routes_proxy, :expected, :top_level_cookie_path)
|
115
|
+
end
|
116
|
+
context 'sitehub_cookie_name' do
|
117
|
+
it 'sets it' do
|
118
|
+
expect(subject.sitehub_cookie_name).to eq(:expected)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'sitehub_cookie_path' do
|
123
|
+
it 'sets it' do
|
124
|
+
expect(subject.sitehub_cookie_path).to eq(routes_proxy[:sitehub_cookie_path])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'returns core with routes' do
|
129
|
+
route_1 = route_1()
|
130
|
+
expected = described_class.new(sitehub_cookie_name: :expected,
|
131
|
+
sitehub_cookie_path: subject.sitehub_cookie_path,
|
132
|
+
mapped_path: subject.mapped_path) do
|
133
|
+
route label: route_1[:label], url: route_1[:url]
|
134
|
+
end
|
135
|
+
expect(subject.candidates).to eq(expected.candidates)
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'default' do
|
139
|
+
it 'sets it' do
|
140
|
+
expect(subject.default_route.app.mapped_url).to eq(routes_proxy[:default])
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'nested routes' do
|
146
|
+
context 'routes inside a split' do
|
147
|
+
subject do
|
148
|
+
described_class.from_hash(nested_route_proxy, :expected, :top_level_cookie_path)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'creates them' do
|
152
|
+
route_1 = route_1()
|
153
|
+
nested_route = nested_route()
|
154
|
+
|
155
|
+
expected = described_class.new(sitehub_cookie_name: :expected,
|
156
|
+
sitehub_cookie_path: subject.sitehub_cookie_path,
|
157
|
+
mapped_path: subject.mapped_path) do
|
158
|
+
split(percentage: nested_route[:percentage], label: nested_route[:label]) do
|
159
|
+
route label: route_1[:label], url: route_1[:url]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
expect(subject).to eq(expected)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'splits in a split' do
|
167
|
+
subject do
|
168
|
+
described_class.from_hash(nested_split_proxy, :expected, :top_level_cookie_path)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'creates them' do
|
172
|
+
split_1 = split_1()
|
173
|
+
split_2 = split_2()
|
174
|
+
nested_split = nested_split()
|
175
|
+
|
176
|
+
expected = described_class.new(sitehub_cookie_name: :expected,
|
177
|
+
sitehub_cookie_path: subject.sitehub_cookie_path,
|
178
|
+
mapped_path: subject.mapped_path) do
|
179
|
+
split(percentage: nested_split[:percentage], label: nested_split[:label]) do
|
180
|
+
split percentage: split_1[:percentage], label: split_1[:label], url: split_1[:url]
|
181
|
+
split percentage: split_2[:percentage], label: split_2[:label], url: split_2[:url]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
expect(subject).to eq(expected)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'default' do
|
190
|
+
#TODO - implement me
|
191
|
+
it 'sets the default' do
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -5,126 +5,6 @@ class SiteHub
|
|
5
5
|
describe CandidateRoutes do
|
6
6
|
include_context :middleware_test
|
7
7
|
|
8
|
-
describe '::from_hash' do
|
9
|
-
include_context :sitehub_json
|
10
|
-
|
11
|
-
context 'splits' do
|
12
|
-
subject do
|
13
|
-
described_class.from_hash(split_proxy, :expected)
|
14
|
-
end
|
15
|
-
context 'sitehub_cookie_name' do
|
16
|
-
it 'sets it' do
|
17
|
-
expect(subject.sitehub_cookie_name).to eq(:expected)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'sitehub_cookie_path' do
|
22
|
-
it 'sets it' do
|
23
|
-
expect(subject.sitehub_cookie_path).to eq(split_proxy[:sitehub_cookie_path])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns core with splits' do
|
28
|
-
split_1 = split_1()
|
29
|
-
split_2 = split_2()
|
30
|
-
expected = described_class.new(sitehub_cookie_name: :expected,
|
31
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
32
|
-
mapped_path: subject.mapped_path) do
|
33
|
-
split percentage: split_1[:percentage], label: split_1[:label], url: split_1[:url]
|
34
|
-
split percentage: split_2[:percentage], label: split_2[:label], url: split_2[:url]
|
35
|
-
end
|
36
|
-
expect(subject.candidates).to eq(expected.candidates)
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'default' do
|
40
|
-
it 'sets it' do
|
41
|
-
expect(subject.default_route.app.mapped_url).to eq(split_proxy[:default])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'routes' do
|
47
|
-
subject do
|
48
|
-
described_class.from_hash(routes_proxy, :expected)
|
49
|
-
end
|
50
|
-
context 'sitehub_cookie_name' do
|
51
|
-
it 'sets it' do
|
52
|
-
expect(subject.sitehub_cookie_name).to eq(:expected)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'sitehub_cookie_path' do
|
57
|
-
it 'sets it' do
|
58
|
-
expect(subject.sitehub_cookie_path).to eq(routes_proxy[:sitehub_cookie_path])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns core with routes' do
|
63
|
-
route_1 = route_1()
|
64
|
-
expected = described_class.new(sitehub_cookie_name: :expected,
|
65
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
66
|
-
mapped_path: subject.mapped_path) do
|
67
|
-
route label: route_1[:label], url: route_1[:url]
|
68
|
-
end
|
69
|
-
expect(subject.candidates).to eq(expected.candidates)
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'default' do
|
73
|
-
it 'sets it' do
|
74
|
-
expect(subject.default_route.app.mapped_url).to eq(routes_proxy[:default])
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'nested routes' do
|
80
|
-
context 'routes inside a split' do
|
81
|
-
subject do
|
82
|
-
described_class.from_hash(nested_route_proxy, :expected)
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'creates them' do
|
86
|
-
route_1 = route_1()
|
87
|
-
nested_route = nested_route()
|
88
|
-
|
89
|
-
expected = described_class.new(sitehub_cookie_name: :expected,
|
90
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
91
|
-
mapped_path: subject.mapped_path) do
|
92
|
-
split(percentage: nested_route[:percentage], label: nested_route[:label]) do
|
93
|
-
route label: route_1[:label], url: route_1[:url]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
expect(subject).to eq(expected)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'splits in a split' do
|
101
|
-
subject do
|
102
|
-
described_class.from_hash(nested_split_proxy, :expected)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'creates them' do
|
106
|
-
split_1 = split_1()
|
107
|
-
split_2 = split_2()
|
108
|
-
nested_split = nested_split()
|
109
|
-
|
110
|
-
expected = described_class.new(sitehub_cookie_name: :expected,
|
111
|
-
sitehub_cookie_path: subject.sitehub_cookie_path,
|
112
|
-
mapped_path: subject.mapped_path) do
|
113
|
-
split(percentage: nested_split[:percentage], label: nested_split[:label]) do
|
114
|
-
split percentage: split_1[:percentage], label: split_1[:label], url: split_1[:url]
|
115
|
-
split percentage: split_2[:percentage], label: split_2[:label], url: split_2[:url]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
expect(subject).to eq(expected)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'default' do
|
124
|
-
it 'sets the default' do
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
8
|
|
129
9
|
subject do
|
130
10
|
described_class.new(sitehub_cookie_name: :cookie_name,
|
@@ -528,33 +408,5 @@ class SiteHub
|
|
528
408
|
end
|
529
409
|
end
|
530
410
|
end
|
531
|
-
|
532
|
-
describe '#method_missing' do
|
533
|
-
context 'calling scope set' do
|
534
|
-
subject do
|
535
|
-
calling_scope = double(:calling_scope, parent_method: :called)
|
536
|
-
described_class.new(sitehub_cookie_name: :cookie_name,
|
537
|
-
mapped_path: '/path',
|
538
|
-
calling_scope: calling_scope)
|
539
|
-
end
|
540
|
-
context 'method on calling_context' do
|
541
|
-
it 'delegates to it' do
|
542
|
-
expect(subject.parent_method).to eq(:called)
|
543
|
-
end
|
544
|
-
end
|
545
|
-
|
546
|
-
context 'method on calling_context' do
|
547
|
-
it 'delegates to it' do
|
548
|
-
expect(subject.parent_method).to eq(:called)
|
549
|
-
end
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
context 'calling scope not set' do
|
554
|
-
it 'raises an error' do
|
555
|
-
expect { subject.parent_method }.to raise_error(NoMethodError)
|
556
|
-
end
|
557
|
-
end
|
558
|
-
end
|
559
411
|
end
|
560
412
|
end
|
data/spec/sitehub/core_spec.rb
CHANGED
@@ -33,13 +33,19 @@ class SiteHub
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context '
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
context 'cookie configuration' do
|
37
|
+
context 'defined at top level' do
|
38
|
+
it 'sets it' do
|
39
|
+
sitehub_json[:sitehub_cookie_name] = 'custom_name'
|
40
|
+
sitehub_json[:sitehub_cookie_path] = 'custom_path'
|
41
|
+
sitehub_json[:proxies].first.delete(:sitehub_cookie_path)
|
42
|
+
|
43
|
+
expect(core.sitehub_cookie_name).to eq(expected.sitehub_cookie_name)
|
44
|
+
expect(core.mappings['/route_1'].sitehub_cookie_name).to eq(sitehub_json[:sitehub_cookie_name])
|
45
|
+
expect(core.mappings['/route_1'].sitehub_cookie_path).to eq(sitehub_json[:sitehub_cookie_path])
|
46
|
+
end
|
42
47
|
end
|
48
|
+
|
43
49
|
end
|
44
50
|
|
45
51
|
context 'reverse_proxies' do
|
@@ -4,7 +4,6 @@ class SiteHub
|
|
4
4
|
module Middleware
|
5
5
|
describe CandidateRouteMappings do
|
6
6
|
let(:base_url) { 'http://google.com' }
|
7
|
-
let(:mapped_path) { '/app' }
|
8
7
|
let(:mapped_path) { '/application_url' }
|
9
8
|
|
10
9
|
let(:forward_proxy_builder) do
|
@@ -20,9 +19,25 @@ class SiteHub
|
|
20
19
|
end.init
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
# describe 'sitehub_cookie_path' do
|
23
|
+
# pending 'defaults to CONSTANT' do
|
24
|
+
#
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# pending 'can be set' do
|
28
|
+
#
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# describe 'sitehub_cookie_name' do
|
33
|
+
# pending 'defaults to CONSTANT' do
|
34
|
+
#
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# pending 'can be set' do
|
38
|
+
#
|
39
|
+
# end
|
40
|
+
# end
|
26
41
|
|
27
42
|
describe '#add_route' do
|
28
43
|
def route(app, id:)
|
@@ -32,12 +47,12 @@ class SiteHub
|
|
32
47
|
sitehub_cookie_path: nil)
|
33
48
|
end
|
34
49
|
|
35
|
-
context '
|
50
|
+
context 'candidate_routes as parameter' do
|
36
51
|
it 'sets it' do
|
37
52
|
another_mapping = '/mapping'
|
38
|
-
|
39
|
-
subject.add_route
|
40
|
-
expect(subject[another_mapping]).to be(
|
53
|
+
candidate_routes = CandidateRoutes.new(sitehub_cookie_name: :sitehub_cookie_name, mapped_path: another_mapping)
|
54
|
+
subject.add_route candidate_routes: candidate_routes
|
55
|
+
expect(subject[another_mapping]).to be(candidate_routes)
|
41
56
|
end
|
42
57
|
end
|
43
58
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.alpha11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ladtech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -340,7 +340,7 @@ files:
|
|
340
340
|
- lib/sitehub.rb
|
341
341
|
- lib/sitehub/builder.rb
|
342
342
|
- lib/sitehub/candidate_routes.rb
|
343
|
-
- lib/sitehub/candidate_routes/
|
343
|
+
- lib/sitehub/candidate_routes/from_json.rb
|
344
344
|
- lib/sitehub/collection.rb
|
345
345
|
- lib/sitehub/collection/route_collection.rb
|
346
346
|
- lib/sitehub/collection/split_route_collection.rb
|
@@ -396,6 +396,7 @@ files:
|
|
396
396
|
- spec/integration/middleware_spec.rb
|
397
397
|
- spec/integration/version_affinity_spec.rb
|
398
398
|
- spec/sitehub/builder_spec.rb
|
399
|
+
- spec/sitehub/candidate_routes/from_json_spec.rb
|
399
400
|
- spec/sitehub/candidate_routes_spec.rb
|
400
401
|
- spec/sitehub/collection/route_collection_spec.rb
|
401
402
|
- spec/sitehub/collection/split_route_collection/split_spec.rb
|
@@ -1,42 +0,0 @@
|
|
1
|
-
class SiteHub
|
2
|
-
class CandidateRoutes
|
3
|
-
module ClassMethods
|
4
|
-
extend CollectionMethods
|
5
|
-
|
6
|
-
# TODO: support nested routes, i.e. support rule name being passed in
|
7
|
-
def from_hash(hash, sitehub_cookie_name)
|
8
|
-
new(sitehub_cookie_name: sitehub_cookie_name,
|
9
|
-
sitehub_cookie_path: hash[:sitehub_cookie_path],
|
10
|
-
mapped_path: hash[:path], calling_scope: self) do
|
11
|
-
handle_routes(hash, self)
|
12
|
-
default url: hash[:default] if hash[:default]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def handle_routes(hash, routes)
|
19
|
-
extract_splits(hash, routes)
|
20
|
-
extract_routes(hash, routes)
|
21
|
-
end
|
22
|
-
|
23
|
-
def extract_routes(hash, routes)
|
24
|
-
collection(hash, :routes).each do |route|
|
25
|
-
routes.route(url: route[:url], label: route[:label])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def extract_splits(hash, routes)
|
30
|
-
collection(hash, :splits).each do |split|
|
31
|
-
if split[:splits] || split[:routes]
|
32
|
-
routes.split(percentage: split[:percentage], label: split[:label]) do
|
33
|
-
handle_routes(split, self)
|
34
|
-
end
|
35
|
-
else
|
36
|
-
routes.split(percentage: split[:percentage], label: split[:label], url: split[:url])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|