sitehub 0.5.0.alpha5 → 0.5.0.alpha6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ require 'sitehub/cookie/rewriting'
2
+
3
+ class SiteHub
4
+ class Cookie
5
+ describe Rewriting do
6
+ include_context :module_spec
7
+
8
+ let(:downstream_domain) { '.downstream_domain.com' }
9
+
10
+ let(:request_mapping) do
11
+ RequestMapping.new(source_url: 'http://example.org',
12
+ mapped_url: "http://#{downstream_domain}",
13
+ mapped_path: '/map')
14
+ end
15
+
16
+ let(:substitute_domain) { URI(request_mapping.source_url).host }
17
+ let(:substitute_path) { '/path' }
18
+ let(:downstream_response) { Rack::Response.new }
19
+ let(:downstream_domain_cookie_name) { 'downstream.cookie' }
20
+
21
+ before do
22
+ downstream_response.set_cookie(downstream_domain_cookie_name, domain: downstream_domain, value: 'value')
23
+ downstream_response.set_cookie('downstream.cookie2', domain: downstream_domain, value: 'value2', httponly: true)
24
+ end
25
+
26
+ describe '#cookies_string_as_hash' do
27
+ it 'returns the string as a hash' do
28
+ cookie_header = downstream_response.headers['Set-Cookie']
29
+
30
+ cookie_strings = cookie_header.lines
31
+ first_cookie = SiteHub::Cookie.new(cookie_strings[0])
32
+ second_cookie = SiteHub::Cookie.new(cookie_strings[1])
33
+ expected = {
34
+ first_cookie.name => first_cookie,
35
+ second_cookie.name => second_cookie
36
+ }
37
+ result = subject.cookies_string_as_hash(cookie_header)
38
+ expect(result).to eq(expected)
39
+ end
40
+ end
41
+
42
+ describe '#cookies_hash_to_string' do
43
+ it 'returns the hash as a correctly formatted string' do
44
+ cookies_hash = subject.cookies_string_as_hash(downstream_response.headers['Set-Cookie'])
45
+ expect(subject.cookies_hash_to_string(cookies_hash)).to eq(downstream_response.headers['Set-Cookie'])
46
+ end
47
+ end
48
+
49
+ describe '#rewrite_cookies' do
50
+ context 'subdomain character present' do
51
+ it 'substitues the domain for the mapped domain' do
52
+ downstream_response.set_cookie(downstream_domain_cookie_name, domain: downstream_domain, value: 'value')
53
+ subject.rewrite_cookies(downstream_response.headers, substitute_domain: substitute_domain)
54
+ expect(downstream_response.cookies[downstream_domain_cookie_name][:domain]).to eq('.example.org')
55
+ end
56
+ end
57
+
58
+ context 'subdomain not character present' do
59
+ it 'substitues the domain for the mapped domain' do
60
+ downstream_response.set_cookie(downstream_domain_cookie_name, domain: 'downstream.com', value: 'value')
61
+ subject.rewrite_cookies(downstream_response.headers, substitute_domain: substitute_domain)
62
+ expect(downstream_response.cookies[downstream_domain_cookie_name][:domain]).to eq('example.org')
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -38,7 +38,7 @@ class SiteHub
38
38
  sitehub_json[:sitehub_cookie_name] = 'custom_name'
39
39
 
40
40
  expect(core.sitehub_cookie_name).to eq(expected.sitehub_cookie_name)
41
- expect(core.routes['/route_1'].sitehub_cookie_name).to eq(expected.sitehub_cookie_name)
41
+ expect(core.mappings['/route_1'].sitehub_cookie_name).to eq(expected.sitehub_cookie_name)
42
42
  end
43
43
  end
44
44
 
@@ -78,13 +78,13 @@ class SiteHub
78
78
 
79
79
  describe '#proxy' do
80
80
  let(:expected_route) do
81
- RouteBuilder.new(sitehub_cookie_name: RECORDED_ROUTES_COOKIE,
82
- mapped_path: '/app')
81
+ CandidateRoutes.new(sitehub_cookie_name: RECORDED_ROUTES_COOKIE,
82
+ mapped_path: '/app')
83
83
  end
84
84
 
85
85
  context 'string as parameters' do
86
86
  it 'treats it as the mapped path' do
87
- expect_any_instance_of(Middleware::Routes)
87
+ expect_any_instance_of(Middleware::CandidateRouteMappings)
88
88
  .to receive(:add_route)
89
89
  .with(url: nil, mapped_path: '/app').and_call_original
90
90
  subject.proxy('/app')
@@ -93,7 +93,7 @@ class SiteHub
93
93
 
94
94
  context 'hash as parameter' do
95
95
  it 'treats the key as the mapped path and the value as downstream url' do
96
- expect_any_instance_of(Middleware::Routes)
96
+ expect_any_instance_of(Middleware::CandidateRouteMappings)
97
97
  .to receive(:add_route)
98
98
  .with(url: :downstream_url, mapped_path: '/app').and_call_original
99
99
  subject.proxy('/app' => :downstream_url)
@@ -104,7 +104,7 @@ class SiteHub
104
104
  it 'uses the block when creating the proxy' do
105
105
  proc = proc {}
106
106
 
107
- expect_any_instance_of(Middleware::Routes).to receive(:add_route) do |*_args, &block|
107
+ expect_any_instance_of(Middleware::CandidateRouteMappings).to receive(:add_route) do |*_args, &block|
108
108
  expect(block).to be(proc)
109
109
  end
110
110
 
@@ -123,7 +123,7 @@ class SiteHub
123
123
 
124
124
  it 'passes the block to the route constructor' do
125
125
  expected_route.split url: :endpoint, percentage: 100, label: :label
126
- expect(subject.routes['/app'].routes).to eq(expected_route.routes)
126
+ expect(subject.mappings['/app'].candidates).to eq(expected_route.candidates)
127
127
  end
128
128
  end
129
129
  end
@@ -1,8 +1,8 @@
1
- require 'sitehub/middleware/routes'
1
+ require 'sitehub/middleware/candidate_route_mappings'
2
2
 
3
3
  class SiteHub
4
4
  module Middleware
5
- describe Routes do
5
+ describe CandidateRouteMappings do
6
6
  let(:base_url) { 'http://google.com' }
7
7
  let(:mapped_path) { '/app' }
8
8
  let(:mapped_path) { '/application_url' }
@@ -35,7 +35,7 @@ class SiteHub
35
35
  context 'RouteBuilder as parameter' do
36
36
  it 'sets it' do
37
37
  another_mapping = '/mapping'
38
- route = RouteBuilder.new(sitehub_cookie_name: :sitehub_cookie_name, mapped_path: another_mapping)
38
+ route = CandidateRoutes.new(sitehub_cookie_name: :sitehub_cookie_name, mapped_path: another_mapping)
39
39
  subject.add_route route_builder: route
40
40
  expect(subject[another_mapping]).to be(route)
41
41
  end
@@ -69,7 +69,7 @@ class SiteHub
69
69
  context 'mapped_route found' do
70
70
  it 'uses the forward proxy' do
71
71
  subject
72
- expect(forward_proxy_builder.routes[Identifier.new(:current)]).to receive(:call) do
72
+ expect(forward_proxy_builder.candidates[Identifier.new(:current)]).to receive(:call) do
73
73
  [200, {}, []]
74
74
  end
75
75
  expect(get(mapped_path).status).to eq(200)
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'rack/test'
3
3
  require 'webmock/rspec'
4
4
  require 'timecop'
5
5
  $LOAD_PATH.unshift("#{__dir__}/..", "#{__dir__}/support")
6
+ require 'async/middleware'
6
7
 
7
8
  require 'support/shared_contexts'
8
9
  require 'support/shared_examples'
@@ -1,26 +1,62 @@
1
1
  shared_context :sitehub_json do
2
2
  let(:sitehub_json) do
3
3
  {
4
- proxies: [proxy_1, proxy_2]
4
+ proxies: [routes_proxy, split_proxy]
5
5
  }
6
6
  end
7
7
 
8
- let(:proxy_1) do
8
+ let(:routes_proxy) do
9
9
  {
10
10
  path: '/route_1',
11
11
  sitehub_cookie_path: 'route_1_cookie_path',
12
- routes: [route_1]
12
+ routes: [route_1],
13
+ default: 'route_proxy_default_url'
13
14
  }
14
15
  end
15
16
 
16
- let(:proxy_2) do
17
+ let(:split_proxy) do
17
18
  {
18
- path: '/route_1',
19
- sitehub_cookie_path: 'route_1_cookie_path',
19
+ path: '/route_2',
20
+ sitehub_cookie_path: 'route_2_cookie_path',
21
+ splits: [split_1, split_2],
22
+ default: 'split_proxy_default_url'
23
+ }
24
+ end
25
+
26
+ let(:nested_split_proxy) do
27
+ {
28
+ path: '/route_3',
29
+ sitehub_cookie_path: 'route_3_cookie_path',
30
+ splits: [nested_split],
31
+ default: 'route_proxy_default_url'
32
+ }
33
+ end
34
+
35
+ let(:nested_route_proxy) do
36
+ {
37
+ path: '/route_3',
38
+ sitehub_cookie_path: 'route_3_cookie_path',
39
+ splits: [nested_route],
40
+ default: 'route_proxy_default_url'
41
+ }
42
+ end
43
+
44
+ let(:nested_split) do
45
+ {
46
+ label: :nested_split_label,
47
+ percentage: 100,
20
48
  splits: [split_1, split_2]
21
49
  }
22
50
  end
23
51
 
52
+ let(:nested_route) do
53
+ {
54
+ label: :nested_route_label,
55
+ percentage: 100,
56
+ routes: [route_1]
57
+ }
58
+ end
59
+
24
60
  let(:route_1) do
25
61
  {
26
62
  label: :route_label_1,
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.alpha5
4
+ version: 0.5.0.alpha6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ladtech
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -339,17 +339,20 @@ files:
339
339
  - circle.yml
340
340
  - lib/sitehub.rb
341
341
  - lib/sitehub/builder.rb
342
+ - lib/sitehub/candidate_routes.rb
343
+ - lib/sitehub/candidate_routes/class_methods.rb
342
344
  - lib/sitehub/collection.rb
343
345
  - lib/sitehub/collection/route_collection.rb
344
346
  - lib/sitehub/collection/split_route_collection.rb
345
347
  - lib/sitehub/collection/split_route_collection/split.rb
348
+ - lib/sitehub/collection_methods.rb
346
349
  - lib/sitehub/constants.rb
347
350
  - lib/sitehub/constants/http_header_keys.rb
348
351
  - lib/sitehub/constants/rack_http_header_keys.rb
349
352
  - lib/sitehub/cookie.rb
350
353
  - lib/sitehub/cookie/attribute.rb
351
354
  - lib/sitehub/cookie/flag.rb
352
- - lib/sitehub/cookie_rewriting.rb
355
+ - lib/sitehub/cookie/rewriting.rb
353
356
  - lib/sitehub/core.rb
354
357
  - lib/sitehub/downstream_client.rb
355
358
  - lib/sitehub/equality.rb
@@ -361,6 +364,7 @@ files:
361
364
  - lib/sitehub/location_rewriters.rb
362
365
  - lib/sitehub/memoize.rb
363
366
  - lib/sitehub/middleware.rb
367
+ - lib/sitehub/middleware/candidate_route_mappings.rb
364
368
  - lib/sitehub/middleware/config_loader.rb
365
369
  - lib/sitehub/middleware/error_handling.rb
366
370
  - lib/sitehub/middleware/logging.rb
@@ -372,7 +376,6 @@ files:
372
376
  - lib/sitehub/middleware/logging/request_log.rb
373
377
  - lib/sitehub/middleware/reverse_proxy.rb
374
378
  - lib/sitehub/middleware/route.rb
375
- - lib/sitehub/middleware/routes.rb
376
379
  - lib/sitehub/middleware/transaction_id.rb
377
380
  - lib/sitehub/nil_location_rewriter.rb
378
381
  - lib/sitehub/nil_route.rb
@@ -380,21 +383,24 @@ files:
380
383
  - lib/sitehub/request_mapping.rb
381
384
  - lib/sitehub/resolver.rb
382
385
  - lib/sitehub/response.rb
383
- - lib/sitehub/route_builder.rb
384
386
  - lib/sitehub/rules.rb
385
387
  - lib/sitehub/string_utils.rb
386
388
  - lib/sitehub/version.rb
387
389
  - mem_usage.txt
388
390
  - sitehub.gemspec
389
391
  - spec/equality_spec.rb
392
+ - spec/integration/access_logs_spec.rb
393
+ - spec/integration/middleware_spec.rb
394
+ - spec/integration/version_affinity_spec.rb
390
395
  - spec/sitehub/builder_spec.rb
396
+ - spec/sitehub/candidate_routes_spec.rb
391
397
  - spec/sitehub/collection/route_collection_spec.rb
392
398
  - spec/sitehub/collection/split_route_collection/split_spec.rb
393
399
  - spec/sitehub/collection/split_route_collection_spec.rb
394
400
  - spec/sitehub/collection_spec.rb
395
401
  - spec/sitehub/cookie/attribute_spec.rb
396
402
  - spec/sitehub/cookie/flag_spec.rb
397
- - spec/sitehub/cookie_rewriting_spec.rb
403
+ - spec/sitehub/cookie/rewriting_spec.rb
398
404
  - spec/sitehub/cookie_spec.rb
399
405
  - spec/sitehub/core_spec.rb
400
406
  - spec/sitehub/downstream_client_spec.rb
@@ -402,10 +408,10 @@ files:
402
408
  - spec/sitehub/forward_proxy_spec.rb
403
409
  - spec/sitehub/http_headers_spec.rb
404
410
  - spec/sitehub/identifier_spec.rb
405
- - spec/sitehub/integration_spec.rb
406
411
  - spec/sitehub/location_rewriter_spec.rb
407
412
  - spec/sitehub/location_rewriters_spec.rb
408
413
  - spec/sitehub/memoize_spec.rb
414
+ - spec/sitehub/middleware/candidate_route_mappings_spec.rb
409
415
  - spec/sitehub/middleware/config_loader_spec.rb
410
416
  - spec/sitehub/middleware/error_handling_spec.rb
411
417
  - spec/sitehub/middleware/logging/access_logger_spec.rb
@@ -416,7 +422,6 @@ files:
416
422
  - spec/sitehub/middleware/logging/request_log_spec.rb
417
423
  - spec/sitehub/middleware/reverse_proxy_spec.rb
418
424
  - spec/sitehub/middleware/route_spec.rb
419
- - spec/sitehub/middleware/routes_spec.rb
420
425
  - spec/sitehub/middleware/transaction_id_spec.rb
421
426
  - spec/sitehub/middleware_spec.rb
422
427
  - spec/sitehub/nil_location_rewriter_spec.rb
@@ -425,7 +430,6 @@ files:
425
430
  - spec/sitehub/request_spec.rb
426
431
  - spec/sitehub/resolver_spec.rb
427
432
  - spec/sitehub/response_spec.rb
428
- - spec/sitehub/route_builder_spec.rb
429
433
  - spec/sitehub_spec.rb
430
434
  - spec/spec_helper.rb
431
435
  - spec/support/async.rb
@@ -1,40 +0,0 @@
1
- require 'sitehub/cookie'
2
- require 'sitehub/constants'
3
- class SiteHub
4
- # TODO: - change in to object and remove .reek exclusions for UtilityFunction
5
- module CookieRewriting
6
- ENDING_WITH_NEWLINE = /#{NEW_LINE}$/
7
-
8
- def rewrite_cookies(headers, substitute_domain:)
9
- cookies_hash = cookies_string_as_hash(headers[Constants::HttpHeaderKeys::SET_COOKIE])
10
-
11
- cookies_hash.values.each do |cookie|
12
- domain_attribute = cookie.find(:domain) || next
13
- update_domain(domain_attribute, substitute_domain)
14
- end
15
- headers[Constants::HttpHeaderKeys::SET_COOKIE] = cookies_hash_to_string(cookies_hash)
16
- end
17
-
18
- def update_domain(domain_attribute, substitute_domain)
19
- substitute = substitute_domain.dup
20
- if domain_attribute.value.start_with?(FULL_STOP)
21
- domain_attribute.update(substitute.prepend(FULL_STOP))
22
- else
23
- domain_attribute.update(substitute)
24
- end
25
- end
26
-
27
- def cookies_hash_to_string(cookies_hash)
28
- cookies_hash.values.inject(EMPTY_STRING.dup) do |cookie_string, cookie|
29
- cookie_string << "#{cookie}#{NEW_LINE}"
30
- end.sub(ENDING_WITH_NEWLINE, EMPTY_STRING)
31
- end
32
-
33
- def cookies_string_as_hash(cookie_string)
34
- cookie_string.lines.each_with_object({}) do |cookie_line, cookies|
35
- cookie = SiteHub::Cookie.new(cookie_line)
36
- cookies[cookie.name] = cookie
37
- end
38
- end
39
- end
40
- end
@@ -1,66 +0,0 @@
1
- require 'sitehub/cookie_rewriting'
2
-
3
- class SiteHub
4
- describe CookieRewriting do
5
- include_context :module_spec
6
-
7
- let(:downstream_domain) { '.downstream_domain.com' }
8
-
9
- let(:request_mapping) do
10
- RequestMapping.new(source_url: 'http://example.org',
11
- mapped_url: "http://#{downstream_domain}",
12
- mapped_path: '/map')
13
- end
14
-
15
- let(:substitute_domain) { URI(request_mapping.source_url).host }
16
- let(:substitute_path) { '/path' }
17
- let(:downstream_response) { Rack::Response.new }
18
- let(:downstream_domain_cookie_name) { 'downstream.cookie' }
19
-
20
- before do
21
- downstream_response.set_cookie(downstream_domain_cookie_name, domain: downstream_domain, value: 'value')
22
- downstream_response.set_cookie('downstream.cookie2', domain: downstream_domain, value: 'value2', httponly: true)
23
- end
24
-
25
- describe '#cookies_string_as_hash' do
26
- it 'returns the string as a hash' do
27
- cookie_header = downstream_response.headers['Set-Cookie']
28
-
29
- cookie_strings = cookie_header.lines
30
- first_cookie = SiteHub::Cookie.new(cookie_strings[0])
31
- second_cookie = SiteHub::Cookie.new(cookie_strings[1])
32
- expected = {
33
- first_cookie.name => first_cookie,
34
- second_cookie.name => second_cookie
35
- }
36
- result = subject.cookies_string_as_hash(cookie_header)
37
- expect(result).to eq(expected)
38
- end
39
- end
40
-
41
- describe '#cookies_hash_to_string' do
42
- it 'returns the hash as a correctly formatted string' do
43
- cookies_hash = subject.cookies_string_as_hash(downstream_response.headers['Set-Cookie'])
44
- expect(subject.cookies_hash_to_string(cookies_hash)).to eq(downstream_response.headers['Set-Cookie'])
45
- end
46
- end
47
-
48
- describe '#rewrite_cookies' do
49
- context 'subdomain character present' do
50
- it 'substitues the domain for the mapped domain' do
51
- downstream_response.set_cookie(downstream_domain_cookie_name, domain: downstream_domain, value: 'value')
52
- subject.rewrite_cookies(downstream_response.headers, substitute_domain: substitute_domain)
53
- expect(downstream_response.cookies[downstream_domain_cookie_name][:domain]).to eq('.example.org')
54
- end
55
- end
56
-
57
- context 'subdomain not character present' do
58
- it 'substitues the domain for the mapped domain' do
59
- downstream_response.set_cookie(downstream_domain_cookie_name, domain: 'downstream.com', value: 'value')
60
- subject.rewrite_cookies(downstream_response.headers, substitute_domain: substitute_domain)
61
- expect(downstream_response.cookies[downstream_domain_cookie_name][:domain]).to eq('example.org')
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,197 +0,0 @@
1
- require 'async/middleware'
2
- require 'stringio'
3
- shared_context :site_hub do
4
- let(:downstream_url) { 'http://localhost:12345' }
5
- let(:experiment1_url) { "#{downstream_url}/experiment1" }
6
- let(:experiment2_url) { "#{downstream_url}/experiment2" }
7
-
8
- before do
9
- WebMock.enable!
10
- stub_request(:get, experiment1_url).to_return(body: 'experiment1_body')
11
- stub_request(:get, experiment2_url).to_return(body: 'experiment2_body')
12
- end
13
-
14
- let(:builder) do
15
- SiteHub::Builder.new.tap do |builder|
16
- builder.access_logger StringIO.new
17
- builder.error_logger StringIO.new
18
- experiment1_url = experiment1_url()
19
- experiment2_url = experiment2_url()
20
-
21
- builder.proxy '/endpoint' do
22
- split(label: :experiment1, percentage: 100) do
23
- split percentage: 100, label: 'variant1', url: experiment1_url
24
- end
25
-
26
- split(label: :experiment2, percentage: 0) do
27
- split percentage: 0, label: 'variant1', url: experiment2_url
28
- split percentage: 100, label: 'variant2', url: experiment2_url
29
- end
30
- end
31
- end
32
- end
33
-
34
- let(:rack_application) do
35
- builder.build
36
- end
37
- end
38
-
39
- describe 'proxying calls' do
40
- include_context :site_hub
41
-
42
- let(:app) { Async::Middleware.new(rack_application) }
43
- describe 'supported HTTP verbs' do
44
- %i(get post put delete).each do |verb|
45
- it 'forwards the downstream' do
46
- stub_request(verb, experiment1_url).to_return(body: 'hello')
47
- send(verb, '/endpoint')
48
- expect(app.last_response.body).to eq(['hello'])
49
- end
50
- end
51
- end
52
-
53
- describe 'route affinity' do
54
- context 'requested route cookie not present' do
55
- it 'drops a cookie to keep you on the same path' do
56
- get('/endpoint')
57
- expect(app.last_response.cookies[SiteHub::RECORDED_ROUTES_COOKIE][:value]).to eq('experiment1|variant1')
58
- end
59
- end
60
-
61
- context 'requested route cookie present' do
62
- it 'proxies to the preselected route' do
63
- get('/endpoint', {}, 'HTTP_COOKIE' => "#{SiteHub::RECORDED_ROUTES_COOKIE}=experiment2|variant1")
64
- expect(app.last_response.body).to eq(['experiment2_body'])
65
-
66
- expect(app.last_response.cookies[SiteHub::RECORDED_ROUTES_COOKIE][:value]).to eq('experiment2|variant1')
67
- end
68
- end
69
- end
70
-
71
- # describe 'middleware' do
72
- #
73
- # include_context :middleware_test
74
- #
75
- # let(:app) { Async::Middleware.new(rack_application) }
76
- #
77
- # def middleware name
78
- # create_middleware.tap do |clazz|
79
- # clazz.class_eval do
80
- # define_method :call do |env|
81
- #
82
- # callback = env['async.callback'] || env['async.orig_callback']
83
- # env['async.orig_callback'] = env['async.callback'] = proc do |status, headers, body|
84
- # body = body.body.join if body.is_a?(Rack::BodyProxy)
85
- #
86
- # callback.call(status, headers, "#{name}, #{body}")
87
- # end
88
- # @app.call(env)
89
- # end
90
- # end
91
- # end
92
- # end
93
- #
94
- # before do
95
- # stub_request(:get, downstream_url).to_return(body: 'hello')
96
- # end
97
- #
98
- # context 'middleware added to top level' do
99
- # let(:builder) do
100
- # middleware = middleware(:middleware1)
101
- # downstream_url = downstream_url()
102
- #
103
- # SiteHub::Builder.new do
104
- # access_logger StringIO.new
105
- # use middleware
106
- # proxy '/1' => downstream_url
107
- # proxy '/2' => downstream_url
108
- # end
109
- # end
110
- #
111
- # it 'adds it to each route' do
112
- # get('/1')
113
- # expect(app.last_response.body.join).to eq('middleware1, hello')
114
- # get('/2')
115
- # expect(app.last_response.body.join).to eq('middleware1, hello')
116
- # end
117
- # end
118
- #
119
- # context 'middleware added to specific route' do
120
- # let(:builder) do
121
- # middleware = middleware(:middleware1)
122
- # downstream_url = downstream_url()
123
- #
124
- # SiteHub::Builder.new do
125
- # access_logger StringIO.new
126
- # proxy '/1' do
127
- # use middleware
128
- # route label: :with_middleware, url: downstream_url
129
- # end
130
- # proxy '/2' => downstream_url
131
- # end
132
- # end
133
- #
134
- # it 'adds it to that route only' do
135
- # get('/1')
136
- # expect(app.last_response.body.join).to eq('middleware1, hello')
137
- # get('/2')
138
- # expect(app.last_response.body.join).to eq('hello')
139
- # end
140
- # end
141
- #
142
- # context 'base inherited middleware' do
143
- # let(:builder) do
144
- # middleware1 = middleware(:middleware1)
145
- # middleware2 = middleware(:middleware2)
146
- # downstream_url = downstream_url()
147
- #
148
- # SiteHub::Builder.new do
149
- # access_logger StringIO.new
150
- # use middleware1
151
- # proxy '/1' do
152
- # use middleware2
153
- # route label: :with_middleware, url: downstream_url
154
- # end
155
- # proxy '/2' => downstream_url
156
- # end
157
- # end
158
- #
159
- # it 'adds it to that route only' do
160
- # get('/1')
161
- # expect(app.last_response.body.join).to eq('middleware1, middleware2, hello')
162
- # get('/2')
163
- # expect(app.last_response.body.join).to eq('middleware1, hello')
164
- # end
165
- # end
166
- #
167
- # context 'nested inherited middleware' do
168
- # let(:builder) do
169
- # middleware1 = middleware(:middleware1)
170
- # middleware2 = middleware(:middleware2)
171
- # downstream_url = downstream_url()
172
- #
173
- # SiteHub::Builder.new do
174
- # access_logger StringIO.new
175
- #
176
- # proxy '/1' do
177
- # split percentage: 100, label: :experiment1 do
178
- # use middleware1
179
- # split percentage: 100, label: :with_middleware do
180
- # use middleware2
181
- # split percentage: 100, label: :with_nested_middleware, url: downstream_url
182
- # end
183
- # end
184
- # end
185
- # proxy '/2' => downstream_url
186
- # end
187
- # end
188
- #
189
- # it 'adds it to that route only' do
190
- # get('/1')
191
- # expect(app.last_response.body.join).to eq('middleware1, middleware2, hello')
192
- # get('/2')
193
- # expect(app.last_response.body.join).to eq('middleware1, hello')
194
- # end
195
- # end
196
- # end
197
- end