From fcc2328a3bf49eb5310413058cc9ebaf8e7819f8 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 4 Dec 2019 18:04:30 +0100 Subject: WIP netiquette --- docker/netiquette/test/iptables.mjs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docker/netiquette/test/iptables.mjs (limited to 'docker/netiquette/test/iptables.mjs') diff --git a/docker/netiquette/test/iptables.mjs b/docker/netiquette/test/iptables.mjs new file mode 100644 index 0000000..1ae1cb0 --- /dev/null +++ b/docker/netiquette/test/iptables.mjs @@ -0,0 +1,28 @@ +'use strict' + +import chai from 'chai' +import iptables from '../src/injector/iptables.mjs' +const expect = chai.expect + +export default [ + (async () => { + const effective_actions = [] + const expected_actions = [ + 'iptables -A INPUT -p tcp --dport 56 -j ACCEPT', + 'iptables -A INPUT -p tcp --dport 53 -j ACCEPT', + 'iptables -A INPUT -p udp --match multiport --dports 25630:25999 -j ACCEPT', + 'iptables -D INPUT -p tcp --dport 54 -j ACCEPT' + ] + + const mockLog = () => {} + const mockReadFile = (file, opt) => '-A INPUT -p tcp --dport 53 -j ACCEPT' + const mockExecCommand = (cmd, opts) => { + if (cmd.match(/^iptables -S/g)) return { stdout: '-A INPUT -p tcp --dport 54 -j ACCEPT' } + else effective_actions.push(cmd) + return { stdout: '' } } + + const fw = await iptables('static', mockReadFile, mockExecCommand, mockLog) + await fw(['public_port=56/tcp', 'public_port=25630-25999/udp', 'public_port=13', 'traefik.entrypoints=Host:im.deuxfleurs.fr;PathPrefix:/_matrix']) + expect(effective_actions).to.have.members(expected_actions) + }) +] -- cgit v1.2.3