Windows: mark downloads as "from the internet"
This commit is contained in:
parent
50378ed9bc
commit
6d2e994f9f
5 changed files with 152 additions and 0 deletions
64
ts/test/util/windowsZoneIdentifier_test.ts
Normal file
64
ts/test/util/windowsZoneIdentifier_test.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { assert } from 'chai';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import * as fse from 'fs-extra';
|
||||
import * as Sinon from 'sinon';
|
||||
import { assertRejects } from '../helpers';
|
||||
|
||||
import { writeWindowsZoneIdentifier } from '../../util/windowsZoneIdentifier';
|
||||
|
||||
describe('writeWindowsZoneIdentifier', () => {
|
||||
before(function thisNeeded() {
|
||||
if (process.platform !== 'win32') {
|
||||
this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(async function thisNeeded() {
|
||||
this.sandbox = Sinon.createSandbox();
|
||||
this.tmpdir = await fs.promises.mkdtemp(
|
||||
path.join(os.tmpdir(), 'signal-test-')
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async function thisNeeded() {
|
||||
this.sandbox.restore();
|
||||
await fse.remove(this.tmpdir);
|
||||
});
|
||||
|
||||
it('writes zone transfer ID 3 (internet) to the Zone.Identifier file', async function thisNeeded() {
|
||||
const file = path.join(this.tmpdir, 'file.txt');
|
||||
await fse.outputFile(file, 'hello');
|
||||
|
||||
await writeWindowsZoneIdentifier(file);
|
||||
|
||||
assert.strictEqual(
|
||||
await fs.promises.readFile(`${file}:Zone.Identifier`, 'utf8'),
|
||||
'[ZoneTransfer]\r\nZoneId=3'
|
||||
);
|
||||
});
|
||||
|
||||
it('fails if there is an existing Zone.Identifier file', async function thisNeeded() {
|
||||
const file = path.join(this.tmpdir, 'file.txt');
|
||||
await fse.outputFile(file, 'hello');
|
||||
await fs.promises.writeFile(`${file}:Zone.Identifier`, '# already here');
|
||||
|
||||
await assertRejects(() => writeWindowsZoneIdentifier(file));
|
||||
});
|
||||
|
||||
it('fails if the original file does not exist', async function thisNeeded() {
|
||||
const file = path.join(this.tmpdir, 'file-never-created.txt');
|
||||
|
||||
await assertRejects(() => writeWindowsZoneIdentifier(file));
|
||||
});
|
||||
|
||||
it('fails if not on Windows', async function thisNeeded() {
|
||||
this.sandbox.stub(process, 'platform').get(() => 'darwin');
|
||||
|
||||
const file = path.join(this.tmpdir, 'file.txt');
|
||||
await fse.outputFile(file, 'hello');
|
||||
|
||||
await assertRejects(() => writeWindowsZoneIdentifier(file));
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue