[PATCH 1/2] Tests for CertRegisterSystemStore

Donat Enikeev donat at enikeev.net
Wed Oct 12 04:32:11 CDT 2016


Per bug https://bugs.winehq.org/show_bug.cgi?id=40314
---
 dlls/crypt32/tests/store.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/dlls/crypt32/tests/store.c b/dlls/crypt32/tests/store.c
index 4483936..2060889 100644
--- a/dlls/crypt32/tests/store.c
+++ b/dlls/crypt32/tests/store.c
@@ -123,6 +123,8 @@ static BOOL (WINAPI *pCertGetStoreProperty)(HCERTSTORE,DWORD,void*,DWORD*);
 static void (WINAPI *pCertRemoveStoreFromCollection)(HCERTSTORE,HCERTSTORE);
 static BOOL (WINAPI *pCertSetStoreProperty)(HCERTSTORE,DWORD,DWORD,const void*);
 static BOOL (WINAPI *pCertAddCertificateLinkToStore)(HCERTSTORE,PCCERT_CONTEXT,DWORD,PCCERT_CONTEXT*);
+static BOOL (WINAPI *pCertRegisterSystemStore)(const void*,DWORD,void*,void*);
+static BOOL (WINAPI *pCertUnregisterSystemStore)(const void*,DWORD);
 
 #define test_store_is_empty(store) _test_store_is_empty(__LINE__,store)
 static void _test_store_is_empty(unsigned line, HCERTSTORE store)
@@ -1868,6 +1870,72 @@ static void testCertOpenSystemStore(void)
     RegDeleteKeyW(HKEY_CURRENT_USER, BogusPathW);
 }
 
+static const struct
+{
+    DWORD cert_store;
+    LONG expected;
+    BOOL todo;
+} reg_system_store_test_data[] = {
+    { CERT_SYSTEM_STORE_CURRENT_USER,  TRUE, 0},
+    /* Following tests could require administrator privileges and thus could be skipped */
+    { CERT_SYSTEM_STORE_CURRENT_SERVICE, TRUE, 1},
+    { CERT_SYSTEM_STORE_LOCAL_MACHINE, TRUE, 0},
+    { CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY, TRUE, 1},
+    { CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY, TRUE, 1},
+    { CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, TRUE, 1}
+};
+
+static void testCertRegisterSystemStore(void)
+{
+    BOOL ret;
+    DWORD err = 0;
+    HCERTSTORE hstore;
+    static const WCHAR WineTestW[] = {'W','i','n','e','T','e','s','t',0};
+    unsigned int i;
+
+    if (!pCertRegisterSystemStore || !pCertUnregisterSystemStore)
+    {
+        win_skip("CertRegisterSystemStore() or CertUnregisterSystemStore() is not available\n");
+        return;
+    }
+
+     for (i = 0; i < sizeof(reg_system_store_test_data) / sizeof(reg_system_store_test_data[0]); i++) {
+        ret = pCertRegisterSystemStore(WineTestW, reg_system_store_test_data[i].cert_store, NULL, NULL);
+        if (!ret) {
+            err = GetLastError();
+            if (err == ERROR_ACCESS_DENIED) {
+                win_skip("Insufficient privileges for the flag %08x test\n", reg_system_store_test_data[i].cert_store);
+                continue;
+            }
+        }
+        todo_wine_if (reg_system_store_test_data[i].todo)
+            ok( ret == reg_system_store_test_data[i].expected, "Registering failed with dwFlags=%08x: got %08x last error %d\n",
+                reg_system_store_test_data[i].cert_store, ret, err);
+
+        hstore = CertOpenSystemStoreW(0, WineTestW);
+        if (hstore == NULL)
+            err = GetLastError();
+        ok ( hstore != NULL, "Opening just registered store failed with dwFlags=%08x, last error %d\n",
+                reg_system_store_test_data[i].cert_store, err);
+        if (hstore != NULL)
+            CertCloseStore(hstore, CERT_CLOSE_STORE_FORCE_FLAG);
+
+        ret = pCertUnregisterSystemStore(WineTestW, reg_system_store_test_data[i].cert_store);
+        if (!ret)
+            err = GetLastError();
+        todo_wine_if (reg_system_store_test_data[i].todo)
+            ok( ret == reg_system_store_test_data[i].expected, "Unregistering failed with dwFlags=%08x: got %08x, last error %d\n",
+                reg_system_store_test_data[i].cert_store, ret, err);
+
+        ret = pCertUnregisterSystemStore(WineTestW, reg_system_store_test_data[i].cert_store);
+        if (!ret)
+            err = GetLastError();
+        ok( !ret, "Unregistering of non-existent store failed with dwFlags=%08x: got %08x, last error %d\n",
+            reg_system_store_test_data[i].cert_store, ret, err);
+     }
+
+}
+
 struct EnumSystemStoreInfo
 {
     BOOL  goOn;
@@ -2808,6 +2876,8 @@ START_TEST(store)
     pCertRemoveStoreFromCollection = (void*)GetProcAddress(hdll, "CertRemoveStoreFromCollection");
     pCertSetStoreProperty = (void*)GetProcAddress(hdll, "CertSetStoreProperty");
     pCertAddCertificateLinkToStore = (void*)GetProcAddress(hdll, "CertAddCertificateLinkToStore");
+    pCertRegisterSystemStore = (void*)GetProcAddress(hdll, "CertRegisterSystemStore");
+    pCertUnregisterSystemStore = (void*)GetProcAddress(hdll, "CertUnregisterSystemStore");
 
     /* various combinations of CertOpenStore */
     testMemStore();
@@ -2821,6 +2891,7 @@ START_TEST(store)
     testSerializedStore();
     testCloseStore();
 
+    testCertRegisterSystemStore();
     testCertOpenSystemStore();
     testCertEnumSystemStore();
     testStoreProperty();
-- 
2.7.4




More information about the wine-patches mailing list