def test_tunnel_static(self): vxnet = 'vxnet-1234abcd' tunnel_entries = [ ('gre', '112.144.3.54', '123'), ('gre', '112.144.5.54', 'abc'), ] static = RouterStaticFactory.create(RouterStaticFactory.TYPE_TUNNEL, vxnet_id=vxnet, tunnel_entries=tunnel_entries) json_data = static.to_json() self.assertEqual(json_data['val1'], 'gre|112.144.3.54|123;gre|112.144.5.54|abc')
def test_vpn_static(self): ip = '192.168.1.1' vpn_type = 'openvpn' static = RouterStaticFactory.create(RouterStaticFactory.TYPE_VPN, vpn_type=vpn_type, ip_network=ip) json_data = static.to_json() self.assertEqual(json_data['val1'], 'openvpn') self.assertEqual(json_data['val2'], '1194') self.assertEqual(json_data['val3'], 'udp') self.assertEqual(json_data['val4'], ip) vpn_type = 'pptp' usr = '******' pwd = 'passwd' static = RouterStaticFactory.create(RouterStaticFactory.TYPE_VPN, vpn_type=vpn_type, usr=usr, pwd=pwd, ip_network=ip) json_data = static.to_json() self.assertEqual(json_data['val1'], 'pptp') self.assertEqual(json_data['val2'], '%s:%s' % (usr, pwd)) self.assertEqual(json_data['val3'], RouterStaticFactory.PPTP_DEFAULT_CONNS) self.assertEqual(json_data['val4'], ip)
def test_port_forwarding_static(self): name = 'unittest' src_port = 10 dst_ip = '192.168.1.1' dst_port = 80 protocol = 'udp' static = RouterStaticFactory.create(RouterStaticFactory.TYPE_PORT_FORWARDING, router_static_name=name, protocol=protocol, src_port=10, dst_ip='192.168.1.1', dst_port=80) json_data = static.to_json() self.assertEqual(json_data['router_static_name'], name) self.assertEqual(json_data['val1'], src_port) self.assertEqual(json_data['val2'], dst_ip) self.assertEqual(json_data['val3'], dst_port) self.assertEqual(json_data['val4'], protocol)
def test_filtering_static(self): name = 'unittest' src_ip = '192.168.1.1' src_port = 10 dst_ip = '192.168.2.1' dst_port = 80 priority = 5 action = 'drop' static = RouterStaticFactory.create(RouterStaticFactory.TYPE_FILTERING, router_static_name=name, src_ip=src_ip, src_port=src_port, dst_ip=dst_ip, dst_port=dst_port, priority=priority, action=action) json_data = static.to_json() self.assertEqual(json_data['val1'], src_ip) self.assertEqual(json_data['val2'], src_port) self.assertEqual(json_data['val3'], dst_ip) self.assertEqual(json_data['val4'], dst_port) self.assertEqual(json_data['val5'], priority) self.assertEqual(json_data['val6'], action)
def test_static_with_existing_id(self): static = RouterStaticFactory.create(RouterStaticFactory.TYPE_VPN, vpn_type='openvpn', ip_network='', router_static_id='fakeid') json_data = static.to_json() self.assertEqual(json_data['router_static_id'], 'fakeid')