Browse Source

refactor file test to typescript

develop
ray-1337 2 years ago
parent
commit
f01ce6c6bd
No known key found for this signature in database GPG Key ID: DED41DCC150FCD32
  1. 15
      Test.ts
  2. 7
      package.json
  3. 49
      test.js

15
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()));

7
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": "[email protected]",

49
test.js

@ -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());
});
Loading…
Cancel
Save