forked from ooni/probe
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some documentation on writing OONI Tests using
the new framework.
- Loading branch information
Showing
7 changed files
with
174 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,50 @@ | ||
.. OONI documentation master file. | ||
========== | ||
About OONI | ||
========== | ||
Welcome to the OONI documentation! | ||
================================== | ||
|
||
The Net interprets censorship as damage and routes around it. | ||
John Gilmore; TIME magazine (6 December 1993) | ||
|
||
Dependencies | ||
************ | ||
OONI, the Open Observatory of Network Interference, is a global observation | ||
network which aims is to collect high quality data using open methodologies, | ||
using Free and Open Source Software (FL/OSS) to share observations and data | ||
about the various types, methods, and amounts of network tampering in the world. | ||
|
||
* Twisted: http://twistedmatrix.com/trac/ | ||
* PyYAML: http://pyyaml.org/ | ||
* Scapy: http://www.secdev.org/projects/scapy/ | ||
* pypcap: http://code.google.com/p/pypcap/ | ||
* libdnet: http://code.google.com/p/libdnet/ | ||
|
||
*Optional* | ||
Getting started | ||
*************** | ||
|
||
* BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/ | ||
If you choose to use virtualenv to setup your development environment you will | ||
need to do the following:: | ||
|
||
Installation | ||
************ | ||
virtualenv ENV | ||
source ENV/bin/activate | ||
pip install twisted Scapy pyyaml | ||
|
||
On debian you can install all the dependecies with apt-get with this command: | ||
To get the latest version of scapy you will need mercurial. You can then install | ||
it with:: | ||
|
||
apt-get install python-twisted python-twisted-names python-yaml python-scapy python-beautifulsoup | ||
|
||
*The "hard" way* | ||
|
||
This involves installing the dependencies installable via easy_install/pip and | ||
the ones that are not by building them from source. | ||
|
||
"simple" dependencies via easy_install: | ||
|
||
sudo easy_install pyyaml | ||
sudo easy_install twisted | ||
sudo easy_install beautifulsoup | ||
|
||
"simple" dependencies via pip: | ||
|
||
sudo pip install pyyaml | ||
sudo pip install twisted | ||
sudo pip install beautifulsoup | ||
pip install hg+http://hg.secdev.org/scapy | ||
|
||
libdnet: | ||
On debian you can install all the dependecies with apt-get with this command:: | ||
|
||
wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz | ||
tar xzf libdnet-1.12.tgz | ||
cd libdnet-1.12 | ||
./configure && make | ||
cd python/ | ||
sudo python setup.py install | ||
cd ../../ && rm -rf libdnet-1.12* | ||
|
||
pypcap: | ||
|
||
svn checkout http://pypcap.googlecode.com/svn/trunk/ pypcap-read-only | ||
cd pypcap-read-only/ | ||
sudo pip install pyrex | ||
make | ||
sudo python setup.py install | ||
cd ../ && rm -rf pypcap-read-only | ||
|
||
scapy: | ||
|
||
wget http://www.secdev.org/projects/scapy/files/scapy-latest.zip | ||
unzip scapy-latest.zip | ||
cd scapy-2.2.0/ | ||
sudo python setup.py install | ||
cd ../ && rm -rf scapy-* | ||
|
||
Running | ||
******* | ||
apt-get install python-twisted python-twisted-names python-yaml python-scapy python-beautifulsoup | ||
|
||
To run ooni probe do | ||
Once you have installed all the dependencies OONI tests can be run like so:: | ||
|
||
$ export PYTHONPATH=`pwd` | ||
bin/ooniprobe path/to/test.py --cmd1 foo --cmd2 bar | ||
|
||
$ python ooni/ooniprobe.py | ||
|
||
Contents | ||
******** | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:maxdepth: 2 | ||
:glob: | ||
|
||
intro | ||
install | ||
tutorial | ||
writing_tests | ||
... | ||
|
||
Indices and tables | ||
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`modindex` | ||
* :ref:`search` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
Installing OONI | ||
=============== | ||
|
||
Currently no installation documentation is present, since OONI is not meant to | ||
be installed and should be handled with care. | ||
|
||
Dependencies | ||
************ | ||
|
||
OONI depends on the following pieces of software. | ||
|
||
* Twisted: http://twistedmatrix.com/trac/ | ||
* PyYAML: http://pyyaml.org/ | ||
* Scapy: http://www.secdev.org/projects/scapy/ | ||
* pypcap: http://code.google.com/p/pypcap/ | ||
* libdnet: http://code.google.com/p/libdnet/ | ||
|
||
*Optional* | ||
|
||
* BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/ | ||
|
||
Manual installation of scapy | ||
---------------------------- | ||
|
||
It is optimal to install scapy, libdnet and pypcap from source. This can be | ||
done with the following code snippets. | ||
|
||
libdnet:: | ||
|
||
wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz | ||
tar xzf libdnet-1.12.tgz | ||
cd libdnet-1.12 | ||
./configure && make | ||
cd python/ | ||
sudo python setup.py install | ||
cd ../../ && rm -rf libdnet-1.12* | ||
|
||
pypcap:: | ||
|
||
svn checkout http://pypcap.googlecode.com/svn/trunk/ pypcap-read-only | ||
cd pypcap-read-only/ | ||
sudo pip install pyrex | ||
make | ||
sudo python setup.py install | ||
cd ../ && rm -rf pypcap-read-only | ||
|
||
scapy:: | ||
|
||
wget http://www.secdev.org/projects/scapy/files/scapy-latest.zip | ||
unzip scapy-latest.zip | ||
cd scapy-2.2.0/ | ||
sudo python setup.py install | ||
cd ../ && rm -rf scapy-* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
======== | ||
Tutorial | ||
======== | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,76 @@ | ||
.. OONI documentation master file. | ||
================== | ||
Writing OONI tests | ||
================== | ||
|
||
OONIProbe tests can be written in two modes: blocking or non-blocking. | ||
|
||
Going the blocking route is not advised and all tests in the end should end up | ||
being written in the non-blocking way. | ||
The OONI testing API is heavily influenced and partially based on the python | ||
:class:`unittest` module and :class:`twsted.trial`. | ||
|
||
|
||
Test Cases | ||
---------- | ||
|
||
The atom of OONI Testing is called a Test Case. A test case class may contain | ||
multiple Test Functions. | ||
|
||
.. autoclass:: ooni.nettest.TestCase | ||
|
||
:class:`ooni.nettest.TestCase` is a subclass of :class:`unittest.TestCase` so | ||
the assert methods that apply to :class:`unittest.TestCase` will also apply to | ||
:class:`ooni.nettest.TestCase`. | ||
|
||
If the test you plan to write is not listed on the `Tor OONI trac page | ||
<https://trac.torproject.org/projects/tor/wiki/doc/OONI/Tests>`_, you should | ||
add it to the list and following the `test template | ||
<https://trac.torproject.org/projects/tor/wiki/doc/OONI/Tests/TestTemplate>`_ | ||
write up a description about it. | ||
|
||
|
||
Inputs | ||
------ | ||
|
||
Inputs are what is given as input to every iteration of the Test Case. You have | ||
100 inputs, then every test case will be run 100 times. | ||
|
||
To configure a static set of inputs you should define the | ||
:class:`ooni.nettest.TestCase` attribute ``inputs``. The test will be run ``len(inputs)`` times. Any iterable object is a valid ``inputs`` attribute. | ||
|
||
If you would like to have inputs be determined from a user specified input | ||
file, then you must set the ``inputFile`` attribute. This is an array that | ||
specifies what command line option may be used to control this value. | ||
|
||
By default the ``inputProcessor`` is set to read the file line by line and | ||
strip newline characters. To change this behavior you must set the | ||
``inputProcessor`` attribute to a function that takes as arugment a file | ||
descriptor and yield the next item. The default ``inputProcessor`` looks like | ||
this:: | ||
|
||
|
||
def lineByLine(fp): | ||
for x in fp.readlines(): | ||
yield x.strip() | ||
fp.close() | ||
|
||
|
||
Test Functions | ||
-------------- | ||
|
||
These shall be defined inside of your :class:`ooni.nettest.TestCase` subclass. | ||
These will be class methods. | ||
|
||
A good way to understand how to write a test is also to take a look at the OONI | ||
Test Interface in the following files: | ||
To add data to the test report you may write directly to the report object like | ||
so:: | ||
|
||
* ooni/plugoo/interface.py | ||
def my_test_function(): | ||
result = do_something() | ||
self.report['something'] = result | ||
|
||
* ooni/plugoo/tests.py | ||
OONI will then handle the writing of the data to the final test report. | ||
|
||
Writing non-blocking tests | ||
-------------------------- | ||
To access the current input you can use the ``input`` attribute, for example:: | ||
|
||
To bootstrap the process of creating a new tests you can run the scaffolding | ||
script in ooni/scaffolding.py. | ||
def my_test_with_input(): | ||
do_something_with_input(self.input) | ||
|
||
This will create a new plugin with the specified name inside of ooni/plugins/. | ||
This will at each iteration over the list of inputs do something with the | ||
input. | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters