# Path: beeswarm/drones/client/client.py
# class Client(object):
#     def __init__(self, work_dir, config):
# 
#         """
#             Main class which runs Beeswarm in Client mode.
# 
#         :param work_dir: Working directory (usually the current working directory)
#         :param config_arg: Beeswarm configuration dictionary.
#         """
#         self.run_flag = True
#         self.config = config
# 
#         # write ZMQ keys to files - as expected by pyzmq
#         extract_keys(work_dir, config)
# 
#         BaitSession.client_id = self.config['general']['id']
# 
#         if self.config['general']['fetch_ip']:
#             self.my_ip = urllib2.urlopen('http://api-sth01.exip.org/?call=ip').read()
#             logger.info('Fetched {0} as my external ip.'.format(self.my_ip))
#         else:
#             self.my_ip = get_most_likely_ip()
# 
#         self.dispatcher_greenlets = []
# 
#     def start(self):
#         """
#             Starts sending client bait to the configured Honeypot.
#         """
#         logger.info('Starting client.')
# 
#         self.dispatcher_greenlets = []
# 
#         for _, entry in self.config['baits'].items():
#             for b in clientbase.ClientBase.__subclasses__():
#                 bait_name = b.__name__.lower()
#                 # if the bait has a entry in the config we consider the bait enabled
#                 if bait_name in entry:
#                     bait_options = entry[bait_name]
#                     dispatcher = BaitDispatcher(b, bait_options)
#                     dispatcher.start()
#                     self.dispatcher_greenlets.append(dispatcher)
#                     logger.info('Adding {0} bait'.format(bait_name))
#                     logger.debug('Bait added with options: {0}'.format(bait_options))
# 
#         gevent.joinall(self.dispatcher_greenlets)
# 
#     def stop(self):
#         """
#             Stop sending bait sessions.
#         """
#         for g in self.dispatcher_greenlets:
#             g.kill()
#         logger.info('All clients stopped')


import unittest
import tempfile
import shutil
import os
from beeswarm.drones.client.client import Client
class ClientTests(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()

    def tearDown(self):
        if os.path.isdir(self.tmp_dir):
            shutil.rmtree(self.tmp_dir)

    def test_client_startup(self):
        # basic test that checks if we instantiate the Client class without errors.

        config = {'general': {'id': 1234, 'fetch_ip': True},
                  "beeswarm_server": {
                      "zmq_command_url": "tcp://127.0.0.1:5713",
                      "zmq_url": "tcp://127.0.0.1:5712",
                      "zmq_own_public": [
                          "#   ****  Generated on 2015-01-13 21:02:44.933568 by pyzmq  ****\n",
                          "#   ZeroMQ CURVE Public Certificate\n",
                          "#   Exchange securely, or use a secure mechanism to verify the contents\n",
                          "#   of this file after exchange. Store public certificates in your home\n",
                          "#   directory, in the .curve subdirectory.\n",
                          "\n",
                          "metadata\n",
                          "curve\n",
                          "    public-key = \"LeZkQ^HXijnRahQkp$&nxpu6Hh>7YHBOzbz[iJg^\"\n"
                      ],
                      "zmq_own_private": [
                          "#   ****  Generated on 2015-01-13 21:02:44.933568 by pyzmq  ****\n",
                          "#   ZeroMQ CURVE **Secret** Certificate\n",
                          "#   DO NOT PROVIDE THIS FILE TO OTHER USERS nor change its permissions.\n",

# Path: beeswarm/drones/client/client.py
# class Client(object):
#     def __init__(self, work_dir, config):
# 
#         """
#             Main class which runs Beeswarm in Client mode.
# 
#         :param work_dir: Working directory (usually the current working directory)
#         :param config_arg: Beeswarm configuration dictionary.
#         """
#         self.run_flag = True
#         self.config = config
# 
#         # write ZMQ keys to files - as expected by pyzmq
#         extract_keys(work_dir, config)
# 
#         BaitSession.client_id = self.config['general']['id']
# 
#         if self.config['general']['fetch_ip']:
#             self.my_ip = urllib2.urlopen('http://api-sth01.exip.org/?call=ip').read()
#             logger.info('Fetched {0} as my external ip.'.format(self.my_ip))
#         else:
#             self.my_ip = get_most_likely_ip()
# 
#         self.dispatcher_greenlets = []
# 
#     def start(self):
#         """
#             Starts sending client bait to the configured Honeypot.
#         """
#         logger.info('Starting client.')
# 
#         self.dispatcher_greenlets = []
# 
#         for _, entry in self.config['baits'].items():
#             for b in clientbase.ClientBase.__subclasses__():
#                 bait_name = b.__name__.lower()
#                 # if the bait has a entry in the config we consider the bait enabled
#                 if bait_name in entry:
#                     bait_options = entry[bait_name]
#                     dispatcher = BaitDispatcher(b, bait_options)
#                     dispatcher.start()
#                     self.dispatcher_greenlets.append(dispatcher)
#                     logger.info('Adding {0} bait'.format(bait_name))
#                     logger.debug('Bait added with options: {0}'.format(bait_options))
# 
#         gevent.joinall(self.dispatcher_greenlets)
# 
#     def stop(self):
#         """
#             Stop sending bait sessions.
#         """
#         for g in self.dispatcher_greenlets:
#             g.kill()
#         logger.info('All clients stopped')


# Path: beeswarm/drones/client/tests/test_client.py
import unittest
import tempfile
import shutil
import os
from beeswarm.drones.client.client import Client

class ClientTests(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()

    def tearDown(self):
        if os.path.isdir(self.tmp_dir):
            shutil.rmtree(self.tmp_dir)

    def test_client_startup(self):
        # basic test that checks if we instantiate the Client class without errors.

        config = {'general': {'id': 1234, 'fetch_ip': True},
                  "beeswarm_server": {
                      "zmq_command_url": "tcp://127.0.0.1:5713",
                      "zmq_url": "tcp://127.0.0.1:5712",
                      "zmq_own_public": [
                          "#   ****  Generated on 2015-01-13 21:02:44.933568 by pyzmq  ****\n",
                          "#   ZeroMQ CURVE Public Certificate\n",
                          "#   Exchange securely, or use a secure mechanism to verify the contents\n",
                          "#   of this file after exchange. Store public certificates in your home\n",
                          "#   directory, in the .curve subdirectory.\n",
                          "\n",
                          "metadata\n",
                          "curve\n",
                          "    public-key = \"LeZkQ^HXijnRahQkp$&nxpu6Hh>7YHBOzbz[iJg^\"\n"
                      ],
                      "zmq_own_private": [
                          "#   ****  Generated on 2015-01-13 21:02:44.933568 by pyzmq  ****\n",
                          "#   ZeroMQ CURVE **Secret** Certificate\n",
                          "#   DO NOT PROVIDE THIS FILE TO OTHER USERS nor change its permissions.\n",

                          "\n",