def test_setup_and_teardown(): cfg = getConfig() cfg.accessPoint = "bacon:yes" actions = TestActions() rulemgr = RuleManager(actions, cfg) actions._runIptables_ret.append(True) actions._runIptables_ret.append(True) actions._runIptables_ret.append(True) actions._runIptables_ret.append(True) actions._runIptables_ret.append(True) rulemgr.setUp() assert actions._saveIptables_called.pop() == True, "Save iptables was not called" eq_("-t nat -N yesyesyes", actions._runIptables_args.pop(0)) eq_("-t nat -N nonono", actions._runIptables_args.pop(0)) eq_("-t nat -A PREROUTING -j nonono", actions._runIptables_args.pop(0)) eq_("-t nat -A yesyesyes -j ACCEPT", actions._runIptables_args.pop(0)) eq_( "-t nat -A nonono -p tcp -m multiport --dport 80 -j DNAT --to-destination bacon:yes", actions._runIptables_args.pop(0), ) actions._restoreIptables_ret.append(True) rulemgr.tearDown() eq_("savedata", actions._restoreIptables_args.pop())
def test_unblock(): cfg = getConfig() actions = TestActions() rulemgr = RuleManager(actions, cfg) actions._runIptables_ret.append(True) rulemgr.unblockUser(MAC) r = "-t nat -I PREROUTING -m mac --mac-source 00:16:CB:08:8D:E8 -j yesyesyes" eq_(actions._runIptables_args.pop(0), r)
def main(): log.startLogging(sys.stdout) rulemgr = RuleManager() site = server.Site(PortalResource(rulemgr)) service = internet.TCPServer(SERVER_PORT, site) service.startService() try: rulemgr.setUp() reactor.run() finally: rulemgr.tearDown()