def __init__(self): self.logger = logger self.faucet_event = [] self.controller = Config().get_config() self.controller['max_concurrent_reinvestigations'] = 10 self.s = SDNConnect(self.controller) if 'POSEIDON_TRAVIS' in os.environ: self.s.r = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.mirror() endpoint.known() self.s.endpoints[endpoint.name] = endpoint endpoint = endpoint_factory('foo2') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.mirror() endpoint.known() self.s.endpoints[endpoint.name] = endpoint self.s.store_endpoints() self.s.get_stored_endpoints()
def test_commands(): commands = Commands(controller=get_test_controller()) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1'} commands.sdnc.endpoints = {} commands.sdnc.endpoints[endpoint.name] = endpoint commands.what_is('foo') commands.history_of('foo') commands.acls_of('foo') commands.where_is('foo') commands.show_devices('foo bar') commands.show_devices('all') commands.change_devices('foo') commands.remove('foo') commands.clear_ignored('foo') commands.clear_ignored('ignored') commands.ignore('foo') commands.ignore('inactive') commands.remove_inactives('foo') commands.remove_ignored('foo') endpoint2 = endpoint_factory('foo2') endpoint2.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1'} commands.sdnc.endpoints[endpoint2.name] = endpoint2 commands.what_is('00:00:00:00:00:00')
def __init__(self): self.logger = logger self.faucet_event = [] self.controller = Config().get_config() self.controller['max_concurrent_reinvestigations'] = 10 self.s = SDNConnect(self.controller) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.mirror() endpoint.known() self.s.endpoints[endpoint.name] = endpoint endpoint = endpoint_factory('foo2') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.mirror() endpoint.known() self.s.endpoints[endpoint.name] = endpoint self.s.store_endpoints() self.s.get_stored_endpoints()
def __init__(self): self.logger = logger self.fa_rabbit_routing_key = 'FAUCET.Event' self.faucet_event = None self.controller = Config().get_config() self.s = SDNConnect(self.controller) self.s.controller['TYPE'] = 'None' self.s.get_sdn_context() self.s.controller['TYPE'] = 'bcf' self.s.get_sdn_context() self.s.controller['TYPE'] = 'faucet' self.s.get_sdn_context() if 'POSEIDON_TRAVIS' in os.environ: self.s.r = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.mirror() endpoint.p_prev_states.append((endpoint.state, int(time.time()))) self.s.endpoints[endpoint.name] = endpoint endpoint = endpoint_factory('foo2') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.p_next_state = 'mirror' endpoint.queue() endpoint.p_prev_states.append((endpoint.state, int(time.time()))) self.s.endpoints[endpoint.name] = endpoint endpoint = endpoint_factory('foo3') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } self.s.endpoints[endpoint.name] = endpoint self.s.store_endpoints() self.s.get_stored_endpoints()
def test_update_history(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'ipv4': '0.0.0.0', 'ipv6': '1212::1' } endpoint.metadata = { 'mac_addresses': { '00:00:00:00:00:00': { '1551805502': { 'labels': ['developer workstation'], 'behavior': 'normal' } } }, 'ipv4_addresses': { '0.0.0.0': { 'os': 'windows' } }, 'ipv6_addresses': { '1212::1': { 'os': 'windows' } } } metadata = {123: {'behavior': 'normal'}} prc = PoseidonRedisClient(None) prc.update_history(endpoint, {'00:00:00:00:00:00': metadata}, {'0.0.0.0': metadata}, {'1212::1': metadata})
def test_update_history(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'ipv4': '0.0.0.0', 'ipv6': '1212::1' } endpoint.metadata = { 'mac_addresses': { '00:00:00:00:00:00': { '1551805502': { 'labels': ['developer workstation'] } } }, 'ipv4_addresses': { '0.0.0.0': { 'os': 'windows' } }, 'ipv6_addresses': { '1212::1': { 'os': 'windows' } } } metadata = {123: {'foo': 'bar'}} logger = logging.getLogger('test') prc = PoseidonRedisClient(logger) prc.update_history(endpoint, {'00:00:00:00:00:00': metadata}, {'0.0.0.0': metadata}, {'1212::1': metadata})
def __init__(self): self.logger = logger self.fa_rabbit_routing_key = 'FAUCET.Event' self.faucet_event = None self.controller = Config().get_config() self.s = SDNConnect(self.controller) self.s.controller['TYPE'] = 'None' self.s.get_sdn_context() self.s.controller['TYPE'] = 'bcf' self.s.get_sdn_context() self.s.controller['TYPE'] = 'faucet' self.s.get_sdn_context() self.job_queue = queue.Queue() self.m_queue = queue.Queue() endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.mirror() endpoint.p_prev_states.append((endpoint.state, int(time.time()))) self.s.endpoints[endpoint.name] = endpoint endpoint = endpoint_factory('foo2') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.p_next_state = 'mirror' endpoint.queue() endpoint.p_prev_states.append((endpoint.state, int(time.time()))) self.s.endpoints[endpoint.name] = endpoint endpoint = endpoint_factory('foo3') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } self.s.endpoints[endpoint.name] = endpoint self.s.store_endpoints() self.s.get_stored_endpoints() self.results = 0
def test_Endpoint(): """ Tests Endpoint """ endpoint = endpoint_factory('foo') b = endpoint.encode() c = EndpointDecoder(b).get_endpoint() a = {'tenant': 'foo', 'mac': '00:00:00:00:00:00'} hashed_val = Endpoint.make_hash(a)
def test_Collector(): """ Tests Collector """ endpoint = endpoint_factory('foo') endpoint.endpoint_data = {'mac': '00:00:00:00:00:00'} a = Collector(endpoint, 'foo') a.start_vent_collector() a.stop_vent_collector() a.get_vent_collectors() a.host_has_active_collectors('foo') endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'mac': '00:00:00:00:00:00', 'container_id': 'foo' } a = Collector(endpoint, 'foo') a.stop_vent_collector()
def test_get_prev_ipv6_oses(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } GetData._get_prev_ipv6_oses(endpoint)
def test_get_vlan(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'vlan': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } vlan = GetData._get_vlan(endpoint) assert vlan == 'foo'
def test_get_ignored(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } ignored = GetData._get_ignored(endpoint) assert ignored == 'False'
def test_get_next_state(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } state = GetData._get_next_state(endpoint) assert state == 'None'
def test_get_port(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } port = GetData._get_port(endpoint) assert port == '1'
def test_get_last_seen(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.unknown() GetData._get_last_seen(endpoint)
def test_get_name(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } name = GetData._get_name(endpoint) assert name == 'foo'
def test_get_switch(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } switch = GetData._get_switch(endpoint) assert switch == 'foo'
def test_get_last_seen(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.p_prev_states = [('unknown', 1551711125)] GetData._get_last_seen(endpoint)
def test_display_results(): parser = Parser() endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'vlan': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'ipv4': '0.0.0.0', 'ipv6': '1212::1' } endpoints = [endpoint] parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4', 'IPv6'], ipv4_only=False, ipv6_only=True) parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv6'], ipv4_only=False, ipv4_and_ipv6=True) parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'], ipv4_only=False, ipv4_and_ipv6=True) parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'], ipv4_only=False, ipv4_and_ipv6=True, unique=True) parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'], ipv4_only=False, ipv4_and_ipv6=True, nonzero=True) parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'], ipv4_only=False, ipv4_and_ipv6=True, nonzero=True, unique=True) parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'], ipv4_only=False, ipv4_and_ipv6=True, nonzero=True, unique=True, output_format='csv') parser.display_results( endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'], ipv4_only=False, ipv4_and_ipv6=True, nonzero=True, unique=True, output_format='json')
def test_get_ipv6(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'ipv6': '1212::1' } ipv6 = GetData._get_ipv6(endpoint) assert ipv6 == '1212::1'
def test_get_ipv4(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'ipv4': '0.0.0.0' } ipv4 = GetData._get_ipv4(endpoint) assert ipv4 == '0.0.0.0'
def test_get_controller_type(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'controller_type': 'foo' } controller_type = GetData._get_controller_type(endpoint) assert controller_type == 'foo' endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } controller_type = GetData._get_controller_type(endpoint) assert controller_type == NO_DATA
def test_unmirror_endpoint(): controller = Config().get_config() s = SDNConnect(controller) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } s.endpoints[endpoint.name] = endpoint s.unmirror_endpoint(endpoint)
def test_get_acls(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'ipv4': '0.0.0.0' } endpoint.acl_data = [] acls = GetData._get_acls(endpoint) assert acls == '[]'
def test_clear_filters(): controller = get_test_controller() s = SDNConnect(controller) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } s.endpoints[endpoint.name] = endpoint s.clear_filters() controller = get_test_controller() s = SDNConnect(controller) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } s.endpoints[endpoint.name] = endpoint s.clear_filters()
def test_get_ipv6_os(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1', 'ipv6': '1212::1' } endpoint.metadata = {'ipv6_addresses': {}} ipv6_os = GetData._get_ipv6_os(endpoint) assert ipv6_os == NO_DATA endpoint.metadata = {'ipv6_addresses': {'1212::1': {'os': 'foo'}}} ipv6_os = GetData._get_ipv6_os(endpoint) assert ipv6_os == 'foo'
def test_get_history(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } history = GetData._get_history(endpoint) assert history == 'No history recorded yet.' endpoint.trigger('mirror') endpoint.trigger('known') endpoint.trigger('inactive') history = GetData._get_history(endpoint) assert history != 'No history recorded yet.'
def test_get_prev_state(): endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } endpoint.p_prev_state = None prev_state = GetData._get_prev_state(endpoint) assert prev_state == NO_DATA endpoint.unknown() GetData._get_prev_state(endpoint) endpoint.queue() GetData._get_prev_state(endpoint)
def test_endpoint_by_name(): controller = Config().get_config() s = SDNConnect(controller) endpoint = s.endpoint_by_name('foo') assert endpoint == None endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } s.endpoints[endpoint.name] = endpoint endpoint2 = s.endpoint_by_name('foo') assert endpoint == endpoint2
def test_Actions(): """ Tests Actions """ endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1'} controller = get_test_controller() s = SDNConnect(controller, logger) a = Actions(endpoint, s.sdnc) a.mirror_endpoint() a.unmirror_endpoint() a.coprocess_endpoint() a.uncoprocess_endpoint() a.shutdown_endpoint()