Ejemplo n.º 1
0
 def test_problematic_paths(self):
     for path in PROBLEMATIC_PATHS:
         encrypted_path = encrypt_path(path, self.key)
         decrypted_path = decrypt_path(encrypted_path, self.key)
         self.assertEqual(path, decrypted_path,
                          "Decrypted path %s not equal to original path %s, encrypted version =%s, key=%s" %
                          (decrypted_path, path, encrypted_path, self.key))
Ejemplo n.º 2
0
 def test_walk(self):
     bp = unicode(BASE_PATH)
     for root, dirnames, filenames in os.walk(bp):
         for filename in filenames:
             fpath = os.path.join(unicode(root), unicode(filename))
             #print "Path = %s" % fpath.encode("utf-8")
             encrypted_path = encrypt_path(fpath, self.key)
             decrypted_path = decrypt_path(encrypted_path, self.key)
             self.assertEqual(fpath, decrypted_path,
                              "Decrypted path %s not equal to original path %s, encrypted version =%s, key=%s" %
                              (decrypted_path, fpath, encrypted_path, self.key))
Ejemplo n.º 3
0
def app(environ, start_response):
  path = None
  try:
    qs = environ.get("QUERY_STRING")
    qdict = urlparse.parse_qs(qs)
    enc_path = qdict["key"][0]
    path = decrypt_path(enc_path, deskey)
    logger.debug("Decrypted path " + path)
    size = os.path.getsize(path)
  except KeyError, e:
    log_exc("Invalid request(KeyError): %s, query string was '%s'" %
            (e, qs))
    start_response('404 Page Not Found', error_headers, sys.exc_info())
    return ["Invalid request"]
Ejemplo n.º 4
0
 def test_url_handling(self):
     bp = unicode(BASE_PATH)
     for root, dirnames, filenames in os.walk(bp):
         for filename in filenames:
             fpath = os.path.join(unicode(root), unicode(filename))
             url = BlockUtils.generate_url_for_path(fpath, key_for_testing=self.key)
             p = urlparse.urlparse(url)
             query_dict = urlparse.parse_qs(p.query)
             expected_len = long(query_dict["len"][0])
             encrypted_path = query_dict["key"][0]
             decrypted_path = decrypt_path(encrypted_path, self.key)
             self.assertEqual(fpath, decrypted_path,
                              "Decrypted path %s not equal to original path %s, url='%s'" %
                              (decrypted_path, encrypted_path, url))