Mercurial > hg > nginx-tests
annotate mp4.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 3ff92feb99d1 |
children | 8659123d2d37 |
rev | line source |
---|---|
384 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for mp4 module. | |
7 # Ensures that requested stream duration is given with sane accuracy. | |
8 | |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
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 | |
389
c24d1c0b4c73
Tests: fixed invocation of has_daemon().
Sergey Kandaurov <pluknet@nginx.com>
parents:
388
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffprobe') |
c24d1c0b4c73
Tests: fixed invocation of has_daemon().
Sergey Kandaurov <pluknet@nginx.com>
parents:
388
diff
changeset
|
27 ->has_daemon('ffmpeg') |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
384 | 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; |
384 | 42 server_name localhost; |
43 | |
44 location / { | |
45 mp4; | |
46 } | |
47 } | |
48 } | |
49 | |
50 EOF | |
51 | |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
52 plan(skip_all => 'no lavfi') |
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
53 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`; |
1268
1923461981c9
Tests: prevent broken terminal after tc[gs]etattr ffmpeg race.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
54 system('ffmpeg -nostdin -loglevel quiet -y ' |
384 | 55 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
56 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' | |
57 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' | |
58 . "${\($t->testdir())}/test.mp4") == 0 | |
59 or die "Can't create mp4 file: $!"; | |
1268
1923461981c9
Tests: prevent broken terminal after tc[gs]etattr ffmpeg race.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
60 system('ffmpeg -nostdin -loglevel quiet -y ' |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
61 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
62 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
63 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
64 . '-movflags +faststart ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
65 . "${\($t->testdir())}/no_mdat.mp4") == 0 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
66 or die "Can't create mp4 file: $!"; |
384 | 67 |
1555
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
68 my $sbad = <<'EOF'; |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
69 00000000: 00 00 00 1c 66 74 79 70 69 73 6f 6d 00 00 02 00 |....ftypisom....| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
70 00000010: 69 73 6f 6d 69 73 6f 32 6d 70 34 31 00 00 00 09 |isomiso2mp41....| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
71 00000020: 6d 64 61 74 00 00 00 00 94 6d 6f 6f 76 00 00 00 |mdat.....moov...| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
72 00000030: 8c 74 72 61 6b 00 00 00 84 6d 64 69 61 00 00 00 |.trak....mdia...| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
73 00000040: 7c 6d 69 6e 66 00 00 00 74 73 74 62 6c 00 00 00 ||minf...tstbl...| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
74 00000050: 18 73 74 74 73 00 00 00 00 00 00 00 01 00 00 03 |.stts...........| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
75 00000060: 3a 00 00 04 00 00 00 00 28 73 74 73 63 00 00 00 |:.......(stsc...| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
76 00000070: 00 00 00 00 02 00 00 00 01 00 00 03 0f 00 00 00 |................| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
77 00000080: 01 00 00 00 02 00 00 00 2b 00 00 00 01 00 00 00 |........+.......| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
78 00000090: 14 73 74 73 7a 00 00 00 00 00 00 05 a9 00 00 03 |.stsz...........| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
79 000000a0: 3b 00 00 00 18 63 6f 36 34 00 00 00 00 00 00 00 |;....co64.......| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
80 000000b0: 01 ff ff ff ff f0 0f fb e7 |.........| |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
81 EOF |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
82 |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
83 $t->write_file('bad.mp4', unhex($sbad)); |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
84 $t->run()->plan(27); |
384 | 85 |
86 ############################################################################### | |
87 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
88 my $test_uri = '/test.mp4'; |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
89 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
90 again: |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
91 |
384 | 92 is(durations($t, 0.0), '10.0 20.0', 'start zero'); |
93 is(durations($t, 2), '8.0 18.0', 'start integer'); | |
94 is(durations($t, 7.1), '2.9 12.9', 'start float'); | |
95 | |
96 is(durations($t, 6, 9), '3.0 3.0', 'start end integer'); | |
97 is(durations($t, 2.7, 5.6), '2.9 2.9', 'start end float'); | |
98 | |
99 is(durations($t, undef, 9), '9.0 9.0', 'end integer'); | |
100 is(durations($t, undef, 5.6), '5.6 5.6', 'end float'); | |
101 | |
102 # invalid range results in ignoring end argument | |
103 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
104 like(http_head("$test_uri?start=1&end=1"), qr/200 OK/, 'zero range'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
105 like(http_head("$test_uri?start=1&end=0"), qr/200 OK/, 'negative range'); |
384 | 106 |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
107 # start/end values exceeding track/file duration |
384 | 108 |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
109 unlike(http_head("$test_uri?end=11"), qr!HTTP/1.1 500!, |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
110 'end beyond short track'); |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
111 unlike(http_head("$test_uri?end=21"), qr!HTTP/1.1 500!, 'end beyond EOF'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
112 unlike(http_head("$test_uri?start=11"), qr!HTTP/1.1 500!, |
388
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
113 'start beyond short track'); |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
114 like(http_head("$test_uri?start=21"), qr!HTTP/1.1 500!, 'start beyond EOF'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
115 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
116 $test_uri = '/no_mdat.mp4', goto again unless $test_uri eq '/no_mdat.mp4'; |
384 | 117 |
1555
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
118 # corrupted formats |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
119 |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
120 TODO: { |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
121 local $TODO = 'not yet' unless $t->has_version('1.17.9'); |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
122 |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
123 like(http_get("/bad.mp4?start=0.5"), qr/500 Internal/, 'co64 chunk beyond EOF'); |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
124 |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
125 } |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
126 |
1556
3ff92feb99d1
Tests: todo_alerts() with sendfile for added mp4 overflow test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1555
diff
changeset
|
127 $t->todo_alerts() if $t->read_file('nginx.conf') =~ /sendfile on/ |
3ff92feb99d1
Tests: todo_alerts() with sendfile for added mp4 overflow test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1555
diff
changeset
|
128 and !$t->has_version('1.17.9'); |
3ff92feb99d1
Tests: todo_alerts() with sendfile for added mp4 overflow test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1555
diff
changeset
|
129 |
384 | 130 ############################################################################### |
131 | |
132 sub durations { | |
133 my ($t, $start, $end) = @_; | |
134 my $path = $t->{_testdir} . '/frag.mp4'; | |
135 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
136 my $uri = $test_uri; |
384 | 137 if (defined $start) { |
138 $uri .= "?start=$start"; | |
139 if (defined $end) { | |
140 $uri .= "&end=$end"; | |
141 } | |
142 | |
143 } elsif (defined $end) { | |
144 $uri .= "?end=$end"; | |
145 } | |
146 | |
147 $t->write_file('frag.mp4', Test::Nginx::http_content(http_get($uri))); | |
148 | |
149 my $r = `ffprobe -show_streams $path 2>/dev/null`; | |
150 Test::Nginx::log_core('||', $r); | |
151 sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g; | |
152 } | |
153 | |
1555
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
154 sub unhex { |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
155 my ($input) = @_; |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
156 my $buffer = ''; |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
157 |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
158 for my $l ($input =~ m/: +((?:[0-9a-f]{2,4} +)+) /gms) { |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
159 for my $v ($l =~ m/[0-9a-f]{2}/g) { |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
160 $buffer .= chr(hex($v)); |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
161 } |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
162 } |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
163 |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
164 return $buffer; |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
165 } |
809d67d48d21
Tests: added mp4 test with chunk offset overflow.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1483
diff
changeset
|
166 |
384 | 167 ############################################################################### |