Пример #1
0
def test_remove_vocab():
    """Tests that a vocab can be removed from a vocab list for a given field."""
    vocab = Setting.find(name='malware-label-ov')
    vocab.set_vocab(sorted(['banker', 'trojan']))
    vocab.remove_value_from_vocab('trojan')
    vocablist = vocab.get_vocab()
    assert vocablist == ['banker']
Пример #2
0
def test_add_vocab():
    """Tests that vocabs can be added to a vocab list for a given field."""
    vocab = Setting.find(name='vocabs')
    vocab.set_vocab_for_field('Malware.type', ['banker'])
    vocab.add_value_to_field_vocab('Malware.type', 'trojan')
    vocablist = vocab.get_vocab_for_field('Malware.type')
    assert vocablist == sorted(['banker', 'trojan'])
Пример #3
0
def test_remove_vocab():
    """Tests that a vocab can be removed from a vocab list for a given field."""
    vocab = Setting.find(name='vocabs')
    vocab.set_vocab_for_field('Malware.type', sorted(['banker', 'trojan']))
    vocab.remove_value_from_field_vocab('Malware.type', 'trojan')
    vocablist = vocab.get_vocab_for_field('Malware.type')
    assert vocablist == ['banker']
Пример #4
0
def test_add_vocab():
    """Tests that vocabs can be added to a vocab list for a given field."""
    vocab = Setting.find(name='malware-label-ov')
    vocab.set_vocab(['banker'])
    vocab.add_value_to_vocab('trojan')
    vocablist = vocab.get_vocab()
    assert vocablist == sorted(['banker', 'trojan'])
Пример #5
0
def test_wrong_remove_vocab_raises():
    """Tests that a RuntimeError is raised when getting a noneixstent vocab."""
    vocab = Setting.find(name='vocabs')
    vocab.set_vocab_for_field('Malware.type', sorted(['banker', 'trojan']))
    with pytest.raises(RuntimeException):
        vocab.remove_value_from_field_vocab('Notexist', ['banker'])
    with pytest.raises(RuntimeException):
        vocab.remove_value_from_field_vocab('Malware.type', 'notexist')
Пример #6
0
 def get_vocab(self, vocab):
     """Return defined vocabularies."""
     try:
         v = Setting.find(name=vocab)
         if not v:
             return '', 404
         return v.get_vocab()
     except RuntimeException as exception:
         return exception, 400
Пример #7
0
 def remove_value_from_field_vocab(self, field):
     """Return defined vocabularies for a field."""
     value = request.json['value']
     v = Setting.find(name='vocabs')
     try:
         v.remove_value_from_field_vocab(field, value)
     except RuntimeException as exception:
         return exception, 400
     return v.get_vocab_for_field(field)
Пример #8
0
 def get_killchain(self, killchain):
     """Return defined killchains."""
     try:
         kc = Setting.find(name=killchain)
         if not kc:
             return '', 404
         return kc.get_killchain()
     except RuntimeException as exception:
         return exception, 400
Пример #9
0
 def remove_phase_from_killchain(self, killchain):
     """Remove a phase from a killchain."""
     phase = request.json['phase']
     kc = Setting.find(name='killchains')
     try:
         kc.remove_phase_from_killchain(killchain, phase)
     except RuntimeException as exception:
         return exception, 400
     return kc.get_killchain(killchain)
Пример #10
0
 def add_phase_to_killchain(self, killchain):
     """Set phases for a killchain."""
     phase = request.json['phase']
     try:
         kc = Setting.find(name='killchains')
         kc.add_phase_to_killchain(killchain, phase)
         return kc.get_killchain(killchain)
     except RuntimeException as exception:
         return exception, 400
Пример #11
0
 def add_value_to_vocab(self, vocab):
     """Set a vocabulary."""
     value = request.json['value']
     try:
         v = Setting.find(name='vocabs')
         v.add_value_to_vocab(vocab, value)
         return v.get_vocab(vocab)
     except RuntimeException as exception:
         return exception, 400
Пример #12
0
 def remove_value_from_vocab(self, vocab):
     """Remove a value from a vocab."""
     value = request.json['value']
     v = Setting.find(name='vocabs')
     try:
         v.remove_value_from_vocab(vocab, value)
     except RuntimeException as exception:
         return exception, 400
     return v.get_vocab(vocab)
Пример #13
0
def test_set_vocab():
    """Tests that a vocab can be set for a given field."""
    vocab = Setting.find(name='vocabs')
    vocab.set_vocab_for_field('Malware.type', ['banker', 'other'])
    vocablist = vocab.get_vocab_for_field('Malware.type')
    assert vocablist == ['banker', 'other']
Пример #14
0
def test_wrong_field_raises():
    """Tests that a RuntimeError is raised when getting a noneixstent vocab."""
    vocab = Setting.find(name='vocabs')
    with pytest.raises(RuntimeException):
        vocab.get_vocab_for_field('Notexist')
Пример #15
0
def test_filter_vocab():
    """Tests that a vocab list for a given list can be filtered."""
    vocab = Setting.find(name='malware-label-ov')
    vocab.set_vocab(sorted(['banker', 'trojan']))
    assert vocab.filter_values_vocab('tro') == ['trojan']
Пример #16
0
def test_filter_vocab():
    """Tests that a vocab list for a given list can be filtered."""
    vocab = Setting.find(name='vocabs')
    vocab.set_vocab_for_field('Malware.type', sorted(['banker', 'trojan']))
    assert vocab.filter_values_for_field_vocab('Malware.type',
                                               'tro') == ['trojan']
Пример #17
0
def test_set_vocab():
    """Tests that a vocab can be set for a given field."""
    vocab = Setting.find(name='vocabs')
    vocab.set_vocab('malware-label-ov', ['toto'])
    vocablist = vocab.get_vocab('malware-label-ov')
    assert vocablist == ['toto']
Пример #18
0
 def get_vocab_for_field(self, field):
     """Return defined vocabularies for a field."""
     v = Setting.find(name='vocabs')
     return v.get_vocab_for_field(field)
Пример #19
0
 def add_value_to_field_vocab(self, field):
     """Return defined vocabularies for a field."""
     value = request.json['value']
     v = Setting.find(name='vocabs')
     v.add_value_to_field_vocab(field, value)
     return v.get_vocab_for_field(field)
Пример #20
0
def test_get_vocab_setting():
    """Tests that a vocab setting can be saved and has correct type."""
    vocab = Setting.find(name='vocabs')
    assert isinstance(vocab, Vocabs)