Skip to content

Commit cd50124

Browse files
committed
fix(common): servers.listen() port validation
Adds more type assertions to check if the provided port number is indeed a finite, positive integer. Fixes hyperledger-cacti#491 Signed-off-by: Peter Somogyvari <[email protected]> (cherry picked from commit 3b16aeb) Signed-off-by: Peter Somogyvari <[email protected]>
1 parent be97c18 commit cd50124

File tree

1 file changed

+7
-1
lines changed
  • packages/cactus-common/src/main/typescript

1 file changed

+7
-1
lines changed

packages/cactus-common/src/main/typescript/servers.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Servers {
3838
});
3939
}
4040

41-
public static async listen(options: IListenOptions): Promise<any> {
41+
public static async listen(options: IListenOptions): Promise<AddressInfo> {
4242
const fnTag = "Servers#listen()";
4343

4444
Checks.truthy(options, `${fnTag} arg options`);
@@ -47,6 +47,12 @@ export class Servers {
4747
options.port || options.port === 0,
4848
`${fnTag} arg options.port`
4949
);
50+
Checks.truthy(
51+
typeof options.port === "number",
52+
`${fnTag} arg options.port is number`
53+
);
54+
Checks.truthy(isFinite(options.port), `${fnTag} arg finite options.port`);
55+
Checks.truthy(options.port > -1, `${fnTag} arg positive options.port`);
5056
Checks.truthy(options.hostname, `${fnTag} arg options.hostname`);
5157
const { server, port, hostname } = options;
5258

0 commit comments

Comments
 (0)