forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(common): servers#listen() port number validation
Fixes hyperledger-cacti#383 Ensures that the when specifying port 0 the liste() method does not throw an exception since it is perfectly valid to bind to port zero in general. Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/cactus-common/src/test/typescript/unit/servers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { createServer } from "http"; | ||
|
||
import test, { Test } from "tape-promise/tape"; | ||
|
||
import { Servers } from "../../../main/typescript/index"; | ||
|
||
test("Servers", async (tParent: Test) => { | ||
test("Servers#listen()", async (t: Test) => { | ||
{ | ||
const server = createServer(); | ||
await t.rejects( | ||
Servers.listen({ hostname: "x", port: "" as any, server }), | ||
/options\.port/, | ||
"Rejects when port specified as empty string OK" | ||
); | ||
} | ||
|
||
{ | ||
const server = createServer(); | ||
await t.rejects( | ||
Servers.listen({ hostname: "localhost", port: false as any, server }), | ||
/options\.port/, | ||
"Rejects when port specified as literal false boolean OK" | ||
); | ||
// await Servers.shutdown(server); | ||
} | ||
|
||
{ | ||
const server = createServer(); | ||
await t.doesNotReject( | ||
Servers.listen({ hostname: "localhost", port: 0, server }), | ||
"Does not rejects when port specified as zero OK" | ||
); | ||
await Servers.shutdown(server); | ||
} | ||
|
||
t.end(); | ||
}); | ||
|
||
tParent.end(); | ||
}); |