1616# under the License.
1717
1818import unittest
19+ import mock
1920from configure import CsForwardingRules
2021
2122
@@ -36,12 +37,27 @@ def test_ftp_helper_on_port_range(self):
3637 self .assertEqual (self .ftp_helper_rules ("tcp" , "1020:1030" , "20:30" ),
3738 [["raw" , "" , "-A PREROUTING -d 10.0.0.2/32 -p tcp -m tcp --dport 1021 -j CT --helper ftp" ]])
3839
40+ def test_ftp_helper_on_port_21 (self ):
41+ self .assertEqual (self .ftp_helper_rules ("tcp" , "21:21" , "21:21" ),
42+ [["raw" , "" , "-A PREROUTING -d 10.0.0.2/32 -p tcp -m tcp --dport 21 -j CT --helper ftp" ]])
43+
3944 def test_no_ftp_helper (self ):
40- self .assertEqual (self .ftp_helper_rules ("tcp" , "21:21" , "21:21" ), [])
4145 self .assertEqual (self .ftp_helper_rules ("tcp" , "2121:2121" , "2121:2121" ), [])
4246 self .assertEqual (self .ftp_helper_rules ("udp" , "2121:2121" , "21:21" ), [])
4347 self .assertEqual (self .ftp_helper_rules ("tcp" , "any" , "any" ), [])
4448
49+ @mock .patch .object (CsForwardingRules , 'getStaticRoutes' , return_value = [])
50+ @mock .patch .object (CsForwardingRules , 'getPrivateGatewayNetworks' , return_value = [])
51+ @mock .patch .object (CsForwardingRules , 'getGuestIpByIp' , return_value = "10.1.1.1" )
52+ @mock .patch .object (CsForwardingRules , 'getNetworkByIp' , return_value = "10.1.1.0/24" )
53+ @mock .patch .object (CsForwardingRules , 'getDeviceByIp' , return_value = "eth2" )
54+ def test_ftp_helper_on_static_nat (self , * _ ):
55+ forwarding = CsForwardingRules .__new__ (CsForwardingRules )
56+ forwarding .fw = []
57+ forwarding .processStaticNatRule ({"public_ip" : "10.0.0.2" , "internal_ip" : "10.1.1.10" })
58+ self .assertIn (["raw" , "" , "-A PREROUTING -d 10.0.0.2/32 -p tcp -m tcp --dport 21 -j CT --helper ftp" ],
59+ forwarding .fw )
60+
4561
4662if __name__ == '__main__' :
4763 unittest .main ()
0 commit comments