Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide API implementation proxies, add tests to check for "proxy leakage" #115530

Merged
merged 11 commits into from
Feb 3, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import 'mocha';
import * as assert from 'assert';
import { join } from 'path';
import { commands, workspace, window, Uri, Range, Position, ViewColumn } from 'vscode';
import { assertNoRpc } from '../utils';

suite('vscode API - commands', () => {

teardown(assertNoRpc);

test('getCommands', function (done) {

let p1 = commands.getCommands().then(commands => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import 'mocha';
import * as assert from 'assert';
import * as vscode from 'vscode';
import { assertNoRpc } from '../utils';

suite('vscode API - configuration', () => {

teardown(assertNoRpc);

test('configurations, language defaults', function () {
const defaultLanguageSettings = vscode.workspace.getConfiguration().get('[abcLang]');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import * as assert from 'assert';
import { debug, workspace, Disposable, commands, window } from 'vscode';
import { disposeAll } from '../utils';
import { assertNoRpc, disposeAll } from '../utils';
import { basename } from 'path';

suite('vscode API - debug', function () {

teardown(assertNoRpc);

test('breakpoints', async function () {
assert.equal(debug.breakpoints.length, 0);
let onDidChangeBreakpointsCounter = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

import * as assert from 'assert';
import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString, Selection, Uri, env } from 'vscode';
import { createRandomFile, deleteFile, closeAllEditors } from '../utils';
import { createRandomFile, deleteFile, closeAllEditors, assertNoRpc } from '../utils';

suite('vscode API - editors', () => {

teardown(closeAllEditors);
teardown(async function () {
assertNoRpc();
await closeAllEditors();
});

function withRandomFileEditor(initialContents: string, run: (editor: TextEditor, doc: TextDocument) => Thenable<void>): Thenable<boolean> {
return createRandomFile(initialContents).then(file => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

import * as assert from 'assert';
import { env, extensions, ExtensionKind, UIKind, Uri } from 'vscode';
import { assertNoRpc } from '../utils';

suite('vscode API - env', () => {

teardown(assertNoRpc);

test('env is set', function () {
assert.equal(typeof env.language, 'string');
assert.equal(typeof env.appRoot, 'string');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import * as assert from 'assert';
import { join } from 'path';
import * as vscode from 'vscode';
import { createRandomFile, testFs } from '../utils';
import { assertNoRpc, createRandomFile, testFs } from '../utils';

suite('vscode API - languages', () => {

teardown(assertNoRpc);

const isWindows = process.platform === 'win32';

function positionToString(p: vscode.Position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as assert from 'assert';
import { window, commands } from 'vscode';
import { closeAllEditors } from '../utils';
import { assertNoRpc, closeAllEditors } from '../utils';

interface QuickPickExpected {
events: string[];
Expand All @@ -20,7 +20,10 @@ interface QuickPickExpected {

suite('vscode API - quick input', function () {

teardown(closeAllEditors);
teardown(async function () {
assertNoRpc();
await closeAllEditors();
});

test('createQuickPick, select second', function (_done) {
let done = (err?: any) => {
Expand Down
13 changes: 13 additions & 0 deletions extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { assertNoRpc } from '../utils';

suite('vscode', function () {

test('no rpc', function () {
assertNoRpc();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable, UIKind, env, EnvironmentVariableMutatorType, EnvironmentVariableMutator, extensions, ExtensionContext, TerminalOptions, ExtensionTerminalOptions } from 'vscode';
import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
import { assertNoRpc } from '../utils';

// Disable terminal tests:
// - Web https://github.com/microsoft/vscode/issues/92826
Expand All @@ -30,6 +31,7 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
let disposables: Disposable[] = [];

teardown(() => {
assertNoRpc();
disposables.forEach(d => d.dispose());
disposables.length = 0;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import 'mocha';
import * as assert from 'assert';
import * as vscode from 'vscode';
import { assertNoRpc } from '../utils';

suite('vscode API - types', () => {

teardown(assertNoRpc);

test('static properties, es5 compat class', function () {
assert.ok(vscode.ThemeIcon.File instanceof vscode.ThemeIcon);
assert.ok(vscode.ThemeIcon.Folder instanceof vscode.ThemeIcon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as assert from 'assert';
import 'mocha';
import * as os from 'os';
import * as vscode from 'vscode';
import { closeAllEditors, delay, disposeAll } from '../utils';
import { assertNoRpc, closeAllEditors, delay, disposeAll } from '../utils';

const webviewId = 'myWebview';

Expand All @@ -26,8 +26,8 @@ suite.skip('vscode API - webview', () => {
}

teardown(async () => {
assertNoRpc();
await closeAllEditors();

disposeAll(disposables);
});

Expand Down
31 changes: 17 additions & 14 deletions extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import * as assert from 'assert';
import { workspace, window, commands, ViewColumn, TextEditorViewColumnChangeEvent, Uri, Selection, Position, CancellationTokenSource, TextEditorSelectionChangeKind, QuickPickItem, TextEditor } from 'vscode';
import { join } from 'path';
import { closeAllEditors, pathEquals, createRandomFile } from '../utils';
import { closeAllEditors, pathEquals, createRandomFile, assertNoRpc } from '../utils';


suite('vscode API - window', () => {

teardown(closeAllEditors);
teardown(async function () {
assertNoRpc();
await closeAllEditors();
});

test('editor, active text editor', async () => {
const doc = await workspace.openTextDocument(join(workspace.rootPath || '', './far.js'));
Expand Down Expand Up @@ -429,8 +432,8 @@ suite('vscode API - window', () => {
});

test('showQuickPick, select first two', async function () {
const label = 'showQuickPick, select first two';
let i = 0;
// const label = 'showQuickPick, select first two';
// let i = 0;
const resolves: ((value: string) => void)[] = [];
let done: () => void;
const unexpected = new Promise<void>((resolve, reject) => {
Expand All @@ -442,26 +445,26 @@ suite('vscode API - window', () => {
canPickMany: true
});
const first = new Promise(resolve => resolves.push(resolve));
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
await new Promise(resolve => setTimeout(resolve, 100)); // Allow UI to update.
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
await commands.executeCommand('workbench.action.quickOpenSelectNext');
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
assert.equal(await first, 'eins');
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
await commands.executeCommand('workbench.action.quickPickManyToggle');
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
const second = new Promise(resolve => resolves.push(resolve));
await commands.executeCommand('workbench.action.quickOpenSelectNext');
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
assert.equal(await second, 'zwei');
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
await commands.executeCommand('workbench.action.quickPickManyToggle');
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
assert.deepStrictEqual(await picks, ['eins', 'zwei']);
console.log(`${label}: ${++i}`);
// console.log(`${label}: ${++i}`);
done!();
return unexpected;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

import * as assert from 'assert';
import * as vscode from 'vscode';
import { createRandomFile, withLogDisabled } from '../utils';
import { assertNoRpc, createRandomFile, disposeAll, withLogDisabled } from '../utils';

suite('vscode API - workspace events', () => {

const disposables: vscode.Disposable[] = [];

teardown(() => {
for (const dispo of disposables) {
dispo.dispose();
}
assertNoRpc();
disposeAll(disposables);
disposables.length = 0;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as assert from 'assert';
import * as vscode from 'vscode';
import { posix } from 'path';
import { assertNoRpc } from '../utils';

suite('vscode API - workspace-fs', () => {

Expand All @@ -15,6 +16,8 @@ suite('vscode API - workspace-fs', () => {
root = vscode.workspace.workspaceFolders![0]!.uri;
});

teardown(assertNoRpc);

test('fs.stat', async function () {
const stat = await vscode.workspace.fs.stat(root);
assert.equal(stat.type, vscode.FileType.Directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as assert from 'assert';
import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomExecution, Pseudoterminal, TaskScope, commands, env, UIKind, ShellExecution, TaskExecution, Terminal, Event } from 'vscode';
import { assertNoRpc } from '../utils';

// Disable tasks tests:
// - Web https://github.com/microsoft/vscode/issues/90528
Expand All @@ -14,6 +15,7 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx
let disposables: Disposable[] = [];

teardown(() => {
assertNoRpc();
disposables.forEach(d => d.dispose());
disposables.length = 0;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@

import * as assert from 'assert';
import * as vscode from 'vscode';
import { createRandomFile, deleteFile, closeAllEditors, pathEquals, rndName, disposeAll, testFs, delay, withLogDisabled, revertAllDirty } from '../utils';
import { createRandomFile, deleteFile, closeAllEditors, pathEquals, rndName, disposeAll, testFs, delay, withLogDisabled, revertAllDirty, assertNoRpc } from '../utils';
import { join, posix, basename } from 'path';
import * as fs from 'fs';
import { TestFS } from '../memfs';

suite('vscode API - workspace', () => {

teardown(closeAllEditors);
teardown(async function () {
assertNoRpc();
await closeAllEditors();
});

test('MarkdownString', function () {
let md = new vscode.MarkdownString();
Expand Down
41 changes: 41 additions & 0 deletions extensions/vscode-api-tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,44 @@ export function withLogDisabled(runnable: () => Promise<any>): () => Promise<voi
}
};
}

export function assertNoRpc() {

const symProxy = Symbol.for('rpcProxy');
const symProtocol = Symbol.for('rpcProtocol');

const proxyPaths: string[] = [];
const rpcPaths: string[] = [];

function walk(obj: any, path: string, seen: Set<any>) {
if (!obj) {
return;
}
if (typeof obj !== 'object' && typeof obj !== 'function') {
return;
}
if (seen.has(obj)) {
return;
}
seen.add(obj);

if (obj[symProtocol]) {
rpcPaths.push(`PROTOCOL via ${path}`);
}
if (obj[symProxy]) {
proxyPaths.push(`PROXY '${obj[symProxy]}' via ${path}`);
}

for (const key in obj) {
walk(obj[key], `${path}.${String(key)}`, seen);
}
}

try {
walk(vscode, 'vscode', new Set());
} catch (err) {
assert.fail(err);
}
assert.strictEqual(rpcPaths.length, 0, rpcPaths.join('\n'));
assert.strictEqual(proxyPaths.length, 0, proxyPaths.join('\n')); // happens...
}
9 changes: 0 additions & 9 deletions src/vs/workbench/api/browser/mainThreadEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class MainThreadTextEditorProperties {
return {
insertSpaces: modelOptions.insertSpaces,
tabSize: modelOptions.tabSize,
indentSize: modelOptions.indentSize,
cursorStyle: cursorStyle,
lineNumbers: lineNumbers
};
Expand Down Expand Up @@ -146,7 +145,6 @@ export class MainThreadTextEditorProperties {
}
return (
a.tabSize === b.tabSize
&& a.indentSize === b.indentSize
&& a.insertSpaces === b.insertSpaces
&& a.cursorStyle === b.cursorStyle
&& a.lineNumbers === b.lineNumbers
Expand Down Expand Up @@ -377,13 +375,6 @@ export class MainThreadTextEditor {
if (typeof newConfiguration.tabSize !== 'undefined') {
newOpts.tabSize = newConfiguration.tabSize;
}
if (typeof newConfiguration.indentSize !== 'undefined') {
if (newConfiguration.indentSize === 'tabSize') {
newOpts.indentSize = newOpts.tabSize || creationOpts.tabSize;
} else {
newOpts.indentSize = newConfiguration.indentSize;
}
}
this._model.updateOptions(newOpts);
}

Expand Down
Loading