2
0
mirror of https://github.com/rehlds/rehlds.git synced 2024-12-29 08:05:50 +03:00

Unit tests for IsSafeFileToDownload (#384)

* Added unit tests for IsSafeFileToDownload

* Fixed tests fail

* fixed crash

* Added more checks
This commit is contained in:
theAsmodai 2017-03-02 01:18:44 +03:00 committed by GitHub
parent b9f88c1de8
commit fbdf8fb47d
3 changed files with 67 additions and 0 deletions

View File

@ -273,6 +273,9 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\unittests\rehlds_tests_shared.cpp" />
<ClCompile Include="..\unittests\security_tests.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\unittests\struct_offsets_tests.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild>

View File

@ -349,6 +349,9 @@
<ClCompile Include="..\engine\sse_mathfun.cpp">
<Filter>engine</Filter>
</ClCompile>
<ClCompile Include="..\unittests\security_tests.cpp">
<Filter>unittests</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\hookers\memory.h">

View File

@ -0,0 +1,61 @@
#include "precompiled.h"
#include "rehlds_tests_shared.h"
#include "cppunitlite/TestHarness.h"
TEST(IsSafeFileExtension, SecurityChecks, 1000)
{
struct testdata_t
{
const char* filename;
bool safe;
};
testdata_t testdata[] = {
{"radio/go.wav", true},
{"radio/go.WAV", true},
{"textures.wad", true},
#ifdef REHLDS_FIXES
{"!QWERTY", true},
// TODO:
//{"file.dll2", true},
//{"noext", false},
//{".hidden", false},
//{"subdir/.hidden", false},
#else
{"file.dll2", false},
#endif
{"../file.txt", false},
{"/home/file.txt", false},
{"C:/Windows/file.txt", false},
{"models\\terror.mdl", false},
{"file~.mdl", false},
{"file.wav.", false},
{"file.dll.txt", false},
{"halflife.wad", false},
{"pak0.pak", false},
{"xeno.wad", false},
{"file.cfg", false},
{"file.lst", false},
{"file.exe", false},
{"file.vbs", false},
{"file.com", false},
{"file.bat", false},
{"file.dll", false},
{"file.ini", false},
{"file.log", false},
{"file.so", false},
{"file.dylib", false},
{"file.sys", false},
{"file.SYS", false},
};
for (int i = 0; i < ARRAYSIZE(testdata); i++) {
testdata_t* d = &testdata[i];
bool result = IsSafeFileToDownload(d->filename);
char msg[256];
Q_snprintf(msg, sizeof msg, "IsSafeFileToDownload(%s) check", d->filename);
CHECK(msg, result == d->safe);
}
}