30 require_once (__DIR__ .
"/../../../testing/db/createEmptyTestEnvironment.php");
38 public $EXE_PATH =
"";
40 public $DB_COMMAND =
"";
56 list($test_name, $DB_CONF, $DB_NAME, $PG_CONN) = setupTestEnv($cwd,
"mimetype");
58 $sql =
"CREATE TABLE mimetype (mimetype_pk SERIAL, mimetype_name text);";
59 $result = pg_query($PG_CONN, $sql);
60 pg_free_result($result);
61 $sql =
"INSERT INTO public.mimetype (mimetype_pk, mimetype_name) VALUES (2, 'application/gzip')," 62 .
" (3, 'application/x-gzip'), (4, 'application/x-compress'), (5, 'application/x-bzip'), (6, 'application/x-bzip2')," 63 .
" (7, 'application/x-upx'), (8, 'application/pdf'), (9, 'application/x-pdf'), (10, 'application/x-zip')," 64 .
" (11, 'application/zip'), (12, 'application/x-tar'), (13, 'application/x-gtar'), (14, 'application/x-cpio')," 65 .
" (15, 'application/x-rar'), (16, 'application/x-cab'), (17, 'application/x-7z-compressed')," 66 .
" (18, 'application/x-7z-w-compressed'), (19, 'application/x-rpm'), (20, 'application/x-archive')," 67 .
" (21, 'application/x-debian-package'), (22, 'application/x-iso'), (23, 'application/x-iso9660-image')," 68 .
" (24, 'application/x-fat'), (25, 'application/x-ntfs'), (26, 'application/x-ext2'), (27, 'application/x-ext3')," 69 .
" (28, 'application/x-x86_boot'), (29, 'application/x-debian-source'), (30, 'application/x-xz')," 70 .
" (31, 'application/jar'), (32, 'application/java-archive'), (33, 'application/x-dosexec')," 71 .
" (34, 'text/plain');";
72 $result = pg_query($PG_CONN, $sql);
73 pg_free_result($result);
75 $EXE_PATH =
'../../agent/mimetype';
77 if(file_exists($EXE_PATH))
79 $usage =
'Usage: ../../agent/mimetype [options] [file [file [...]]';
83 $this->assertFileExists($EXE_PATH,
84 $message =
'FATAL: cannot find executable file, stop testing\n');
87 $EXE_PATH = $EXE_PATH.
" -C -c $DB_CONF";
88 $last = exec(
"$EXE_PATH -h 2>&1", $out, $rtn);
89 $this->assertEquals($usage, $out[0]);
104 $mimeType1 =
"application/x-executable";
106 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType1');";
107 $result = pg_query($PG_CONN, $sql);
108 pg_free_result($result);
111 $filePath =
"../../agent/mimetype";
112 $command =
"$EXE_PATH $filePath";
113 exec($command, $out, $rtn);
114 $this->assertStringStartsWith($mimeType1, $out[0]);
117 $filePath =
"../../mimetype.conf";
118 $command =
"$EXE_PATH $filePath";
120 exec($command, $out, $rtn);
121 $mimeType2 =
"text/plain";
122 $this->assertStringStartsWith($mimeType2, $out[0]);
124 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType1');";
125 $result = pg_query($PG_CONN, $sql);
126 pg_free_result($result);
140 $mimeType =
"text/x-makefile";
142 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType');";
143 $result = pg_query($PG_CONN, $sql);
144 pg_free_result($result);
146 $sql =
"INSERT INTO mimetype(mimetype_pk, mimetype_name) VALUES(10000, '$mimeType');";
147 $result = pg_query($PG_CONN, $sql);
148 pg_free_result($result);
150 $filePath =
"./Makefile";
151 $command =
"$EXE_PATH $filePath";
152 exec($command, $out, $rtn);
153 $expected_string =
"text/x-makefile : mimetype_pk=10000";
154 $this->assertStringStartsWith($expected_string, $out[0]);
157 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType');";
158 $result = pg_query($PG_CONN, $sql);
159 pg_free_result($result);
172 exec(
"$DB_COMMAND -d $DB_NAME");
173 exec(
"rm -rf $DB_CONF");
Test mimetype agent from cli.
testMimetypeNotInDB()
Test mimetype name is not in table mimetype.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
testMimetypeInDB()
The mimetype name is in table mimetype.