Beispiel #1
0
class TestHashGen(unittest.TestCase, SimpleKVTest):
    def setUp(self):
        self.store = HashDecorator(DictStore())
        self.hash_regexp = r'^[0-9a-f]{%d}$' % (
            self.store.hashfunc().digest_size * 2,
        )

    def test_put_generates_valid_form(self):
        key = self.store.put(None, 'some_data')
        self.assertRegexpMatches(key, self.hash_regexp)

    def test_put_file_generates_valid_form(self):
        key = self.store.put_file(None, open('/dev/null', 'rb'))
        self.assertRegexpMatches(key, self.hash_regexp)

        key2 = self.store.put_file(None, '/dev/null')
        self.assertRegexpMatches(key2, self.hash_regexp)

    def test_put_generates_correct_hash(self):
        data = 'abcdXefg'
        key = self.store.put(None, data)

        hash = self.store.hashfunc(data).hexdigest()

        self.assertEqual(hash, key)

    def test_put_file_generates_correct_hash(self):
        data = '!bcdXefQ'
        hash = self.store.hashfunc(data).hexdigest()
        tmpfile = tempfile.NamedTemporaryFile(delete=False)
        try:
            tmpfile.write(data)
            tmpfile.close()
            with open(tmpfile.name, 'rb') as f:
                key = self.store.put_file(None, f)
            self.assertEqual(key, hash)

            key2 = self.store.put_file(None, tmpfile.name)
            self.assertEqual(key2, hash)
        finally:
            if os.path.exists:
                os.unlink(tmpfile.name)

    def test_put_hashfunc_is_sha1(self):
        data = 'some_test_string'
        hash = '7a3ae7e083965679a6965e4a4d89c5f0d6a1f7e4'

        self.assertEqual(self.store.put(None, data), hash)
Beispiel #2
0
 def dstore(self, request, store, secret_key):
     if request.param == 'hash':
         return HashDecorator(store)
     elif request.param == 'uuid':
         return self.ustore(store)
     elif request.param == 'hmac':
         return HMACDecorator(secret_key, store)
     elif request.param == 'prefix':
         return PrefixDecorator('SaMpLe_PrEfIX', store)
Beispiel #3
0
class TestHashGen(unittest.TestCase, SimpleKVTest):
    def setUp(self):
        self.store = HashDecorator(DictStore())
        self.hash_regexp = r'^[0-9a-f]{%d}$' % (
            self.store.hashfunc().digest_size * 2, )

    def test_put_generates_valid_form(self):
        key = self.store.put(None, 'some_data')
        self.assertRegexpMatches(key, self.hash_regexp)

    def test_put_file_generates_valid_form(self):
        key = self.store.put_file(None, open('/dev/null', 'rb'))
        self.assertRegexpMatches(key, self.hash_regexp)

        # this is not correct according to our interface
        # /dev/null cannot be claimed by the store
        # key2 = self.store.put_file(None, '/dev/null')
        # self.assertRegexpMatches(key2, self.hash_regexp)

    def test_put_generates_correct_hash(self):
        data = 'abcdXefg'
        key = self.store.put(None, data)

        hash = self.store.hashfunc(data).hexdigest()

        self.assertEqual(hash, key)

    def test_put_file_generates_correct_hash(self):
        data = '!bcdXefQ'
        hash = self.store.hashfunc(data).hexdigest()
        tmpfile = tempfile.NamedTemporaryFile(delete=False)
        try:
            tmpfile.write(data)
            tmpfile.close()
            with open(tmpfile.name, 'rb') as f:
                key = self.store.put_file(None, f)
            self.assertEqual(key, hash)

            key2 = self.store.put_file(None, tmpfile.name)
            self.assertEqual(key2, hash)
        finally:
            if os.path.exists(tmpfile.name):
                os.unlink(tmpfile.name)

    def test_put_hashfunc_is_sha1(self):
        data = 'some_test_string'
        hash = '7a3ae7e083965679a6965e4a4d89c5f0d6a1f7e4'

        self.assertEqual(self.store.put(None, data), hash)
Beispiel #4
0
class TestHashGen(unittest.TestCase, SimpleKVTest):
    def setUp(self):
        self.store = HashDecorator(DictStore())
        self.hash_regexp = r"^[0-9a-f]{%d}$" % (self.store.hashfunc().digest_size * 2,)

    def test_put_generates_valid_form(self):
        key = self.store.put(None, "some_data")
        self.assertRegexpMatches(key, self.hash_regexp)

    def test_put_file_generates_valid_form(self):
        key = self.store.put_file(None, open("/dev/null", "rb"))
        self.assertRegexpMatches(key, self.hash_regexp)

        # this is not correct according to our interface
        # /dev/null cannot be claimed by the store
        # key2 = self.store.put_file(None, '/dev/null')
        # self.assertRegexpMatches(key2, self.hash_regexp)

    def test_put_generates_correct_hash(self):
        data = "abcdXefg"
        key = self.store.put(None, data)

        hash = self.store.hashfunc(data).hexdigest()

        self.assertEqual(hash, key)

    def test_put_file_generates_correct_hash(self):
        data = "!bcdXefQ"
        hash = self.store.hashfunc(data).hexdigest()
        tmpfile = tempfile.NamedTemporaryFile(delete=False)
        try:
            tmpfile.write(data)
            tmpfile.close()
            with open(tmpfile.name, "rb") as f:
                key = self.store.put_file(None, f)
            self.assertEqual(key, hash)

            key2 = self.store.put_file(None, tmpfile.name)
            self.assertEqual(key2, hash)
        finally:
            if os.path.exists(tmpfile.name):
                os.unlink(tmpfile.name)

    def test_put_hashfunc_is_sha1(self):
        data = "some_test_string"
        hash = "7a3ae7e083965679a6965e4a4d89c5f0d6a1f7e4"

        self.assertEqual(self.store.put(None, data), hash)
Beispiel #5
0
 def setUp(self):
     self.store = HashDecorator(DictStore())
     self.hash_regexp = r'^[0-9a-f]{%d}$' % (
         self.store.hashfunc().digest_size * 2,
     )
Beispiel #6
0
from flask_app.middleware import *
from flask_app.middleware.csrf import CSRFProtectionExtension

load_dotenv()
# get environment variables
configure_logging()
# configure loggers before starting app

app = Flask(__name__)
app.config.update(**config)

# Configure Session using standard web session files,
# more store types available in simplekv package
# Hash Decorator provides session id
session_store = HashDecorator(
    WebFilesystemStore(os.getenv("FLASK_SESSION_FILE_PATH"),
                       os.getenv("FLASK_SESSION_URL_PREFIX")))
KVSessionExtension(session_store, app)

# Add CSRFProtect extension to flask app
# NOTE: this extends flask_wtf.CSRFProtect class; see class definition for details
CSRFProtectionExtension(app)

# Create Api blueprint and add resources (routes)
api_blueprint = Blueprint('api', __name__)
api = ElectroAPI(api_blueprint, catch_all_404s=True)
# contains custom error handler
api.add_resource(BillResource, "/bills", "/bills/<int:id>", endpoint="bill")
api.add_resource(UserResource, "/login", "/logout", endpoint="login")

# Register blueprint to app
Beispiel #7
0
 def templated_hashstore(self, store, hashfunc, idgen_template):
     return HashDecorator(store, hashfunc, idgen_template)
Beispiel #8
0
 def hashstore(self, store, hashfunc):
     return HashDecorator(store, hashfunc)
Beispiel #9
0
 def setUp(self):
     self.store = HashDecorator(DictStore())
     self.hash_regexp = r'^[0-9a-f]{%d}$' % (
         self.store.hashfunc().digest_size * 2, )
Beispiel #10
0
 def setUp(self):
     TestHashGen.setUp(self)
     self.tmpdir = tempfile.mkdtemp()
     self.store = HashDecorator(FilesystemStore(self.tmpdir))