2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-03-28 17:09:26 +00:00
|
|
|
import { assert } from 'chai';
|
2022-03-04 19:59:47 +00:00
|
|
|
import { pathExists } from 'fs-extra';
|
|
|
|
import { stat, mkdir } from 'fs/promises';
|
|
|
|
import { join } from 'path';
|
2019-03-28 17:09:26 +00:00
|
|
|
|
2019-08-02 21:11:10 +00:00
|
|
|
import {
|
2022-02-24 21:01:41 +00:00
|
|
|
createUpdateCacheDirIfNeeded,
|
2019-08-02 21:11:10 +00:00
|
|
|
getUpdateFileName,
|
|
|
|
getVersion,
|
|
|
|
isUpdateFileNameValid,
|
|
|
|
validatePath,
|
2021-08-19 22:56:29 +00:00
|
|
|
parseYaml,
|
2022-03-04 19:59:47 +00:00
|
|
|
createTempDir,
|
|
|
|
getTempDir,
|
|
|
|
deleteTempDir,
|
2019-08-02 21:11:10 +00:00
|
|
|
} from '../../updater/common';
|
2023-03-02 17:57:36 +00:00
|
|
|
import * as log from '../../logging/log';
|
2019-03-28 17:09:26 +00:00
|
|
|
|
|
|
|
describe('updater/signatures', () => {
|
2021-08-19 22:56:29 +00:00
|
|
|
const windows = parseYaml(`version: 1.23.2
|
2019-03-28 17:09:26 +00:00
|
|
|
files:
|
|
|
|
- url: signal-desktop-win-1.23.2.exe
|
|
|
|
sha512: hhK+cVAb+QOK/Ln0RBcq8Rb1iPcUC0KZeT4NwLB25PMGoPmakY27XE1bXq4QlkASJN1EkYTbKf3oUJtcllziyQ==
|
|
|
|
size: 92020776
|
|
|
|
path: signal-desktop-win-1.23.2.exe
|
|
|
|
sha512: hhK+cVAb+QOK/Ln0RBcq8Rb1iPcUC0KZeT4NwLB25PMGoPmakY27XE1bXq4QlkASJN1EkYTbKf3oUJtcllziyQ==
|
|
|
|
releaseDate: '2019-03-29T16:58:08.210Z'
|
2021-08-19 22:56:29 +00:00
|
|
|
`);
|
|
|
|
const mac = parseYaml(`version: 1.23.2
|
2019-03-28 17:09:26 +00:00
|
|
|
files:
|
2021-12-03 22:49:15 +00:00
|
|
|
- url: signal-desktop-mac-x64-1.23.2.zip
|
|
|
|
sha512: STurwHhpE2rwwpwz3/RQBbMbVYY2Hh1DVpeofwIWPXoDTX/41zia+ByKXq8BvnjIMdQ3YmPHu+UppAW/+CFkFQ==
|
|
|
|
size: 150317727
|
|
|
|
- url: signal-desktop-mac-arm64-1.23.2.zip
|
|
|
|
sha512: PGFqCtiFep27rJcE3s8J2BAH9GQIRg460J0IVwbUCQERLZlN8YP71B1xWW09gCmA5YeEY4oDynqBLmgQfEFtfw==
|
|
|
|
size: 148022367
|
|
|
|
- url: signal-desktop-mac-x64-1.23.2.dmg
|
|
|
|
sha512: xbX5QDyzdvQd6rVzpamRLfWu+oIbhlW9pLbpKywQSiEx6BPZHTYCulBx9V5zrKh7TNM9nRpZJ3Sph2bU3v+5uQ==
|
|
|
|
size: 154866781
|
|
|
|
- url: signal-desktop-mac-arm64-1.23.2.dmg
|
|
|
|
sha512: 7wgGWCogQ9OWMGnqEUmiSeRct3w60zyzYp5cIUvJIVFe8WoB/qS7n721n+xCsrdteclR6yu1cqkOh/xN/wgS0Q==
|
|
|
|
size: 152618547
|
|
|
|
path: signal-desktop-mac-x64-1.23.2.zip
|
|
|
|
sha512: STurwHhpE2rwwpwz3/RQBbMbVYY2Hh1DVpeofwIWPXoDTX/41zia+ByKXq8BvnjIMdQ3YmPHu+UppAW/+CFkFQ==
|
|
|
|
releaseDate: '2021-12-03T19:00:23.754Z'
|
2021-08-19 22:56:29 +00:00
|
|
|
`);
|
|
|
|
const windowsBeta = parseYaml(`version: 1.23.2-beta.1
|
2019-03-28 17:09:26 +00:00
|
|
|
files:
|
|
|
|
- url: signal-desktop-beta-win-1.23.2-beta.1.exe
|
|
|
|
sha512: ZHM1F3y/Y6ulP5NhbFuh7t2ZCpY4lD9BeBhPV+g2B/0p/66kp0MJDeVxTgjR49OakwpMAafA1d6y2QBail4hSQ==
|
|
|
|
size: 92028656
|
|
|
|
path: signal-desktop-beta-win-1.23.2-beta.1.exe
|
|
|
|
sha512: ZHM1F3y/Y6ulP5NhbFuh7t2ZCpY4lD9BeBhPV+g2B/0p/66kp0MJDeVxTgjR49OakwpMAafA1d6y2QBail4hSQ==
|
|
|
|
releaseDate: '2019-03-29T01:56:00.544Z'
|
2021-08-19 22:56:29 +00:00
|
|
|
`);
|
|
|
|
const macBeta = parseYaml(`version: 1.23.2-beta.1
|
2019-03-28 17:09:26 +00:00
|
|
|
files:
|
2021-12-03 22:49:15 +00:00
|
|
|
- url: signal-desktop-mac-x64-1.23.2-beta.1.zip
|
|
|
|
sha512: STurwHhpE2rwwpwz3/RQBbMbVYY2Hh1DVpeofwIWPXoDTX/41zia+ByKXq8BvnjIMdQ3YmPHu+UppAW/+CFkFQ==
|
|
|
|
size: 150317727
|
|
|
|
- url: signal-desktop-mac-arm64-1.23.2-beta.1.zip
|
|
|
|
sha512: PGFqCtiFep27rJcE3s8J2BAH9GQIRg460J0IVwbUCQERLZlN8YP71B1xWW09gCmA5YeEY4oDynqBLmgQfEFtfw==
|
|
|
|
size: 148022367
|
|
|
|
- url: signal-desktop-mac-x64-1.23.2-beta.1.dmg
|
|
|
|
sha512: xbX5QDyzdvQd6rVzpamRLfWu+oIbhlW9pLbpKywQSiEx6BPZHTYCulBx9V5zrKh7TNM9nRpZJ3Sph2bU3v+5uQ==
|
|
|
|
size: 154866781
|
|
|
|
- url: signal-desktop-mac-arm64-1.23.2-beta.1.dmg
|
|
|
|
sha512: 7wgGWCogQ9OWMGnqEUmiSeRct3w60zyzYp5cIUvJIVFe8WoB/qS7n721n+xCsrdteclR6yu1cqkOh/xN/wgS0Q==
|
|
|
|
size: 152618547
|
|
|
|
path: signal-desktop-mac-x64-1.23.2-beta.1.zip
|
|
|
|
sha512: STurwHhpE2rwwpwz3/RQBbMbVYY2Hh1DVpeofwIWPXoDTX/41zia+ByKXq8BvnjIMdQ3YmPHu+UppAW/+CFkFQ==
|
|
|
|
releaseDate: '2021-12-03T19:00:23.754Z'
|
2021-08-19 22:56:29 +00:00
|
|
|
`);
|
2019-03-28 17:09:26 +00:00
|
|
|
|
|
|
|
describe('#getVersion', () => {
|
|
|
|
it('successfully gets version', () => {
|
|
|
|
const expected = '1.23.2';
|
|
|
|
assert.strictEqual(getVersion(windows), expected);
|
|
|
|
assert.strictEqual(getVersion(mac), expected);
|
|
|
|
|
|
|
|
const expectedBeta = '1.23.2-beta.1';
|
|
|
|
assert.strictEqual(getVersion(windowsBeta), expectedBeta);
|
|
|
|
assert.strictEqual(getVersion(macBeta), expectedBeta);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getUpdateFileName', () => {
|
|
|
|
it('successfully gets version', () => {
|
|
|
|
assert.strictEqual(
|
2021-12-03 22:49:15 +00:00
|
|
|
getUpdateFileName(windows, 'win32', 'x64'),
|
2019-03-28 17:09:26 +00:00
|
|
|
'signal-desktop-win-1.23.2.exe'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-12-03 22:49:15 +00:00
|
|
|
getUpdateFileName(mac, 'darwin', 'x64'),
|
|
|
|
'signal-desktop-mac-x64-1.23.2.zip'
|
2019-03-28 17:09:26 +00:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-12-03 22:49:15 +00:00
|
|
|
getUpdateFileName(mac, 'darwin', 'arm64'),
|
|
|
|
'signal-desktop-mac-arm64-1.23.2.zip'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
getUpdateFileName(windowsBeta, 'win32', 'x64'),
|
2019-03-28 17:09:26 +00:00
|
|
|
'signal-desktop-beta-win-1.23.2-beta.1.exe'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-12-03 22:49:15 +00:00
|
|
|
getUpdateFileName(macBeta, 'darwin', 'x64'),
|
|
|
|
'signal-desktop-mac-x64-1.23.2-beta.1.zip'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
getUpdateFileName(macBeta, 'darwin', 'arm64'),
|
|
|
|
'signal-desktop-mac-arm64-1.23.2-beta.1.zip'
|
2019-03-28 17:09:26 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-08-02 21:11:10 +00:00
|
|
|
|
|
|
|
describe('#isUpdateFileNameValid', () => {
|
|
|
|
it('returns true for normal filenames', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
isUpdateFileNameValid('signal-desktop-win-1.23.2.exe'),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-12-03 22:49:15 +00:00
|
|
|
isUpdateFileNameValid('signal-desktop-mac-x64-1.23.2-beta.1.zip'),
|
2019-08-02 21:11:10 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('returns false for problematic names', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
isUpdateFileNameValid('../signal-desktop-win-1.23.2.exe'),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-12-03 22:49:15 +00:00
|
|
|
isUpdateFileNameValid('%signal-desktop-mac-x64-1.23.2-beta.1.zip'),
|
2019-08-02 21:11:10 +00:00
|
|
|
false
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-12-03 22:49:15 +00:00
|
|
|
isUpdateFileNameValid('@signal-desktop-mac-x64-1.23.2-beta.1.zip'),
|
2019-08-02 21:11:10 +00:00
|
|
|
false
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#validatePath', () => {
|
|
|
|
it('succeeds for simple children', async () => {
|
2022-02-24 21:01:41 +00:00
|
|
|
const base = await createUpdateCacheDirIfNeeded();
|
2019-08-02 21:11:10 +00:00
|
|
|
validatePath(base, `${base}/child`);
|
|
|
|
validatePath(base, `${base}/child/grandchild`);
|
|
|
|
});
|
|
|
|
it('returns false for problematic names', async () => {
|
2022-02-24 21:01:41 +00:00
|
|
|
const base = await createUpdateCacheDirIfNeeded();
|
2019-08-02 21:11:10 +00:00
|
|
|
assert.throws(() => {
|
|
|
|
validatePath(base, `${base}/../child`);
|
|
|
|
});
|
|
|
|
assert.throws(() => {
|
|
|
|
validatePath(base, '/root');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-03-04 19:59:47 +00:00
|
|
|
|
|
|
|
describe('createTempDir', () => {
|
|
|
|
it('creates a temporary directory', async () => {
|
|
|
|
const dir = await createTempDir();
|
|
|
|
assert.isTrue((await stat(dir)).isDirectory());
|
|
|
|
|
2023-03-02 17:57:36 +00:00
|
|
|
await deleteTempDir(log, dir);
|
2022-03-04 19:59:47 +00:00
|
|
|
|
|
|
|
assert.isFalse(await pathExists(dir), 'Directory should be deleted');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getTempDir', () => {
|
|
|
|
it('reserves a temporary directory', async () => {
|
|
|
|
const dir = await getTempDir();
|
|
|
|
assert.isTrue(
|
|
|
|
(await stat(join(dir, '..'))).isDirectory(),
|
|
|
|
'Parent folder should exist'
|
|
|
|
);
|
|
|
|
assert.isFalse(await pathExists(dir), 'Reserved folder should not exist');
|
|
|
|
|
|
|
|
await mkdir(dir);
|
|
|
|
|
2023-03-02 17:57:36 +00:00
|
|
|
await deleteTempDir(log, dir);
|
2022-03-04 19:59:47 +00:00
|
|
|
|
|
|
|
assert.isFalse(await pathExists(dir), 'Directory should be deleted');
|
|
|
|
});
|
|
|
|
});
|
2019-03-28 17:09:26 +00:00
|
|
|
});
|