-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Check if binary exists before passing it to node-pty #44440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,8 +112,13 @@ export class PtyEventsStreamHandler { | |
}) | ||
); | ||
}); | ||
this.ptyProcess.start(event.columns, event.rows); | ||
this.logger.info(`stream has started`); | ||
// PtyProcess.prototype.start always returns a fulfilled promise. If an error is caught during | ||
// start, it's reported through PtyProcess.prototype.onStartError. Similarly, the information | ||
// about a successful start is also conveyed through an emitted event rather than the method | ||
// returning with no error. Hence why we can ignore what this promise returns. | ||
void this.ptyProcess.start(event.columns, event.rows).then(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using the syntax recommended by no-floating-promises to explicitly mark a promise that we ignore. https://typescript-eslint.io/rules/no-floating-promises/#ignorevoid |
||
this.logger.info(`stream has started`); | ||
}); | ||
} | ||
|
||
private handleDataEvent(event: PtyEventData): void { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import crypto from 'node:crypto'; | ||
|
||
import Logger, { NullService } from 'teleterm/logger'; | ||
|
||
import { PtyProcess } from './ptyProcess'; | ||
|
||
beforeAll(() => { | ||
Logger.init(new NullService()); | ||
}); | ||
|
||
describe('PtyProcess', () => { | ||
describe('start', () => { | ||
it('emits a start error when attempting to execute a nonexistent command', async () => { | ||
const path = `nonexistent-executable-${crypto.randomUUID()}`; | ||
const pty = new PtyProcess({ | ||
path, | ||
args: [], | ||
env: { PATH: '/foo/bar' }, | ||
ptyId: '1234', | ||
}); | ||
|
||
const startErrorCb = jest.fn(); | ||
|
||
pty.onStartError(startErrorCb); | ||
|
||
await pty.start(80, 20); | ||
|
||
expect(startErrorCb).toHaveBeenCalledWith( | ||
expect.stringContaining(`not found: ${path}`) | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a small package, but maybe we could add
@types/which
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, mostly to check out the flow of adding a new package with pnpm. ;)