Mercurial > trustbridge
changeset 330:1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
This was supposed to fix the block on error. But it did not.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 08 Apr 2014 15:08:57 +0000 |
parents | b1059360a0c7 |
children | 455d6d00e896 |
files | cinst/nssstore_win.c ui/tests/nsstest.cpp |
diffstat | 2 files changed, 51 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/cinst/nssstore_win.c Tue Apr 08 14:52:31 2014 +0000 +++ b/cinst/nssstore_win.c Tue Apr 08 15:08:57 2014 +0000 @@ -32,53 +32,50 @@ * Writes the null terminated list of instructions to * the handle. * -* @param [in] instructions instructions to write +* @param [in] base64 encoded der certificates to write * @param [in] write_handle to write to +* @param [in] remove weather the certificate should be installed or removed * * @returns true on success, false on failure */ static bool -write_instructions(char **instructions, HANDLE write_handle) +write_instructions(char **certificates, HANDLE write_handle, + bool remove) { - bool retval = false; int i = 0; - const char *line_end = "\n\0"; + int cHandle = -1; + FILE *write_stream = NULL; - if (!instructions) + if (!certificates) { return true; } - for (i = 0; instructions[i]; i++) + cHandle = _open_osfhandle ((intptr_t)write_handle, 0); + + if (cHandle == -1) { - DWORD written = 0; - DWORD inst_len = strlen (instructions[i]); - retval = WriteFile (write_handle, (LPCVOID) instructions[i], inst_len, &written, NULL); - if (!retval) - { - PRINTLASTERROR ("Failed to write\n"); - return false; - } - if (inst_len != written) + ERRORPRINTF ("Failed to open write handle.\n"); + } + + write_stream = _fdopen(cHandle, "w"); + for (i = 0; certificates[i]; i++) + { + int ret = 0; + DEBUGPRINTF("Writing \n"); + if (remove) + ret = fprintf (write_stream, "R:%s\n", certificates[i]); + else + ret = fprintf (write_stream, "I:%s\n", certificates[i]); + + if (ret <= 0) { - ERRORPRINTF ("Failed to write everything\n"); - retval = false; - return false; - } - written = 0; - retval = WriteFile (write_handle, (LPCVOID) line_end, 2, &written, NULL); - if (!retval) - { - PRINTLASTERROR ("Failed to write line end\n"); - return false; - } - if (inst_len != written) - { - ERRORPRINTF ("Failed to write full line end\n"); - retval = false; - return false; + DEBUGPRINTF ("Failed to write everything.\n"); + break; } } + + DEBUGPRINTF("Write done\n"); return true; } @@ -151,7 +148,7 @@ siStartInfo.cb = sizeof (STARTUPINFO); siStartInfo.hStdError = h_stdout_child_w; siStartInfo.hStdOutput = h_stdout_child_w; - siStartInfo.hStdInput = h_stdin_child_w; + siStartInfo.hStdInput = h_stdin_child_r; siStartInfo.dwFlags = STARTF_USESTDHANDLES; success = CreateProcessAsUserW (hToken, @@ -160,7 +157,7 @@ NULL, /* Process attributes. Take hToken */ NULL, /* Thread attribues. Take hToken */ TRUE, /* Inherit Handles */ - 0, /* Creation flags. Use default */ + CREATE_UNICODE_ENVIRONMENT, /* Creation flags. */ lpEnvironment, NULL, /* Current working directory */ &siStartInfo, @@ -171,12 +168,12 @@ goto closepipes; } - if (!write_instructions (to_install, h_stdin_child_w)) + if (!write_instructions (to_install, h_stdin_child_w, false)) { ERRORPRINTF ("Failed to write install instructions.\n"); goto closepipes; } - if (!write_instructions (to_remove, h_stdin_child_w)) + if (!write_instructions (to_remove, h_stdin_child_w, true)) { ERRORPRINTF ("Failed to write remove instructions.\n"); goto closepipes; @@ -225,19 +222,21 @@ closeprocess: if (piProcInfo.hProcess) - CloseHandle(piProcInfo.hProcess); + CloseHandle (piProcInfo.hProcess); if (piProcInfo.hThread) - CloseHandle(piProcInfo.hThread); + CloseHandle (piProcInfo.hThread); closepipes: + if (lpEnvironment) + DestroyEnvironmentBlock (lpEnvironment); if (h_stdin_child_w) - CloseHandle(h_stdin_child_w); + CloseHandle (h_stdin_child_w); if (h_stdin_child_r) - CloseHandle(h_stdin_child_r); + CloseHandle (h_stdin_child_r); if (h_stdout_child_w) - CloseHandle(h_stdout_child_w); + CloseHandle (h_stdout_child_w); if (h_stdout_child_r) - CloseHandle(h_stdout_child_r); + CloseHandle (h_stdout_child_r); return retval; }
--- a/ui/tests/nsstest.cpp Tue Apr 08 14:52:31 2014 +0000 +++ b/ui/tests/nsstest.cpp Tue Apr 08 15:08:57 2014 +0000 @@ -10,6 +10,11 @@ #include "strhelp.h" #include <QTest> +#include <QTextCodec> + +#ifdef WIN32 +#define endl "\r\n" +#endif QList<QByteArray> NSSTest::get_nss_certs (QTemporaryDir *nssDir) { @@ -40,9 +45,9 @@ void NSSTest::setupTestDir(QTemporaryDir *nssDir) { /* Copy the empty nss db in the temporary dir */ - QFile::copy(":/nss/cert8.db", nssDir->path() + "/" +"cert8.db"); - QFile::copy(":/nss/key3.db", nssDir->path() + "/" +"key3.db"); - QFile::copy(":/nss/secmod.db", nssDir->path() + "/" +"secmod.db"); + QVERIFY(QFile::copy(":/nss/cert8.db", nssDir->path() + "/" +"cert8.db")); + QVERIFY(QFile::copy(":/nss/key3.db", nssDir->path() + "/" +"key3.db")); + QVERIFY(QFile::copy(":/nss/secmod.db", nssDir->path() + "/" +"secmod.db")); QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"cert8.db", QFileDevice::ReadOwner | QFileDevice::WriteOwner)); @@ -50,9 +55,11 @@ QFileDevice::ReadOwner | QFileDevice::WriteOwner)); QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"secmod.db", QFileDevice::ReadOwner | QFileDevice::WriteOwner)); + nssDir->setAutoRemove(false); } void NSSTest::initTestCase() { + QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); /* use system default */ /* Set up a temporary list */ QFile res(":/list-valid-signed.txt"); @@ -67,6 +74,7 @@ validList = CertificateList(validListFile.fileName().toLocal8Bit().data()); /* Create the profiles.ini `s set environment variables*/ + fakeHome.setAutoRemove(false); #ifndef WIN32 QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1)); fakeFirefoxDir = QDir(fakeHome.path() + "/.mozilla/firefox");