Skip to content

Commit f2f5fe2

Browse files
Check config type in the ChildProcessAttachEvents (#21272)
1 parent 4b4e5b7 commit f2f5fe2

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/client/debugger/extension/hooks/childProcessAttachHandler.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { swallowExceptions } from '../../../common/utils/decorators';
99
import { AttachRequestArguments } from '../../types';
1010
import { DebuggerEvents } from './constants';
1111
import { IChildProcessAttachService, IDebugSessionEventHandlers } from './types';
12+
import { DebuggerTypeName } from '../../constants';
1213

1314
/**
1415
* This class is responsible for automatically attaching the debugger to any
@@ -25,7 +26,7 @@ export class ChildProcessAttachEventHandler implements IDebugSessionEventHandler
2526

2627
@swallowExceptions('Handle child process launch')
2728
public async handleCustomEvent(event: DebugSessionCustomEvent): Promise<void> {
28-
if (!event) {
29+
if (!event || event.session.configuration.type !== DebuggerTypeName) {
2930
return;
3031
}
3132

src/test/debugger/extension/hooks/childProcessAttachHandler.unit.test.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ChildProcessAttachEventHandler } from '../../../../client/debugger/exte
99
import { ChildProcessAttachService } from '../../../../client/debugger/extension/hooks/childProcessAttachService';
1010
import { DebuggerEvents } from '../../../../client/debugger/extension/hooks/constants';
1111
import { AttachRequestArguments } from '../../../../client/debugger/types';
12+
import { DebuggerTypeName } from '../../../../client/debugger/constants';
1213

1314
suite('Debug - Child Process', () => {
1415
test('Do not attach if the event is undefined', async () => {
@@ -21,23 +22,31 @@ suite('Debug - Child Process', () => {
2122
const attachService = mock(ChildProcessAttachService);
2223
const handler = new ChildProcessAttachEventHandler(instance(attachService));
2324
const body: any = {};
24-
const session: any = {};
25+
const session: any = { configuration: { type: DebuggerTypeName } };
26+
await handler.handleCustomEvent({ event: 'abc', body, session });
27+
verify(attachService.attach(body, session)).never();
28+
});
29+
test('Do not attach to child process if debugger type is different', async () => {
30+
const attachService = mock(ChildProcessAttachService);
31+
const handler = new ChildProcessAttachEventHandler(instance(attachService));
32+
const body: any = {};
33+
const session: any = { configuration: { type: 'other-type' } };
2534
await handler.handleCustomEvent({ event: 'abc', body, session });
2635
verify(attachService.attach(body, session)).never();
2736
});
2837
test('Do not attach to child process if ptvsd_attach event is invalid', async () => {
2938
const attachService = mock(ChildProcessAttachService);
3039
const handler = new ChildProcessAttachEventHandler(instance(attachService));
3140
const body: any = {};
32-
const session: any = {};
41+
const session: any = { configuration: { type: DebuggerTypeName } };
3342
await handler.handleCustomEvent({ event: DebuggerEvents.PtvsdAttachToSubprocess, body, session });
3443
verify(attachService.attach(body, session)).never();
3544
});
3645
test('Do not attach to child process if debugpy_attach event is invalid', async () => {
3746
const attachService = mock(ChildProcessAttachService);
3847
const handler = new ChildProcessAttachEventHandler(instance(attachService));
3948
const body: any = {};
40-
const session: any = {};
49+
const session: any = { configuration: { type: DebuggerTypeName } };
4150
await handler.handleCustomEvent({ event: DebuggerEvents.DebugpyAttachToSubprocess, body, session });
4251
verify(attachService.attach(body, session)).never();
4352
});
@@ -51,9 +60,11 @@ suite('Debug - Child Process', () => {
5160
port: 1234,
5261
subProcessId: 2,
5362
};
54-
const session: any = {};
63+
const session: any = {
64+
configuration: { type: DebuggerTypeName },
65+
};
5566
when(attachService.attach(body, session)).thenThrow(new Error('Kaboom'));
56-
await handler.handleCustomEvent({ event: DebuggerEvents.DebugpyAttachToSubprocess, body, session: {} as any });
67+
await handler.handleCustomEvent({ event: DebuggerEvents.DebugpyAttachToSubprocess, body, session });
5768
verify(attachService.attach(body, anything())).once();
5869
const [, secondArg] = capture(attachService.attach).last();
5970
expect(secondArg).to.deep.equal(session);

0 commit comments

Comments
 (0)