$username, 'password' => $password); $Event = new FakeEvent(); return eval("namespace $ns; ".$block.' return $content;'); } // The query of every URL in the manifest, as the receiving index.php sees // it: anything after a # is a fragment and never reaches the server. function segment_params($content) { preg_match_all('#/zm/index\.php\?[^"\n]+#', $content, $m); $out = array(); foreach ($m[0] as $url) { parse_str(parse_url($url, PHP_URL_QUERY), $params); $out[] = $params; } return $out; } $failures = 0; $passes = 0; function check($name, $got, $expected) { global $failures, $passes; if ($got === $expected) { $passes++; echo "ok $name\n"; } else { $failures++; echo "FAIL $name: expected ".var_export($expected, true).', got '.var_export($got, true)."\n"; } } // Ordinary names are unchanged on the wire. $content = manifest('HlsTestPlain', 'admin', 'pw'); check('plain, plain name, segment line', strpos($content, "\n/zm/index.php?view=view_video&eid=5&file=seg1.m4s&user=admin&pass=pw\n") !== false, true); check('plain, plain name, map uri', strpos($content, 'URI="/zm/index.php?view=view_video&eid=5&file=init.mp4&user=admin&pass=pw"') !== false, true); $content = manifest('HlsTestHashed', 'admin', 'pw'); check('hashed, segment line', strpos($content, "\n/zm/index.php?view=view_video&eid=5&file=seg1.m4s&auth=0123456789abcdef0123456789abcdef\n") !== false, true); $cases = array( 'ampersand and equals' => array('ad&min', 'a&b=c'), 'hash' => array('admin', 'pa#ss'), 'plus, percent and space' => array('ad min', '1+1 100%'), 'back reference' => array('admin', 'x$1y\\1z'), ); foreach ($cases as $label => $creds) { list($u, $p) = $creds; $params = segment_params(manifest('HlsTestPlain', $u, $p)); check("plain, $label, two urls", count($params), 2); foreach ($params as $i => $q) { check("plain, $label, url $i user", $q['user'] ?? null, $u); check("plain, $label, url $i pass", $q['pass'] ?? null, $p); check("plain, $label, url $i file kept", isset($q['file']), true); } $params = segment_params(manifest('HlsTestNone', $u, $p)); foreach ($params as $i => $q) { check("none, $label, url $i user", $q['user'] ?? null, $u); } } unlink($m3u8_path); echo "\n$passes passed, $failures failed\n"; exit($failures ? 1 : 0); }