fix: http port validation (#312)
* fix: validate and parse HTTP port as integer Commander leaves --port as a string, so invalid values like abc previously passed numeric range checks. Parse ports strictly before starting HTTP transport. * test: add parsePort unit tests and npm test script Introduce node:test coverage for HTTP port parsing edge cases using the existing tsx dev dependency. * docs: correct README port default and image search description Align BRAVE_MCP_PORT default with runtime behavior (8080) and remove the outdated v1.x base64 image search note.
This commit is contained in:
1 parent
feeab77f13
commit
e3f77ced06
5 files changed
+56
-3
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { parsePort } from './utils.js';
|
||||
|
||||
describe('parsePort', () => {
|
||||
it('accepts valid integer ports', () => {
|
||||
assert.equal(parsePort(8080), 8080);
|
||||
assert.equal(parsePort('8080'), 8080);
|
||||
assert.equal(parsePort(1), 1);
|
||||
assert.equal(parsePort(65535), 65535);
|
||||
});
|
||||
|
||||
it('rejects non-numeric and out-of-range values', () => {
|
||||
assert.equal(parsePort('abc'), null);
|
||||
assert.equal(parsePort('8080abc'), null);
|
||||
assert.equal(parsePort('8080.5'), null);
|
||||
assert.equal(parsePort(0), null);
|
||||
assert.equal(parsePort(65536), null);
|
||||
assert.equal(parsePort(-1), null);
|
||||
assert.equal(parsePort(''), null);
|
||||
assert.equal(parsePort(null), null);
|
||||
assert.equal(parsePort(undefined), null);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user