diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2019-12-04 18:04:30 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2019-12-04 18:04:30 +0100 |
commit | fcc2328a3bf49eb5310413058cc9ebaf8e7819f8 (patch) | |
tree | c6faabae8badd96455453b72472ac08a2fe0b1c2 /docker/netiquette/test | |
parent | 0b3eb8ec1b3ba3691410744f6397437c9832e74d (diff) | |
download | infrastructure-fcc2328a3bf49eb5310413058cc9ebaf8e7819f8.tar.gz infrastructure-fcc2328a3bf49eb5310413058cc9ebaf8e7819f8.zip |
WIP netiquette
Diffstat (limited to 'docker/netiquette/test')
-rw-r--r-- | docker/netiquette/test/io.mjs | 10 | ||||
-rw-r--r-- | docker/netiquette/test/iptables.mjs | 28 | ||||
-rw-r--r-- | docker/netiquette/test/runner.mjs | 28 |
3 files changed, 66 insertions, 0 deletions
diff --git a/docker/netiquette/test/io.mjs b/docker/netiquette/test/io.mjs new file mode 100644 index 0000000..d88ad15 --- /dev/null +++ b/docker/netiquette/test/io.mjs @@ -0,0 +1,10 @@ +import chai from 'chai' +import { readFile } from '../src/io/files.mjs' +const expect = chai.expect + +export default [ + (async () => { + const dirname = import.meta.url.replace(/^file:\/\//g, '').replace(/io.mjs$/g, '') + expect(await readFile(`${dirname}/../package.json`, 'utf-8')).to.include('Quentin') + }) +] 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) + }) +] diff --git a/docker/netiquette/test/runner.mjs b/docker/netiquette/test/runner.mjs new file mode 100644 index 0000000..b4da1de --- /dev/null +++ b/docker/netiquette/test/runner.mjs @@ -0,0 +1,28 @@ +'use strict' + +import io from './io.mjs' +import iptables from './iptables.mjs' + +(async () => { + const res = await [ + ...io, + ...iptables + ].map(async f => { + try { + await f() + return 'passed' + } + catch(e) { + console.error(e) + return 'failed' + } + }).reduce(async (acc, r) => { + const accumulator = await acc + const result = await r + accumulator.total++ + accumulator[result]++ + return accumulator + }, {total: 0, passed: 0, failed: 0}) + + console.log(`Done. passed: ${res.passed}, failed: ${res.failed}, total: ${res.total}`) +})() |