Milestone 5: deliver embedded RDP sessions and lifecycle hardening
This commit is contained in:
23
third_party/FreeRDP/winpr/libwinpr/dsparse/test/CMakeLists.txt
vendored
Normal file
23
third_party/FreeRDP/winpr/libwinpr/dsparse/test/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
set(MODULE_NAME "TestDsParse")
|
||||
set(MODULE_PREFIX "TEST_DSPARSE")
|
||||
|
||||
disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
|
||||
|
||||
set(${MODULE_PREFIX}_TESTS TestDsMakeSpn.c)
|
||||
|
||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS})
|
||||
|
||||
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
target_link_libraries(${MODULE_NAME} winpr)
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
|
||||
|
||||
foreach(test ${${MODULE_PREFIX}_TESTS})
|
||||
get_filename_component(TestName ${test} NAME_WE)
|
||||
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
|
||||
endforeach()
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
|
||||
155
third_party/FreeRDP/winpr/libwinpr/dsparse/test/TestDsMakeSpn.c
vendored
Normal file
155
third_party/FreeRDP/winpr/libwinpr/dsparse/test/TestDsMakeSpn.c
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/dsparse.h>
|
||||
|
||||
static BOOL test_DsMakeSpnA(void)
|
||||
{
|
||||
LPCSTR testServiceClass = "HTTP";
|
||||
LPCSTR testServiceName = "LAB1-W2K8R2-GW.lab1.awake.local";
|
||||
LPCSTR testSpn = "HTTP/LAB1-W2K8R2-GW.lab1.awake.local";
|
||||
BOOL rc = FALSE;
|
||||
CHAR Spn[100] = WINPR_C_ARRAY_INIT;
|
||||
DWORD status = 0;
|
||||
DWORD SpnLength = -1;
|
||||
|
||||
status =
|
||||
DsMakeSpnA(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
|
||||
|
||||
if (status != ERROR_INVALID_PARAMETER)
|
||||
{
|
||||
printf("DsMakeSpnA: expected ERROR_INVALID_PARAMETER\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
SpnLength = 0;
|
||||
status =
|
||||
DsMakeSpnA(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
|
||||
|
||||
if (status != ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
printf("DsMakeSpnA: expected ERROR_BUFFER_OVERFLOW\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (SpnLength != 37)
|
||||
{
|
||||
printf("DsMakeSpnA: SpnLength mismatch: Actual: %" PRIu32 ", Expected: 37\n", SpnLength);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
status = DsMakeSpnA(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, Spn);
|
||||
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("DsMakeSpnA: expected ERROR_SUCCESS\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (strcmp(Spn, testSpn) != 0)
|
||||
{
|
||||
printf("DsMakeSpnA: SPN mismatch: Actual: %s, Expected: %s\n", Spn, testSpn);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
printf("DsMakeSpnA: %s\n", Spn);
|
||||
rc = TRUE;
|
||||
fail:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static BOOL test_DsMakeSpnW(void)
|
||||
{
|
||||
const CHAR ctestServiceClass[] = { 'H', 'T', 'T', 'P', '\0' };
|
||||
const CHAR ctestServiceName[] = { 'L', 'A', 'B', '1', '-', 'W', '2', 'K', '8', 'R', '2',
|
||||
'-', 'G', 'W', '.', 'l', 'a', 'b', '1', '.', 'a', 'w',
|
||||
'a', 'k', 'e', '.', 'l', 'o', 'c', 'a', 'l', '\0' };
|
||||
const CHAR ctestSpn[] = { 'H', 'T', 'T', 'P', '/', 'L', 'A', 'B', '1', '-', 'W', '2', 'K',
|
||||
'8', 'R', '2', '-', 'G', 'W', '.', 'l', 'a', 'b', '1', '.', 'a',
|
||||
'w', 'a', 'k', 'e', '.', 'l', 'o', 'c', 'a', 'l', '\0' };
|
||||
WCHAR testServiceClass[ARRAYSIZE(ctestServiceClass)] = WINPR_C_ARRAY_INIT;
|
||||
WCHAR testServiceName[ARRAYSIZE(ctestServiceName)] = WINPR_C_ARRAY_INIT;
|
||||
WCHAR testSpn[ARRAYSIZE(ctestSpn)] = WINPR_C_ARRAY_INIT;
|
||||
|
||||
BOOL rc = FALSE;
|
||||
WCHAR Spn[100] = WINPR_C_ARRAY_INIT;
|
||||
DWORD status = 0;
|
||||
DWORD SpnLength = -1;
|
||||
|
||||
(void)ConvertUtf8NToWChar(ctestServiceClass, ARRAYSIZE(ctestServiceClass), testServiceClass,
|
||||
ARRAYSIZE(testServiceClass));
|
||||
(void)ConvertUtf8NToWChar(ctestServiceName, ARRAYSIZE(ctestServiceName), testServiceName,
|
||||
ARRAYSIZE(testServiceName));
|
||||
(void)ConvertUtf8NToWChar(ctestSpn, ARRAYSIZE(ctestSpn), testSpn, ARRAYSIZE(testSpn));
|
||||
|
||||
status =
|
||||
DsMakeSpnW(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
|
||||
|
||||
if (status != ERROR_INVALID_PARAMETER)
|
||||
{
|
||||
printf("DsMakeSpnW: expected ERROR_INVALID_PARAMETER\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
SpnLength = 0;
|
||||
status =
|
||||
DsMakeSpnW(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
|
||||
|
||||
if (status != ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
printf("DsMakeSpnW: expected ERROR_BUFFER_OVERFLOW\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (SpnLength != 37)
|
||||
{
|
||||
printf("DsMakeSpnW: SpnLength mismatch: Actual: %" PRIu32 ", Expected: 37\n", SpnLength);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
status = DsMakeSpnW(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, Spn);
|
||||
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("DsMakeSpnW: expected ERROR_SUCCESS\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (_wcscmp(Spn, testSpn) != 0)
|
||||
{
|
||||
char buffer1[8192] = WINPR_C_ARRAY_INIT;
|
||||
char buffer2[8192] = WINPR_C_ARRAY_INIT;
|
||||
char* SpnA = buffer1;
|
||||
char* testSpnA = buffer2;
|
||||
|
||||
(void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer1));
|
||||
(void)ConvertWCharToUtf8(testSpn, testSpnA, ARRAYSIZE(buffer2));
|
||||
printf("DsMakeSpnW: SPN mismatch: Actual: %s, Expected: %s\n", SpnA, testSpnA);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
{
|
||||
char buffer[8192] = WINPR_C_ARRAY_INIT;
|
||||
char* SpnA = buffer;
|
||||
|
||||
(void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer));
|
||||
printf("DsMakeSpnW: %s\n", SpnA);
|
||||
}
|
||||
|
||||
rc = TRUE;
|
||||
fail:
|
||||
return rc;
|
||||
}
|
||||
int TestDsMakeSpn(int argc, char* argv[])
|
||||
{
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
|
||||
if (!test_DsMakeSpnA())
|
||||
return -1;
|
||||
if (!test_DsMakeSpnW())
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user