Example #1
0
def test_graph_api():
    '''
    Test the graph api method.
    '''
    responses.add(method='POST',
                  url='https://localhost:443/graphql',
                  json={
                      'data': {
                          'asset': {
                              'id': 'something',
                              'type': 'EngType',
                              'name': 'Eng. Station #40',
                              'criticality': 'HighCriticality',
                              'location': None
                          }
                      }
                  })
    ot = TenableOT(address='localhost')
    resp = ot.graphql(variables={'asset': 'something'},
                      query='''
            query getAssetDetails($asset: ID!) {
                asset(id: $asset) {
                    id
                    type
                    name
                    criticality
                    location
                }
            }
        ''')
    assert resp.data.asset.id == 'something'
    assert resp.data.asset.type == 'EngType'
    assert resp.data.asset.name == 'Eng. Station #40'
    assert resp.data.asset.criticality == 'HighCriticality'
    assert resp.data.asset.location == None
def test_details():
    '''
    Tests the details method
    '''
    responses.add(
        method='GET',
        url=
        'https://localhost:443/v1/networkinterfaces/d7f06b04-5733-44ac-9e84-096f6fdb181b',
        json={
            'id': 'd7f06b04-5733-44ac-9e84-096f6fdb181b',
            'ips': ['192.168.101.154'],
            'dnsNames': None,
            'lastSeen': '2020-07-09T00:10:51.125735Z',
            'firstSeen': '2020-07-09T00:01:22.618953Z',
            'family': 'Unknown'
        })
    ot = TenableOT(address='localhost')
    resp = ot.network_interfaces.details(
        'd7f06b04-5733-44ac-9e84-096f6fdb181b')
    assert resp.id == 'd7f06b04-5733-44ac-9e84-096f6fdb181b'
    assert resp.ips == ['192.168.101.154']
    assert resp.dnsNames == None
    assert resp.lastSeen == '2020-07-09T00:10:51.125735Z'
    assert resp.firstSeen == '2020-07-09T00:01:22.618953Z'
    assert resp.family == 'Unknown'
def test_connections():
    '''
    Test the connections method
    '''
    responses.add(
        method='GET',
        url=
        'https://localhost:443/v1/networkinterfaces/d7f06b04-5733-44ac-9e84-096f6fdb181b/connections',
        json=[{
            'asset': '026fd8a1-2d50-4b2b-9cd5-285489d7fda4',
            'networkInterface': 'd7f06b04-5733-44ac-9e84-096f6fdb181b',
            'local': True,
            'direct': True,
            'connector': {
                'parts': [{
                    'connectionType': 'Direct'
                }]
            }
        }])
    ot = TenableOT(address='localhost')
    resp = ot.network_interfaces.connections(
        'd7f06b04-5733-44ac-9e84-096f6fdb181b')
    for item in resp:
        assert item.asset == '026fd8a1-2d50-4b2b-9cd5-285489d7fda4'
        assert item.networkInterface == 'd7f06b04-5733-44ac-9e84-096f6fdb181b'
        assert item.local == True
        assert item.direct == True
        assert item.connector.parts[0].connectionType == 'Direct'
Example #4
0
def test_list():
    '''
    Tests the list iterator
    '''
    responses.add(method='POST',
                  url='https://localhost:443/v1/assets',
                  json=[{
                      'id': '000b3456-35f6-4b83-8ffe-45aceb288ce4',
                      'name': 'Endpoint #548',
                      'firstSeen': '2020-05-22T15:36:48.323534Z',
                      'lastSeen': '2020-07-14T13:42:48.855494Z',
                      'addresses': ['192.168.106.254'],
                      'directAddresses': ['192.168.106.254'],
                      'type': 'UnknownType',
                      'purdueLevel': 'UnknownLevel',
                      'vendor': 'Cisco',
                      'runStatus': 'Unknown',
                      'runStatusTime': '0001-01-01T00:00:00Z',
                      'risk': 15.651708757702835,
                      'criticality': 'LowCriticality',
                      'hidden': False,
                      'site': 'e4f7997b-8470-483c-a4b2-8fddcae22df3'
                  }])
    ot = TenableOT(address='localhost')
    resp = ot.assets.list()
    item = resp.next()
    assert item.id == '000b3456-35f6-4b83-8ffe-45aceb288ce4'
    assert item.name == 'Endpoint #548'
    assert item.firstSeen == '2020-05-22T15:36:48.323534Z'
    assert item.lastSeen == '2020-07-14T13:42:48.855494Z'
    assert item.addresses == ['192.168.106.254']
    assert item.directAddresses == ['192.168.106.254']
    assert item.type == 'UnknownType'
    assert item.purdueLevel == 'UnknownLevel'
Example #5
0
def fixture_ot():
    '''fixture ot'''
    return TenableOT(url='https://localhost',
                     api_key='some_random_key',
                     vendor='pytest',
                     product='pytenable-automated-testing',
                     build=version)
Example #6
0
def test_vuln_asset_intermixer():
    '''
    Tests the intermixer iterator
    '''
    load_responses(responses)
    ot = TenableOT(address='localhost')
    vulns = ot.vulns.extract()

    # assert the iterator returns itself.
    assert vulns == vulns.__iter__()

    # as __next__() calls next(), we will use the internal method to clear the
    # testing requirements.
    v = vulns.__next__()

    assert v.asset.id == '8fe5cdb1-723e-4996-9d3c-7787445bc38a'
    assert v.asset.connections
    assert v.asset.connections[0].networkInterface.id == 'd7f06b04-5733-44ac-9e84-096f6fdb181b'
    assert v.impact.baseMetricV2.cvssV2.baseScore == 7.8

    # Validate that merge_cache should always return the same asset cache.
    w = vulns._merge_cache(Box({'id': '8fe5cdb1-723e-4996-9d3c-7787445bc38a'}))
    assert v.asset.id == w.asset.id
    assert v.cve.id == w.cve.id

    # test that the stop iterator works as expected.
    with pytest.raises(StopIteration):
        vulns.next()
Example #7
0
def test_details():
    '''
    Tests the details method
    '''
    responses.add(
        method='GET',
        url=
        'https://localhost:443/v1/assets/026fd8a1-2d50-4b2b-9cd5-285489d7fda4',
        json={
            'addresses': ['192.168.101.154'],
            'criticality': 'LowCriticality',
            'directAddresses': ['192.168.101.154'],
            'firstSeen': '2020-07-09T00:01:22.635465Z',
            'hidden': False,
            'id': '026fd8a1-2d50-4b2b-9cd5-285489d7fda4',
            'incidents': ['DirectConnectorIncident'],
            'lastSeen': '2020-07-09T00:10:51.125735Z',
            'name': 'Endpoint #608',
            'purdueLevel': 'UnknownLevel',
            'risk': 44.050849231996736,
            'runStatus': 'Unknown',
            'runStatusTime': '0001-01-01T00:00:00Z',
            'site': 'e4f7997b-8470-483c-a4b2-8fddcae22df3',
            'type': 'UnknownType'
        })
    ot = TenableOT(address='localhost')
    resp = ot.assets.details('026fd8a1-2d50-4b2b-9cd5-285489d7fda4')
    assert resp.id == '026fd8a1-2d50-4b2b-9cd5-285489d7fda4'
    assert resp.name == 'Endpoint #608'
    assert resp.lastSeen == '2020-07-09T00:10:51.125735Z'
    assert resp.addresses == ['192.168.101.154']
    assert resp.directAddresses == ['192.168.101.154']
    assert resp.type == 'UnknownType'
    assert resp.purdueLevel == 'UnknownLevel'
Example #8
0
def test_ot_interfaces():
    '''
    Testing that the right interfaces are returned.
    '''
    ot = TenableOT()
    assert isinstance(ot.assets, AssetsAPI)
    assert isinstance(ot.network_interfaces, NetworkInterfacesAPI)
    assert isinstance(ot.vulns, VulnsAPI)
Example #9
0
def test_list():
    '''
    Tests the list method
    '''
    load_responses(responses)
    ot = TenableOT(address='localhost')
    vulns = ot.vulns.list()

    for vuln in vulns:
        assert vuln.cve.CVE_data_meta.ID == 'CVE-2020-9464'
        assert vuln.impact.baseMetricV2.cvssV2.baseScore == 7.8
Example #10
0
def ot():
    responses.add(method='GET',
                  url='https://localhost:443/v1/version',
                  json={
                      'Module': 'Cobex',
                      'Version': '3.7.0',
                      'NvdVersion': '1.12.0'
                  })
    return TenableOT(address='localhost',
                     vendor='pytest',
                     product='pytenable-automated-testing',
                     build=version)
Example #11
0
def test_assets_list():
    responses.add(
        method='GET',
        url='https://localhost:443/v1/vulnerabilities/assets',
        json=[
            {
                'cveId': 'CVE-2017-14463',
                'assetCount': 1
            }, {
                'cveId': 'CVE-2017-14472',
                'assetCount': 1
            }
        ]
    )
    ot = TenableOT(address='localhost')
    counts = ot.vulns.assets_list()
    for c in counts:
        assert c.cveId
        assert c.assetCount
Example #12
0
def test_iterator():
    responses.add(
        method='POST',
        url='https://localhost:443/v1/iterator_test',
        json=['item1', 'item2', 'item3', 'item4', 'item5', 'item6']
    )
    ot = TenableOT(address='localhost')

    # iterate through multiple pages
    items = OTIterator(ot, path='iterator_test', payload=dict(), limit=6, max_pages=3)
    for item in items:
        assert isinstance(item, str)
    assert items.count == 18
    assert items.num_pages == 3

    # insure that the iterator will bail when the limit is larger than the page.
    items = OTIterator(ot, path='iterator_test', payload=dict(), max_pages=3)
    for item in items:
        assert isinstance(item, str)
    assert items.count == 6
    assert items.num_pages == 1
Example #13
0
def ot():
    return TenableOT(
        vendor='pytest',
        product='pytenable-automated-testing',
        build=version
    )