Skip to content

Commit

Permalink
SDA-4714 - Add missing latestAutoUpdateChannelEnabled into plist file (
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan authored Nov 8, 2024
1 parent 5488ef8 commit 5c76460
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions installer/mac/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
65 changes: 65 additions & 0 deletions spec/postinstall.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 5c76460

Please sign in to comment.