Mercurial > hg > nginx-tests
annotate empty_gif.t @ 1260:eadd24ccfda1
Tests: postponed startup in certain ssl certificate tests on win32.
At least, some win32 hosts exhibit a round-off error or some such in the
notBefore field of the certificate generated before starting nginx, such
that it can be set to the value one second ahead of the current time.
This manifests in spurious test failures due to certificate verify error
with a failure reason "certificate is not yet valid".
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 12 Dec 2017 12:53:53 +0300 |
parents | 882267679006 |
children | c544b7120a6d |
rev | line source |
---|---|
326 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 | |
5 # Tests for empty gif module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 use Socket qw/ CRLF /; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http empty_gif/)->plan(4); | |
27 | |
28 $t->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8080; |
326 | 42 server_name localhost; |
43 | |
44 location / { | |
45 empty_gif; | |
46 } | |
47 } | |
48 } | |
49 | |
50 EOF | |
51 | |
52 $t->run(); | |
53 | |
54 my $gif = unhex(<<'EOF'); | |
55 0x0000: 47 49 46 38 39 61 01 00 01 00 80 01 00 00 00 00 |GIF89a.. ........| | |
56 0x0010: ff ff ff 21 f9 04 01 00 00 01 00 2c 00 00 00 00 |...!.... ...,....| | |
57 0x0020: 01 00 01 00 00 02 02 4c 01 00 3b |.......L ..;| | |
58 EOF | |
59 | |
60 ############################################################################### | |
61 | |
62 is(http_get_body('/'), $gif, 'empty gif'); | |
63 like(http_get('/'), qr!Content-Type: image/gif!i, 'get content type'); | |
64 like(http_head('/'), qr!Content-Type: image/gif!i, 'head content type'); | |
65 like(http('PUT / HTTP/1.0' . CRLF . CRLF), qr!405 Not Allowed!i, 'put'); | |
66 | |
67 ############################################################################### | |
68 | |
69 sub unhex { | |
70 my ($input) = @_; | |
71 my $buffer = ''; | |
72 | |
73 for my $l ($input =~ m/: +((?:[0-9a-f]{2,4} +)+) /gms) { | |
74 for my $v ($l =~ m/[0-9a-f]{2}/g) { | |
75 $buffer .= chr(hex($v)); | |
76 } | |
77 } | |
78 | |
79 return $buffer; | |
80 } | |
81 | |
82 sub http_get_body { | |
83 my ($uri) = @_; | |
84 | |
85 return undef if !defined $uri; | |
86 | |
87 my $text = http_get($uri); | |
88 | |
89 if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) { | |
90 return undef; | |
91 } | |
92 | |
93 return $2; | |
94 } | |
95 | |
96 ############################################################################### |