From f01ce6c6bd59065ef54c0ea030bff33ead776836 Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Sun, 4 Jun 2023 22:20:37 +0200 Subject: [PATCH] refactor file test to typescript --- Test.ts | 15 +++++++++++++++ package.json | 7 ++++++- test.js | 49 ------------------------------------------------- 3 files changed, 21 insertions(+), 50 deletions(-) create mode 100644 Test.ts delete mode 100644 test.js diff --git a/Test.ts b/Test.ts new file mode 100644 index 0000000..08d8532 --- /dev/null +++ b/Test.ts @@ -0,0 +1,15 @@ +import test from "ava"; +import * as ufw from "./src/Index"; + +test("allow port", async (t) => t.true(await ufw.allow.port(1337))); +test("allow ip address", async (t) => t.true(await ufw.allow.address("1.1.1.1"))); + +test("delete specific rule", async (t) => t.true(await ufw.delete(1))); + +test("deny port", async (t) => t.true(await ufw.deny.port(1337))); +test("deny ip address", async (t) => t.true(await ufw.deny.address("1.1.1.1"))); + +test("enable firewall", async (t) => t.true(await ufw.enable())); +test("disable firewall", async (t) => t.true(await ufw.disable())); +test("reload firewall", async (t) => t.true(await ufw.reload())); +test("reset firewall", async (t) => t.true(await ufw.reset())); \ No newline at end of file diff --git a/package.json b/package.json index 86d00b7..51d057a 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,13 @@ "url": "https://github.com/ray-1337/node-ufw/issues" }, "scripts": { - "test": "ava test.js" + "test": "ava Test.ts" }, + "ava": { + "extensions": [ "ts" ], + "environmentVariables": { "TS_NODE_LOG_ERROR": "true" }, + "require": [ "ts-node/register" ] + }, "author": { "name": "Hizkia Ray", "email": "personal@13373333.one", diff --git a/test.js b/test.js deleted file mode 100644 index 19effa3..0000000 --- a/test.js +++ /dev/null @@ -1,49 +0,0 @@ -const test = require("ava"); -const nodeUfw = require("./src/Main"); -const nodeUfwUtil = require("./src/Util"); - -test("exceeded port", async (t) => { - await t.throwsAsync(async () => { - await nodeUfw.allow.port(12341242); - }, {instanceOf: Error, message: 'Error: Exceeded port limit.'}); - - await t.throwsAsync(async () => { - await nodeUfw.deny.port(12341242); - }, {instanceOf: Error, message: 'Error: Exceeded port limit.'}); -}); - -test("wrongish", async (t) => { - // port checking - await t.throwsAsync(async () => {await nodeUfw.allow.port("SADOASD")}, {instanceOf: Error, message: "Error: The port must be type of number."}); - await t.throwsAsync(async () => {await nodeUfw.deny.port("ASMJDKNSC")}, {instanceOf: Error, message: "Error: The port must be type of number."}); - - // protocol checking - await t.throwsAsync(async () => {await nodeUfw.allow.port(12, 123124)}, {instanceOf: Error, message: "Error: The protocol must be type of string."}); - await t.throwsAsync(async () => {await nodeUfw.deny.port(12, 123124)}, {instanceOf: Error, message: "Error: The protocol must be type of string."}); - - // wrong protocol - await t.throwsAsync(async () => {await nodeUfw.allow.port(12, "SDSD")}, {instanceOf: Error, message: 'Error: The protocol must be either "tcp" or "udp"'}); - await t.throwsAsync(async () => {await nodeUfw.deny.port(12, "SDSD")}, {instanceOf: Error, message: 'Error: The protocol must be either "tcp" or "udp"'}); -}); - -test("status raw cond", async (t) => { - t.pass(await nodeUfw.status(true)); -}); - -test("parsed status", async (t) => { - t.pass(await nodeUfw.status()); -}); - -test("sfw disabled", async (t) => { - t.true(await nodeUfw.disable()); -}); - -test("sfw enabled", async (t) => { - t.true(await nodeUfw.enable()); -}); - -test("check version", async (t) => { - t.true(nodeUfwUtil.checkNodeVersion()); - t.true(nodeUfwUtil.checkPlatform()); - t.true(await nodeUfwUtil.checkPlatformExact()); -}); \ No newline at end of file