mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-01 01:25:38 +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:
parent
b9f88c1de8
commit
fbdf8fb47d
@ -273,6 +273,9 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\unittests\rehlds_tests_shared.cpp" />
|
<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">
|
<ClCompile Include="..\unittests\struct_offsets_tests.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild>
|
||||||
|
@ -349,6 +349,9 @@
|
|||||||
<ClCompile Include="..\engine\sse_mathfun.cpp">
|
<ClCompile Include="..\engine\sse_mathfun.cpp">
|
||||||
<Filter>engine</Filter>
|
<Filter>engine</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\unittests\security_tests.cpp">
|
||||||
|
<Filter>unittests</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\hookers\memory.h">
|
<ClInclude Include="..\hookers\memory.h">
|
||||||
|
61
rehlds/unittests/security_tests.cpp
Normal file
61
rehlds/unittests/security_tests.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user