Removed unit tests for legacy known_hosts file

This commit is contained in:
akallabeth 2021-04-13 10:53:51 +02:00 committed by akallabeth
parent 384f997aa7
commit c3171b90cb

View File

@ -23,15 +23,13 @@
#include <freerdp/crypto/certificate.h>
static int prepare(const char* currentFileV2, const char* legacyFileV2, const char* legacyFile)
static int prepare(const char* currentFileV2)
{
const char* legacy[] = { "someurl ff:11:22:dd\r\n", "otherurl aa:bb:cc:dd\r",
"legacyurl aa:bb:cc:dd\n" };
int rc = -1;
const char* hosts[] = { "#somecomment\r\n"
"someurl 3389 ff:11:22:dd subject issuer\r\n"
" \t#anothercomment\r\n"
"otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r" };
FILE* fl = NULL;
FILE* fc = NULL;
size_t i;
fc = fopen(currentFileV2, "w+");
@ -39,61 +37,33 @@ static int prepare(const char* currentFileV2, const char* legacyFileV2, const ch
if (!fc)
goto finish;
fl = fopen(legacyFileV2, "w+");
if (!fl)
goto finish;
for (i = 0; i < ARRAYSIZE(hosts); i++)
{
if (fwrite(hosts[i], strlen(hosts[i]), 1, fl) != 1 ||
fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
if (fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
goto finish;
}
fclose(fc);
fc = NULL;
fclose(fl);
fl = NULL;
fl = fopen(legacyFile, "w+");
if (!fl)
goto finish;
for (i = 0; i < ARRAYSIZE(legacy); i++)
{
if (fwrite(legacy[i], strlen(legacy[i]), 1, fl) != 1)
goto finish;
}
fclose(fl);
return 0;
rc = 0;
finish:
if (fl)
fclose(fl);
if (fc)
fclose(fc);
return -1;
return rc;
}
int TestKnownHosts(int argc, char* argv[])
{
int rc = -1;
rdpSettings current;
rdpSettings legacy;
rdpCertificateData* data = NULL;
rdpCertificateStore* store = NULL;
char* currentFileV2 = NULL;
char* legacyFileV2 = NULL;
char* legacyFile = NULL;
char* subject = NULL;
char* issuer = NULL;
char* fp = NULL;
char sname[8192];
char dname[8192];
SYSTEMTIME systemTime;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
@ -103,14 +73,8 @@ int TestKnownHosts(int argc, char* argv[])
"%02" PRIu16 "%04" PRIu16,
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour,
systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds);
sprintf_s(dname, sizeof(dname),
"TestKnownHostsLegacy-%04" PRIu16 "%02" PRIu16 "%02" PRIu16 "%02" PRIu16 "%02" PRIu16
"%02" PRIu16 "%04" PRIu16,
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour,
systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds);
current.ConfigPath = GetKnownSubPath(KNOWN_PATH_TEMP, sname);
legacy.ConfigPath = GetKnownSubPath(KNOWN_PATH_TEMP, dname);
if (!PathFileExistsA(current.ConfigPath))
{
@ -121,15 +85,6 @@ int TestKnownHosts(int argc, char* argv[])
}
}
if (!PathFileExistsA(legacy.ConfigPath))
{
if (!CreateDirectoryA(legacy.ConfigPath, NULL))
{
fprintf(stderr, "Could not create %s!\n", legacy.ConfigPath);
goto finish;
}
}
currentFileV2 = GetCombinedPath(current.ConfigPath, "known_hosts2");
if (!currentFileV2)
@ -138,22 +93,6 @@ int TestKnownHosts(int argc, char* argv[])
goto finish;
}
legacyFileV2 = GetCombinedPath(legacy.ConfigPath, "known_hosts2");
if (!legacyFileV2)
{
fprintf(stderr, "Could not get file path!\n");
goto finish;
}
legacyFile = GetCombinedPath(legacy.ConfigPath, "known_hosts");
if (!legacyFile)
{
fprintf(stderr, "Could not get file path!\n");
goto finish;
}
store = certificate_store_new(&current);
if (!store)
@ -162,7 +101,7 @@ int TestKnownHosts(int argc, char* argv[])
goto finish;
}
if (prepare(currentFileV2, legacyFileV2, legacyFile))
if (prepare(currentFileV2))
goto finish;
/* Test if host is found in current file. */
@ -283,51 +222,9 @@ int TestKnownHosts(int argc, char* argv[])
goto finish;
}
certificate_data_free(data);
certificate_store_free(store);
store = certificate_store_new(&legacy);
if (!store)
{
fprintf(stderr, "could not create certificate store!\n");
goto finish;
}
/* test if host found in legacy file. */
data = certificate_data_new("legacyurl", 1234, "", "", "aa:bb:cc:dd");
if (!data)
{
fprintf(stderr, "Could not create certificate data!\n");
goto finish;
}
if (0 != certificate_data_match(store, data))
{
fprintf(stderr, "Could not find host in file!\n");
goto finish;
}
certificate_data_free(data);
/* test if host not found. */
data = certificate_data_new("somehost-not-in-file", 1234, "", "", "ff:aa:bb:cc");
if (!data)
{
fprintf(stderr, "Could not create certificate data!\n");
goto finish;
}
if (0 == certificate_data_match(store, data))
{
fprintf(stderr, "Invalid host found in file!\n");
goto finish;
}
rc = 0;
finish:
free(current.ConfigPath);
free(legacy.ConfigPath);
if (store)
certificate_store_free(store);
@ -337,12 +234,7 @@ finish:
DeleteFileA(currentFileV2);
// RemoveDirectoryA(current.ConfigPath);
DeleteFileA(legacyFileV2);
DeleteFileA(legacyFile);
// RemoveDirectoryA(legacy.ConfigPath);
free(currentFileV2);
free(legacyFileV2);
free(legacyFile);
free(subject);
free(issuer);
free(fp);