def setUp(self):
     self.tmp_dir = tempfile.mkdtemp()
     self.host = '127.0.0.1'
     databus = conpot_core.get_databus()
     databus.initialize('conpot/templates/default.xml')
     self.snmp_server = SNMPServer(self.host, 0, 'conpot/templates/default.xml', [self.tmp_dir], [self.tmp_dir])
     self.port = self.snmp_server.get_port()
     self.server_greenlet = gevent.spawn(self.snmp_server.start)
 def setUp(self):
     self.tmp_dir = tempfile.mkdtemp()
     self.host = '127.0.0.1'
     databus = conpot_core.get_databus()
     databus.initialize('conpot/templates/default/template.xml')
     args = namedtuple('FakeArgs', 'mibpaths raw_mib')
     args.mibpaths = [self.tmp_dir]
     args.raw_mib = [self.tmp_dir]
     self.snmp_server = SNMPServer('conpot/templates/default/snmp/snmp.xml',
                                   'none', args)
     self.server_greenlet = gevent.spawn(self.snmp_server.start, self.host,
                                         0)
     gevent.sleep(1)
     self.port = self.snmp_server.get_port()
Exemple #3
0
 def setUp(self):
     self.tmp_dir = tempfile.mkdtemp()
     self.host = "127.0.0.1"
     databus = conpot_core.get_databus()
     # get the current directory
     self.dir_name = os.path.dirname(conpot.__file__)
     databus.initialize(self.dir_name + "/templates/default/template.xml")
     args = namedtuple("FakeArgs", "mibcache")
     args.mibcache = self.tmp_dir
     self.snmp_server = SNMPServer(
         self.dir_name + "/templates/default/snmp/snmp.xml", "none", args
     )
     self.server_greenlet = gevent.spawn(self.snmp_server.start, self.host, 0)
     gevent.sleep(1)
     self.port = self.snmp_server.get_port()
 def setUp(self):
     self.tmp_dir = tempfile.mkdtemp()
     self.host = '127.0.0.1'
     databus = conpot_core.get_databus()
     databus.initialize('conpot/templates/default.xml')
     self.snmp_server = SNMPServer(self.host, 0, 'conpot/templates/default.xml', [self.tmp_dir], [self.tmp_dir])
     self.port = self.snmp_server.get_port()
     self.server_greenlet = gevent.spawn(self.snmp_server.start)
Exemple #5
0
class TestSNMPServer(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.host = "127.0.0.1"
        databus = conpot_core.get_databus()
        # get the current directory
        self.dir_name = os.path.dirname(conpot.__file__)
        databus.initialize(self.dir_name + "/templates/default/template.xml")
        args = namedtuple("FakeArgs", "mibcache")
        args.mibcache = self.tmp_dir
        self.snmp_server = SNMPServer(
            self.dir_name + "/templates/default/snmp/snmp.xml", "none", args
        )
        self.server_greenlet = gevent.spawn(self.snmp_server.start, self.host, 0)
        gevent.sleep(1)
        self.port = self.snmp_server.get_port()

    def tearDown(self):
        shutil.rmtree(self.tmp_dir)

    def test_snmp_get(self):
        """
        Objective: Test if we can get data via snmp_get
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        oid = ((1, 3, 6, 1, 2, 1, 1, 1, 0), None)
        client.get_command(oid, callback=self.mock_callback)
        self.assertEqual("Siemens, SIMATIC, S7-200", self.result)

    def test_snmp_set(self):
        """
        Objective: Test if we can set data via snmp_set
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        # syslocation
        oid = ((1, 3, 6, 1, 2, 1, 1, 6, 0), rfc1902.OctetString("TESTVALUE"))
        client.set_command(oid, callback=self.mock_callback)
        databus = conpot_core.get_databus()
        self.assertEqual("TESTVALUE", databus.get_value("sysLocation")._value.decode())

    def mock_callback(
        self,
        sendRequestHandle,
        errorIndication,
        errorStatus,
        errorIndex,
        varBindTable,
        cbCtx,
    ):
        self.result = None
        if errorIndication:
            self.result = errorIndication
        elif errorStatus:
            self.result = errorStatus.prettyPrint()
        else:
            for oid, val in varBindTable:
                self.result = val.prettyPrint()
Exemple #6
0
 def setUp(self):
     self.tmp_dir = tempfile.mkdtemp()
     self.host = '127.0.0.1'
     databus = conpot_core.get_databus()
     databus.initialize('conpot/templates/default/template.xml')
     args = namedtuple('FakeArgs', 'mibpaths raw_mib')
     args.mibpaths = [self.tmp_dir]
     args.raw_mib = [self.tmp_dir]
     self.snmp_server = SNMPServer('conpot/templates/default/snmp/snmp.xml', 'none', args)
     self.server_greenlet = gevent.spawn(self.snmp_server.start, self.host, 0)
     gevent.sleep(1)
     self.port = self.snmp_server.get_port()
class TestBase(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.host = '127.0.0.1'
        databus = conpot_core.get_databus()
        databus.initialize('conpot/templates/default/template.xml')
        args = namedtuple('FakeArgs', 'mibpaths raw_mib')
        args.mibpaths = [self.tmp_dir]
        args.raw_mib = [self.tmp_dir]
        self.snmp_server = SNMPServer('conpot/templates/default/snmp/snmp.xml',
                                      'none', args)
        self.server_greenlet = gevent.spawn(self.snmp_server.start, self.host,
                                            0)
        gevent.sleep(1)
        self.port = self.snmp_server.get_port()

    def tearDown(self):
        shutil.rmtree(self.tmp_dir)

    def test_snmp_get(self):
        """
        Objective: Test if we can get data via snmp_get
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        oid = ((1, 3, 6, 1, 2, 1, 1, 1, 0), None)
        client.get_command(oid, callback=self.mock_callback)
        self.assertEqual("Siemens, SIMATIC, S7-200", self.result)

    def test_snmp_set(self):
        """
        Objective: Test if we can set data via snmp_set
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        # syslocation
        oid = ((1, 3, 6, 1, 2, 1, 1, 6, 0), rfc1902.OctetString('TESTVALUE'))
        client.set_command(oid, callback=self.mock_callback)
        databus = conpot_core.get_databus()
        self.assertEqual('TESTVALUE', databus.get_value('sysLocation'))

    def mock_callback(self, sendRequestHandle, errorIndication, errorStatus,
                      errorIndex, varBindTable, cbCtx):
        self.result = None
        if errorIndication:
            self.result = errorIndication
        elif errorStatus:
            self.result = errorStatus.prettyPrint()
        else:
            for oid, val in varBindTable:
                self.result = val.prettyPrint()
Exemple #8
0
class TestSNMPServer(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.host = '127.0.0.1'
        databus = conpot_core.get_databus()
        # get the current directory
        self.dir_name = os.path.dirname(conpot.__file__)
        databus.initialize(self.dir_name + '/templates/default/template.xml')
        args = namedtuple('FakeArgs', 'mibpaths raw_mib')
        args.mibpaths = [self.tmp_dir]
        args.raw_mib = [self.tmp_dir]
        self.snmp_server = SNMPServer(self.dir_name + '/templates/default/snmp/snmp.xml', 'none', args)
        self.server_greenlet = gevent.spawn(self.snmp_server.start, self.host, 0)
        gevent.sleep(1)
        self.port = self.snmp_server.get_port()

    def tearDown(self):
        shutil.rmtree(self.tmp_dir)

    def test_snmp_get(self):
        """
        Objective: Test if we can get data via snmp_get
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        oid = ((1, 3, 6, 1, 2, 1, 1, 1, 0), None)
        client.get_command(oid, callback=self.mock_callback)
        self.assertEqual("Siemens, SIMATIC, S7-200", self.result)

    def test_snmp_set(self):
        """
        Objective: Test if we can set data via snmp_set
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        # syslocation
        oid = ((1, 3, 6, 1, 2, 1, 1, 6, 0), rfc1902.OctetString('TESTVALUE'))
        client.set_command(oid, callback=self.mock_callback)
        databus = conpot_core.get_databus()
        self.assertEqual('TESTVALUE', databus.get_value('sysLocation')._value.decode())

    def mock_callback(self, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBindTable, cbCtx):
        self.result = None
        if errorIndication:
            self.result = errorIndication
        elif errorStatus:
            self.result = errorStatus.prettyPrint()
        else:
            for oid, val in varBindTable:
                self.result = val.prettyPrint()
class TestBase(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.host = '127.0.0.1'
        databus = conpot_core.get_databus()
        databus.initialize('conpot/templates/default.xml')
        self.snmp_server = SNMPServer(self.host, 0, 'conpot/templates/default.xml', [self.tmp_dir], [self.tmp_dir])
        self.port = self.snmp_server.get_port()
        self.server_greenlet = gevent.spawn(self.snmp_server.start)

    def tearDown(self):
        shutil.rmtree(self.tmp_dir)

    def test_snmp_get(self):
        """
        Objective: Test if we can get data via snmp_get
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        OID = ((1, 3, 6, 1, 2, 1, 1, 1, 0), None)
        client.get_command(OID, callback=self.mock_callback)
        self.assertEqual("Siemens, SIMATIC, S7-200", self.result)

    def test_snmp_set(self):
        """
        Objective: Test if we can set data via snmp_set
        """
        client = snmp_client.SNMPClient(self.host, self.port)
        # syslocation
        OID = ((1, 3, 6, 1, 2, 1, 1, 6, 0), rfc1902.OctetString('TESTVALUE'))
        client.set_command(OID, callback=self.mock_callback)
        databus = conpot_core.get_databus()
        self.assertEqual('TESTVALUE', databus.get_value('sysLocation'))

    def mock_callback(self, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBindTable, cbCtx):
        self.result = None
        if errorIndication:
            self.result = errorIndication
        elif errorStatus:
            self.result = errorStatus.prettyPrint()
        else:
            for oid, val in varBindTable:
                self.result = val.prettyPrint()