mirror of https://github.com/MISP/PyMISP
Update testing
parent
76812f96aa
commit
cdcb1cca5e
|
@ -1,3 +1,6 @@
|
||||||
|
[](https://travis-ci.org/MISP/PyMISP)
|
||||||
|
[](https://coveralls.io/github/MISP/PyMISP?branch=master)
|
||||||
|
|
||||||
# PyMISP - Python Library to access MISP
|
# PyMISP - Python Library to access MISP
|
||||||
|
|
||||||
PyMISP is a Python library to access [MISP](https://github.com/MISP/MISP) platforms via their REST API.
|
PyMISP is a Python library to access [MISP](https://github.com/MISP/MISP) platforms via their REST API.
|
||||||
|
@ -20,7 +23,7 @@ git clone https://github.com/CIRCL/PyMISP.git && cd PyMISP
|
||||||
python setup.py install
|
python setup.py install
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
## Samples and how to use PyMISP
|
## Samples and how to use PyMISP
|
||||||
|
|
||||||
Various examples and samples scripts are in the [examples/](examples/) directory.
|
Various examples and samples scripts are in the [examples/](examples/) directory.
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,13 @@ import argparse
|
||||||
|
|
||||||
|
|
||||||
def init(url, key):
|
def init(url, key):
|
||||||
return PyMISP(url, key, True, 'json')
|
return PyMISP(url, key, True, 'json', debug=True)
|
||||||
|
|
||||||
|
|
||||||
def up_event(m, event, content):
|
def up_event(m, event, content):
|
||||||
with open(content, 'r') as f:
|
with open(content, 'r') as f:
|
||||||
result = m.update_event(event, f.read())
|
result = m.update_event(event, f.read())
|
||||||
print result.text
|
print(result)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='Get an event from a MISP instance.')
|
parser = argparse.ArgumentParser(description='Get an event from a MISP instance.')
|
||||||
|
|
|
@ -86,23 +86,6 @@ class NoKey(PyMISPError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def deprecated(func):
|
|
||||||
'''This is a decorator which can be used to mark functions
|
|
||||||
as deprecated. It will result in a warning being emitted
|
|
||||||
when the function is used.'''
|
|
||||||
|
|
||||||
@functools.wraps(func)
|
|
||||||
def new_func(*args, **kwargs):
|
|
||||||
warnings.warn_explicit(
|
|
||||||
"Call to deprecated function {}.".format(func.__name__),
|
|
||||||
category=DeprecationWarning,
|
|
||||||
filename=func.__code__.co_filename,
|
|
||||||
lineno=func.__code__.co_firstlineno + 1
|
|
||||||
)
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
return new_func
|
|
||||||
|
|
||||||
|
|
||||||
class PyMISP(object):
|
class PyMISP(object):
|
||||||
"""
|
"""
|
||||||
Python API for MISP
|
Python API for MISP
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import unittest
|
||||||
import requests_mock
|
import requests_mock
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import pymisp
|
||||||
from pymisp import PyMISP
|
from pymisp import PyMISP
|
||||||
|
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
class TestOffline(object):
|
class TestOffline(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.domain = 'http://misp.local/'
|
self.domain = 'http://misp.local/'
|
||||||
|
@ -17,12 +19,44 @@ class TestOffline(object):
|
||||||
self.types = json.load(open('tests/describeTypes.json', 'r'))
|
self.types = json.load(open('tests/describeTypes.json', 'r'))
|
||||||
|
|
||||||
def initURI(self, m):
|
def initURI(self, m):
|
||||||
m.register_uri('GET', self.domain + 'servers/getVersion', json={"version": "2.4.50"})
|
m.register_uri('GET', self.domain + 'servers/getVersion', json={"version": pymisp.__version__[1:]})
|
||||||
m.register_uri('GET', self.domain + 'attributes/describeTypes.json', json=self.types)
|
m.register_uri('GET', self.domain + 'attributes/describeTypes.json', json=self.types)
|
||||||
m.register_uri('GET', self.domain + 'events/2', json=self.event)
|
m.register_uri('GET', self.domain + 'events/2', json=self.event)
|
||||||
|
m.register_uri('POST', self.domain + 'events/2', json=self.event)
|
||||||
|
m.register_uri('DELETE', self.domain + 'events/2', json={'message': 'Event deleted.'})
|
||||||
|
m.register_uri('DELETE', self.domain + 'events/3', json={'errors': ['Invalid event'], 'message': 'Invalid event', 'name': 'Invalid event', 'url': '/events/3'})
|
||||||
|
m.register_uri('DELETE', self.domain + 'attribute/2', json={'message': 'Attribute deleted.'})
|
||||||
|
|
||||||
def test_getEvent(self, m):
|
def test_getEvent(self, m):
|
||||||
self.initURI(m)
|
self.initURI(m)
|
||||||
pymisp = PyMISP(self.domain, self.key, debug=True)
|
pymisp = PyMISP(self.domain, self.key, debug=True)
|
||||||
e = pymisp.get_event(2)
|
e1 = pymisp.get_event(2)
|
||||||
print(e)
|
e2 = pymisp.get(2)
|
||||||
|
self.assertEqual(e1, e2)
|
||||||
|
self.assertEqual(self.event, e2)
|
||||||
|
|
||||||
|
def test_updateEvent(self, m):
|
||||||
|
self.initURI(m)
|
||||||
|
pymisp = PyMISP(self.domain, self.key, debug=True)
|
||||||
|
e0 = pymisp.update_event(2, json.dumps(self.event))
|
||||||
|
e1 = pymisp.update_event(2, self.event)
|
||||||
|
self.assertEqual(e0, e1)
|
||||||
|
e = {'Event': self.event}
|
||||||
|
e2 = pymisp.update(e)
|
||||||
|
self.assertEqual(e1, e2)
|
||||||
|
self.assertEqual(self.event, e2)
|
||||||
|
|
||||||
|
def test_deleteEvent(self, m):
|
||||||
|
self.initURI(m)
|
||||||
|
pymisp = PyMISP(self.domain, self.key, debug=True)
|
||||||
|
d = pymisp.delete_event(2)
|
||||||
|
self.assertEqual(d, {'message': 'Event deleted.'})
|
||||||
|
d = pymisp.delete_event(3)
|
||||||
|
self.assertEqual(d, {'errors': ['Invalid event'], 'message': 'Invalid event', 'name': 'Invalid event', 'url': '/events/3'})
|
||||||
|
|
||||||
|
def test_deleteAttribute(self, m):
|
||||||
|
# FIXME: https://github.com/MISP/MISP/issues/1449
|
||||||
|
self.initURI(m)
|
||||||
|
pymisp = PyMISP(self.domain, self.key, debug=True)
|
||||||
|
d = pymisp.delete_attribute(2)
|
||||||
|
self.assertEqual(d, {'message': 'Event deleted.'})
|
||||||
|
|
Loading…
Reference in New Issue