Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix key and registry tests to work on Windows 10 #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RupW
Copy link

@RupW RupW commented Jun 15, 2018

  • Open keys in HKCR as read-only, not all access
  • Create a new key HKCU\Software\windows-registry-node for read/write tests. (This key is not cleaned up on test completion, in case there's a problem with the delete code.)

I haven't fixed the file association or elevation tests though, which are still failing for me. The file association code tries to open HKCR as all access which fails for me even with elevation, and the elevation test times out before the confirmation dialog opens.

- Open keys in HKCR as read-only, not all access
- Create a new key HKCU\Software\windows-registry-node for read/write
  tests.

Note that this key is not cleaned up on test completion, in case the
delete function deletes something it shouldn't!

The file association test still attempts to write to HKCR and will fail.
@RupW
Copy link
Author

RupW commented Jun 21, 2018

This doesn't yet work with TEST_MOCKS_ON=true because there's no mock for RegDeleteValue and because I'm using subkeys beyond what the mock currently supports. Will have a go at that at some point!

@simonbuchan
Copy link

For me the tests are failing later on File Association Test with access denied in utils.associateExeForFile(), since that tries to actually set it in HKCU, which fails of course. I got it working with TEST_MOCKS_ON with:

diff --git i/test/mock/adv_api.js w/test/mock/adv_api.js
index f55dea9..1d148d3 100644
--- i/test/mock/adv_api.js
+++ w/test/mock/adv_api.js
@@ -26,12 +26,15 @@ function findValueInHash(value, hash) {

 var keys = {
 };
-keys[windef.HKEY.HKEY_CLASSES_ROOT] = {
-    predefValue: true,
-    open: false,
-    values: {
-    }
-};
+Object.keys(windef.HKEY).forEach(function (k) {
+    keys[windef.HKEY[k]] = {
+        predefValue: true,
+        open: false,
+        values: {
+        }
+    };
+});
+
 var mockIndex = 0x00000001;

 var advApi = {
@@ -203,6 +206,22 @@ var advApi = {
         delete keys[hKey.address()];
         return 0;
     },
+    /*
+      LONG WINAPI RegDeleteValue(
+      _In_     HKEY    hKey,
+      _In_opt_ LPCTSTR lpValueName
+      );
+    */
+    RegDeleteValueA: function (hKey, valueName) {
+        if (typeof hKey === 'number') {
+            assert(findValueInHash(hKey, windef.HKEY), 'Mock: Invalid predefined key specified');
+        } else {
+            assert(hKey.constructor === Buffer, 'Mock: hKey should be of type buffer if not a number');
+        }
+        assert(typeof valueName === 'string');
+        delete keys[hKey.address()].values[valueName];
+        return 0;
+    },
     /*
     LONG WINAPI RegCloseKey(
     _In_ HKEY hKey

@RupW
Copy link
Author

RupW commented Sep 25, 2018

Thanks, and apologies I never came back to the file association or elevation tests myself.

I had glanced at enhancing the mocks but I'd thought it needed more work than that, but that looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants