Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Add the supportsLaunchUnelevatedProcessRequest flag to the telemetry. #680

Merged
merged 1 commit into from Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/chromeDebugAdapter.ts
Expand Up @@ -28,8 +28,8 @@ const DefaultWebSourceMapPathOverrides: ISourceMapPathOverrides = {
'meteor://💻app/*': '${webRoot}/*'
};

interface IExtendedInitializeRequestArguments extends DebugProtocol.InitializeRequestArguments{
supportsLaunchUnelevatedProcessRequest?: boolean
interface IExtendedInitializeRequestArguments extends DebugProtocol.InitializeRequestArguments {
supportsLaunchUnelevatedProcessRequest?: boolean;
}

export class ChromeDebugAdapter extends CoreDebugAdapter {
Expand Down Expand Up @@ -67,6 +67,9 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
if (args.shouldLaunchChromeUnelevated !== undefined) {
telemetryPropertyCollector.addTelemetryProperty('shouldLaunchChromeUnelevated', args.shouldLaunchChromeUnelevated.toString());
}
if (this._doesHostSupportLaunchUnelevatedProcessRequest) {
telemetryPropertyCollector.addTelemetryProperty('doesHostSupportLaunchUnelevated', 'true');
}
if (args.runtimeExecutable) {
const re = findExecutable(args.runtimeExecutable);
if (!re) {
Expand Down Expand Up @@ -450,14 +453,14 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
return parseInt(pidStr, 10);
}

return null
return null;
}

private async spawnChromeUnelevatedWithClient(chromePath: string, chromeArgs: string[]): Promise<number> {
return new Promise<number>((resolve, reject) => {
this._session.sendRequest("launchUnelevated", {
"process": chromePath,
"args": chromeArgs
this._session.sendRequest('launchUnelevated', {
'process': chromePath,
'args': chromeArgs
}, 10000, (response) => {
if (!response.success) {
reject(new Error(response.message));
Expand Down
2 changes: 1 addition & 1 deletion src/chromeDebugInterfaces.d.ts
Expand Up @@ -34,7 +34,7 @@ export interface ISetExpressionArgs {
expression: string;
value: string;
frameId: number;
format?: DebugProtocol.ValueFormat
format?: DebugProtocol.ValueFormat;
timeout?: number;
}

Expand Down
108 changes: 97 additions & 11 deletions test/chromeDebugAdapter.test.ts
Expand Up @@ -3,7 +3,7 @@
*--------------------------------------------------------*/

import { DebugProtocol } from 'vscode-debugprotocol';
import { chromeConnection, ISourceMapPathOverrides, telemetry } from 'vscode-chrome-debug-core';
import { chromeConnection, ISourceMapPathOverrides, telemetry, utils as coreUtils, ChromeDebugSession } from 'vscode-chrome-debug-core';

import * as mockery from 'mockery';
import { EventEmitter } from 'events';
Expand All @@ -30,6 +30,7 @@ suite('ChromeDebugAdapter', () => {
let mockEventEmitter: EventEmitter;
let mockChrome: IMockChromeConnectionAPI;

let mockChromeDebugSession: IMock<MockChromeDebugSession>;
let chromeDebugAdapter: _ChromeDebugAdapter;

setup(() => {
Expand All @@ -41,6 +42,14 @@ suite('ChromeDebugAdapter', () => {
mockChromeConnection = Mock.ofType(chromeConnection.ChromeConnection, MockBehavior.Strict);
mockChrome = getMockChromeConnectionApi();
mockEventEmitter = mockChrome.mockEventEmitter;
mockChromeDebugSession = Mock.ofType(MockChromeDebugSession, MockBehavior.Strict);
mockChromeDebugSession
.setup(x => x.sendEvent(It.isAny()))
.verifiable(Times.atLeast(0));
mockChromeDebugSession
.setup(x => x.sendRequest(It.isAnyString(), It.isAny(), It.isAnyNumber(), It.isAny()))
.verifiable(Times.atLeast(0));

mockChromeConnection
.setup(x => x.api)
.returns(() => mockChrome.apiObjects)
Expand All @@ -67,7 +76,7 @@ suite('ChromeDebugAdapter', () => {

// Instantiate the ChromeDebugAdapter, injecting the mock ChromeConnection
const cDAClass: typeof _ChromeDebugAdapter = require(MODULE_UNDER_TEST).ChromeDebugAdapter;
chromeDebugAdapter = new cDAClass({ chromeConnection: function() { return mockChromeConnection.object; } } as any, new MockChromeDebugSession() as any);
chromeDebugAdapter = new cDAClass({ chromeConnection: function() { return mockChromeConnection.object; } } as any, mockChromeDebugSession.object as any);
});

teardown(() => {
Expand All @@ -82,6 +91,17 @@ suite('ChromeDebugAdapter', () => {
let originalSpawn: any;
let originalStatSync: any;

setup(() => {
mockChromeConnection
.setup(x => x.attach(It.isValue(undefined), It.isAnyNumber(), It.isAnyString(), It.isValue(undefined), It.isValue(undefined)))
.returns(() => Promise.resolve())
.verifiable();

mockChrome.Runtime
.setup(x => x.evaluate(It.isAny()))
.returns(() => Promise.resolve<any>({ result: { type: 'string', value: '123' }}));
});

teardown(() => {
// Hacky mock cleanup
require('child_process').fork = originalFork;
Expand Down Expand Up @@ -117,19 +137,85 @@ suite('ChromeDebugAdapter', () => {
originalStatSync = require('fs').statSync;
require('fs').statSync = () => true;

mockChromeConnection
.setup(x => x.attach(It.isValue(undefined), It.isAnyNumber(), It.isAnyString(), It.isValue(undefined), It.isValue(undefined)))
.returns(() => Promise.resolve())
.verifiable();

mockChrome.Runtime
.setup(x => x.evaluate(It.isAny()))
.returns(() => Promise.resolve<any>({ result: { type: 'string', value: '123' }}));

return chromeDebugAdapter.launch({ file: 'c:\\path with space\\index.html', runtimeArgs: ['abc', 'def'] },
new telemetry.TelemetryPropertyCollector())
.then(() => assert(spawnCalled));
});

test('launches unelevated with client', async () => {
let telemetryPropertyCollector = new telemetry.TelemetryPropertyCollector();
chromeDebugAdapter.initialize({
adapterID: 'test debug adapter',
pathFormat: 'path',
supportsLaunchUnelevatedProcessRequest: true
});

const originalGetPlatform = require('os').platform;
require('os').platform = () => { return 'win32'; };

const originalGetBrowser = require('../src/utils').getBrowserPath;
require('../src/utils').getBrowserPath = () => { return 'c:\\someplace\\chrome.exe'; };

const expectedProcessId = 325;
let collectedLaunchParams: any;
mockChromeDebugSession
.setup(x => x.sendRequest('launchUnelevated',
It.is((x: any) => {
collectedLaunchParams = x;
return true;
}),
10000,
It.is(
(callback: (response: DebugProtocol.Response) => void) => {
callback({
seq: null,
type: 'command',
request_seq: 100,
command: 'launchUnelevated',
success: true,
body: {
processId: expectedProcessId
}
});
return true;
})))
.verifiable(Times.atLeast(1));

await chromeDebugAdapter.launch({
file: 'c:\\path with space\\index.html',
runtimeArgs: ['abc', 'def'],
shouldLaunchChromeUnelevated: true
}, telemetryPropertyCollector);

assert.equal(expectedProcessId, (<any>chromeDebugAdapter)._chromePID, 'Debug Adapter should receive the Chrome process id');
assert(collectedLaunchParams.process != null);
assert(collectedLaunchParams.process.match(/chrome/i));
assert(collectedLaunchParams.args != null);

assert(collectedLaunchParams.args.filter((x) => x == '--no-default-browser-check').length != 0,
'Should have seen the --no-default-browser-check parameter');
assert(collectedLaunchParams.args.filter((x) => x == '--no-first-run').length != 0,
'Should have seen the --no-first-run parameter');
assert(collectedLaunchParams.args.filter((x) => x == 'abc').length != 0,
'Should have seen the abc parameter');
assert(collectedLaunchParams.args.filter((x) => x == 'def').length != 0,
'Should have seen the def parameter');
assert(collectedLaunchParams.args.filter((x) => x == 'about:blank').length != 0,
'Should have seen the about:blank parameter');
assert(collectedLaunchParams.args.filter((x) => x.match(/remote-debugging-port/)).length != 0,
'Should have seen a parameter like remote-debugging-port');
assert(collectedLaunchParams.args.filter((x) => x.match(/user-data-dir/)).length != 0,
'Should have seen a parameter like user-data-dir');

const telemetryProperties = telemetryPropertyCollector.getProperties();
assert.equal(telemetryProperties.shouldLaunchChromeUnelevated, 'true', "Should send telemetry that Chrome is requested to be launched unelevated.'");
assert.equal(telemetryProperties.doesHostSupportLaunchUnelevated, 'true', "Should send telemetry that host supports launcheing Chrome unelevated.'");

require('os').platform = originalGetPlatform;
require('../src/utils').getBrowserPath = originalGetBrowser;

return Promise.resolve();
});
});

suite('resolveWebRootPattern', () => {
Expand Down