Exemplo n.º 1
0
def test_poll_collection(mocker):
    """
    Given:
        - A collection of indicators in STIX format.

    When:
        - fetch_indicators_command is running.

    Then:
        - Validate the indicator extract as expected.
    """
    import requests_mock
    from FeedTAXII import fetch_indicators_command
    client = TAXIIClient(collection='a collection',
                         poll_service='http://example/taxii-data')

    with open('FeedTAXII_test/TestCommands/collection_example.xml',
              'rb') as xml_f:
        stix_content = xml_f.read()

    with requests_mock.Mocker() as m:
        m.post('http://example/taxii-data', content=stix_content)
        res = fetch_indicators_command(client)

    with open('FeedTAXII_test/TestCommands/indicators_example.json') as json_f:
        expected_result = json.load(json_f)

    assert res == expected_result
Exemplo n.º 2
0
 def test_fetch_indicators(self, mocker):
     client = TAXIIClient(collection='a collection')
     with open('FeedTAXII_test/TestCommands/raw_indicators.json', 'r') as f:
         raw_indicators = json.load(f)
         mocker.patch.object(client, 'build_iterator', return_value=raw_indicators)
         res = fetch_indicators_command(client)
         with open('FeedTAXII_test/TestCommands/indicators_results.json') as exp_f:
             expected = json.load(exp_f)
             assert res == expected
Exemplo n.º 3
0
def test_tags_parameter(mocker, tags):
    """
    Given:
    - tags parameters
    When:
    - Executing any command on feed
    Then:
    - Validate the tags supplied exists in the indicators
    """
    client = TAXIIClient(collection='a collection', tags=json.dumps(tags))
    with open('FeedTAXII_test/TestCommands/raw_indicators.json', 'r') as f:
        raw_indicators = json.load(f)
        mocker.patch.object(client, 'build_iterator', return_value=raw_indicators)
        res = fetch_indicators_command(client)
        assert tags == res[0]['fields']['tags']