def test_interface_serialization(self): iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06") iface.setDescription("Some description") iface.setOwned(True) iface.addHostname("www.test.com") iface.setIPv4({ "address": "192.168.10.168", "mask": "255.255.255.0", "gateway": "192.168.10.1", "DNS": "192.168.10.1" }) iface.setPortsOpened(2) iface.setPortsClosed(3) iface.setPortsFiltered(4) iserialized = self.imapper.serialize(iface) # if serialization fails, returns None self.assertNotEqual(iserialized, None, "Serialized interface shouldn't be None") # we check the interface attributes self.assertEquals(iserialized.get("_id"), iface.getID(), "Serialized ID is not the same as Interface ID") self.assertEquals(iserialized.get("name"), iface.getName(), "Serialized name is not the same as Interface name") self.assertEquals(iserialized.get("mac"), iface.getMAC(), "Serialized MAC is not the same as Interface MAC") self.assertEquals( iserialized.get("network_segment"), iface.getNetworkSegment(), "Serialized Network Segment is not the same as Interface Network Segment" ) self.assertEquals( iserialized.get("description"), iface.getDescription(), "Serialized description is not the same as Interface description") self.assertEquals( iserialized.get("owned"), iface.isOwned(), "Serialized owned flag is not the same as Interface owned flag")
def test_composite_host(self): # add host host = Host(name="pepito", os="linux") host.setDescription("Some description") host.setOwned(True) self.mapper_manager.save(host) # add inteface iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06") iface.setDescription("Some description") iface.setOwned(True) iface.addHostname("www.test.com") iface.setIPv4({ "address": "192.168.10.168", "mask": "255.255.255.0", "gateway": "192.168.10.1", "DNS": "192.168.10.1" }) iface.setPortsOpened(2) iface.setPortsClosed(3) iface.setPortsFiltered(4) host.addChild(iface) self.mapper_manager.save(iface) h = self.mapper_manager.find(host.getID()) self.assertEquals( len(h.getAllInterfaces()), len(host.getAllInterfaces()), "Interfaces from original host should be equals to retrieved host's interfaces" ) i = self.mapper_manager.find(h.getAllInterfaces()[0].getID()) self.assertEquals( i.getID(), iface.getID(), "Interface's id' from original host should be equals to retrieved host's interface's id" )
def test_interface_creation(self): iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06") iface.setDescription("Some description") iface.setOwned(True) iface.addHostname("www.test.com") iface.setIPv4({ "address": "192.168.10.168", "mask": "255.255.255.0", "gateway": "192.168.10.1", "DNS": "192.168.10.1" }) iface.setPortsOpened(2) iface.setPortsClosed(3) iface.setPortsFiltered(4) self.imapper.save(iface) i = self.imapper.find(iface.getID()) self.assertEquals( i, iface, "Interface retrieved should be the same as persisted") self.assertEquals( i.getID(), iface.getID(), "Interface retrieved's Id should be the same as persisted's Id")
def test_composite_host(self): # add host host = Host(name="pepito", os="linux") host.setDescription("Some description") host.setOwned(True) self.mapper_manager.save(host) # add inteface iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06") iface.setDescription("Some description") iface.setOwned(True) iface.addHostname("www.test.com") iface.setIPv4({ "address": "192.168.10.168", "mask": "255.255.255.0", "gateway": "192.168.10.1", "DNS": "192.168.10.1" }) iface.setPortsOpened(2) iface.setPortsClosed(3) iface.setPortsFiltered(4) host.addChild(iface) self.mapper_manager.save(iface) h = self.mapper_manager.find(host.getID()) self.assertEquals( len(h.getAllInterfaces()), len(host.getAllInterfaces()), "Interfaces from original host should be equals to retrieved host's interfaces") i = self.mapper_manager.find(h.getAllInterfaces()[0].getID()) self.assertEquals( i.getID(), iface.getID(), "Interface's id' from original host should be equals to retrieved host's interface's id")
def create_interface(self): iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06") iface.setDescription("Some description") iface.setOwned(True) iface.addHostname("www.test.com") iface.setIPv4({ "address": "192.168.10.168", "mask": "255.255.255.0", "gateway": "192.168.10.1", "DNS": "192.168.10.1" }) iface.setPortsOpened(2) iface.setPortsClosed(3) iface.setPortsFiltered(4) return iface
def test_interface_serialization(self): iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06") iface.setDescription("Some description") iface.setOwned(True) iface.addHostname("www.test.com") iface.setIPv4({ "address": "192.168.10.168", "mask": "255.255.255.0", "gateway": "192.168.10.1", "DNS": "192.168.10.1" }) iface.setPortsOpened(2) iface.setPortsClosed(3) iface.setPortsFiltered(4) iserialized = self.imapper.serialize(iface) # if serialization fails, returns None self.assertNotEqual( iserialized, None, "Serialized interface shouldn't be None") # we check the interface attributes self.assertEquals( iserialized.get("_id"), iface.getID(), "Serialized ID is not the same as Interface ID") self.assertEquals( iserialized.get("name"), iface.getName(), "Serialized name is not the same as Interface name") self.assertEquals( iserialized.get("mac"), iface.getMAC(), "Serialized MAC is not the same as Interface MAC") self.assertEquals( iserialized.get("network_segment"), iface.getNetworkSegment(), "Serialized Network Segment is not the same as Interface Network Segment") self.assertEquals( iserialized.get("description"), iface.getDescription(), "Serialized description is not the same as Interface description") self.assertEquals( iserialized.get("owned"), iface.isOwned(), "Serialized owned flag is not the same as Interface owned flag")