Skip to content

Commit

Permalink
Extensions are now string:string, not string:bool.
Browse files Browse the repository at this point in the history
So registry values for special objects can be both numeric and strings.

Signed-off-by: Eric Promislow <[email protected]>
  • Loading branch information
ericpromislow committed May 4, 2023
1 parent 0f5c049 commit fe879d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions pkg/rancher-desktop/main/__tests__/deploymentProfiles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ const defaultsUserRegFile = `Windows Registry Editor Version 5.00
"magog"=dword:0
[HKEY_CURRENT_USER\\SOFTWARE\\Rancher Desktop\\Profile\\${ testingDefaultsHiveName }\\extensions]
"bellingham"=dword:1
"seattle"=dword:1
"olympia"=dword:0
"winthrop"=dword:1
"bellingham"="WA"
"portland"="OR"
"shasta"="CA"
"elko"="NV"
`;

const lockedUserRegFile = `Windows Registry Editor Version 5.00
Expand Down Expand Up @@ -198,7 +198,7 @@ const arrayFromSingleStringDefaultsUserRegFile = `Windows Registry Editor Versio
`;

describeWindows('windows deployment profiles', () => {
/** Mocked console.log() to check messages. */
/* Mock console.error() to capture error messages. */
let consoleMock: jest.SpyInstance<void, [message?: any, ...optionalArgs: any[]]>;

beforeEach(async() => {
Expand Down Expand Up @@ -237,8 +237,7 @@ describeWindows('windows deployment profiles', () => {
showMuted: true,
mutedChecks: { montreal: true, 'riviere du loup': false, magog: false },
},
// @ts-ignore
extensions: { bellingham: true, seattle: true, olympia: false, winthrop: true },
extensions: { bellingham: 'WA', portland: 'OR', shasta: 'CA', elko: 'NV' },
};
const lockedUserProfile = {
containerEngine: {
Expand Down
8 changes: 4 additions & 4 deletions pkg/rancher-desktop/main/deploymentProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function readRegistryObject(regKey: nativeReg.HKEY, pathParts: string[], isSpeci
const newObject: Record<string, string[]|string|boolean|number> = {};

for (const k of nativeReg.enumValueNames(regKey)) {
let newValue = readRegistryValue(undefined, regKey, pathParts, k);
let newValue = readRegistryValue(undefined, regKey, pathParts, k, isSpecialObject);

if (newValue !== null) {
if (isSpecialObject) {
Expand All @@ -334,7 +334,7 @@ function readRegistryObject(regKey: nativeReg.HKEY, pathParts: string[], isSpeci
return newObject;
}

function readRegistryValue(schemaVal: any, regKey: nativeReg.HKEY, pathParts: string[], valueName: string): string[]|string|boolean|number|null {
function readRegistryValue(schemaVal: any, regKey: nativeReg.HKEY, pathParts: string[], valueName: string, isSpecialObject=false): string[]|string|boolean|number|null {
const fullPath = `\\${ pathParts.join('\\') }\\${ valueName }`;
const valueTypeNames = [
'NONE', // 0
Expand All @@ -356,7 +356,7 @@ function readRegistryValue(schemaVal: any, regKey: nativeReg.HKEY, pathParts: st
if (rawValue === null) {
// This shouldn't happen
return null;
} else if (schemaVal && typeof schemaVal === 'object' && !Array.isArray(schemaVal)) {
} else if (!isSpecialObject && schemaVal && typeof schemaVal === 'object' && !Array.isArray(schemaVal)) {
console.error(`Expecting registry entry ${ fullPath } to be a registry object, but it's a ${ valueTypeNames[rawValue.type] }, value: ${ parsedValueForErrorMessage }`);

return null;
Expand All @@ -366,7 +366,7 @@ function readRegistryValue(schemaVal: any, regKey: nativeReg.HKEY, pathParts: st

switch (rawValue.type) {
case nativeReg.ValueType.SZ:
if (typeof schemaVal === 'string') {
if (isSpecialObject || (typeof schemaVal) === 'string') {
return nativeReg.parseValue(rawValue) as string;
} else if (expectingArray) {
return [nativeReg.parseValue(rawValue) as string];
Expand Down

0 comments on commit fe879d4

Please sign in to comment.