Browse Source

added few testing

develop
ray-1337 3 years ago
parent
commit
79772c0c49
  1. 44
      package.json
  2. 42
      test.js

44
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": "[email protected]",
@ -22,8 +25,19 @@
"engines": {
"node": ">=14"
},
"files": ["./src/Main.js", "index.d.ts"],
"keywords": ["ufw", "firewall", "ubuntu", "sudo", "linux", "cli"],
"dependencies": {},
"devDependencies": {}
}
"files": [
"./src/Main.js",
"index.d.ts"
],
"keywords": [
"ufw",
"firewall",
"ubuntu",
"sudo",
"linux",
"cli"
],
"devDependencies": {
"ava": "^4.2.0"
}
}

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