Node.js interface to UFW forked to allow execution of your Node process as non-root user.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

49 lines
1.9 KiB

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