Bug 1382251: Part 10 - Add nsWindowsDllInterceptor tests for the new functions r=aklotz
☠☠ backed out by 398fb8533bcb ☠ ☠
authorDavid Parks <dparks@mozilla.com>
Mon, 06 Nov 2017 10:45:13 -0800
changeset 454127 f9f8aba058c1e12cf479c7540395aadc1db33852
parent 454126 dc0ce4cae588d9a27a5629c16919de37e45bbacc
child 454128 a5f447c3bde85b6240d7b029edeec6259529d303
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1382251
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382251: Part 10 - Add nsWindowsDllInterceptor tests for the new functions r=aklotz Adds tests for the DLL interception of the SSL APIs included in the previous patch.
toolkit/xre/test/win/TestDllInterceptor.cpp
--- a/toolkit/xre/test/win/TestDllInterceptor.cpp
+++ b/toolkit/xre/test/win/TestDllInterceptor.cpp
@@ -1,15 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <shlobj.h>
 #include <stdio.h>
 #include <commdlg.h>
+#define SECURITY_WIN32
+#include <security.h>
+#include <wininet.h>
+#include <schnlsp.h>
 
 #include "mozilla/WindowsVersion.h"
 #include "nsWindowsDllInterceptor.h"
 #include "nsWindowsHelpers.h"
 
 using namespace mozilla;
 
 struct payload {
@@ -435,16 +439,151 @@ bool TestTlsFree(void* aFunc)
 bool TestPrintDlgW(void* aFunc)
 {
   auto patchedPrintDlgW =
     reinterpret_cast<decltype(&PrintDlgW)>(aFunc);
   patchedPrintDlgW(0);
   return true;
 }
 
+bool TestInternetConnectA(void* aFunc)
+{
+  auto patchedInternetConnectA =
+    reinterpret_cast<decltype(&InternetConnectA)>(aFunc);
+  return patchedInternetConnectA(0, 0, 0, 0, 0, 0, 0, 0) == 0;
+}
+
+HINTERNET sInternet = 0;
+
+bool TestInternetOpenA(void* aFunc)
+{
+  auto patchedInternetOpenA =
+    reinterpret_cast<decltype(&InternetOpenA)>(aFunc);
+  sInternet = patchedInternetOpenA(0, 0, 0, 0, 0);
+  return sInternet != 0;
+}
+
+bool TestInternetCloseHandle(void* aFunc)
+{
+  auto patchedInternetCloseHandle =
+    reinterpret_cast<decltype(&InternetCloseHandle)>(aFunc);
+  return patchedInternetCloseHandle(sInternet);
+}
+
+bool TestInternetQueryDataAvailable(void* aFunc)
+{
+  auto patchedInternetQueryDataAvailable =
+    reinterpret_cast<decltype(&InternetQueryDataAvailable)>(aFunc);
+  return patchedInternetQueryDataAvailable(0, 0, 0, 0) == FALSE;
+}
+
+bool TestInternetReadFile(void* aFunc)
+{
+  auto patchedInternetReadFile =
+    reinterpret_cast<decltype(&InternetReadFile)>(aFunc);
+  return patchedInternetReadFile(0, 0, 0, 0) == FALSE;
+}
+
+bool TestInternetWriteFile(void* aFunc)
+{
+  auto patchedInternetWriteFile =
+    reinterpret_cast<decltype(&InternetWriteFile)>(aFunc);
+  return patchedInternetWriteFile(0, 0, 0, 0) == FALSE;
+}
+
+bool TestInternetSetOptionA(void* aFunc)
+{
+  auto patchedInternetSetOptionA =
+    reinterpret_cast<decltype(&InternetSetOptionA)>(aFunc);
+  return patchedInternetSetOptionA(0, 0, 0, 0) == FALSE;
+}
+
+bool TestHttpAddRequestHeadersA(void* aFunc)
+{
+  auto patchedHttpAddRequestHeadersA =
+    reinterpret_cast<decltype(&HttpAddRequestHeadersA)>(aFunc);
+  return patchedHttpAddRequestHeadersA(0, 0, 0, 0) == FALSE;
+}
+
+bool TestHttpOpenRequestA(void* aFunc)
+{
+  auto patchedHttpOpenRequestA =
+    reinterpret_cast<decltype(&HttpOpenRequestA)>(aFunc);
+  return patchedHttpOpenRequestA(0, 0, 0, 0, 0, 0, 0, 0) == 0;
+}
+
+bool TestHttpQueryInfoA(void* aFunc)
+{
+  auto patchedHttpQueryInfoA =
+    reinterpret_cast<decltype(&HttpQueryInfoA)>(aFunc);
+  return patchedHttpQueryInfoA(0, 0, 0, 0, 0) == FALSE;
+}
+
+bool TestHttpSendRequestA(void* aFunc)
+{
+  auto patchedHttpSendRequestA =
+    reinterpret_cast<decltype(&HttpSendRequestA)>(aFunc);
+  return patchedHttpSendRequestA(0, 0, 0, 0, 0) == FALSE;
+}
+
+bool TestHttpSendRequestExA(void* aFunc)
+{
+  auto patchedHttpSendRequestExA =
+    reinterpret_cast<decltype(&HttpSendRequestExA)>(aFunc);
+  return patchedHttpSendRequestExA(0, 0, 0, 0, 0) == FALSE;
+}
+
+bool TestHttpEndRequestA(void* aFunc)
+{
+  auto patchedHttpEndRequestA =
+    reinterpret_cast<decltype(&HttpEndRequestA)>(aFunc);
+  return patchedHttpEndRequestA(0, 0, 0, 0) == FALSE;
+}
+
+bool TestInternetQueryOptionA(void* aFunc)
+{
+  auto patchedInternetQueryOptionA =
+    reinterpret_cast<decltype(&InternetQueryOptionA)>(aFunc);
+  return patchedInternetQueryOptionA(0, 0, 0, 0) == FALSE;
+}
+
+bool TestInternetErrorDlg(void* aFunc)
+{
+  auto patchedInternetErrorDlg =
+    reinterpret_cast<decltype(&InternetErrorDlg)>(aFunc);
+  return patchedInternetErrorDlg(0, 0, 0, 0, 0) == ERROR_INVALID_HANDLE;
+}
+
+CredHandle sCredHandle;
+
+bool TestAcquireCredentialsHandleA(void* aFunc)
+{
+  auto patchedAcquireCredentialsHandleA =
+    reinterpret_cast<decltype(&AcquireCredentialsHandleA)>(aFunc);
+  SCHANNEL_CRED cred;
+  memset(&cred, 0, sizeof(cred));
+  cred.dwVersion = SCHANNEL_CRED_VERSION;
+  return patchedAcquireCredentialsHandleA(0, UNISP_NAME, SECPKG_CRED_OUTBOUND,
+                                          0, &cred, 0, 0, &sCredHandle, 0) == S_OK;
+}
+
+bool TestQueryCredentialsAttributesA(void* aFunc)
+{
+  auto patchedQueryCredentialsAttributesA =
+    reinterpret_cast<decltype(&QueryCredentialsAttributesA)>(aFunc);
+  return patchedQueryCredentialsAttributesA(&sCredHandle, 0, 0) == SEC_E_UNSUPPORTED_FUNCTION;
+}
+
+bool TestFreeCredentialsHandle(void* aFunc)
+{
+  auto patchedFreeCredentialsHandle =
+    reinterpret_cast<decltype(&FreeCredentialsHandle)>(aFunc);
+  return patchedFreeCredentialsHandle(&sCredHandle) == S_OK;
+}
+
 int main()
 {
   // We disable this part of the test because the code coverage instrumentation
   // injects code in rotatePayload in a way that WindowsDllInterceptor doesn't
   // understand.
 #ifndef MOZ_CODE_COVERAGE
   payload initial = { 0x12345678, 0xfc4e9d31, 0x87654321 };
   payload p0, p1;
@@ -551,16 +690,36 @@ int main()
 #endif
       MaybeTestHook(ShouldTestTipTsf(), TestProcessCaretEvents, "tiptsf.dll", "ProcessCaretEvents") &&
 #ifdef _M_IX86
       TestHook(TestSendMessageTimeoutW, "user32.dll", "SendMessageTimeoutW") &&
 #endif
       TestHook(TestSetCursorPos, "user32.dll", "SetCursorPos") &&
       TestHook(TestTlsAlloc, "kernel32.dll", "TlsAlloc") &&
       TestHook(TestTlsFree, "kernel32.dll", "TlsFree") &&
+
+      TestHook(TestInternetOpenA, "wininet.dll", "InternetOpenA") &&
+      TestHook(TestInternetCloseHandle, "wininet.dll", "InternetCloseHandle") &&
+      TestHook(TestInternetConnectA, "wininet.dll", "InternetConnectA") &&
+      TestHook(TestInternetQueryDataAvailable, "wininet.dll", "InternetQueryDataAvailable") &&
+      TestHook(TestInternetReadFile, "wininet.dll", "InternetReadFile") &&
+      TestHook(TestInternetWriteFile, "wininet.dll", "InternetWriteFile") &&
+      TestHook(TestInternetSetOptionA, "wininet.dll", "InternetSetOptionA") &&
+      TestHook(TestHttpAddRequestHeadersA, "wininet.dll", "HttpAddRequestHeadersA") &&
+      TestHook(TestHttpOpenRequestA, "wininet.dll", "HttpOpenRequestA") &&
+      TestHook(TestHttpQueryInfoA, "wininet.dll", "HttpQueryInfoA") &&
+      TestHook(TestHttpSendRequestA, "wininet.dll", "HttpSendRequestA") &&
+      TestHook(TestHttpSendRequestExA, "wininet.dll", "HttpSendRequestExA") &&
+      TestHook(TestHttpEndRequestA, "wininet.dll", "HttpEndRequestA") &&
+      TestHook(TestInternetQueryOptionA, "wininet.dll", "InternetQueryOptionA") &&
+
+      TestHook(TestAcquireCredentialsHandleA, "sspicli.dll", "AcquireCredentialsHandleA") &&
+      TestHook(TestQueryCredentialsAttributesA, "sspicli.dll", "QueryCredentialsAttributesA") &&
+      TestHook(TestFreeCredentialsHandle, "sspicli.dll", "FreeCredentialsHandle") &&
+
       TestDetour("kernel32.dll", "BaseThreadInitThunk") &&
       TestDetour("ntdll.dll", "LdrLoadDll")) {
     printf("TEST-PASS | WindowsDllInterceptor | all checks passed\n");
     return 0;
   }
 
   return 1;
 }