-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtest.lua
1220 lines (1043 loc) · 51.7 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Test suite for fullmoon
-- 1. Include fullmoon.lua in ./redbean.com
-- 2. execute `./redbean.com -i test.lua`
-- `test.lua` can also be run by Lua 5.4 interpreter for a subset of tests
local fm = require "fullmoon"
local unpack = table.unpack or unpack
local out = ""
local reqenv = fm.test.reqenv
local routes = fm.test.routes
local headerMap = fm.test.headerMap
local getRequest = fm.test.getRequest
local detectType = fm.test.detectType
local matchRoute = fm.test.matchRoute
local setSession = fm.test.setSession
local getSession = fm.test.getSession
local route2regex = fm.test.route2regex
local handleRequest = fm.test.handleRequest
local matchCondition = fm.test.matchCondition
reqenv.write = function(s) out = out..s end
Write = reqenv.write
local isRedbean = ProgramBrand ~= nil
if not isRedbean then
re = {compile = function(exp) return {search = function(self, path)
local res = {path:match(exp)}
if #res > 0 then table.insert(res, 1, path) end
return unpack(res)
end}
end}
EscapeHtml = function(s)
return (string.gsub(s, "&", "&"):gsub('"', """):gsub("<","<"):gsub(">",">"):gsub("'","'"))
end
FormatHttpDateTime = function(s) return os.date("%a, %d %b %Y %X GMT", s) end
ParseIp = function(str)
local v1, v2, v3, v4 = str:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
return (v1 and (tonumber(v1) << 24) + (tonumber(v2) << 16) + (tonumber(v3) << 8) + tonumber(v4)
or -1) -- match ParseIp logic in redbean
end
reqenv.escapeHtml = EscapeHtml
end
-- provide methods not available outside of Redbean or outside of request handling
SetStatus = function() end
SetHeader = function() end
ServeError = function() end
IsLoopbackIp = function() return true end
GetRemoteAddr = function() end
GetHttpReason = function(status) return tostring(status).." reason" end
Log = function(_, ...) print("#", ...) end
local num, success = 0, 0
local section = ""
local function outformat(s) return type(s) == "string" and ("%q"):format(s):gsub("\n","n") or tostring(s) end
local function is(result, expected, message)
local ok = result == expected
num = num + 1
success = success + (ok and 1 or 0)
local msg = ("%s %d\t%s%s%s"):format((ok and "ok" or "not ok"), num,
(section > "" and section.." " or ""), message or "",
ok and "" or " at line "..debug.getinfo(2).currentline
)
if not ok then
msg = msg .. ("\n\treceived: %s\n\texpected: %s"):format(outformat(result), outformat(expected))
end
print(msg)
out = ""
end
local function rt(opt)
local saved = {}
for f, v in pairs(opt) do
if type(f) == "string" then saved[f], _G[f] = _G[f], v end
end
for _, test in ipairs(opt) do test() end
for f, v in pairs(saved) do _G[f] = v end
end
local function done() print(("1..%d # Passed %d/%d"):format(num, success, num)) end
--[[-- misc tests --]]--
section = "(misc)"
local X = fm.reg2x{"FIRST", "SECOND", "THIRD"}
is(X.THIRD, 4, "reg2x multiplies")
local P = fm.reg1p{"FIRST", "SECOND", "THIRD"}
is(P.THIRD, 3, "reg1p adds")
--[[-- template engine tests --]]--
section = "(template)"
local tmpl1 = "tmpl1"
fm.setTemplate(tmpl1, "Hello, World!")
fm.render(tmpl1)
is(out, "Hello, World!", "text rendering")
fm.setTemplate(tmpl1, "Hello, {%& title %}!")
fm.render(tmpl1, {title = "World"})
is(out, "Hello, World!", "text with parameter")
fm.setTemplate(tmpl1, "Hello, {%& title -- & comment %}!")
fm.render(tmpl1, {title = "World"})
is(out, "Hello, World!", "text with parameter and a line comment")
fm.render(tmpl1, {title = "World&"})
is(out, "Hello, World&!", "text with encoded parameter")
fm.render(tmpl1, {})
is(out, "Hello, !", "text with missing enscaped parameter")
fm.setTemplate(tmpl1, "Hello, {% for i, v in ipairs({3,2,1}) do -- comment %}-{%= v %}{% end %}")
fm.render(tmpl1)
is(out, "Hello, -3-2-1", "Lua code with comments at the end")
fm.setTemplate(tmpl1, [[
Hello{% if counter == 1 then
-- if counter is not one, do something
if counter ~= 1 then %}World{% end
end %}]])
fm.render(tmpl1)
is(out, "Hello", "Lua code with comments in code")
fm.setTemplate(tmpl1, [[
Hello{% if counter == 1 then
--[=[ if counter is not one, do something
end ]=] if counter ~= 1 then %}World{% end
end %}]])
fm.render(tmpl1)
is(out, "Hello", "Lua code with multi-line comments")
local tmpl2 = "tmpl2"
fm.setTemplate(tmpl2, [[{a: "{%= title %}"}]])
fm.render(tmpl2)
is(out, '{a: ""}', "JSON with missing non-escaped parameter")
fm.setTemplateVar('if-nil', function() error"missing value" end)
local ok, err = pcall(fm.render, tmpl2)
is(err:find("missing value") ~= nil, true, "throw an error on undefined value")
fm.setTemplateVar('if-nil', nil)
do
fm.setTemplate(tmpl2, [[{a: "{%= title %}"}]], {title = "set when adding template"})
fm.render(tmpl2)
is(out, '{a: "set when adding template"}', "JSON with value set when adding template")
fm.render(tmpl2, {title = "set from render"})
is(out, '{a: "set from render"}', "JSON with a passed value set at rendering")
fm.render(tmpl2)
is(out, '{a: "set when adding template"}',
"JSON with value set when adding template (after another assignment)")
fm.setTemplate(tmpl2, [[{% local title = "set from template" %}{a: "{%= title %}"}]])
fm.render(tmpl2)
is(out, '{a: "set from template"}', "JSON with value set from template")
fm.setTemplateVar("num", 123)
fm.setTemplateVar("fun", function() return "abc" end)
fm.setTemplate(tmpl2, "{%= vars.num %}{%= vars.fun() %}")
fm.render(tmpl2)
is(out, '123abc', "templates vars are set with numbers and functions")
end
fm.setTemplate(tmpl2, [[{a: "{%= title %}"}]], {title = "set when adding"})
fm.setTemplate(tmpl1, "Hello, {% render('tmpl2') %}")
fm.render(tmpl1)
is(out, [[Hello, {a: "set when adding"}]], "`include` other template with a local value")
fm.setTemplate(tmpl1, [[Hello, {% render('tmpl2', {title = "value"}) %}]])
fm.render(tmpl1)
is(out, [[Hello, {a: "value"}]], "`include` other template with passed value set at rendering")
fm.setTemplate(tmpl1, "Hello, World!\n{% something.missing() %}")
local ok, err = pcall(fm.render, tmpl1)
is(err ~= nil, true, "report Lua error in template")
is(err:match('tmpl1:'), 'tmpl1:', "error references original template name")
is(err:match(':2: '), ':2: ', "error references expected line number")
fm.setTemplate(tmpl1, "{%if title then%}full{%else%}empty{%end%}")
fm.render(tmpl1)
is(out, "empty", "`if` checks for an empty parameter")
fm.render(tmpl1, {title = ""})
is(out, "full", "`if` checks for a non-empty parameter")
fm.setTemplate(tmpl1, "Hello, {% main() %}World!", {main = function() end})
fm.render(tmpl1)
is(out, [[Hello, World!]], "used function can be passed when adding template")
rt({
GetZipPaths = function() return {"/views/hello1.fmt", "/views/hello2.fmg"} end,
LoadAsset = function(s) return ({
["/views/hello1.fmt"] = "Hello, {%& title %}",
["/views/hello2.fmg"] = [[{ h1{"Hello, ", title}, p{include"hello1"} }]],
["/views/hello3.aaa"] = "Hello",
})[s] end,
function()
local tmpls = fm.setTemplate({"/views/", fmt = "fmt", fmg = "fmg"}, nil, {title = "value 0"})
is(tmpls["hello1"], true, "setTemplate for a folder returns list of templates 1/2")
is(tmpls["hello2"], true, "setTemplate for a folder returns list of templates 2/2")
fm.render("hello1")
is(out, [[Hello, value 0]], "rendered default template loaded from an asset with a default value")
fm.render("hello1", {title = "value 1"})
is(out, [[Hello, value 1]], "rendered default template loaded from an asset")
fm.render("hello2", {title = "value 2"})
is(out, [[<h1>Hello, value 2</h1><p>Hello, value 0</p>]],
"rendered html generator template loaded from an asset")
local _, err = pcall(fm.render, "hello3")
is(err:match("unknown template name"), "unknown template name", "only specified extensions loaded from an asset")
fm.setTemplate({"/", fmt = "fmt", fmg = "fmg"})
fm.render("views/hello1", {title = "value 1"})
is(out, [[Hello, value 1]], "rendered default template loaded from an asset with folder name")
fm.render("views/hello2", {title = "value 2"})
is(out, [[<h1>Hello, value 2</h1><p>Hello, value 0</p>]],
"rendered html generator template loaded from an asset with folder name")
end,
})
--[[-- template engine block tests --]]--
section = "(blocks)"
local function tel(s) return s:gsub("\n+","\n"):gsub("^\n","") end -- trim empty lines
fm.setTemplate("main", [[
{% function block.header() %}Hi from main header.
{% function block.title() %}Title.{% end %}{%= block.title() %}
{% end %}{%= block.header and block.header() %}
{% function block.body() %}Hi from main body.{% end %}{%= block.body() %}
{%= block.footer and block.footer() %}
]])
fm.render("main")
is(tel(out), [[
Hi from main header.
Title.
Hi from main body.
]], "block template renders with sub-blocks and optional blocks")
fm.setTemplate("section", [[
{% function block.header() %}Hi from section header.{% end %}
{% function block.body() %}{%= block.main.body() %}Hi from section body.{% end %}
{% function block.footer() %}Hi from section footer.{% end %}
{% render "main" %}
]])
fm.render("section")
is(tel(out), [[
Hi from section header.
Hi from main body.Hi from section body.
Hi from section footer.
]], "block template renders with an inherited template block")
fm.setTemplate("subsection1", [[
{% function block.title() %}Subsection1 Title.{% end %}
{% function block.header() %}{%= block.main.header() %}Hi from subsection1 header.{% end %}
{% function block.body() %}Hi from subsection1 body.{% end %}
{% render "section" %}
{% function block.body() %}Hi from another subsection1 body.{% end %}
{% render "section" %}
]])
fm.render("subsection1")
is(tel(out), [[
Hi from main header.
Subsection1 Title.
Hi from subsection1 header.
Hi from subsection1 body.
Hi from section footer.
Hi from main header.
Subsection1 Title.
Hi from subsection1 header.
Hi from another subsection1 body.
Hi from section footer.
]], "block template renders with multiple inherited templates")
fm.setTemplate("subsection2", [[
{% function block.title() %}Subsection2 Title{% end %}
{% function block.body() %}{%= block.main.body() %} Hi from subsection2 body.{% end %}
{% render "section" %}
]])
fm.render("subsection2")
is(tel(out), [[
Hi from section header.
Hi from main body. Hi from subsection2 body.
Hi from section footer.
]], "block template renders with a reference to a parent template block")
--[[-- routing engine tests --]]--
section = "(routing)"
is(route2regex("/foo/bar"), "^/foo/bar$", "simple route")
is(route2regex("/foo/:bar"), "^/foo/([^/]+)$", "route with a named parameter")
is(route2regex("/foo/:bar_none/"), "^/foo/([^/]+)/$", "route with a named parameter with underscore")
is(route2regex("/foo(/:bar)"), "^/foo(/([^/]+))?$", "route with a named optional parameter")
is(route2regex("/foo/:bar[%d]"), "^/foo/([0-9]+)$", "route with a named parameter and a customer set")
is(route2regex("/foo/:bar[^/]more"), "^/foo/([^/]+)more$", "route with a named parameter and some text")
is(route2regex("/foo/:bar[^%d]"), "^/foo/([^0-9]+)$", "route with a named parameter and not-in-set")
is(route2regex("/foo/:bar[]5]"), "^/foo/([]5]+)$", "route with a starting closing bracket in a set")
is(route2regex("/foo/:bar[]5].:some"), "^/foo/([]5]+)\\.([^/]+)$", "route with a closing bracket in a set followed by another parameter")
is(route2regex("/foo/:bar[^]5]"), "^/foo/([^]5]+)$", "route with a starting closing bracket in not-in-set")
is(route2regex("/foo/:bar[1%]2%-%+]"), "^/foo/([1[.].]2[.-.]+]+)$", "route with a closed bracked")
is(route2regex("/foo(/:bar(/:more))"), "^/foo(/([^/]+)(/([^/]+))?)?$", "route with two named optional parameters")
is(route2regex("/foo(/:bar)/*.zip"), "^/foo(/([^/]+))?/(.*)\\.zip$", "route with an optional parameter and a splat")
is(route2regex("/foo(/:bar)/*splat.zip"), "^/foo(/([^/]+))?/(.*)\\.zip$", "route with an optional parameter and a named splat")
is(select(2, pcall(route2regex, "/foo/:bar[%o]")):match(": (.+)"), "Invalid escape sequence %o",
"route with invalid sequence is reported")
local _, params = route2regex("foo(/:bar)/*.zip")
is(params[1], false, "'foo(/:bar)/*.zip' - parameter 1 is optional")
is(params[2], "bar", "'foo(/:bar)/*.zip' - parameter 2 is 'bar'")
is(params[3], "splat", "'foo(/:bar)/*.zip' - parameter 3 is 'splat'")
local handler = function() end
fm.setRoute("/foo/bar", handler)
local index = routes["/foo/bar"]
is(routes[index].handler, handler, "assign handler to a regular route")
do
local _, err = pcall(fm.setRoute, "/foo/bar", nil)
is(err and err:find("bad argument #2"), 1, "route with `nil` handler is reported")
_, err = pcall(fm.setRoute, {})
is(err and err:find("(one or more routes expected)") > 0, true, "route with no path is reported")
_, err = pcall(fm.setRoute, {"/foo/bar", name = {regex = "{}"}})
is(err and err:find("(valid regex expected for 'name')") > 0, true, "route with invalid regex is reported")
end
fm.setRoute("/foo/bar")
is(routes["/foo/bar"], index, "route with the same name is not added")
is(routes[routes["/foo/bar"]].handler, nil, "assign no handler to a static route")
fm.setRoute(fm.PUT"/foo/bar")
is(routes["/foo/bar"], index+1, "route with the same name and different method is added")
local route = "/foo(/:bar(/:more[%d]))(.:ext)/*.zip"
fm.setRoute(route, function(r)
is(r.params.bar, "some", "default optional parameter matches (1/4)")
is(r.params.more, "123", "customer set matches (2/4)")
is(r.params.ext, "myext", "optional extension matches (3/4)")
is(r.params.splat, "mo/re", "splat matches path separators (4/4)")
end)
matchRoute("/foo/some/123.myext/mo/re.zip", {params = {}})
fm.setRoute(route, function(r)
is(r.params.bar, "some.myext", "default optional parameter matches dots (1/4)")
is(not r.params.more, true, "missing optional parameter gets `false` value (2/4)")
is(not r.params.ext, true, "missing optional parameter gets `false` value (3/4)")
is(r.params.splat, "more", "splat matches (4/4)")
end)
matchRoute("/foo/some.myext/more.zip", {params = {}})
if isRedbean then
local called = false
fm.setRoute(route, function() called = true end)
matchRoute("/foo/some.myext/more", {params = {}})
is(called, false, "non-matching route handler is not called")
end
do
local rp = RoutePath
local gm = GetAssetMode
GetAssetMode = function() return nil end
local status
SetStatus = function(s) status = s end
fm.setRoute("/*path", "/asset/*path")
handleRequest("/nofail") -- GetAssetMode returns `nil`
is(status, 404, "Hanler doesn't fail on missing resource")
GetAssetMode = function(m) return m:find("/$") and 2^14 or 2^15 end
local path
RoutePath = function(s) path = s; return s ~= nil end
fm.setRoute("/*path", "/asset/*path")
handleRequest("/")
is(path, nil, "Directory is not returned for empty parameter with internal routing")
fm.setRoute("/*path", "/*path.lua")
-- confirm that forwarded existing path is returned
RoutePath = function(s) path = s; return s ~= nil end
handleRequest("/foo/some.myext/more")
is(path, "/foo/some.myext/more.lua", "Forwarded path is returned for internal routing")
-- confirm that 404 is returned if nothing is matched
RoutePath = function() return false end
handleRequest("/foo/some.myext/more")
is(status, 404, "No match in forwarded path sets 404")
fm.setRoute("/*path") -- remove the path from subsequent matching
GetAssetMode = gm
RoutePath = rp
end
is(headerMap.CacheControl, "Cache-Control", "Cache-Control header is mapped")
is(headerMap.IfRange, "If-Range", "If-Range header is mapped")
is(headerMap.Host, "Host", "Host header is mapped")
is(headerMap.RetryAfter, "Retry-After", "Retry-After header is mapped")
is(detectType(" <"), "text/html", "auto-detect html content")
is(detectType("{"), "application/json", "auto-detect json content")
is(detectType("abc"), "text/plain", "auto-detect text content")
section = "(matchAttr)"
is(matchCondition("GET", "GET"), true, "attribute matches based on simple value")
is(matchCondition("GET", {GET = true}), true, "attribute matches based on simple value in condition table")
is(matchCondition("GET", {}), false, "non-existing attribute doesn't match")
is(matchCondition(nil, "GET"), false, "`nil` value doesn't match a simple value")
is(matchCondition(nil, {GET = true}), true, "`nil` value matches a value in condition table")
is(matchCondition("GET", {GET = true, POST = true}), true,
"attribute matches based on simple value in condition table (among other values)")
is(matchCondition("text/html; charset=utf-8", {regex = re.compile("text/")}), true, "attribute matches based on regex")
is(matchCondition("text/html; charset=utf-8", {pattern = "%f[%w]text/html%f[%W]"}), true, "attribute matches based on Lua pattern")
is(matchCondition("GET", "POST"), false, "attribute doesn't match another simple value")
is(matchCondition("GET", {POST = true}), false, "attribute doesn't match if not present in condition table")
is(matchCondition("text/html; charset=utf-8", {regex = re.compile("text/plain")}), false, "attribute doesn't match another regex")
is(matchCondition(nil, function() return true end), true, "`nil` value matches function that return `true`")
is(matchCondition(nil, function() return false end), false, "`nil` value doesn't match function that return `false`")
is(matchCondition("GET", function() return true end), true, "attribute matches function that return `true`")
is(matchCondition("GET", function() return false end), false, "attribute doesn't match function that return `false`")
is(matchCondition("GET", {function() return true end}), true,
"attribute matches function in condition table that return `true`")
is(matchCondition("GET", {function() return false end}), false,
"attribute doesn't match function in condition table that return `false`")
fm.setRoute({"acceptencoding", AcceptEncoding = "gzip"})
is(routes[routes.acceptencoding].options.AcceptEncoding.pattern, "%f[%w]gzip%f[%W]", "known header generates pattern-based match")
is(rawget(fm, "GET"), nil, "GET doesn't exist before first use")
local groute = fm.GET"route"
is(rawget(fm, "GET"), fm.GET, "GET is cached after first use")
is(type(groute), "table", "GET method returns condition table")
is(groute.method, "GET", "GET method sets method")
is(groute[1], "route", "GET method sets route")
local proute = fm.POST{"route", more = "parameters"}
is(type(proute), "table", "POST method on a table returns condition table")
is(proute.method, "POST", "POST method on a table sets method")
is(proute.more, "parameters", "POST method on a table preserves existing conditions")
--[[-- schedule engine tests --]]--
section = "(schedule)"
do local res={}
OnServerHeartbeat = function() res.hook = true end
fm.setSchedule("* * * * *", function() res.everymin = true end, {sameProc = true})
fm.setSchedule{"*/2 * * * *", function() res.everyothermin = true end, sameProc = true}
fm.setHook("OnServerHeartbeat.testhook", function() res.hookcalls = true end)
GetTime = function() return 1*60 end
OnServerHeartbeat()
is(res.everymin, true, "* is called on minute 1")
is(res.everyothermin, nil, "*/2 is not called on minute 1")
is(res.hook, true, "'original' hook is called as well")
is(res.hookcalls, true, "setHook sets hook that is then called")
res={}
GetTime = function() return 2*60 end
fm.setHook("OnServerHeartbeat.testhook") -- remove hook
OnServerHeartbeat()
is(res.everymin, true, "* is called on minute 2")
is(res.everyothermin, true, "*/2 is called on minute 2")
is(res.hookcalls, nil, "setHook removes hook that is then not called")
end
--[[-- request tests --]]--
section = "(request)"
-- headers processing (retrieve and set)
GetHeader = function() return "text/plain" end
GetPath = function() return "/" end
EncodeJson = function() return "" end
handleRequest("")
local r = getRequest()
is(r.headers.ContentType, "text/plain", "ContentType header retrieved")
do local header, value
SetHeader = function(h,v) header, value = h, v end
fm.setRoute("/", function(r) r.headers.ContentLength = 42; return true end)
handleRequest()
is(value, nil, "Content-Length header is not allowed to be set")
fm.setRoute("/", function(r) r.headers.ContentType = "text/plain"; return true end)
handleRequest()
is(header, "Content-Type", "Header is remaped to its full name")
is(value, "text/plain", "Header is set to its correct value")
fm.setRoute("/", function(r) r.headers.RetryAfter = 5; return true end)
handleRequest()
is(value, "5", "Header with numeric value is allowed to be set")
fm.setTemplate(tmpl2, function() return "text", {foo = "bar"} end)
fm.setRoute("/", fm.serveContent(tmpl2))
handleRequest()
is(out, 'text', "template returns text directly")
is(header, 'foo', "template returns set of headers (name)")
is(value, 'bar', "template returns set of headers (value)")
fm.setRoute("/", fm.serveContent("sse", {data = "Line 1\nLine 2"}))
handleRequest()
is(out, "data: Line 1\ndata: Line 2\n\n", "SSE template with data element")
fm.setTemplate(tmpl2, {[[{a: "{%= title %}"}]], ContentType = "application/json"})
fm.setRoute("/", fm.serveContent(tmpl2))
handleRequest()
is(out, '{a: ""}', "JSON template with options and empty local value")
is(header, 'Content-Type', "custom template with options sets Content-Type")
is(value, 'application/json', "custom template with options sets expected Content-Type")
fm.setRoute("/", function() return fm.serveContent("json", {}) end)
handleRequest()
is(header, 'Content-Type', "preset template with options sets Content-Type")
is(value, 'application/json', "preset template with options sets expected Content-Type")
fm.setRoute("/", fm.serveContent("fmg",
{{"h1", "Title"}, {"div", a = 1, {"p", checked = true, "text"}}}))
handleRequest()
is(out, [[<h1>Title</h1><div a="1"><p checked="checked">text</p></div>]],
"preset template with html generation")
fm.setTemplate(tmpl1, {type = "fmg", [[{
doctype, body{h1{title}, "<!>", raw"<!-- -->"},
div{hx={post="url"}},
{"script", "a<b"}, p"text",
table{style=raw"b<a", tr{td"3", td"4", td{table.concat({1,2}, "")}}},
table{"more"}, p{"1"..notitle}, br,
each{function(v) return p{v} end, {3,2,1}},
{"div", a = "\"1'", p{"text+", include{"tmpl2", {title = "T"}}}},
{"div", {b = 2}, "text"},
{"iframe", function() return raw{p{1},p{2},p{3}} end},
}]]})
fm.setRoute("/", fm.serveContent(tmpl1, {title = "post title"}))
handleRequest()
is(out, "<!doctype html><body><h1>post title</h1><!><!-- --></body>"
.."<div hx-post=\"url\"></div><script>a<b</script><p>text</p>"
.."<table style=\"b<a\"><tr><td>3</td><td>4</td><td>12</td></tr></table>"
.."<table>more</table><p>1</p><br/><p>3</p><p>2</p><p>1</p>"
.."<div a=\""1'\"><p>text+{a: \"T\"}</p></div>"
.."<div b=\"2\">text</div>"
.."<iframe><p>1</p><p>2</p><p>3</p></iframe>",
"preset template with html generation")
fm.setTemplate(tmpl1, fm.serveContent("fmg", {{"h1", "Title"}}))
fm.setRoute("/", fm.serveContent(tmpl1))
handleRequest()
is(out, "<h1>Title</h1>")
fm.setTemplate(tmpl1, {type = "fmg", [[{{"h1", title}}]]})
fm.setRoute("/", fm.serveContent(tmpl1, {title = "post title"}))
handleRequest()
is(out, "<h1>post title</h1>")
for k,v in pairs{text = "text/plain", ["{}"] = "application/json", ["<br>"] = "text/html"} do
fm.setRoute("/", function() return k end)
handleRequest()
is(value, v, v.." value is auto-detected after being returned")
fm.setRoute("/", fm.serveResponse(200, k))
handleRequest()
is(value, v, v.." value is auto-detected after serveResponse")
end
fm.setRoute("/", fm.serveResponse(200, {ContentType = "text/html"}, "text"))
handleRequest()
is(value, "text/html", "explicitly set content-type takes precedence over auto-detected one")
fm.setRoute("/", fm.serveResponse("response text"))
handleRequest()
is(out, "response text", "serve response with text only")
fm.setRoute("/", function() error(fm.serveResponse("error response")) end)
handleRequest()
is(out, "error response", "serve response wrapped into an error")
fm.setTemplate(tmpl2, {[[no content-type]]})
fm.setRoute("/", fm.serveContent(tmpl2))
value = nil
handleRequest()
is(value, nil, "template with no content-type doesn't set content type")
local routeNum = #routes
fm.setRoute({"/route1", "/route2", method = "GET", routeName = "routeOne"}, fm.serve404)
is(routes["/route1"], routeNum+1, "mutiple routes can be added 1/2")
is(routes["/route2"], routeNum+2, "mutiple routes can be added 2/2")
is(routes.routeOne, routes["/route1"], "first route (our of several) gets name assigned")
end
-- cookie processing (retrieve and set)
GetCookie = function() return "cookie value" end
is(r.cookies.MyCookie, "cookie value", "Cookie value retrieved")
do local cookie, value, options
SetCookie = function(c,v,o)
cookie, value, options = c, v, {}
for k,v in pairs(o) do options[k] = v end
end
fm.setRoute("/", function(r) r.cookies.MyCookie = "new value"; return true end)
handleRequest()
is(cookie, "MyCookie", "Cookie is processed when set")
is(value, "new value", "Cookie value is set")
fm.setRoute("/", function(r) r.cookies.MyCookie = {"new value", secure = true}; return true end)
handleRequest()
is(value, "new value", "Cookie value is set (even with options)")
is(options.secure, true, "Cookie option is set")
fm.setRoute("/", function(r) r.cookies.MyCookie = false; return true end)
handleRequest()
is(cookie, "MyCookie", "Deleted cookie is processed when set to `false` (value)")
is(value, "", "Deleted cookie gets empty value (value)")
is(options.maxage, 0, "Deleted cookie gets MaxAge set to 0 (value)")
fm.setRoute("/", function(r) r.cookies.MyCookie = {false, secure = true}; return true end)
handleRequest()
is(value, "", "Deleted cookie gets empty value (table)")
is(options.maxage, 0, "Deleted cookie gets MaxAge set to 0 (table)")
is(options.secure, true, "Deleted cookie gets option set (table)")
if isRedbean then
fm.sessionOptions.secret = ""
setSession({a=""})
is(cookie, "fullmoon_session")
is(value, "e2E9IiJ9.lua.SHA256.AYDGTB6O7W4ohlbpRtgvY2NiDFUdS1efkd0ZpROoL+Q=")
GetCookie = function(c) return value end
fm.sessionOptions.secret = false
local session = getSession()
is(session.a, "", "getSession works with secret set to false")
end
end
fm.setRoute("/", function(r)
is(type(r.escapeHtml), "function", "escapeHtml function is available")
is(type(r.escapePath), "function", "escapePath function is available")
is(type(r.formatIp), "function", "formatIp function is available")
is(type(r.formatHttpDateTime), "function", "formatHttpDateTime function is available")
end)
if isRedbean then handleRequest() end
route = "/foo(/:bar(/:more[%d]))(.:ext)/*.zip"
do local rname
fm.setRoute({"/something/else", routeName = "foobar"})
local index = routes["foobar"]
fm.setRoute({route, routeName = "foobar"})
is(routes["foobar"] ~= index, true, "different route with the same routeName is registered anew")
is(routes["/something/else"], index, "overwritten route is still present")
end
is(routes.foobar, routes[route], "route name can be used as alias")
is(routes[routes.foobar].routeName, nil, "route name is removed from conditions")
--[[-- makePath tests --]]--
section = "(makePath)"
_, err = pcall(fm.makePath, route)
is(err:match("missing required parameter splat"), "missing required parameter splat", "required splat is checked")
_, err = pcall(fm.makePath, "/foo/:bar")
is(err:match("missing required parameter bar"), "missing required parameter bar", "required parameter is checked")
is(fm.makePath(route, {splat = "name"}), "/foo/name.zip", "required splat is filled in")
is(fm.makePath("/assets/*asset", {asset = false}), "/assets/", "empty splat is filled in")
is(fm.makePath("/foo/*more/*splat.zip", {more = "some", splat = "name"}), "/foo/some/name.zip",
"multiple required splats are filled in when specified")
is(fm.makePath("/foo/*more/*.zip", {more = "some", splat = "name"}), "/foo/some/name.zip",
"multiple required splats are filled in when under-specified")
is(fm.makePath("foobar", {splat = "name"}),
fm.makePath(route, {splat = "name"}),
"`makePath` by name and route produce same results")
is(fm.makePath(route, {splat = "name", more = "foo"}), "/foo/name.zip",
"missing optional parameter inside another missing parameter is removed")
is(fm.makePath(route, {splat = "name", bar = "some"}), "/foo/some/name.zip", "single optional parameter is filled in")
is(fm.makePath(route, {splat = "name", bar = "some", more = 12, ext = "json"}), "/foo/some/12.json/name.zip",
"multiple optional parameters are filled in")
is(fm.makePath("/foo/:bar", {bar = "more"}), "/foo/more", "unregistered route is handled")
is(fm.makePath("/foo(/*.zip)"), "/foo", "optional splat is not required")
is(fm.makePath("/foo(/*.zip)", {splat = "more"}), "/foo/more.zip", "optional splat is filled in")
is(fm.makePath("/foo"), "/foo", "relative route generates absolute path")
is(fm.makePath("/foo"), "/foo", "absolute route generates absolute path")
is(fm.makePath("http://some.website.com:8080/:foo?param=:bar", {foo = "some", bar = 123}),
"http://some.website.com:8080/some?param=123", "external/static path")
-- test using makePath from a template
fm.setTemplate(tmpl1, "Hello, {%= makePath('foobar', {splat = 'name'}) %}")
fm.render(tmpl1)
is(out, [[Hello, /foo/name.zip]], "`makePath` inside template")
--[[-- makeUrl tests --]]--
section = "(makeUrl)"
if isRedbean then
local url = "http://domain.com/path/more/name.ext?param1=val1¶m2=val2#frag"
GetUrl = function() return url end
is(fm.makeUrl(), url, "makeUrl produces original url")
is(fm.makeUrl({path = "/short"}), url:gsub("/path/more/name.ext", "/short"), "makeUrl uses path")
is(fm.makeUrl({scheme = "https"}), url:gsub("http:", "https:"), "makeUrl uses scheme")
is(fm.makeUrl({fragment = "newfrag"}), url:gsub("#frag", "#newfrag"), "makeUrl uses fragment")
is(fm.makeUrl({fragment = false}), url:gsub("#frag", ""), "makeUrl removes fragment")
is(fm.makeUrl("", {path = "/path", params = {{"a", 1}, {"b", 2}, {"c"}}}), "/path?a=1&b=2&c",
"makeUrl generates path and query string")
is(fm.makeUrl("", {params = {a = 1, b = "", c = true, ["d[1][name]"] = "file" }}),
"?a=1&b=&c&d%5B1%5D%5Bname%5D=file", "makeUrl generates query string from hash table")
-- test using makeUrl from a template
-- confirm that the URL is both url (%xx) and html (&...) escaped
fm.setTemplate(tmpl1, "Hello, {%& makeUrl({path = '<some&/path>'}) %}")
fm.render(tmpl1)
is(out, [[Hello, http://domain.com/%3Csome&/path%3E?param1=val1&param2=val2#frag]],
"`makeUrl` inside template")
end
--[[-- multipart tests --]]--
section = "(multipart)"
local ct1 = "multipart/mixed; boundary=41111539122868; start=photo2"
local m1 = ([[
preamble
--41111539122868
Content-Disposition: form-data;
name="files[]";
filename="photo1.jpg"
Content-Type: image/jpeg
SomeBinaryData
--41111539122868
Content-Disposition: form-data; name="files[]"; filename="photo2.jpg"
Content-Type: image/jpeg
content-ID: photo2
MoreBinaryData
--41111539122868
Content-Disposition: form-data;
name="simple"
Simple value
--41111539122868
No header
--41111539122868--
epilogue
]]):gsub("\r?\n", "\r\n")
local r1 = fm.parseMultipart(m1, ct1)
is(r1[1].filename, "photo2.jpg", "multipart message shows 'start' content-id first")
is(r1.simple.data, "Simple value", "multipart message handles simple value")
is(r1[4].data, "No header", "multipart message returns value with no header")
is(#r1, 4, "multipart message reports number of parts")
HasParam = function(p) return p == "foo" end
GetParam = function(p) return p == "foo" and "bar" or nil end
GetBody = function() return m1 end
GetHeader = function(h) return h == "Content-Type" and ct1 or nil end
fm.setTemplate(tmpl1, "-{%= table.concat({a[1].data, a[2].data, b, c, n[1], n[2], d}, '-') %}-")
local pnum = 0
-- match multipart "simple" parameter to its value as a filter
fm.setRoute({"/params/multi", simple = "Simple value"}, function(r)
local none = r.params.none -- access non-existing parameter
local foo = r.params.foo -- access existing, but not multipart parameter
pnum = #r.params.multipart
local fnames = {}
for i, v in ipairs(r.params.files) do
table.insert(fnames, v.filename or "?")
end
none = r.params.none -- access non-existing parameter again
return fm.render(tmpl1,
{a = r.params["files[]"], b = r.params.simple, c = r.params[1], d = foo, n = fnames})
end)
handleRequest("/params/multi")
is(out, "-MoreBinaryData-SomeBinaryData-Simple value-MoreBinaryData-photo2.jpg-photo1.jpg-bar-",
"multipart parameters with [] are returned as array")
is(pnum, 4, "multipart returns all multipart components")
local ct2 = "multipart/form-data; boundary=AaB03x"
local m2 = ([[
--AaB03x
content-disposition: form-data; name="field1"
Joe Blow
--AaB03x
content-disposition: form-data; name="pics"
Content-type: multipart/mixed; boundary=BbC04y
--BbC04y
Content-disposition: attachment; filename="file1.txt"
Content-Type: text/plain
...contents of file1.txt...
--BbC04y
Content-disposition: attachment; filename="file2.gif"
Content-type: image/gif
Content-Transfer-Encoding: binary
...contents of file2.gif...
--BbC04y--
--AaB03x--
]]):gsub("\r?\n", "\r\n")
local r2 = fm.parseMultipart(m2, ct2)
is(#r2, 2, "multipart recursive message reports number of parts")
is(r2[1].data, "Joe Blow", "multipart recursive message shows parts in the original order")
is(#(r2[2].data), 2, "multipart recursive message returns number of sub-parts")
is(r2[2].data[1].filename, "file1.txt", "multipart recursive message shows parts in the original order")
is(r2[2].data.boundary, "BbC04y", "multipart recursive message returns enclosed boundary")
--[[-- serve* tests --]]--
local status
SetStatus = function(s) status = s end
local url = "/status"
GetPath = function() return url end
section = "(serveError)"
fm.setRoute("/status", fm.serveError(403, "Access forbidden"))
fm.setTemplate("403", "Server Error: {%& reason %}")
local error403 = routes[routes["/status"]].handler()
is(out, "Server Error: Access forbidden", "serveError used as a route handler")
is(error403, "", "serveError finds registered template")
fm.setRoute("/status", fm.serveError(405))
handleRequest()
is(status, 405, "direct serveError(405) sets expected status")
fm.setRoute("/status", function() return fm.serveError(402) end)
handleRequest()
is(status, 402, "handler calling serveError(402) sets expected status")
section = "(serveResponse)"
is(rawget(fm, "serve401"), nil, "serve401 doesn't exist before first use")
fm.setRoute("/status", fm.serve401)
handleRequest()
is(status, 401, "direct serve401 sets expected status")
is(rawget(fm, "serve401"), fm.serve401, "serve401 is cached after first use")
GetParam = function(key) return ({foo=123, bar=456})[key] end
HasParam = function() return true end
GetHeader = function(h)
if h == "Content-Type" then return "text/plain.with-special+chars" end
end
GetMethod = function() return "GET" end
fm.setRoute({"/statusspecial", ContentType = "text/plain.with-special+chars"}, fm.serve204)
handleRequest("/statusspecial")
is(status, 204, "ContentType header matched with special characters")
fm.setRoute({"/statuserr", method = {"SOME", otherwise = 404}}, fm.serve402)
handleRequest("/statuserr")
is(status, 404, "not matched condition triggers configured otherwise processing")
fm.setRoute({"/statuserr", method = {"SOME", otherwise = fm.serveResponse(405)}}, fm.serve402)
handleRequest("/statuserr")
is(status, 405, "not matched condition triggers dynamic otherwise processing")
fm.setRoute({"/statusoth", method = "GET", otherwise = 404}, fm.serve402)
handleRequest("/statusoth")
is(status, 402, "`otherwise` value is not checked as filter value")
GetMethod = function() return "HEAD" end
fm.setRoute({"/statusget", method = {"GET", otherwise = 405}}, fm.serve402)
handleRequest("/statusget")
is(status, 402, "HEAD is accepted when GET is allowed")
fm.setRoute({"/statusnohead", method = {"GET", HEAD = false, otherwise = 405}}, fm.serve402)
handleRequest("/statusnohead")
is(status, 405, "HEAD is not accepted when is explicitly disallowed")
is(getRequest().headers.Allow, "GET, OPTIONS", "Allow header is returned along with 405 status")
GetMethod = function() return "PUT" end
fm.setRoute({"/statusput", method = "DELETE"}, fm.serve402)
fm.setRoute({"/statusput", method = {"GET", "POST", otherwise = 405}}, fm.serve402)
handleRequest("/statusput")
is(getRequest().headers.Allow, "DELETE, GET, HEAD, POST, OPTIONS",
"Allow header includes methods from all matched routes")
GetMethod = function() return "PUT" end
fm.setRoute({"/statusput", method = "DELETE"}) -- disable this route
fm.setRoute({"/statusput", method = {"GET", "POST", otherwise = 405}}, fm.serve402)
handleRequest("/statusput")
is(getRequest().headers.Allow, "GET, HEAD, POST, OPTIONS", "Allow header includes HEAD when 405 status is returned")
section = "(serveContent)"
fm.setTemplate(tmpl1, "Hello, {%& title %}!")
fm.setRoute("/content", fm.serveContent(tmpl1, {title = "World"}))
routes[routes["/content"]].handler()
is(out, "Hello, World!", "serveContent used as a route handler")
do local status, loc
section = "(serveRedirect)"
ServeRedirect = function(s, l) status, loc = s, l end
fm.setRoute("/content", fm.serveRedirect())
routes[routes["/content"]].handler()
is(status, 303, "serveRedirect without parameters sets 303 status")
is(loc, GetPath(), "serveRedirect without parameters uses current path as location")
fm.setRoute("/content", fm.serveRedirect("link"))
routes[routes["/content"]].handler()
is(status, 307, "serveRedirect without status sets 307 status when location is set")
is(loc, "link", "serveRedirect with one string parameter sets it as location")
fm.setRoute("/content", fm.serveRedirect(302))
routes[routes["/content"]].handler()
is(status, 302, "serveRedirect with one numeric parameter sets it as status")
is(loc, GetPath(), "serveRedirect without location uses current path")
fm.setRoute("/content", fm.serveRedirect(307, "link"))
routes[routes["/content"]].handler()
is(status, 307, "serveRedirect with two parameters in the corect order sets status")
is(loc, "link", "serveRedirect with two parameters in the correct order sets location")
-- this order of parameters is obsolete, but is still supported
fm.setRoute("/content", fm.serveRedirect("link", 302))
routes[routes["/content"]].handler()
is(status, 302, "serveRedirect with two parameters in the 'wrong' order sets status")
is(loc, "link", "serveRedirect with two parameters in the 'wrong' order sets location")
end
section = "(params)"
url = "/params/789"
fm.setTemplate(tmpl1, "{%= foo %}-{%= bar %}")
fm.setRoute("/params/:bar", function(r)
return fm.render(tmpl1, {foo = r.params.foo, bar = r.params.bar})
end)
handleRequest()
is(out, "123-789", "route parameter takes precedence over URL parameter with the same name")
fm.setTemplate(tmpl1, "-{%= baz %}-")
fm.setRoute("/params/:bar", function(r)
return fm.render(tmpl1, {baz = tostring(r.params.baz)})
end)
handleRequest()
is(out, "-false-", "empty existing parameter returns `false`")
HasParam = function(s) return s == "a[]" end
GetParams = function()
return {
{"a[]", "10"},
{"a[]"},
{"a[]", "12"},
{"a[]", ""},
} end
fm.setTemplate(tmpl1, "-{%= a[1]..(a[2] or 'false')..a[3]..a[4] %}-")
fm.setRoute("/params/:bar", function(r)
return fm.render(tmpl1, {a = r.params["a[]"]})
end)
handleRequest()
is(out, "-10false12-", "parameters with [] are returned as array")
fm.setRoute("/params/:bar", function(r)
return fm.render(tmpl1, {a = r.params.a})
end)
handleRequest()
is(out, "-10false12-", "parameters with [] are returned as array when short name is used")
--[[-- validator tests --]]--
section = "(validator)"
local validator = fm.makeValidator{
{"name", minlen=5, maxlen=64, },
otherwise = function() end,
}
is(validator{name = "abcdef"}, true, "valid name is allowed")
local res, msg = validator{params = {name = "a"}}
is(res, nil, "minlen is checked")
is(msg, "name is shorter than 5 chars", "minlen message is reported")
is(validator{params = {name = ("a"):rep(100)}}, nil, "maxlen is checked")
is(type(validator[1]), "function", "makeValidator returns table with a filter handler")
is(type(validator.otherwise), "function", "makeValidator return table with an 'otherwise' handler")
validator = fm.makeValidator{
{"name", msg = "Invalid name format", minlen=5, maxlen=64, },
{"pass", minlen=5, maxlen=64, },
key = true,
all = true,
}
res, msg = validator{params = {name = "a"}}
is(type(msg), "table", "error messages reported in a table")
is(msg.name, "Invalid name format", "error message is keyed on parameter name")
is(msg.pass, "pass is shorter than 5 chars", "multiple error message are provided when `all=true` is set")
validator = fm.makeValidator{
{"name", msg="Invalid name format", minlen=5, maxlen=64, optional=true, },
{"pass", msg="Invalid pass format", minlen=5, maxlen=64, optional=true, },
key = true,
}
res = validator{name = "a"}
is(res, nil, "validation fails for invalid optional parameters")
res = validator{}
is(res, true, "validation passes for missing optional parameters")
res, err = validator"a"
is(res, nil, "validation fails for invalid scalar parameters")
is(err.name, "Invalid name format", "scalar parameters get their name from the first rule")
res = {notcalled = true}
fm.setRoute({"/params/:bar",
_ = fm.makeValidator({{"bar", minlen = 5}, all = true,
otherwise = function(errors) res.errors = errors end}),
}, function() res.notcalled = false end)
handleRequest()
is(res.notcalled, true, "route action not executed after a failed validator check")
is(type(res.errors), "table", "failed validator check triggers `otherwise` processing")
is(res.errors[1], "bar is shorter than 5 chars", "`otherwise` processing gets the list of errors")
--[[-- security tests --]]--
section = "(security)"
res = fm.makeBasicAuth({user = "pass"})
is(type(res[1]), "function", "makeBasicAuth returns table with a filter handler")
is(type(res.otherwise), "function", "makeBasicAuth returns table with an 'otherwise' handler")
local matcherTests = {
{"0.0.0.0/0", "1.2.3.4", true},
{"192.168.2.1", "192.168.2.1", true},