cunit: migrate Sspi tests to CTest

This commit is contained in:
Marc-André Moreau 2012-09-30 20:15:42 -04:00
parent 440a4e23f2
commit a18ebef019
13 changed files with 263 additions and 262 deletions

2
.gitignore vendored
View File

@ -6,9 +6,11 @@ install_manifest.txt
CTestTestfile.cmake CTestTestfile.cmake
freerdp.pc freerdp.pc
Makefile Makefile
Testing
cmake_install.cmake cmake_install.cmake
CPackConfig.cmake CPackConfig.cmake
CPackSourceConfig.cmake CPackSourceConfig.cmake
DartConfiguration.tcl
# Eclipse # Eclipse
*.project *.project

View File

@ -185,6 +185,14 @@ add_definitions("-DHAVE_CONFIG_H")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/freerdp/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/freerdp/config.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/freerdp/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/freerdp/config.h)
# Unit Tests
INCLUDE(CTest)
if(BUILD_TESTING)
enable_testing()
endif()
# WinPR # WinPR
set(WINPR_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/winpr/include") set(WINPR_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/winpr/include")
include_directories(${WINPR_INCLUDE_DIR}) include_directories(${WINPR_INCLUDE_DIR})
@ -201,9 +209,9 @@ endif()
#find_optional_package(IPP) #find_optional_package(IPP)
# Build CUnit # Build CUnit
find_optional_package(CUnit) find_optional_package(CUnit)
if(WITH_CUNIT) if(WITH_CUNIT)
enable_testing()
add_subdirectory(cunit) add_subdirectory(cunit)
endif() endif()

View File

@ -74,4 +74,5 @@ target_link_libraries(test_freerdp freerdp-crypto)
target_link_libraries(test_freerdp winpr-sspi) target_link_libraries(test_freerdp winpr-sspi)
add_test(CUnitTests ${EXECUTABLE_OUTPUT_PATH}/test_freerdp) add_test(CUnitTests ${CMAKE_SOURCE_DIR}/cunit/test_freerdp)

View File

@ -24,7 +24,6 @@
#include "test_color.h" #include "test_color.h"
#include "test_bitmap.h" #include "test_bitmap.h"
#include "test_gdi.h" #include "test_gdi.h"
#include "test_sspi.h"
#include "test_orders.h" #include "test_orders.h"
#include "test_ntlm.h" #include "test_ntlm.h"
#include "test_license.h" #include "test_license.h"
@ -120,19 +119,18 @@ const static test_suite suites[] =
//{ "cliprdr", add_cliprdr_suite }, //{ "cliprdr", add_cliprdr_suite },
{ "color", add_color_suite }, { "color", add_color_suite },
//{ "drdynvc", add_drdynvc_suite }, //{ "drdynvc", add_drdynvc_suite },
{ "gcc", add_gcc_suite }, //{ "gcc", add_gcc_suite },
{ "gdi", add_gdi_suite }, { "gdi", add_gdi_suite },
{ "license", add_license_suite }, { "license", add_license_suite },
{ "mcs", add_mcs_suite }, //{ "mcs", add_mcs_suite },
{ "mppc", add_mppc_suite }, { "mppc", add_mppc_suite },
{ "mppc_enc", add_mppc_enc_suite }, { "mppc_enc", add_mppc_enc_suite },
{ "ntlm", add_ntlm_suite }, { "ntlm", add_ntlm_suite },
{ "orders", add_orders_suite }, //{ "orders", add_orders_suite },
{ "pcap", add_pcap_suite }, { "pcap", add_pcap_suite },
//{ "rail", add_rail_suite }, //{ "rail", add_rail_suite },
{ "rfx", add_rfx_suite }, { "rfx", add_rfx_suite },
{ "nsc", add_nsc_suite }, { "nsc", add_nsc_suite }
{ "sspi", add_sspi_suite }
}; };
#define N_SUITES (sizeof suites / sizeof suites[0]) #define N_SUITES (sizeof suites / sizeof suites[0])

View File

@ -1,225 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Security Support Provider Interface (SSPI) Tests
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <winpr/sspi.h>
#include <freerdp/freerdp.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/hexdump.h>
#include "test_sspi.h"
#define NTLM_PACKAGE_NAME "NTLM"
int init_sspi_suite(void)
{
sspi_GlobalInit();
return 0;
}
int clean_sspi_suite(void)
{
sspi_GlobalFinish();
return 0;
}
int add_sspi_suite(void)
{
add_test_suite(sspi);
add_test_function(EnumerateSecurityPackages);
add_test_function(QuerySecurityPackageInfo);
add_test_function(AcquireCredentialsHandle);
add_test_function(InitializeSecurityContext);
return 0;
}
void test_EnumerateSecurityPackages(void)
{
ULONG cPackages;
SECURITY_STATUS status;
SecPkgInfo* pPackageInfo;
status = EnumerateSecurityPackages(&cPackages, &pPackageInfo);
if (status == SEC_E_OK)
{
int index;
printf("\nEnumerateSecurityPackages (%d):\n", (unsigned int)cPackages);
for (index = 0; index < cPackages; index++)
{
printf("\"%s\", \"%s\"\n",
pPackageInfo[index].Name, pPackageInfo[index].Comment);
}
}
FreeContextBuffer(pPackageInfo);
}
void test_QuerySecurityPackageInfo(void)
{
SECURITY_STATUS status;
SecPkgInfo* pPackageInfo;
status = QuerySecurityPackageInfo("NTLM", &pPackageInfo);
if (status == SEC_E_OK)
{
printf("\nQuerySecurityPackageInfo:\n");
printf("\"%s\", \"%s\"\n", pPackageInfo->Name, pPackageInfo->Comment);
}
}
const char* test_User = "User";
const char* test_Domain = "Domain";
const char* test_Password = "Password";
void test_AcquireCredentialsHandle(void)
{
SECURITY_STATUS status;
CredHandle credentials;
TimeStamp expiration;
SEC_WINNT_AUTH_IDENTITY identity;
SecurityFunctionTable* table;
SecPkgCredentials_Names credential_names;
table = InitSecurityInterface();
identity.User = (uint16*) xstrdup(test_User);
identity.UserLength = sizeof(test_User);
identity.Domain = (uint16*) xstrdup(test_Domain);
identity.DomainLength = sizeof(test_Domain);
identity.Password = (uint16*) xstrdup(test_Password);
identity.PasswordLength = sizeof(test_Password);
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
status = table->AcquireCredentialsHandle(NULL, NTLM_PACKAGE_NAME,
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
if (status == SEC_E_OK)
{
status = table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names);
if (status == SEC_E_OK)
{
printf("\nQueryCredentialsAttributes: %s\n", credential_names.sUserName);
}
}
}
void test_InitializeSecurityContext(void)
{
uint32 cbMaxLen;
uint32 fContextReq;
void* output_buffer;
CtxtHandle context;
ULONG pfContextAttr;
SECURITY_STATUS status;
CredHandle credentials;
TimeStamp expiration;
SecPkgInfo* pPackageInfo;
SEC_WINNT_AUTH_IDENTITY identity;
SecurityFunctionTable* table;
SecBuffer* p_SecBuffer;
SecBuffer output_SecBuffer;
SecBufferDesc output_SecBuffer_desc;
table = InitSecurityInterface();
status = QuerySecurityPackageInfo(NTLM_PACKAGE_NAME, &pPackageInfo);
if (status != SEC_E_OK)
{
printf("QuerySecurityPackageInfo status: 0x%08X\n", status);
return;
}
cbMaxLen = pPackageInfo->cbMaxToken;
identity.User = (uint16*) xstrdup(test_User);
identity.UserLength = sizeof(test_User);
identity.Domain = (uint16*) xstrdup(test_Domain);
identity.DomainLength = sizeof(test_Domain);
identity.Password = (uint16*) xstrdup(test_Password);
identity.PasswordLength = sizeof(test_Password);
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
status = table->AcquireCredentialsHandle(NULL, NTLM_PACKAGE_NAME,
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
if (status != SEC_E_OK)
{
printf("AcquireCredentialsHandle status: 0x%08X\n", status);
return;
}
fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_REQ_DELEGATE;
output_buffer = xmalloc(cbMaxLen);
output_SecBuffer_desc.ulVersion = 0;
output_SecBuffer_desc.cBuffers = 1;
output_SecBuffer_desc.pBuffers = &output_SecBuffer;
output_SecBuffer.cbBuffer = cbMaxLen;
output_SecBuffer.BufferType = SECBUFFER_TOKEN;
output_SecBuffer.pvBuffer = output_buffer;
status = table->InitializeSecurityContext(&credentials, NULL, NULL, fContextReq, 0, 0, NULL, 0,
&context, &output_SecBuffer_desc, &pfContextAttr, &expiration);
if (status != SEC_I_CONTINUE_NEEDED)
{
printf("InitializeSecurityContext status: 0x%08X\n", status);
return;
}
printf("cBuffers: %ld ulVersion: %ld\n", output_SecBuffer_desc.cBuffers, output_SecBuffer_desc.ulVersion);
p_SecBuffer = &output_SecBuffer_desc.pBuffers[0];
printf("BufferType: 0x%04lX cbBuffer:%ld\n", p_SecBuffer->BufferType, p_SecBuffer->cbBuffer);
freerdp_hexdump((uint8*) p_SecBuffer->pvBuffer, p_SecBuffer->cbBuffer);
table->FreeCredentialsHandle(&credentials);
FreeContextBuffer(pPackageInfo);
}

View File

@ -1,29 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Security Support Provider Interface (SSPI) Tests
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test_freerdp.h"
int init_sspi_suite(void);
int clean_sspi_suite(void);
int add_sspi_suite(void);
void test_EnumerateSecurityPackages(void);
void test_QuerySecurityPackageInfo(void);
void test_AcquireCredentialsHandle(void);
void test_InitializeSecurityContext(void);

View File

@ -90,3 +90,8 @@ else()
target_link_libraries(winpr-sspi ${WINPR_SSPI_LIBS}) target_link_libraries(winpr-sspi ${WINPR_SSPI_LIBS})
install(TARGETS winpr-sspi DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(TARGETS winpr-sspi DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif() endif()
if(BUILD_TESTING)
add_subdirectory(test)
endif()

3
winpr/libwinpr/sspi/test/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
TestSspi
TestSspi.c

View File

@ -0,0 +1,25 @@
set(MODULE_NAME "TestSspi")
set(MODULE_PREFIX "TEST_SSPI")
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
TestQuerySecurityPackageInfo.c
TestEnumerateSecurityPackages.c
TestInitializeSecurityContext.c
TestAcquireCredentialsHandle.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-sspi)
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${EXECUTABLE_OUTPUT_PATH}/${MODULE_NAME} ${TestName})
endforeach()

View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/sspi.h>
#include <winpr/winpr.h>
static const char* test_User = "User";
static const char* test_Domain = "Domain";
static const char* test_Password = "Password";
int TestAcquireCredentialsHandle(int argc, char* argv[])
{
SECURITY_STATUS status;
CredHandle credentials;
TimeStamp expiration;
SEC_WINNT_AUTH_IDENTITY identity;
SecurityFunctionTable* table;
SecPkgCredentials_Names credential_names;
sspi_GlobalInit();
table = InitSecurityInterface();
identity.User = (UINT16*) _strdup(test_User);
identity.UserLength = sizeof(test_User);
identity.Domain = (UINT16*) _strdup(test_Domain);
identity.DomainLength = sizeof(test_Domain);
identity.Password = (UINT16*) _strdup(test_Password);
identity.PasswordLength = sizeof(test_Password);
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
status = table->AcquireCredentialsHandle(NULL, NTLMSP_NAME,
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
if (status != SEC_E_OK)
{
sspi_GlobalFinish();
return -1;
}
status = table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names);
if (status != SEC_E_OK)
{
sspi_GlobalFinish();
return -1;
}
sspi_GlobalFinish();
return 0;
}

View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/sspi.h>
#include <winpr/winpr.h>
int TestEnumerateSecurityPackages(int argc, char* argv[])
{
int index;
ULONG cPackages;
SECURITY_STATUS status;
SecPkgInfo* pPackageInfo;
sspi_GlobalInit();
status = EnumerateSecurityPackages(&cPackages, &pPackageInfo);
if (status != SEC_E_OK)
{
sspi_GlobalFinish();
return -1;
}
printf("\nEnumerateSecurityPackages (%d):\n", (unsigned int)cPackages);
for (index = 0; index < cPackages; index++)
{
printf("\"%s\", \"%s\"\n", pPackageInfo[index].Name, pPackageInfo[index].Comment);
}
FreeContextBuffer(pPackageInfo);
sspi_GlobalFinish();
return 0;
}

View File

@ -0,0 +1,96 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/sspi.h>
#include <winpr/winpr.h>
static const char* test_User = "User";
static const char* test_Domain = "Domain";
static const char* test_Password = "Password";
int TestInitializeSecurityContext(int argc, char* argv[])
{
UINT32 cbMaxLen;
UINT32 fContextReq;
void* output_buffer;
CtxtHandle context;
ULONG pfContextAttr;
SECURITY_STATUS status;
CredHandle credentials;
TimeStamp expiration;
PSecPkgInfo pPackageInfo;
SEC_WINNT_AUTH_IDENTITY identity;
SecurityFunctionTable* table;
PSecBuffer p_SecBuffer;
SecBuffer output_SecBuffer;
SecBufferDesc output_SecBuffer_desc;
sspi_GlobalInit();
table = InitSecurityInterface();
status = QuerySecurityPackageInfo(NTLMSP_NAME, &pPackageInfo);
if (status != SEC_E_OK)
{
printf("QuerySecurityPackageInfo status: 0x%08X\n", status);
return -1;
}
cbMaxLen = pPackageInfo->cbMaxToken;
identity.User = (UINT16*) _strdup(test_User);
identity.UserLength = sizeof(test_User);
identity.Domain = (UINT16*) _strdup(test_Domain);
identity.DomainLength = sizeof(test_Domain);
identity.Password = (UINT16*) _strdup(test_Password);
identity.PasswordLength = sizeof(test_Password);
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
status = table->AcquireCredentialsHandle(NULL, NTLMSP_NAME,
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
if (status != SEC_E_OK)
{
printf("AcquireCredentialsHandle status: 0x%08X\n", status);
sspi_GlobalFinish();
return -1;
}
fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_REQ_DELEGATE;
output_buffer = malloc(cbMaxLen);
output_SecBuffer_desc.ulVersion = 0;
output_SecBuffer_desc.cBuffers = 1;
output_SecBuffer_desc.pBuffers = &output_SecBuffer;
output_SecBuffer.cbBuffer = cbMaxLen;
output_SecBuffer.BufferType = SECBUFFER_TOKEN;
output_SecBuffer.pvBuffer = output_buffer;
status = table->InitializeSecurityContext(&credentials, NULL, NULL, fContextReq, 0, 0, NULL, 0,
&context, &output_SecBuffer_desc, &pfContextAttr, &expiration);
if (status != SEC_I_CONTINUE_NEEDED)
{
printf("InitializeSecurityContext status: 0x%08X\n", status);
sspi_GlobalFinish();
return -1;
}
printf("cBuffers: %ld ulVersion: %ld\n", output_SecBuffer_desc.cBuffers, output_SecBuffer_desc.ulVersion);
p_SecBuffer = &output_SecBuffer_desc.pBuffers[0];
printf("BufferType: 0x%04lX cbBuffer:%ld\n", p_SecBuffer->BufferType, p_SecBuffer->cbBuffer);
table->FreeCredentialsHandle(&credentials);
FreeContextBuffer(pPackageInfo);
sspi_GlobalFinish();
return 0;
}

View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <winpr/sspi.h>
#include <winpr/winpr.h>
int TestQuerySecurityPackageInfo(int argc, char* argv[])
{
SECURITY_STATUS status;
SecPkgInfo* pPackageInfo;
sspi_GlobalInit();
status = QuerySecurityPackageInfo(NTLMSP_NAME, &pPackageInfo);
if (status != SEC_E_OK)
{
sspi_GlobalFinish();
return -1;
}
printf("\nQuerySecurityPackageInfo:\n");
printf("\"%s\", \"%s\"\n", pPackageInfo->Name, pPackageInfo->Comment);
sspi_GlobalFinish();
return 0;
}