commit 6b6dd406123169404907e8d556d9ab3ad9af29fa Author: Arturo Filastò art@fuffa.org Date: Tue Aug 27 17:07:59 2013 +0200
More through e2e testing revealing some other bugs..
* Kill'em all.. --- oonib/deck/api.py | 2 +- oonib/deck/handlers.py | 15 +++++++-------- oonib/errors.py | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/oonib/deck/api.py b/oonib/deck/api.py index 6fbc7f4..ffccb0a 100644 --- a/oonib/deck/api.py +++ b/oonib/deck/api.py @@ -5,6 +5,6 @@ from oonib import config deckAPI = [ (r"/deck", handlers.DeckListHandler), (r"/deck/([a-z0-9]{64})$", handlers.DeckDescHandler), - (r"/deck/([a-z0-9]{64})/yaml$", web.StaticFileHandler, {"path": + (r"/deck/([a-z0-9]{64})/file$", web.StaticFileHandler, {"path": config.main.deck_dir}), ] diff --git a/oonib/deck/handlers.py b/oonib/deck/handlers.py index 558ca6a..c8aed69 100644 --- a/oonib/deck/handlers.py +++ b/oonib/deck/handlers.py @@ -4,6 +4,7 @@ import os import re import yaml
+from oonib import errors as e from oonib.handlers import OONIBHandler from oonib import config, log
@@ -12,7 +13,7 @@ class DeckDescHandler(OONIBHandler): # note: # we don't have to sanitize deckID, because it's already checked # against matching a certain pattern in the handler. - bn = os.path.basename(deckID) + bn = os.path.basename(deckID + '.desc') try: with open(os.path.join(config.main.deck_dir, bn)) as f: response = {} @@ -23,23 +24,21 @@ class DeckDescHandler(OONIBHandler):
except IOError: log.err("Deck %s missing" % deckID) - self.set_status(404) - self.write({'error': 'missing-deck'}) + raise e.MissingDeck
except KeyError: - self.set_status(400) log.err("Deck %s missing required keys!" % deckID) - self.write({'error': 'missing-deck-keys'}) + raise e.MissingDeckKeys
class DeckListHandler(OONIBHandler): def get(self): if not config.main.deck_dir: self.set_status(501) - self.write({'error': 'no-decks-configured'}) - return + raise e.NoDecksConfigured + path = os.path.abspath(config.main.deck_dir) + "/*" decknames = map(os.path.basename, glob.iglob(path)) - decknames = filter(lambda y: re.match("[a-z0-9]{40}", y), decknames) + decknames = filter(lambda y: re.match("[a-z0-9]{64}.desc", y), decknames) deckList = [] for deckname in decknames: with open(os.path.join(config.main.deck_dir, deckname)) as f: diff --git a/oonib/errors.py b/oonib/errors.py index 2385a6f..8d6015e 100644 --- a/oonib/errors.py +++ b/oonib/errors.py @@ -1,11 +1,14 @@ from cyclone.web import HTTPError
class OONIBError(HTTPError): + status_code = 500 + log_message = 'oonib-error' def __init__(self): pass
class InvalidRequest(OONIBError): - pass + status_code = 400 + log_message = 'invalid-request'
class NoHelperFound(OONIBError): status_code = 404 @@ -38,6 +41,18 @@ class MissingReportHeaderKey(OONIBError): self.status_code = 406 self.log_message = "missing-report-header-key %s" % key
+class MissingDeckKeys(OONIBError): + status_code = 400 + log_message = "missing-deck-keys" + +class MissingDeck(OONIBError): + status_code = 400 + log_message = "missing-deck" + +class NoDecksConfigured(OONIBError): + status_code = 501 + log_message = "no-decks-configured" + class InvalidReportHeader(OONIBError): def __init__(self, key): self.status_code = 406