[tor-commits] [ooni-probe/master] Start outlining the classes for policy handling
art at torproject.org
art at torproject.org
Tue Aug 27 09:21:51 UTC 2013
commit 3ddc95bd9841770dfe08cbf92265563cf17baf45
Author: Arturo Filastò <art at fuffa.org>
Date: Thu Aug 22 19:02:06 2013 +0200
Start outlining the classes for policy handling
---
.travis.yml | 1 -
ooni/nettest.py | 6 ++++++
ooni/oonibclient.py | 24 ++++++++++++++++++++++--
ooni/tests/test_oonibclient.py | 2 +-
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index fed5d7c..568f42d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,6 @@ before_install:
- sudo apt-get install tor libpcap-dev
python:
- "2.7"
- - "2.6"
# command to install dependencies
# the first is for testing pip and the second for setuptools
install:
diff --git a/ooni/nettest.py b/ooni/nettest.py
index b8cdf65..1699f19 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -1,6 +1,7 @@
import os
import re
import time
+from hashlib import sha256
from twisted.internet import defer, reactor
from twisted.trial.runner import filenameToModule
@@ -206,6 +207,11 @@ class NetTestLoader(object):
input_file['hash'] = m.group(2)
else:
input_file['filename'] = filename
+ with open(filename) as f:
+ h = sha256()
+ for l in f:
+ h.update(l)
+ input_file['hash'] = h.hexdigest()
input_files.append(input_file)
return input_files
diff --git a/ooni/oonibclient.py b/ooni/oonibclient.py
index 9d2085b..5861ff4 100644
--- a/ooni/oonibclient.py
+++ b/ooni/oonibclient.py
@@ -50,7 +50,7 @@ class InputFile(object):
'date': self.date,
'description': self.description
}, f)
-
+
def load(self, descriptor):
self.name = descriptor['name']
self.version = descriptor['version']
@@ -64,6 +64,23 @@ class InputFile(object):
file_hash = sha256(f.read())
assert file_hash.hexdigest() == digest
+ def validate(self, policy):
+ """
+ Validate this input file against the specified input policy.
+ """
+ for input_file
+
+class Collector(object):
+ def __init__(self):
+ self.nettest_policy = None
+ self.input_policy = None
+
+ def validateInput(self, input_hash):
+ pass
+
+ def validateNettest(self, nettest):
+ pass
+
class OONIBClient(object):
def __init__(self, address):
self.address = address
@@ -155,4 +172,7 @@ class OONIBClient(object):
return d
def getInputPolicy(self):
- pass
+ return self.queryBackend('GET', '/policy/input')
+
+ def getNettestPolicy(self):
+ return self.queryBackend('GET', '/policy/nettest')
diff --git a/ooni/tests/test_oonibclient.py b/ooni/tests/test_oonibclient.py
index 47a3d47..c039c65 100644
--- a/ooni/tests/test_oonibclient.py
+++ b/ooni/tests/test_oonibclient.py
@@ -17,7 +17,7 @@ class TestOONIBClient(unittest.TestCase):
s.shutdown(2)
except Exception as ex:
self.skipTest("OONIB must be listening on port 8888 to run this test (tor_hidden_service: false)")
- self.oonibclient = OONIBClient('http://'+host+':'+str(port))
+ self.oonibclient = OONIBClient('http://' + host + ':' + str(port))
@defer.inlineCallbacks
def test_query(self):
More information about the tor-commits
mailing list