Best Python code snippet using autotest_python
reflector.py
Source: reflector.py
...24 group.add_argument("-v", "--verbose", action="store_true")25 group.add_argument("-q", "--quiet", action="store_true")26 args = parser.parse_args()27 return args28def remove_checksum(pkt):29 del pkt.chksum30 if pkt.haslayer(TCP):31 del pkt[TCP].chksum32 if pkt.haslayer(UDP):33 del pkt[UDP].chksum34 if pkt.haslayer(ICMP):35 del pkt[ICMP].chksum36 return pkt37class Reflector:38 def __init__(self, int_face, v_ip, v_eth, r_ip, r_eth):39 self.int_face = int_face40 self.v_ip = v_ip41 self.v_eth = v_eth42 self.r_ip = r_ip43 self.r_eth = r_eth44 sniff(prn=self.main_pkt_checker, iface=self.int_face)45 def main_pkt_checker(self, pkt):46 print(pkt.summary())47 new_pkt = None48 # # Handle APR49 if ARP in pkt and pkt[ARP].pdst == self.v_ip:50 new_pkt = self.send_arp_from_victim(pkt)51 if ARP in pkt and pkt[ARP].pdst == self.r_ip:52 new_pkt = self.send_arp_from_reflector(pkt)53 if IP in pkt and pkt[IP].dst == self.v_ip:54 new_pkt = self.send_from_reflector(pkt)55 if IP in pkt and pkt[IP].dst == self.r_ip:56 new_pkt = self.send_from_victim(pkt)57 if new_pkt is not None:58 sendp(new_pkt, iface=self.int_face)59 def send_arp_from_victim(self, pkt):60 # set pkt src as reflector61 # print("---------ORIGINAL PKT------------")62 # pkt.show()63 # print("----------send_arp_from_victim-----------")64 p = pkt.copy()65 p[ARP].op = 2 # casue we are saying is at.66 p[Ether].dst = pkt[ARP].hwsrc67 p[ARP].pdst = pkt[ARP].psrc # attack was the src68 p[ARP].hwdst = pkt[ARP].hwsrc # attack was the src69 p[Ether].src = self.v_eth70 p[ARP].psrc = self.v_ip71 p[ARP].hwsrc = self.v_eth72 # p.show2()73 return p74 def send_arp_from_reflector(self, pkt):75 # set pkt src as reflector76 # print("---------ORIGINAL PKT------------")77 # pkt.show()78 # print("----------send_arp_from_victim-----------")79 p = pkt.copy()80 p.op = 2 # casue we are saying is at.81 p[Ether].dst = pkt[ARP].hwsrc82 p[ARP].pdst = pkt[ARP].psrc # attack was the src83 p[ARP].hwdst = pkt[ARP].hwsrc # attack was the src84 p[Ether].src = self.r_eth85 p[ARP].psrc = self.r_ip86 p[ARP].hwsrc = self.r_eth87 # p.show2()88 return p89 def send_from_reflector(self, pkt):90 p = pkt.copy()91 print("Check sum : ", p.chksum)92 p = remove_checksum(p)93 p[IP].src = self.r_ip94 p[Ether].src = self.r_eth95 p[IP].dst = pkt[IP].src96 p[Ether].dst = pkt[Ether].src # attack was the src97 p.show2()98 return p99 def send_from_victim(self, pkt):100 p = pkt.copy()101 print("Check sum : ", p.chksum)102 p = remove_checksum(p)103 # set src and dst104 p[IP].src = self.v_ip105 p[Ether].src = self.v_eth106 p[IP].dst = pkt[IP].src107 p[Ether].dst = pkt[Ether].src # attack was the src108 p.show2()109 return p110# def arp_monitor_callback(pkt):111# if ARP in pkt and pkt[ARP].op in (1,2): #who-has or is-at112# return pkt.sprintf("%ARP.hwsrc% %ARP.psrc%")113def main():114 my_args = get_input_args()115 my_reflector = Reflector(116 my_args.interface,...
test_only_keep_recent_boxes.py
Source: test_only_keep_recent_boxes.py
1from mock import call2from vagrant_catalog_generator.manage_boxfiles import only_keep_recent_boxes3from vagrant_catalog_generator.tests.testcase import TestCase4class TestOnlyKeepRecentBoxes(TestCase):5 def setUp(self):6 self.remove_boxfile = self.set_up_patch('vagrant_catalog_generator.manage_boxfiles.remove_boxfile')7 self.remove_checksum = self.set_up_patch('vagrant_catalog_generator.manage_boxfiles.remove_checksum')8 self.recent_box_amount = self.set_up_patch('vagrant_catalog_generator.manage_boxfiles.RECENT_BOX_AMOUNT')9 self.boxes = [10 'hypernode.release-latest.box',11 'hypernode.virtualbox.release-1.box',12 'hypernode.lxc.release-1.box',13 'hypernode.virtualbox.release-2635.box',14 'hypernode.lxc.release-2635.box',15 'hypernode.virtualbox.release-2638.box',16 'hypernode.lxc.release-2638.box',17 'hypernode.virtualbox.release-2653.box',18 'hypernode.lxc.release-2653.box',19 'hypernode.virtualbox.release-2659.box',20 'hypernode.lxc.release-2659.box',21 'hypernode.virtualbox.release-2674.box',22 'hypernode.lxc.release-2674.box'23 ]24 def test_only_keep_recent_boxes_removes_boxfiles(self):25 only_keep_recent_boxes('/some/dir', self.boxes, amount=6)26 expected_calls = [call('/some/dir', box) for box in [27 'hypernode.virtualbox.release-2635.box',28 'hypernode.lxc.release-2635.box',29 'hypernode.virtualbox.release-2638.box',30 'hypernode.lxc.release-2638.box',31 ]]32 self.assertEqual(expected_calls, self.remove_boxfile.mock_calls)33 def test_only_keep_recent_boxes_removes_checksum(self):34 only_keep_recent_boxes('/some/dir', self.boxes, amount=6)35 expected_calls = [call('/some/dir', box) for box in [36 'hypernode.virtualbox.release-2635.box',37 'hypernode.lxc.release-2635.box',38 'hypernode.virtualbox.release-2638.box',39 'hypernode.lxc.release-2638.box',40 ]]41 self.assertEqual(expected_calls, self.remove_checksum.mock_calls)42 def test_only_keep_recent_boxes_doesnt_remove_latest_link(self):43 only_keep_recent_boxes('/some/dir', self.boxes, amount=0)44 self.assertNotIn(call('/some/dir', 'hypernode.release-latest.box'), self.remove_boxfile.mock_calls)45 def test_only_keep_recent_boxes_doesnt_remove_latest_checksum(self):46 only_keep_recent_boxes('/some/dir', self.boxes, amount=0)...
test_remove_checksum.py
Source: test_remove_checksum.py
...5 self.path = self.set_up_patch('vagrant_catalog_generator.manage_boxfiles.path')6 self.path.join.return_value = '/some/dir/hypernode.vagrant.release-2638.box'7 self.remove = self.set_up_patch('vagrant_catalog_generator.manage_boxfiles.remove')8 def test_remove_checksum_gets_box_abspath(self):9 remove_checksum('/some/dir', 'hypernode.vagrant.release-2638.box')10 self.path.join.assert_called_once_with('/some/dir', 'hypernode.vagrant.release-2638.box')11 def test_remove_checksum_removes_checksum_path(self):12 remove_checksum('/some/dir', 'hypernode.vagrant.release-2638.box')13 self.remove.assert_called_once_with(14 self.path.join.return_value + '.sha256'15 )16 def test_remove_checksum_catches_gone_files_and_other_oserrors(self):17 self.remove.side_effect = OSError...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!