rails_health_check 3.0.0

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,679 @@
1
+ #!/bin/bash
2
+
3
+ route_prefix=medical_check
4
+
5
+ err_report() {
6
+ echo "$0: Error on line $1 - aborted"
7
+ exit 1
8
+ }
9
+
10
+ trap 'err_report $LINENO' ERR
11
+
12
+ # Any failure causes exit
13
+ set -e
14
+ export DISABLE_SPRING=1
15
+
16
+ cleanup_db()
17
+ {
18
+ echo Dropping database ...
19
+ $rake db:drop
20
+ echo Removing migrations ...
21
+ rm -f db/migrate/* db/schema.rb
22
+ case `ruby -e 'puts JRUBY_VERSION' 2> /dev/null` in
23
+ [0-9]*)
24
+ echo 'Jruby requires the database to be created before the server is started: running rake db:migrate'
25
+ $rake db:migrate
26
+ ;;
27
+ esac
28
+ }
29
+
30
+ case "$1" in
31
+ redo)
32
+ . test/init_variables
33
+ cd $railsapp
34
+ cleanup_db
35
+ actual_rails_version=`$rails -v`
36
+ ;;
37
+ *)
38
+ . test/setup_railsapp $1
39
+ ;;
40
+ esac
41
+
42
+ run_test=$2
43
+
44
+ cd $railsapp
45
+ date > $custom_file
46
+ rm -f $catchall_file
47
+
48
+ case `egrep '^[^#]*MiddlewareHealthcheck' config/application.rb` in
49
+ '')
50
+ export has_middleware=false
51
+ ;;
52
+ ?*)
53
+ export has_middleware=true
54
+ ;;
55
+ esac
56
+
57
+
58
+ testurl="$base_dir/test/testurl"
59
+ fake_smtp_server="$base_dir/test/fake_smtp_server"
60
+
61
+ server_pid=''
62
+ fake_smtp_pid=''
63
+
64
+ pick_a_port()
65
+ {
66
+ while :
67
+ do
68
+ port=`expr 10000 + $RANDOM`
69
+ # Check Tcp ports in Listen mode with No address resolution
70
+ if (netstat -tln | egrep ":${port} .*:"); then
71
+ echo "(Skipping used port)"
72
+ else
73
+ break
74
+ fi
75
+ done
76
+ }
77
+
78
+
79
+ start_server()
80
+ {
81
+ # restart migration list
82
+ rm -rf db/migrate db/schema.rb
83
+ mkdir -p db/migrate
84
+
85
+ # Increment port each time to make sure we have not trouble with address/port already allocated
86
+ pick_a_port
87
+ host=http://127.0.0.1:${port}
88
+ bundle_prefix=''
89
+ if [ -f Gemfile ]
90
+ then
91
+ bundle_prefix='bundle exec'
92
+ fi
93
+ server_arg=${RAILS_SERVER:-webrick}
94
+ echo "start_server called using: `env | egrep '^RAILS|^RACK|^PATH='` $bundle_prefix $server_arg"
95
+ case "$server_arg" in
96
+ puma)
97
+ $bundle_prefix puma -b tcp://127.0.0.1:$port &
98
+ ;;
99
+ passenger)
100
+ $bundle_prefix passenger start -p $port &
101
+ ;;
102
+ thin)
103
+ $bundle_prefix thin start -p $port &
104
+ ;;
105
+ unicorn)
106
+ $bundle_prefix unicorn_rails -l 127.0.0.1:$port &
107
+ ;;
108
+ *)
109
+ if [ -x script/server ]
110
+ then
111
+ echo Starting server on port $port using $bundle_prefix ./script/server ...
112
+ $bundle_prefix ./script/server $server_arg -p $port &
113
+ else
114
+ echo Starting server on port $port using $rails s ...
115
+ $bundle_prefix $rails server $server_arg -p $port &
116
+ fi
117
+ ;;
118
+ esac
119
+ server_pid=$!
120
+ echo Server pid: $server_pid
121
+ sleep 3
122
+ echo
123
+ echo 'Checking server is up ...'
124
+ for i in 1 2 3 4 5 6
125
+ do
126
+ if $testurl ${host}/static.txt ; then
127
+ break
128
+ fi
129
+ if kill -0 $server_pid ; then
130
+ echo "waiting ${i} ..."
131
+ else
132
+ echo "ERROR: Server has died!!"
133
+ exit 3
134
+ fi
135
+ done
136
+ }
137
+
138
+ stop_server()
139
+ {
140
+ case "$server_pid" in
141
+ [0-9]*)
142
+ echo ========================================================
143
+ echo "Killing rails server [pid: $server_pid]"
144
+ kill -QUIT $server_pid || echo server has already exited ..
145
+ if [ -x bin/spring ] ; then
146
+ echo Stopping spring ...
147
+ bin/spring stop || echo spring had already exited ..
148
+ fi
149
+ sleep 1
150
+ kill -9 $server_pid || echo server had already exited ...
151
+ sleep 1
152
+ # needed for unicorn - it doesn't die when it is supposed to
153
+ killall "$server_arg" || echo server and child processes had already stopped ...
154
+ ;;
155
+ esac
156
+ case "$fake_smtp_pid" in
157
+ [0-9]*)
158
+ echo ========================================================
159
+ echo "Killing fake smtp server [pid: $fake_smtp_pid]"
160
+ kill -QUIT $fake_smtp_pid || echo fake_smtp had already exited ..
161
+ sleep 2
162
+ kill -9 $fake_smtp_pid || echo fake_smtp had already exited ..
163
+ ;;
164
+ esac
165
+ server_pid=''
166
+ fake_smtp_pid=''
167
+ ps -f
168
+ echo Waiting for sub processes to complete ...
169
+ wait
170
+ echo Finished waiting for sub processes, sleeping 2 seconds ...
171
+ sleep 2
172
+ }
173
+
174
+ finish()
175
+ {
176
+ set +e
177
+ echo ========================================================
178
+ echo TEST ${1:-FAILED}
179
+ echo ========================================================
180
+ echo Result of: ls -lR $railsapp/log $railsapp/db
181
+ ls -lR $railsapp/log $railsapp/db
182
+
183
+ if [ -s $railsapp/log/test.log ]
184
+ then
185
+ echo ========================================================
186
+ echo Last 50 lines of test log
187
+ tail -50 $railsapp/log/test.log
188
+ fi
189
+
190
+ if [ -s $railsapp/log/production.log ]
191
+ then
192
+ echo ========================================================
193
+ echo Last 50 lines of production log
194
+ tail -50 $railsapp/log/production.log
195
+ fi
196
+
197
+ stop_server
198
+ trap "" 0
199
+ echo ========================================================
200
+ ps uxf || echo ps failed
201
+ echo ========================================================
202
+ echo TEST ${1:-FAILED}, exiting with status ${2:-2}
203
+ echo ========================================================
204
+ exit ${2:-2}
205
+ }
206
+
207
+ trap "finish FAILED 1" 0
208
+
209
+ common_tests()
210
+ {
211
+
212
+ test_no=$1
213
+
214
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
215
+ echo "${test_no}: CHECKING routes exist..."
216
+ $rake routes | tee /tmp/t$$
217
+ echo
218
+ case `egrep ${route_prefix} /tmp/t$$ || true` in
219
+ '')
220
+ echo WARNING - routes for ${route_prefix} not listed!
221
+ ;;
222
+ esac
223
+ echo
224
+ fi
225
+
226
+ test_no=`expr 1 + $test_no`
227
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
228
+ echo "${test_no}: TESTING can get a static file ..."
229
+ case "$RAILS_ENV=`egrep '^\s*config.serve_static_[asetfil]* *= *false' config/environments/${RAILS_ENV}.rb`" in
230
+ production*static*false*)
231
+ echo " SKIPPED (disabled in production)"
232
+ ;;
233
+ *)
234
+ grep serve_static_files config/environments/${RAILS_ENV}.rb config/[a-z]*.rb || echo no serve_static_files entry
235
+ $testurl ${host}/static.txt 200 text/plain STATIC-FILE
236
+ ;;
237
+ esac
238
+ echo
239
+ fi
240
+
241
+ test_no=`expr 1 + $test_no`
242
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
243
+ echo "${test_no}: TESTING can get an example controller ..."
244
+ $testurl ${host}/example 200 text/plain 'example page'
245
+ echo
246
+ fi
247
+
248
+ test_no=`expr 1 + $test_no`
249
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
250
+ echo "${test_no}: TESTING direct call to catchall method on example controller ..."
251
+ $testurl ${host}/example/catchall 200 text/plain 'catch all route'
252
+ echo
253
+ fi
254
+
255
+ test_no=`expr 1 + $test_no`
256
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
257
+ echo "${test_no}: TESTING ${route_prefix}/migration should pass with no database migrations ..."
258
+ ls db/migrate
259
+ $testurl ${host}/${route_prefix}/migration 200 text/plain $success
260
+ echo
261
+ fi
262
+
263
+ test_no=`expr 1 + $test_no`
264
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
265
+ echo "${test_no}: TESTING ${route_prefix}/migration should fail without initial database migration ..."
266
+ cp $base_dir/test/migrate/nine/* db/migrate
267
+ ls db/migrate
268
+ $testurl ${host}/${route_prefix}/migration 550 text/plain failed
269
+ echo
270
+ fi
271
+
272
+ test_no=`expr 1 + $test_no`
273
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
274
+ echo "${test_no}: TESTING ${route_prefix}/database should pass without initial database migration (since it ignores the difference) ..."
275
+ $testurl ${host}/${route_prefix}/database 200 text/plain $success
276
+ echo
277
+ fi
278
+
279
+
280
+
281
+ test_no=`expr 1 + $test_no`
282
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
283
+ echo "${test_no}: TESTING ${route_prefix}/site should pass ..."
284
+ $testurl ${host}/${route_prefix}/site 200 text/plain $success
285
+ echo
286
+ fi
287
+
288
+ test_no=`expr 1 + $test_no`
289
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
290
+ echo "${test_no}: TESTING ${route_prefix}/migration should pass after initial database migration ..."
291
+ $rake db:migrate
292
+ $testurl ${host}/${route_prefix}/migration 200 text/plain $success
293
+ echo
294
+ fi
295
+
296
+ #test with coruppted DB
297
+ rm -rf db.bak
298
+ cp -R db db.bak
299
+ for f in db/*.sqlite3
300
+ do
301
+ echo CORRUPTED > $f
302
+ done
303
+
304
+ test_no=`expr 1 + $test_no`
305
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
306
+ echo "${test_no}: TESTING ${route_prefix}/database should fail if the database has been corrupted ..."
307
+
308
+ $testurl ${host}/${route_prefix}/database 550 text/plain failed
309
+ echo
310
+ fi
311
+
312
+ export HIDE_ERROR_RESPONSE=true
313
+ stop_server
314
+ start_server
315
+
316
+ test_no=`expr 1 + $test_no`
317
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
318
+ echo "${test_no}: TESTING ${route_prefix}/database should have response body 'failure' if include_error_in_response_body is false"
319
+ $testurl ${host}/${route_prefix}/database 550 text/plain failure
320
+ echo
321
+ fi
322
+
323
+ unset HIDE_ERROR_RESPONSE
324
+ stop_server
325
+ start_server
326
+
327
+ test_no=`expr 1 + $test_no`
328
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
329
+ echo "${test_no}: TESTING ${route_prefix}/site should pass ..."
330
+ $testurl ${host}/${route_prefix}/site 200 text/plain $success
331
+ if $has_middleware; then
332
+ echo "${test_no}: TESTING ${route_prefix}/middleware_site should pass ..."
333
+ $testurl ${host}/${route_prefix}/middleware_site 200 text/plain $success
334
+ fi
335
+ echo
336
+ fi
337
+
338
+ # Restore database
339
+ cp -f db.bak/*.sqlite3 db/
340
+
341
+ test_no=`expr 1 + $test_no`
342
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
343
+ echo "${test_no}: TESTING ${route_prefix}/migration should fail without all migrations ..."
344
+ cp $base_dir/test/migrate/twelve/* db/migrate
345
+
346
+ ls db/migrate
347
+ $testurl ${host}/${route_prefix}/migration 550 text/plain failed
348
+ echo
349
+ fi
350
+
351
+ test_no=`expr 1 + $test_no`
352
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
353
+ echo "${test_no}: TESTING ${route_prefix}/migration should pass after both database migrations ..."
354
+ $rake db:migrate
355
+ $testurl ${host}/${route_prefix}/migration 200 text/plain $success
356
+ echo
357
+ fi
358
+
359
+ test_no=`expr 1 + $test_no`
360
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
361
+ echo "${test_no}: TESTING ${route_prefix}/migration should pass after both database migrations ..."
362
+ $rake db:migrate
363
+ $testurl ${host}/${route_prefix}/migration 200 text/plain $success
364
+ echo
365
+ fi
366
+
367
+ test_no=`expr 1 + $test_no`
368
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
369
+ echo "${test_no}: TESTING ${route_prefix}/email should fail without smtp available ..."
370
+ $testurl ${host}/${route_prefix}/email 550 text/plain failed
371
+ echo
372
+ fi
373
+
374
+ test_no=`expr 1 + $test_no`
375
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
376
+ echo "${test_no}: TESTING ${route_prefix}/email should pass with smtp available ..."
377
+ $fake_smtp_server &
378
+ fake_smtp_pid=$!
379
+ sleep 5
380
+ $testurl ${host}/${route_prefix}/email 200 text/plain $success
381
+ echo
382
+ fi
383
+
384
+ test_no=`expr 1 + $test_no`
385
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
386
+ echo "${test_no}: TESTING ${route_prefix} (all) should fail without smtp available ..."
387
+ $testurl ${host}/${route_prefix} 550 text/plain failed
388
+ echo
389
+ fi
390
+
391
+ test_no=`expr 1 + $test_no`
392
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
393
+ echo "${test_no}: TESTING ${route_prefix}/all should fail without smtp available ..."
394
+ $testurl ${host}/${route_prefix} 550 text/plain failed
395
+ echo
396
+ fi
397
+
398
+ kill -9 $fake_smtp_pid || echo fake_smtp_server had finished as expected
399
+ test_no=`expr 1 + $test_no`
400
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
401
+ echo "${test_no}: TESTING ${route_prefix} (all) should pass with smtp available ..."
402
+ $fake_smtp_server &
403
+ fake_smtp_pid=$!
404
+ sleep 5
405
+ $testurl ${host}/${route_prefix} 200 text/plain $success
406
+ echo
407
+ fi
408
+
409
+ kill -9 $fake_smtp_pid || echo fake_smtp_server had finished as expected
410
+ test_no=`expr 1 + $test_no`
411
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
412
+ echo "${test_no}: TESTING ${route_prefix}/all should pass with smtp available ..."
413
+ $fake_smtp_server &
414
+ fake_smtp_pid=$!
415
+ sleep 5
416
+ $testurl ${host}/${route_prefix}/all 200 text/plain $success
417
+ echo
418
+ fi
419
+
420
+ test_no=`expr 1 + $test_no`
421
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
422
+ echo "${test_no}: TESTING ${route_prefix}/pass should pass ..."
423
+ $testurl ${host}/${route_prefix}/pass 200 text/plain $success
424
+ echo
425
+ fi
426
+
427
+ test_no=`expr 1 + $test_no`
428
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
429
+ echo "${test_no}: TESTING ${route_prefix}/custom should pass ..."
430
+ $testurl ${host}/${route_prefix}/custom 200 text/plain $success
431
+ echo
432
+ fi
433
+
434
+ test_no=`expr 1 + $test_no`
435
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
436
+ echo "${test_no}: TESTING ${route_prefix}/custom.html should pass (returning plain text) ..."
437
+ $testurl ${host}/${route_prefix}/custom.html 200 text/plain $success
438
+ echo
439
+ fi
440
+
441
+ test_no=`expr 1 + $test_no`
442
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
443
+ echo "${test_no}: TESTING ${route_prefix}/custom.json should pass ..."
444
+ $testurl ${host}/${route_prefix}/custom.json 200 application/json '"healthy":true'
445
+ $testurl ${host}/${route_prefix}/custom.json 200 application/json "\"message\":\"$success\""
446
+ echo
447
+ fi
448
+
449
+ test_no=`expr 1 + $test_no`
450
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
451
+ echo "${test_no}: TESTING ${route_prefix}/custom.xml should pass ..."
452
+ $testurl ${host}/${route_prefix}/custom.xml 200 application/xml '<healthy type="boolean">true</healthy>'
453
+ $testurl ${host}/${route_prefix}/custom.xml 200 application/xml "<message>$success</message>"
454
+ echo
455
+ fi
456
+
457
+ test_no=`expr 1 + $test_no`
458
+ rm -f $custom_file
459
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
460
+ echo "${test_no}: TESTING ${route_prefix}/custom should fail when custom returns string ..."
461
+ $testurl ${host}/${route_prefix}/custom 550 text/plain failed
462
+ echo
463
+ fi
464
+
465
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
466
+ echo "${test_no}: TESTING ${route_prefix}/pass should pass even if other custom test returns string ..."
467
+ $testurl ${host}/${route_prefix}/pass 200 text/plain $success
468
+ echo
469
+ fi
470
+
471
+ test_no=`expr 1 + $test_no`
472
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
473
+ echo "${test_no}: TESTING ${route_prefix} (all) should fail when custom check fails ..."
474
+ $testurl ${host}/${route_prefix} 550 text/plain "$custom_file is missing!"
475
+ echo
476
+ fi
477
+
478
+ test_no=`expr 1 + $test_no`
479
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
480
+ echo "${test_no}: TESTING ${route_prefix}.json (all) should fail when custom check fails ..."
481
+ $testurl ${host}/${route_prefix}.json 555 application/json '"healthy":false'
482
+ $testurl ${host}/${route_prefix}.json 555 application/json "$custom_file is missing!"
483
+ echo
484
+ fi
485
+
486
+ test_no=`expr 1 + $test_no`
487
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
488
+ echo "${test_no}: TESTING ${route_prefix}.xml (all) should fail when custom check fails ..."
489
+ $testurl ${host}/${route_prefix}.xml 555 application/xml '<healthy type="boolean">false</healthy>'
490
+ echo
491
+ fi
492
+
493
+ test_no=`expr 1 + $test_no`
494
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
495
+ if $has_middleware; then
496
+ echo "${test_no}: TESTING ${route_prefix}/middleware_site should pass ..."
497
+ $testurl ${host}/${route_prefix}/middleware_site 200 text/plain $success
498
+ else
499
+ echo "${test_no}: TESTING ${route_prefix}/middleware_site should fail ..."
500
+ $testurl ${host}/${route_prefix}/middleware_site 550 text/plain failed
501
+ fi
502
+ echo
503
+ fi
504
+
505
+ test_no=`expr 1 + $test_no`
506
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
507
+ echo "${test_no}: TESTING log files to check for deprecation warnings ..."
508
+ if egrep ' is deprecated|DEPRECATION WARNING' $railsapp/log/[tp][er][so][td]*.log
509
+ then
510
+ echo Found deprecation warnings - failed test
511
+ exit 99
512
+ fi
513
+ fi
514
+
515
+ date > $custom_file
516
+ }
517
+
518
+ # required for rails 4.1+ in production mode
519
+ export SECRET_KEY_BASE=cf2f49c38a3fe67416ddf680f4f3187c0fce7dd1b9b117b34d195df75b274e08a04877e23803b2fdf1aa9a655269d94bc4888aa325cf7e721cc47368cfe56a80
520
+
521
+ # required for rails 5 to server static files
522
+ export RAILS_SERVE_STATIC_FILES=on
523
+
524
+ export IP_WHITELIST='123.123.123.123'
525
+ unset AUTH_USER
526
+ unset AUTH_PASSWORD
527
+
528
+ case "$run_test" in
529
+ ''|[12])
530
+ echo ========================================================
531
+ echo TESTING whitelist ban WITHOUT CATCHALL in test env
532
+ echo ========================================================
533
+ export RAILS_ENV=test RACK_ENV=test
534
+
535
+ start_server
536
+
537
+ echo '1: TESTING controller prohibited by ip...'
538
+ expected_status=403
539
+ $testurl ${host}/${route_prefix}/site $expected_status
540
+
541
+ if $has_middleware; then
542
+ echo
543
+ echo '2: TESTING middleware prohibited by ip...'
544
+ expected_status=403
545
+ $testurl ${host}/${route_prefix}/middleware $expected_status
546
+ fi
547
+ ;;
548
+ esac
549
+
550
+ export IP_WHITELIST=''
551
+ export AUTH_USER='someone'
552
+ export AUTH_PASSWORD='secret'
553
+
554
+ case "$run_test" in
555
+ ''|[3456789]|10)
556
+ echo ========================================================
557
+ echo TESTING basic auth, no whitelist WITHOUT CATCHALL in test env
558
+ echo ========================================================
559
+ export RAILS_ENV=test RACK_ENV=test
560
+
561
+ case "$run_trest" in
562
+ '')
563
+ stop_server
564
+ cleanup_db
565
+ ;;
566
+ esac
567
+
568
+ start_server
569
+
570
+ expected_status=401
571
+ echo '3: TESTING controller without authentication insists on authentication ...'
572
+ AUTH_USER= $testurl ${host}/${route_prefix}/site $expected_status
573
+
574
+ echo '4: TESTING controller with wrong password insists on authentication ...'
575
+ AUTH_PASSWORD=wrong $testurl ${host}/${route_prefix}/site $expected_status
576
+
577
+ echo '5: TESTING controller with wrong user insists on authentication ...'
578
+ AUTH_USER=wrong $testurl ${host}/${route_prefix}/site $expected_status
579
+
580
+ echo '6: TESTING controller with authentication works ...'
581
+ expected_status=200
582
+ $testurl ${host}/${route_prefix}/site $expected_status
583
+
584
+ if $has_middleware; then
585
+ echo
586
+ echo '7: TESTING middleware without authentication insists on authentication ...'
587
+ expected_status=401
588
+ AUTH_USER= $testurl ${host}/${route_prefix}/middleware $expected_status
589
+
590
+ echo
591
+ echo '8: TESTING middleware with wrong password insists on authentication ...'
592
+ AUTH_PASSWORD=wrong $testurl ${host}/${route_prefix}/middleware $expected_status
593
+
594
+ echo
595
+ echo '9: TESTING middleware with wrong user insists on authentication ...'
596
+ AUTH_USER=wrong $testurl ${host}/${route_prefix}/middleware $expected_status
597
+
598
+ echo
599
+ echo '10: TESTING middleware with authentication works ...'
600
+ expected_status=200
601
+ $testurl ${host}/${route_prefix}/middleware $expected_status
602
+ else
603
+ echo
604
+ echo "Skipped middleware tests as it is not configured..."
605
+ fi
606
+ ;;
607
+ esac
608
+
609
+ unset AUTH_USER
610
+ unset AUTH_PASSWORD
611
+
612
+ case "$run_test" in
613
+ ''|1??)
614
+ echo ========================================================
615
+ echo TESTING WITHOUT CATCHALL, no whitelist or user in test env
616
+ echo ========================================================
617
+ export RAILS_ENV=test RACK_ENV=test
618
+
619
+ case "$run_trest" in
620
+ '')
621
+ stop_server
622
+ cleanup_db
623
+ ;;
624
+ esac
625
+
626
+ start_server
627
+
628
+ # get a static file
629
+
630
+ echo
631
+ echo 'TESTING no catchall route active ...'
632
+ expected_status=404,500,502
633
+ $testurl ${host}/another/url $expected_status
634
+
635
+ echo 'TESTING default route has been overriden ...'
636
+ expected_status=404,500,502
637
+ $testurl ${host}/health_check/site $expected_status
638
+
639
+ common_tests 100
640
+ ;;
641
+ esac
642
+
643
+ export IP_WHITELIST='127.0.0.1'
644
+ export AUTH_USER='someone'
645
+ export AUTH_PASSWORD='secret'
646
+
647
+ case "$run_test" in
648
+ ''|2??)
649
+ echo ========================================================
650
+ echo TESTING WITH CATCHALL with whitelist and user in ${RAILS_ENV2:-production} env
651
+ echo ========================================================
652
+ export RAILS_ENV=${RAILS_ENV2:-production} RACK_ENV=${RAILS_ENV2:-production}
653
+
654
+ case "$run_trest" in
655
+ '')
656
+ stop_server
657
+ cleanup_db
658
+ ;;
659
+ esac
660
+
661
+ date > $catchall_file
662
+
663
+ start_server
664
+
665
+ echo
666
+ echo 'TESTING catchall route active ...'
667
+ $testurl ${host}/another/url 200 text/plain 'catch all route'
668
+ echo
669
+
670
+ common_tests 200
671
+ ;;
672
+ esac
673
+
674
+ rm -f $catchall_file
675
+
676
+ finish PASSED 0
677
+ exit 0
678
+
679
+ # vi: sw=4 ai sm: