Skip to content

Commit

Permalink
fix(common): servers.listen() port validation
Browse files Browse the repository at this point in the history
Adds more type assertions to check if the
provided port number is indeed a finite,
positive integer.

Fixes #491

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
(cherry picked from commit 3b16aeb)
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Jan 15, 2021
1 parent be97c18 commit cd50124
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/cactus-common/src/main/typescript/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Servers {
});
}

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

Checks.truthy(options, `${fnTag} arg options`);
Expand All @@ -47,6 +47,12 @@ export class Servers {
options.port || options.port === 0,
`${fnTag} arg options.port`
);
Checks.truthy(
typeof options.port === "number",
`${fnTag} arg options.port is number`
);
Checks.truthy(isFinite(options.port), `${fnTag} arg finite options.port`);
Checks.truthy(options.port > -1, `${fnTag} arg positive options.port`);
Checks.truthy(options.hostname, `${fnTag} arg options.hostname`);
const { server, port, hostname } = options;

Expand Down

0 comments on commit cd50124

Please sign in to comment.