@@ -22,6 +22,14 @@ def setup
22
22
Admin . delete_all
23
23
FactoryBot . create ( :admin )
24
24
override_config_set ( @default_config , [ "--router" , "--web" ] )
25
+ prepend_api_backends ( [
26
+ {
27
+ :frontend_host => "frontend.foo" ,
28
+ :backend_host => "example.com" ,
29
+ :servers => [ { :host => "127.0.0.1" , :port => 9444 } ] ,
30
+ :url_matches => [ { :frontend_prefix => "/#{ unique_test_class_id } /front/end/path" , :backend_prefix => "/backend-prefix" } ] ,
31
+ } ,
32
+ ] )
25
33
end
26
34
end
27
35
@@ -46,6 +54,12 @@ def test_default_headers
46
54
when :admin_oauth2_http
47
55
assert_response_code ( 301 , response )
48
56
assert_equal ( "https://127.0.0.1:9081/admins/auth/google_oauth2" , response . headers [ "Location" ] )
57
+ when :api_backend_redirect_http
58
+ assert_response_code ( 302 , response )
59
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
60
+ when :api_backend_redirect_https
61
+ assert_response_code ( 302 , response )
62
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
49
63
when :website_https
50
64
assert_response_code ( 200 , response )
51
65
when :website_http
@@ -78,6 +92,12 @@ def test_forwarded_port
78
92
when :admin_oauth2_http
79
93
assert_response_code ( 301 , response )
80
94
assert_equal ( "https://127.0.0.1:9081/admins/auth/google_oauth2" , response . headers [ "Location" ] )
95
+ when :api_backend_redirect_http
96
+ assert_response_code ( 302 , response )
97
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
98
+ when :api_backend_redirect_https
99
+ assert_response_code ( 302 , response )
100
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
81
101
when :website_https
82
102
assert_response_code ( 200 , response )
83
103
when :website_http
@@ -105,6 +125,12 @@ def test_forwarded_proto_http
105
125
when :admin_oauth2_https , :admin_oauth2_http
106
126
assert_response_code ( 301 , response )
107
127
assert_equal ( "https://127.0.0.1:9081/admins/auth/google_oauth2" , response . headers [ "Location" ] )
128
+ when :api_backend_redirect_http
129
+ assert_response_code ( 302 , response )
130
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
131
+ when :api_backend_redirect_https
132
+ assert_response_code ( 302 , response )
133
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
108
134
when :website_https , :website_http
109
135
assert_response_code ( 301 , response )
110
136
assert_equal ( "https://127.0.0.1:9081/" , response . headers [ "Location" ] )
@@ -130,6 +156,12 @@ def test_forwarded_proto_https
130
156
when :admin_oauth2_http
131
157
assert_response_code ( 302 , response )
132
158
assert_oauth2_redirect_uri ( "https://127.0.0.1:9080/admins/auth/google_oauth2/callback" , response )
159
+ when :api_backend_redirect_http
160
+ assert_response_code ( 302 , response )
161
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
162
+ when :api_backend_redirect_https
163
+ assert_response_code ( 302 , response )
164
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
133
165
when :website_https , :website_http
134
166
assert_response_code ( 200 , response )
135
167
when :website_signup_https , :website_signup_http
@@ -151,6 +183,12 @@ def test_forwarded_proto_http_and_port
151
183
when :admin_oauth2_https , :admin_oauth2_http
152
184
assert_response_code ( 301 , response )
153
185
assert_equal ( "https://127.0.0.1:9081/admins/auth/google_oauth2" , response . headers [ "Location" ] )
186
+ when :api_backend_redirect_http
187
+ assert_response_code ( 302 , response )
188
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
189
+ when :api_backend_redirect_https
190
+ assert_response_code ( 302 , response )
191
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
154
192
when :website_https , :website_http
155
193
assert_response_code ( 301 , response )
156
194
assert_equal ( "https://127.0.0.1:9081/" , response . headers [ "Location" ] )
@@ -173,6 +211,12 @@ def test_forwarded_proto_https_and_port
173
211
when :admin_oauth2_https , :admin_oauth2_http
174
212
assert_response_code ( 302 , response )
175
213
assert_oauth2_redirect_uri ( "https://127.0.0.1:1111/admins/auth/google_oauth2/callback" , response )
214
+ when :api_backend_redirect_http
215
+ assert_response_code ( 302 , response )
216
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
217
+ when :api_backend_redirect_https
218
+ assert_response_code ( 302 , response )
219
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
176
220
when :website_https , :website_http
177
221
assert_response_code ( 200 , response )
178
222
when :website_signup_https , :website_signup_http
@@ -202,6 +246,12 @@ def test_override_public_http_port
202
246
when :admin_oauth2_http
203
247
assert_response_code ( 301 , response )
204
248
assert_equal ( "https://127.0.0.1:9081/admins/auth/google_oauth2" , response . headers [ "Location" ] )
249
+ when :api_backend_redirect_http
250
+ assert_response_code ( 302 , response )
251
+ assert_equal ( "http://frontend.foo:2222/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
252
+ when :api_backend_redirect_https
253
+ assert_response_code ( 302 , response )
254
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
205
255
when :website_https
206
256
assert_response_code ( 200 , response )
207
257
when :website_http
@@ -238,6 +288,12 @@ def test_override_public_https_port
238
288
when :admin_oauth2_http
239
289
assert_response_code ( 301 , response )
240
290
assert_equal ( "https://127.0.0.1:3333/admins/auth/google_oauth2" , response . headers [ "Location" ] )
291
+ when :api_backend_redirect_http
292
+ assert_response_code ( 302 , response )
293
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
294
+ when :api_backend_redirect_https
295
+ assert_response_code ( 302 , response )
296
+ assert_equal ( "https://frontend.foo:3333/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
241
297
when :website_https
242
298
assert_response_code ( 200 , response )
243
299
when :website_http
@@ -274,6 +330,12 @@ def test_override_public_http_proto
274
330
when :admin_oauth2_http
275
331
assert_response_code ( 302 , response )
276
332
assert_oauth2_redirect_uri ( "https://127.0.0.1:9080/admins/auth/google_oauth2/callback" , response )
333
+ when :api_backend_redirect_http
334
+ assert_response_code ( 302 , response )
335
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
336
+ when :api_backend_redirect_https
337
+ assert_response_code ( 302 , response )
338
+ assert_equal ( "https://frontend.foo:9081/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
277
339
when :website_https
278
340
assert_response_code ( 301 , response )
279
341
assert_equal ( "https://127.0.0.1:9081/" , response . headers [ "Location" ] )
@@ -310,6 +372,12 @@ def test_override_public_https_proto
310
372
when :admin_oauth2_http
311
373
assert_response_code ( 302 , response )
312
374
assert_oauth2_redirect_uri ( "https://127.0.0.1:9080/admins/auth/google_oauth2/callback" , response )
375
+ when :api_backend_redirect_http
376
+ assert_response_code ( 302 , response )
377
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
378
+ when :api_backend_redirect_https
379
+ assert_response_code ( 302 , response )
380
+ assert_equal ( "http://frontend.foo:9080/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
313
381
when :website_https
314
382
assert_response_code ( 301 , response )
315
383
assert_equal ( "https://127.0.0.1:9081/" , response . headers [ "Location" ] )
@@ -347,6 +415,12 @@ def test_override_public_ports_defaults
347
415
when :admin_oauth2_http
348
416
assert_response_code ( 301 , response )
349
417
assert_equal ( "https://127.0.0.1/admins/auth/google_oauth2" , response . headers [ "Location" ] )
418
+ when :api_backend_redirect_http
419
+ assert_response_code ( 302 , response )
420
+ assert_equal ( "http://frontend.foo/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
421
+ when :api_backend_redirect_https
422
+ assert_response_code ( 302 , response )
423
+ assert_equal ( "https://frontend.foo/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
350
424
when :website_https
351
425
assert_response_code ( 200 , response )
352
426
when :website_http
@@ -380,6 +454,9 @@ def test_override_public_ports_and_proto_ssl_terminator
380
454
when :admin_oauth2_https , :admin_oauth2_http
381
455
assert_response_code ( 302 , response )
382
456
assert_oauth2_redirect_uri ( "https://127.0.0.1/admins/auth/google_oauth2/callback" , response )
457
+ when :api_backend_redirect_http , :api_backend_redirect_https
458
+ assert_response_code ( 302 , response )
459
+ assert_equal ( "https://frontend.foo/hello?api_key=#{ api_key } " , response . headers [ "Location" ] )
383
460
when :website_https , :website_http
384
461
assert_response_code ( 200 , response )
385
462
when :website_signup_https , :website_signup_http
@@ -405,6 +482,8 @@ def make_requests(headers)
405
482
:admin_http => admin_http_request ( headers ) ,
406
483
:admin_oauth2_https => admin_oauth2_https_request ( headers ) ,
407
484
:admin_oauth2_http => admin_oauth2_http_request ( headers ) ,
485
+ :api_backend_redirect_http => api_backend_redirect_http ( headers ) ,
486
+ :api_backend_redirect_https => api_backend_redirect_https ( headers ) ,
408
487
:website_https => website_https_request ( headers ) ,
409
488
:website_http => website_http_request ( headers ) ,
410
489
:website_signup_https => website_signup_https_request ( headers ) ,
@@ -428,6 +507,28 @@ def admin_oauth2_http_request(headers = {})
428
507
Typhoeus . get ( "http://127.0.0.1:9080/admins/auth/google_oauth2" , keyless_http_options . deep_merge ( :headers => headers ) )
429
508
end
430
509
510
+ def api_backend_redirect_http ( headers = { } )
511
+ Typhoeus . get ( "http://127.0.0.1:9080/#{ unique_test_class_id } /front/end/path/redirect" , http_options . deep_merge ( {
512
+ :headers => {
513
+ "Host" => "frontend.foo" ,
514
+ } ,
515
+ :params => {
516
+ :to => "http://example.com/hello" ,
517
+ } ,
518
+ } ) . deep_merge ( :headers => headers ) )
519
+ end
520
+
521
+ def api_backend_redirect_https ( headers = { } )
522
+ Typhoeus . get ( "http://127.0.0.1:9080/#{ unique_test_class_id } /front/end/path/redirect" , http_options . deep_merge ( {
523
+ :headers => {
524
+ "Host" => "frontend.foo" ,
525
+ } ,
526
+ :params => {
527
+ :to => "https://example.com/hello" ,
528
+ } ,
529
+ } ) . deep_merge ( :headers => headers ) )
530
+ end
531
+
431
532
def website_https_request ( headers = { } )
432
533
Typhoeus . get ( "https://127.0.0.1:9081/" , keyless_http_options . deep_merge ( :headers => headers ) )
433
534
end
0 commit comments