1# vi:filetype=
2
3use Test::Nginx::Socket;
4
5repeat_each(3);
6
7plan tests => repeat_each() * 2 * blocks();
8
9no_long_string();
10
11run_tests();
12
13#no_diff();
14
15__DATA__
16
17=== TEST 1: base32 (5 bytes)
18--- config
19    set_base32_padding off;
20    location /bar {
21        set $a 'abcde';
22        set_encode_base32 $a;
23        set $b $a;
24        set_decode_base32 $b;
25
26        echo $a;
27        echo $b;
28    }
29--- request
30    GET /bar
31--- response_body
32c5h66p35
33abcde
34
35
36
37=== TEST 2: base32 (1 byte)
38--- config
39    set_base32_padding off;
40    location /bar {
41        set $a '!';
42        set_encode_base32 $a;
43        set $b $a;
44        set_decode_base32 $b;
45
46        echo $a;
47        echo $b;
48    }
49--- request
50    GET /bar
51--- response_body
5244
53!
54
55
56
57=== TEST 3: base32 (1 byte) - not in-place editing
58--- config
59    location /bar {
60        set_base32_padding off;
61        set $a '!';
62        set_encode_base32 $a $a;
63        set_decode_base32 $b $a;
64
65        echo $a;
66        echo $b;
67    }
68--- request
69    GET /bar
70--- response_body
7144
72!
73
74
75
76=== TEST 4: base32 (hello world)
77--- config
78    set_base32_padding off;
79    location /bar {
80        set $a '"hello, world!\nhiya"';
81        set_encode_base32 $a;
82        set $b $a;
83        set_decode_base32 $b;
84
85        echo $a;
86        echo $b;
87    }
88--- request
89    GET /bar
90--- response_body
9149k6ar3cdsm20trfe9m6888ad1knio92
92"hello, world!
93hiya"
94
95
96
97=== TEST 5: base32 (0 bytes left)
98--- config
99    set_base32_padding off;
100    location /bar {
101        set $a '"hello, world!"';
102        set_encode_base32 $a;
103
104        echo $a;
105    }
106--- request
107    GET /bar
108--- response_body
10949k6ar3cdsm20trfe9m68892
110
111
112
113=== TEST 6: base32 (6 bytes padded)
114--- config
115    set_base32_padding off;
116    location /bar {
117        set $a '"hello, world!"a';
118        set_encode_base32 $a;
119
120        echo $a;
121    }
122--- request
123    GET /bar
124--- response_body
12549k6ar3cdsm20trfe9m68892c4
126
127
128
129=== TEST 7: base32 (4 bytes left)
130--- config
131    set_base32_padding off;
132    location /bar {
133        set $a '"hello, world!"ab';
134        set_encode_base32 $a;
135
136        echo $a;
137    }
138--- request
139    GET /bar
140--- response_body
14149k6ar3cdsm20trfe9m68892c5h0
142
143
144
145=== TEST 8: base32 (3 bytes left)
146--- config
147    set_base32_padding off;
148    location /bar {
149        set $a '"hello, world!"abc';
150        set_encode_base32 $a;
151
152        echo $a;
153    }
154--- request
155    GET /bar
156--- response_body
15749k6ar3cdsm20trfe9m68892c5h66
158
159
160
161=== TEST 9: base32 (1 bytes left)
162--- config
163    set_base32_padding off;
164    location /bar {
165        set $a '"hello, world!"abcd';
166        set_encode_base32 $a;
167
168        echo $a;
169    }
170--- request
171    GET /bar
172--- response_body
17349k6ar3cdsm20trfe9m68892c5h66p0
174
175
176
177=== TEST 10: base32 standard alphabet (5 bytes)
178--- config
179    set_base32_padding off;
180    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
181    location /bar {
182        set $a 'abcde';
183        set_encode_base32 $a;
184        set $b $a;
185        set_decode_base32 $b;
186
187        echo $a;
188        echo $b;
189    }
190--- request
191    GET /bar
192--- response_body
193MFRGGZDF
194abcde
195
196
197
198=== TEST 11: base32 standard alphabet (1 byte)
199--- config
200    set_base32_padding off;
201    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
202    location /bar {
203        set $a '!';
204        set_encode_base32 $a;
205        set $b $a;
206        set_decode_base32 $b;
207
208        echo $a;
209        echo $b;
210    }
211--- request
212    GET /bar
213--- response_body
214EE
215!
216
217
218
219=== TEST 12: base32 standard alphabet (1 byte) - not in-place editing
220--- config
221    location /bar {
222        set_base32_padding off;
223        set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
224        set $a '!';
225        set_encode_base32 $a $a;
226        set_decode_base32 $b $a;
227
228        echo $a;
229        echo $b;
230    }
231--- request
232    GET /bar
233--- response_body
234EE
235!
236
237
238
239=== TEST 13: base32 standard alphabet (hello world)
240--- config
241    set_base32_padding off;
242    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
243    location /bar {
244        set $a '"hello, world!\nhiya"';
245        set_encode_base32 $a;
246        set $b $a;
247        set_decode_base32 $b;
248
249        echo $a;
250        echo $b;
251    }
252--- request
253    GET /bar
254--- response_body
255EJUGK3DMN4WCA53POJWGIIIKNBUXSYJC
256"hello, world!
257hiya"
258
259
260
261=== TEST 14: base32 standard alphabet (0 bytes left)
262--- config
263    set_base32_padding off;
264    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
265    location /bar {
266        set $a '"hello, world!"';
267        set_encode_base32 $a;
268
269        echo $a;
270    }
271--- request
272    GET /bar
273--- response_body
274EJUGK3DMN4WCA53POJWGIIJC
275
276
277
278=== TEST 15: base32 standard alphabet (6 bytes padded)
279--- config
280    set_base32_padding off;
281    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
282    location /bar {
283        set $a '"hello, world!"a';
284        set_encode_base32 $a;
285
286        echo $a;
287    }
288--- request
289    GET /bar
290--- response_body
291EJUGK3DMN4WCA53POJWGIIJCME
292
293
294
295=== TEST 16: base32 standard alphabet (4 bytes left)
296--- config
297    set_base32_padding off;
298    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
299    location /bar {
300        set $a '"hello, world!"ab';
301        set_encode_base32 $a;
302
303        echo $a;
304    }
305--- request
306    GET /bar
307--- response_body
308EJUGK3DMN4WCA53POJWGIIJCMFRA
309
310
311
312=== TEST 17: base32 standard alphabet (3 bytes left)
313--- config
314    set_base32_padding off;
315    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
316    location /bar {
317        set $a '"hello, world!"abc';
318        set_encode_base32 $a;
319
320        echo $a;
321    }
322--- request
323    GET /bar
324--- response_body
325EJUGK3DMN4WCA53POJWGIIJCMFRGG
326
327
328
329=== TEST 18: base32 standard alphabet (1 bytes left)
330--- config
331    set_base32_padding off;
332    set_base32_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
333    location /bar {
334        set $a '"hello, world!"abcd';
335        set_encode_base32 $a;
336
337        echo $a;
338    }
339--- request
340    GET /bar
341--- response_body
342EJUGK3DMN4WCA53POJWGIIJCMFRGGZA
343
344
345
346=== TEST 19: base32 custom alphabet (5 bytes)
347--- config
348    set_base32_padding off;
349    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
350    location /bar {
351        set $a 'abcde';
352        set_encode_base32 $a;
353        set $b $a;
354        set_decode_base32 $b;
355
356        echo $a;
357        echo $b;
358    }
359--- request
360    GET /bar
361--- response_body
362ohtii2fh
363abcde
364
365
366
367=== TEST 20: base32 custom alphabet (1 byte)
368--- config
369    set_base32_padding off;
370    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
371    location /bar {
372        set $a '!';
373        set_encode_base32 $a;
374        set $b $a;
375        set_decode_base32 $b;
376
377        echo $a;
378        echo $b;
379    }
380--- request
381    GET /bar
382--- response_body
383gg
384!
385
386
387
388=== TEST 21: base32 custom alphabet (1 byte) - not in-place editing
389--- config
390    location /bar {
391        set_base32_padding off;
392        set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
393        set $a '!';
394        set_encode_base32 $a $a;
395        set_decode_base32 $b $a;
396
397        echo $a;
398        echo $b;
399    }
400--- request
401    GET /bar
402--- response_body
403gg
404!
405
406
407
408=== TEST 22: base32 custom alphabet (hello world)
409--- config
410    set_base32_padding off;
411    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
412    location /bar {
413        set $a '"hello, world!\nhiya"';
414        set_encode_base32 $a;
415        set $b $a;
416        set_decode_base32 $b;
417
418        echo $a;
419        echo $b;
420    }
421--- request
422    GET /bar
423--- response_body
424glwim4fop5yec64rqlyikkkmpdwzu1le
425"hello, world!
426hiya"
427
428
429
430=== TEST 23: base32 custom alphabet (0 bytes left)
431--- config
432    set_base32_padding off;
433    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
434    location /bar {
435        set $a '"hello, world!"';
436        set_encode_base32 $a;
437
438        echo $a;
439    }
440--- request
441    GET /bar
442--- response_body
443glwim4fop5yec64rqlyikkle
444
445
446
447=== TEST 24: base32 custom alphabet (6 bytes padded)
448--- config
449    set_base32_padding off;
450    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
451    location /bar {
452        set $a '"hello, world!"a';
453        set_encode_base32 $a;
454
455        echo $a;
456    }
457--- request
458    GET /bar
459--- response_body
460glwim4fop5yec64rqlyikkleog
461
462
463
464=== TEST 25: base32 custom alphabet (4 bytes left)
465--- config
466    set_base32_padding off;
467    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
468    location /bar {
469        set $a '"hello, world!"ab';
470        set_encode_base32 $a;
471
472        echo $a;
473    }
474--- request
475    GET /bar
476--- response_body
477glwim4fop5yec64rqlyikkleohtc
478
479
480
481=== TEST 26: base32 custom alphabet (3 bytes left)
482--- config
483    set_base32_padding off;
484    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
485    location /bar {
486        set $a '"hello, world!"abc';
487        set_encode_base32 $a;
488
489        echo $a;
490    }
491--- request
492    GET /bar
493--- response_body
494glwim4fop5yec64rqlyikkleohtii
495
496
497
498=== TEST 27: base32 custom alphabet (1 bytes left)
499--- config
500    set_base32_padding off;
501    set_base32_alphabet "cdefghijklmnopqrstuvwxyz12345678";
502    location /bar {
503        set $a '"hello, world!"abcd';
504        set_encode_base32 $a;
505
506        echo $a;
507    }
508--- request
509    GET /bar
510--- response_body
511glwim4fop5yec64rqlyikkleohtii2c
512
513
514
515=== TEST 28: deprecated set_misc_base32_padding
516--- config
517    set_misc_base32_padding off;
518    location /bar {
519        set $a 'abcde';
520        set_encode_base32 $a;
521        set $b $a;
522        set_decode_base32 $b;
523
524        echo $a;
525        echo $b;
526    }
527--- request
528    GET /bar
529--- response_body
530c5h66p35
531abcde
532