Example #1
0
def test_hostname_creation():
    """Tests the creation of a single hostname."""
    obs = Hostname(value='asd.com')
    assert obs.id is None
    obs = obs.save()
    assert isinstance(obs, Hostname)
    assert obs.id is not None
def test_observable_get_or_create():
    """Tests the get_or_create function on observables."""
    count = len(Observable.list())
    first_object = Hostname.get_or_create(value='asd0.com')
    second_object = Hostname.get_or_create(value='asd0.com')
    assert count == len(Observable.list())
    assert first_object.id == second_object.id
    Hostname.get_or_create(value='asd999.com')
    assert count + 1 == len(Observable.list())
Example #3
0
def clean_db():
    # pylint: disable=protected-access
    # We need to access the collections to make sure they are in the cache
    Entity._get_collection()
    Malware._get_collection()
    Observable._get_collection()
    Hostname._get_collection()
    Tag._get_collection()
    Vocabs._get_collection()
    db.clear()
Example #4
0
def populate_hostnames():
    hostnames = []
    for num in range(10):
        hostname = Hostname.get_or_create(value='asd{0:d}.com'.format(num))
        hostnames.append(hostname)
    return hostnames
def test_observable_get():
    """Tests fetching a single observable by id."""
    obs = Hostname(value='asd.com').save()
    fetched_obs = Observable.get(obs.id)
    assert isinstance(fetched_obs, Observable)
    assert fetched_obs.id == obs.id
Example #6
0
def test_hostname_fails():
    """Test that invalid hostnames cannot be created."""
    for failing_value in FAILING_TESTS:
        with pytest.raises(ValidationError):
            Hostname(value=failing_value)
Example #7
0
def test_hostname_idna():
    """Tests that a Hostname's value and IDNA are correctly normalized."""
    for value, expected, _ in NORMALIZATION_TESTS:
        obs = Hostname(value=value)
        obs.normalize()
        assert obs.value == expected
Example #8
0
def test_hostnames_list():
    """Tests fetching all Hostnames in the database."""
    allitems = Hostname.list()
    assert isinstance(allitems[0], Hostname)
    assert len(allitems) == 10
Example #9
0
def test_hostname_fetch():
    """Tests that a fetched Hostname is of the correct type."""
    obs = Hostname(value='asd.com').save()
    fetched_obs = Hostname.get(obs.id)
    assert isinstance(fetched_obs, Hostname)
    assert fetched_obs.id == obs.id
Example #10
0
def test_hostname_attributes():
    """Tests that a created Hostname has all needed attributes."""
    allitems = Hostname.list()
    for hostname in allitems:
        assert hostname.value.startswith('asd')