diff --git a/installer/mac/postinstall.sh b/installer/mac/postinstall.sh index a5ddb5e90..50354c297 100755 --- a/installer/mac/postinstall.sh +++ b/installer/mac/postinstall.sh @@ -118,6 +118,7 @@ if [ "$EUID" -ne 0 ]; then defaults write "$plistFilePath" userDataPath -string "" defaults write "$plistFilePath" chromeFlags -string "" defaults write "$plistFilePath" betaAutoUpdateChannelEnabled -bool true + defaults write "$plistFilePath" latestAutoUpdateChannelEnabled -bool true defaults write "$plistFilePath" installVariant -string "$uuid" else sudo -u "$userName" defaults write "$plistFilePath" url -string "$pod_url" @@ -161,6 +162,7 @@ else sudo -u "$userName" defaults write "$plistFilePath" userDataPath -string "" sudo -u "$userName" defaults write "$plistFilePath" chromeFlags -string "" sudo -u "$userName" defaults write "$plistFilePath" betaAutoUpdateChannelEnabled -bool true + sudo -u "$userName" defaults write "$plistFilePath" latestAutoUpdateChannelEnabled -bool true sudo -u "$userName" defaults write "$plistFilePath" installVariant -string "$uuid" fi diff --git a/spec/postinstall.spec.ts b/spec/postinstall.spec.ts new file mode 100644 index 000000000..5344244c9 --- /dev/null +++ b/spec/postinstall.spec.ts @@ -0,0 +1,65 @@ +import * as fs from 'fs'; + +const extractUserDefaults = (filePath: string) => { + const content = fs.readFileSync(filePath, 'utf-8'); + const fieldRegex = + /^\s*sudo -u "\$userName"\s+defaults write "\$plistFilePath"\s+([a-zA-Z_][a-zA-Z0-9_]*)/gm; + return Array.from(content.matchAll(fieldRegex), (match) => match[1]); +}; + +const extractSystemDefaults = (filePath: string) => { + const content = fs.readFileSync(filePath, 'utf-8'); + const fieldRegex = + /^\s*defaults write "\$plistFilePath"\s+([a-zA-Z_][a-zA-Z0-9_]*)/gm; + return Array.from(content.matchAll(fieldRegex), (match) => match[1]); +}; + +const isArraySubset = (array1: string[], array2: string[]): boolean => { + return array2.every((item) => array1.includes(item)); +}; + +const removeFields = (array: string[], stringsToRemove: string[]): string[] => { + return array.filter((item) => !stringsToRemove.includes(item)); +}; + +describe('Shell Script Field Validation', () => { + it('should contain all the user defaults fields from JSON', async () => { + const jsonFilePath = './config/Symphony.config'; + const scriptFilePath = './installer/mac/postinstall.sh'; + + // Read Symphony config JSON file + const jsonContent = JSON.parse(fs.readFileSync(jsonFilePath, 'utf-8')); + const fields = Object.keys(jsonContent) as []; + const filteredFields = removeFields(fields, [ + 'notificationSettings', + 'customFlags', + 'permissions', + ]); + + // Read fields from post install script file + const scriptFields = extractUserDefaults(scriptFilePath); + scriptFields.splice(scriptFields.indexOf('ApplicationName'), 1); + + expect(isArraySubset(scriptFields, filteredFields)).toBe(true); + }); + + it('should contain all the system defaults fields from JSON', async () => { + const jsonFilePath = './config/Symphony.config'; + const scriptFilePath = './installer/mac/postinstall.sh'; + + // Read Symphony config JSON file + const jsonContent = JSON.parse(fs.readFileSync(jsonFilePath, 'utf-8')); + const fields = Object.keys(jsonContent) as []; + const filteredFields = removeFields(fields, [ + 'notificationSettings', + 'customFlags', + 'permissions', + ]); + + // Read fields from post install script file + const scriptFields = extractSystemDefaults(scriptFilePath); + scriptFields.splice(scriptFields.indexOf('ApplicationName'), 1); + + expect(isArraySubset(scriptFields, filteredFields)).toBe(true); + }); +});