Example #1
0
    def __init__(self, mailhost, path):
        self.path = path
        self.mailhost = mailhost

        if not os.path.exists(path):
            os.mkdir(path)

        self.dbm = dirdbm.DirDBM(path)
Example #2
0
    def testRecovery(self):
        """DirDBM: test recovery from directory after a faked crash"""
        k = self.dbm._encode("key1")
        with open(os.path.join(self.path, k + ".rpl"), "wb") as f:
            f.write("value")

        k2 = self.dbm._encode("key2")
        with open(os.path.join(self.path, k2), "wb") as f:
            f.write("correct")
        with open(os.path.join(self.path, k2 + ".rpl"), "wb") as f:
            f.write("wrong")

        with open(os.path.join(self.path, "aa.new"), "wb") as f:
            f.write("deleted")

        dbm = dirdbm.DirDBM(self.path)
        assert dbm["key1"] == "value"
        assert dbm["key2"] == "correct"
        assert not glob.glob(os.path.join(self.path, "*.new"))
        assert not glob.glob(os.path.join(self.path, "*.rpl"))
Example #3
0
    def test_recovery(self):
        """
        DirDBM: test recovery from directory after a faked crash
        """
        k = self.dbm._encode(b"key1")
        with self.path.child(k + b".rpl").open(mode="wb") as f:
            f.write(b"value")

        k2 = self.dbm._encode(b"key2")
        with self.path.child(k2).open(mode="wb") as f:
            f.write(b"correct")
        with self.path.child(k2 + b".rpl").open(mode="wb") as f:
            f.write(b"wrong")

        with self.path.child("aa.new").open(mode="wb") as f:
            f.write(b"deleted")

        dbm = dirdbm.DirDBM(self.path.path)
        self.assertEqual(dbm[b"key1"], b"value")
        self.assertEqual(dbm[b"key2"], b"correct")
        self.assertFalse(self.path.globChildren("*.new"))
        self.assertFalse(self.path.globChildren("*.rpl"))
Example #4
0
 def __init__(self, args):
     self.args = args
     if len(self.args) != 1:
         raise ValueError, "Expected exactly one argument for the DB."
     self.path = args[0]
     self.db = dirdbm.DirDBM(self.path)
"""
Standalone userdb implementation for Katzenpost server.
"""
import json
from klein import run, route
from twisted.persisted import dirdbm

# Config ----------------------------------
PROVIDER = "idefix"
SERVER = "0.0.0.0"
PORT = 7900
DBPATH = "./userDB"
# -----------------------------------------

userdb = dirdbm.DirDBM(DBPATH)


def success(action):
    return json.dumps({action: True})


def failure(action, request, message="", code=401):
    request.setResponseCode(code)
    return json.dumps({action: False, 'message': message})


@route('/exists', methods=['POST'])
def exists(request):
    action = 'exists'
    print "ARGS", request.args
    try: