diff --git a/package.json b/package.json index 7dc93db..b7eb262 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,19 @@ "description": "Manipulate UFW (Linux distribution only, works best on Ubuntu) via Node.", "license": "MIT", "repository": "ray-1337/node-ufw", - "funding": [ - { - "type": "individual", - "url": "https://trakteer.id/ray1337" - }, - { - "type": "paypal", - "url": "https://paypal.me/ray0001" - } - ], + "funding": [ + { + "type": "individual", + "url": "https://trakteer.id/ray1337" + }, + { + "type": "paypal", + "url": "https://paypal.me/ray0001" + } + ], + "scripts": { + "test": "ava test.js" + }, "author": { "name": "Hizkia Ray", "email": "personal@13373333.one", @@ -22,8 +25,19 @@ "engines": { "node": ">=14" }, - "files": ["./src/Main.js", "index.d.ts"], - "keywords": ["ufw", "firewall", "ubuntu", "sudo", "linux", "cli"], - "dependencies": {}, - "devDependencies": {} -} \ No newline at end of file + "files": [ + "./src/Main.js", + "index.d.ts" + ], + "keywords": [ + "ufw", + "firewall", + "ubuntu", + "sudo", + "linux", + "cli" + ], + "devDependencies": { + "ava": "^4.2.0" + } +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..87e4065 --- /dev/null +++ b/test.js @@ -0,0 +1,42 @@ +const test = require("ava"); +const nodeUfw = require("./src/Main"); + +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()); +}); \ No newline at end of file