1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/3.0/ */
#include "gtest/gtest.h"
#include "mozilla/ArrayUtils.h"
#include "nsLocalFileCommon.h"
#include "ApplicationReputation.h"
// clang-format off
// PLEASE read the comment in ApplicationReputation.cpp before modifying this
// list.
static const char* const kTestFileExtensions[] = {
".accda", // MS Access database
".accdb", // MS Access database
".accde", // MS Access database
".accdr", // MS Access database
".action", // Nac script
".ad", // Windows (ignored for app rep)
".ade", // MS Access
".adp", // MS Access
".afploc", // Apple Filing Protocol Location (ignored for app rep)
".air", // Adobe Air (ignored for app rep)
".apk", // Android package
".app", // Executable application
".applescript",
".application", // MS ClickOnce
".appref-ms", // MS ClickOnce
".appx",
".appxbundle",
".as", // Mac archive
".asp", // Windows Server script
".asx", // Windows Media Player
".atloc", // Appletalk Location (ignored for app rep)
".bas", // Basic script
".bash", // Linux shell
".bat", // Windows shell
".bin",
".btapp", // uTorrent and Transmission
".btinstall", // uTorrent and Transmission
".btkey", // uTorrent and Transmission
".btsearch", // uTorrent and Transmission
".btskin", // uTorrent and Transmission
".bz", // Linux archive (bzip)
".bz2", // Linux archive (bzip2)
".bzip2", // Linux archive (bzip2)
".cab", // Windows archive
".caction", // Automator action
".cdr", // Mac disk image
".cer", // Signed certificate file
".cfg", // Windows
".chi", // Windows Help
".chm", // Windows Help
".class", // Java
".cmd", // Windows executable
".com", // Windows executable
".command", // Mac script
".configprofile", // Configuration file for Apple systems
".cpgz", // Mac archive
".cpi", // Control Panel Item. Executable used for adding icons
// to Control Panel
".cpl", // Windows executable
".crt", // Windows signed certificate
".crx", // Chrome extensions
".csh", // Linux shell
".dart", // Mac disk image
".dc42", // Apple DiskCopy Image
".deb", // Linux package
".definition", // Automator action
".der", // Signed certificate file
".desktop", // A shortcut that runs other files
".dex", // Android
".dht", // HTML
".dhtm", // HTML
".dhtml", // HTML
".diagcab", // Windows archive
".diskcopy42", // Apple DiskCopy Image
".dll", // Windows executable
".dmg", // Mac disk image
".dmgpart", // Mac disk image
".doc", // MS Office
".docb", // MS Office
".docm", // MS Word
".docx", // MS Word
".dot", // MS Word
".dotm", // MS Word
".dott", // MS Office
".dotx", // MS Word
".drv", // Windows driver
".dvdr", // Mac Disk image
".dylib", // Mach object dynamic library file
".efi", // Firmware
".eml", // MS Outlook
".exe", // Windows executable
".fileloc", // Apple finder internet location data file
".fon", // Windows font
".ftploc", // Apple FTP Location (ignored for app rep)
".fxp", // MS FoxPro
".gadget", // Windows
".grp", // Windows
".gz", // Linux archive (gzip)
".gzip", // Linux archive (gzip)
".hfs", // Mac disk image
".hlp", // Windows Help
".hqx", // Mac archive
".hta", // HTML trusted application
".htm", ".html",
".htt", // MS HTML template
".img", // Mac disk image
".imgpart", // Mac disk image
".inetloc", // Apple finder internet location data file
".inf", // Windows installer
".ini", // Generic config file
".ins", // IIS config
".internetconnect", // Configuration file for Apple system
".iso", // CD image
".isp", // IIS config
".jar", // Java
#ifndef MOZ_ESR
".jnlp", // Java
#endif
".js", // JavaScript script
".jse", // JScript
".ksh", // Linux shell
".library-ms", // Windows Library Files
".lnk", // Windows
".local", // Windows
".mad", // MS Access
".maf", // MS Access
".mag", // MS Access
".mam", // MS Access
".manifest", // Windows
".maq", // MS Access
".mar", // MS Access
".mas", // MS Access
".mat", // MS Access
".mau", // Media attachment
".mav", // MS Access
".maw", // MS Access
".mda", // MS Access
".mdb", // MS Access
".mde", // MS Access
".mdt", // MS Access
".mdw", // MS Access
".mdz", // MS Access
".mht", // MS HTML
".mhtml", // MS HTML
".mim", // MS Mail
".mmc", // MS Office
".mobileconfig", // Configuration file for Apple systems
".mof", // Windows
".mpkg", // Mac installer
".msc", // Windows executable
".msg", // MS Outlook
".msh", // Windows shell
".msh1", // Windows shell
".msh1xml", // Windows shell
".msh2", // Windows shell
".msh2xml", // Windows shell
".mshxml", // Windows
".msi", // Windows installer
".msix", // Windows installer
".msixbundle", // Windows installer
".msp", // Windows installer
".mst", // Windows installer
".ndif", // Mac disk image
".networkconnect", // Configuration file for Apple system
".ocx", // ActiveX
".ops", // MS Office
".osas", // AppleScript
".osax", // AppleScript
".oxt", // OpenOffice extension, can execute arbitrary code
".partial", // Downloads
".pax", // Mac archive
".pcd", // Microsoft Visual Test
".pdf", // Adobe Acrobat
".pet", // Linux package
".pif", // Windows
".pkg", // Mac installer
".pl", // Perl script
".plg", // MS Visual Studio
".pot", // MS PowerPoint
".potm", // MS PowerPoint
".potx", // MS PowerPoint
".ppam", // MS PowerPoint
".pps", // MS PowerPoint
".ppsm", // MS PowerPoint
".ppsx", // MS PowerPoint
".ppt", // MS PowerPoint
".pptm", // MS PowerPoint
".pptx", // MS PowerPoint
".prf", // MS Outlook
".prg", // Windows
".ps1", // Windows shell
".ps1xml", // Windows shell
".ps2", // Windows shell
".ps2xml", // Windows shell
".psc1", // Windows shell
".psc2", // Windows shell
".pst", // MS Outlook
".pup", // Linux package
".py", // Python script
".pyc", // Python binary
".pyd", // Equivalent of a DLL, for python libraries
".pyo", // Compiled python code
".pyw", // Python GUI
".rb", // Ruby script
".reg", // Windows Registry
".rels", // MS Office
".rpm", // Linux package
".rtf", // MS Office
".scf", // Windows shell
".scpt", // AppleScript
".scptd", // AppleScript
".scr", // Windows
".sct", // Windows shell
".search-ms", // Windows
".seplugin", // AppleScript
".service", // Systemd service unit file
".settingcontent-ms", // Windows settings
".sh", // Linux shell
".shar", // Linux shell
".shb", // Windows
".shs", // Windows shell
".sht", // HTML
".shtm", // HTML
".shtml", // HTML
".sldm", // MS PowerPoint
".sldx", // MS PowerPoint
".slk", // MS Excel
".slp", // Linux package
".smi", // Mac disk image
".sparsebundle", // Mac disk image
".sparseimage", // Mac disk image
".spl", // Adobe Flash
".svg",
".swf", // Adobe Flash
".swm", // Windows Imaging
".sys", // Windows
".tar", // Linux archive
".taz", // Linux archive (bzip2)
".tbz", // Linux archive (bzip2)
".tbz2", // Linux archive (bzip2)
".tcsh", // Linux shell
".terminal", // Apple Terminal configuration files
".tgz", // Linux archive (gzip)
".torrent", // Bittorrent
".tpz", // Linux archive (gzip)
".txz", // Linux archive (xz)
".tz", // Linux archive (gzip)
".udf", // MS Excel
".udif", // Mac disk image
".url", // Windows
".vb", // Visual Basic script
".vbe", // Visual Basic script
".vbs", // Visual Basic script
".vdx", // MS Visio
".vhd", // Windows virtual hard drive
".vhdx", // Windows virtual hard drive
".vmdk", // VMware virtual disk
".vsd", // MS Visio
".vsdm", // MS Visio
".vsdx", // MS Visio
".vsmacros", // MS Visual Studio
".vss", // MS Visio
".vssm", // MS Visio
".vssx", // MS Visio
".vst", // MS Visio
".vstm", // MS Visio
".vstx", // MS Visio
".vsw", // MS Visio
".vsx", // MS Visio
".vtx", // MS Visio
".webloc", // MacOS website location file
".website", // Windows
".wflow", // Automator action
".wim", // Windows Imaging
".workflow", // Mac Automator
".ws", // Windows script
".wsc", // Windows script
".wsf", // Windows script
".wsh", // Windows script
".xar", // MS Excel
".xbap", // XAML Browser Application
".xht", ".xhtm", ".xhtml",
".xip", // Mac archive
".xla", // MS Excel
".xlam", // MS Excel
".xldm", // MS Excel
".xll", // MS Excel
".xlm", // MS Excel
".xls", // MS Excel
".xlsb", // MS Excel
".xlsm", // MS Excel
".xlsx", // MS Excel
".xlt", // MS Excel
".xltm", // MS Excel
".xltx", // MS Excel
".xlw", // MS Excel
".xml", // MS Excel
".xnk", // MS Exchange
".xrm-ms", // Windows
".xsd", // XML schema definition
".xsl", // XML Stylesheet
".xz", // Linux archive (xz)
".z", // InstallShield
#ifdef XP_WIN // disable on Mac/Linux, see 1167493
".zip", // Generic archive
#endif
".zipx", // WinZip
};
// clang-format on
#define CheckListSorted(_list) \
{ \
for (size_t i = 1; i < mozilla::ArrayLength(_list); ++i) { \
nsDependentCString str1((_list)[i - 1]); \
nsDependentCString str2((_list)[i]); \
EXPECT_LE(Compare(str1, str2), -1) \
<< "Expected " << str1.get() << " to be sorted after " \
<< str2.get(); \
} \
}
// First, verify that the 2 lists are both sorted. This helps when checking for
// duplicates manually, ensures we could start doing more efficient lookups if
// we felt that was necessary (e.g. if the lists get much bigger), and that it's
// easy for humans to find things...
TEST(TestExecutableLists, ListsAreSorted)
{
CheckListSorted(sExecutableExts);
CheckListSorted(ApplicationReputationService::kBinaryFileExtensions);
CheckListSorted(ApplicationReputationService::kNonBinaryExecutables);
CheckListSorted(kTestFileExtensions);
}
bool _IsInList(const char* ext, const char* const _list[], const size_t len) {
nsDependentCString extStr(ext);
for (size_t i = 0; i < len; ++i) {
if (extStr.EqualsASCII(_list[i])) {
return true;
}
}
return false;
}
#define IsInList(_ext, _list) \
_IsInList(_ext, _list, mozilla::ArrayLength(_list))
TEST(TestExecutableLists, NonBinariesInExecutablesList)
{
for (auto nonBinary : ApplicationReputationService::kNonBinaryExecutables) {
EXPECT_TRUE(IsInList(nonBinary, sExecutableExts))
<< "Expected " << nonBinary << " to be part of sExecutableExts list";
}
}
TEST(TestExecutableLists, AllExtensionsInTestList)
{
for (auto ext : ApplicationReputationService::kBinaryFileExtensions) {
EXPECT_TRUE(IsInList(ext, kTestFileExtensions))
<< "Expected binary extension " << ext
<< " to be listed in the test extension list";
}
for (auto ext : sExecutableExts) {
EXPECT_TRUE(IsInList(ext, kTestFileExtensions))
<< "Expected executable extension " << ext
<< " to be listed in the test extension list";
}
for (auto ext : ApplicationReputationService::kNonBinaryExecutables) {
EXPECT_TRUE(IsInList(ext, kTestFileExtensions))
<< "Expected non-binary executable extension " << ext
<< " to be listed in the test extension list";
}
}
TEST(TestExecutableLists, TestListExtensionsExistSomewhere)
{
for (auto ext : kTestFileExtensions) {
EXPECT_TRUE(
IsInList(ext, ApplicationReputationService::kBinaryFileExtensions) !=
IsInList(ext, sExecutableExts))
<< "Expected test extension " << ext
<< " to be in exactly one of the other lists.";
}
}
|