toBe(['2', 0]) ->and(ss_webhits($log))->toBe('2'); file_put_contents($log, ''); expect(ss_webhits_collect($log))->toBe(['0', 0]); } finally { unlink($log); } }); test('counts across read chunks', function () { $stream = fopen('php://memory', 'w+b'); fwrite($stream, str_repeat("x\n", 1500000)); rewind($stream); expect(ss_webhits_count($stream))->toBe(1500000); fclose($stream); }); test('a path with shell metacharacters is only ever a file name', function () { expect(ss_webhits_collect('/tmp/x; touch /tmp/cacti-webhits-pwned'))->toBe(['U', 1]) ->and(file_exists('/tmp/cacti-webhits-pwned'))->toBeFalse(); }); test('missing files and directories return U', function () { expect(ss_webhits_collect('/nonexistent/access_log'))->toBe(['U', 1]) ->and(ss_webhits_collect(sys_get_temp_dir()))->toBe(['U', 1]); }); test('an empty path falls back to the httpd access log', function () { $expected = is_file('/var/log/httpd/access_log') && is_readable('/var/log/httpd/access_log') ? 0 : 1; expect(ss_webhits_collect('')[1])->toBe($expected); });