windows-registry-node
windows-registry-node copied to clipboard
Fix key and registry tests to work on Windows 10
- 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.
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!
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
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!