Example #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']
Example #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'])
Example #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']
Example #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'])
Example #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')
Example #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
Example #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)
Example #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
Example #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)
Example #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
Example #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
Example #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)
Example #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']
Example #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')
Example #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']
Example #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']
Example #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']
Example #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)
Example #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)
Example #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)