예제 #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)