summaryrefslogtreecommitdiff
path: root/lua-resty-string-0.16/t/random.t
blob: 8f601cead96ad231dd153787f32c2604bc45b001 (plain)
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
# vi:ft=

use Test::Nginx::Socket::Lua;

repeat_each(2);

plan tests => repeat_each() * (3 * blocks());

our $HttpConfig = <<'_EOC_';
    lua_package_path 'lib/?.lua;;';
    lua_package_cpath 'lib/?.so;;';
_EOC_

no_long_string();

run_tests();

__DATA__

=== TEST 1: pseudo random bytes
--- http_config eval: $::HttpConfig
--- config
    location /t {
        content_by_lua '
            local rand = require "resty.random"
            local str = require "resty.string"
            local s = rand.bytes(5)
            ngx.say("res: ", str.to_hex(s))
        ';
    }
--- request
GET /t
--- response_body_like
^res: [a-f0-9]{10}$
--- no_error_log
[error]



=== TEST 2: strong random bytes
--- http_config eval: $::HttpConfig
--- config
    location /t {
        content_by_lua '
            local rand = require "resty.random"
            local str = require "resty.string"
            local s = rand.bytes(5, true)
            ngx.say("res: ", str.to_hex(s))
        ';
    }
--- request
GET /t
--- response_body_like
^res: [a-f0-9]{10}$
--- no_error_log
[error]