def test_creation_path_with_unicode():
    tcex = utility.init_tcex(requires_tc_token=True)
    resource = tcex.resources.DataStore(tcex)
    body = {'four': 4}
    results = resource.create('organization', TEST_DATASTORE_PATH, 'niño', json.dumps(body)).get('data')
    assert results
    assert results['_shards']['successful'] == 1
    assert results['_type'] == TEST_DATASTORE_PATH
def test_retrieval_path_with_unicode():
    tcex = utility.init_tcex(requires_tc_token=True)
    resource = tcex.resources.DataStore(tcex)
    results = resource.read('organization', TEST_DATASTORE_PATH, 'niño').get('data')
    assert results
    assert results['_source'] == {'four': 4}
    assert results['found'] == True
    assert results['_type'] == TEST_DATASTORE_PATH
def test_retrieval():
    tcex = utility.init_tcex(requires_tc_token=True)
    resource = tcex.resources.DataStore(tcex)
    results = resource.read('organization', TEST_DATASTORE_PATH, 1).get('data')
    assert results
    assert results['_source'] == {'one': 1}
    assert results['found'] == True
    assert results['_type'] == TEST_DATASTORE_PATH
def test_retrieval_path_with_spaces():
    """Try retrieving an entry in the datastore where the path has a space in it."""
    tcex = utility.init_tcex(requires_tc_token=True)
    resource = tcex.resources.DataStore(tcex)
    results = resource.read('organization', TEST_DATASTORE_PATH, 'test ing').get('data')
    assert results
    assert results['_source'] == {'three': 3}
    assert results['found'] == True
    assert results['_type'] == TEST_DATASTORE_PATH
def test_creation_path_with_spaces():
    """Try creating an entry in the datastore where the path has a space in it."""
    tcex = utility.init_tcex(requires_tc_token=True)
    resource = tcex.resources.DataStore(tcex)
    body = {'three': 3}
    results = resource.create('organization', TEST_DATASTORE_PATH, 'test ing', json.dumps(body)).get('data')
    assert results
    assert results['_shards']['successful'] == 1
    assert results['_type'] == TEST_DATASTORE_PATH
def test_interface_3():
    """Test indicator creation via the third interface."""
    tcex_instance = utility.init_tcex()
    owner = tcex_instance.args.api_default_org
    batch = tcex_instance.batch(owner)
    batch_ind_creation_interface_3.address_create(batch)
    batch_ind_creation_interface_3.email_address_create(batch)
    batch_ind_creation_interface_3.file_create(batch)
    batch_ind_creation_interface_3.host_create(batch)
    batch_ind_creation_interface_3.url_create(batch)
    batch.submit_all()
    validator.validate(tcex_instance, expected_indicators=5)
 def clear_datastore():
     tcex = utility.init_tcex(requires_tc_token=True)
     resource = tcex.resources.DataStore(tcex)
     results = resource.delete('organization', TEST_DATASTORE_PATH, 1).get('data')
     assert results['_shards']['successful'] == 1
     assert results['result'] == 'deleted'
     results = resource.delete('organization', TEST_DATASTORE_PATH, 'testing').get('data')
     assert results['_shards']['successful'] == 1
     assert results['result'] == 'deleted'
     results = resource.delete('organization', TEST_DATASTORE_PATH, 'test ing').get('data')
     assert results['_shards']['successful'] == 1
     assert results['result'] == 'deleted'
     results = resource.delete('organization', TEST_DATASTORE_PATH, 'niño').get('data')
     assert results['_shards']['successful'] == 1
     assert results['result'] == 'deleted'
def test_interface_3():
    """Test group creation via the third interface."""
    tcex_instance = utility.init_tcex()
    owner = tcex_instance.args.api_default_org
    batch = tcex_instance.batch(owner)
    batch_group_creation_interface_3.adversary_create(batch)
    batch_group_creation_interface_3.campaign_create(batch)
    batch_group_creation_interface_3.document_create(batch)
    batch_group_creation_interface_3.document_malware_create(batch)
    batch_group_creation_interface_3.email_create(batch)
    batch_group_creation_interface_3.event_create(batch)
    batch_group_creation_interface_3.incident_create(batch)
    batch_group_creation_interface_3.intrusion_set_create(batch)
    batch_group_creation_interface_3.report_create(batch)
    batch_group_creation_interface_3.signature_create(batch)
    batch_group_creation_interface_3.threat_create(batch)
    results = batch.submit_all()
    assert results[0]['errorCount'] == 0
    assert results[0]['successCount'] == 11
    validator.validate(tcex_instance, expected_groups=11)
예제 #9
0
def test_document_download():
    """Test downloading a document from TC."""
    tcex_instance = utility.init_tcex()
    owner = tcex_instance.args.api_default_org

    # create a document
    batch = tcex_instance.batch(owner)
    batch_group_creation_interface_1.document_create(batch)
    batch.submit_all()

    # get the group
    groups = validator.get_groups(tcex_instance)
    document_id = groups[0]['id']

    # try to download the document
    doc = tcex_instance.resources.Document(tcex_instance)
    doc.owner = owner
    doc.download(document_id)

    document_contents = ''
    for results in doc:  # pagination
        document_contents = results['data']
    assert document_contents == 'Example file content'
예제 #10
0
def test_indicator_associations():
    """."""
    tcex = utility.init_tcex()
    tcex.jobs.indicator({
        "summary": "4.5.6.7",
        "type": "Address",
    })
    tcex.jobs.indicator({
        "summary": "ASN1234",
        "type": tcex.safe_rt('ASN', lower=False),
    })
    tcex.jobs.association({
        'association_value': 'ASN1234',
        'association_type': tcex.safe_rt('ASN', lower=False),
        'resource_value': '4.5.6.7',
        'resource_type': 'Address'
    })
    tcex.jobs.process(tcex.args.api_default_org)
    assert len(tcex.jobs.indicator_results['failed']) == 0
    assert len(tcex.jobs.indicator_results['not_saved']) == 0
    assert len(tcex.jobs.indicator_results['saved']) == 2

    verify_association_created(tcex)
    cleaner.clean()