Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def setUp(self):
     self.store = HMACDecorator('my_secret_key', DictStore())
Ejemplo n.º 3
0
 def test_copy_raises_not_implemented(self, store):
     with pytest.raises(NotImplementedError):
         HMACDecorator(b'secret', store).copy(u'src', u'dest')
Ejemplo n.º 4
0
class TestHMACDictBackend(unittest.TestCase, SimpleKVTest):
    def setUp(self):
        self.store = HMACDecorator('my_secret_key', DictStore())

    def test_get_fails_on_manipulation(self):
        self.store.put('the_key', 'somevalue')

        self.store.d['the_key'] += 'a'
        with self.assertRaises(VerificationException):
            val = self.store.get('the_key')

    def test_get_file_fails_on_manipulation(self):
        k = 'the_key!'
        self.store.put(k, 'somevalue')

        self.store.d[k] += 'a'
        with tempfile.TemporaryFile() as tmp:
            with self.assertRaises(VerificationException):
                val = self.store.get_file(k, tmp)

        with tempfile.NamedTemporaryFile(delete=False) as tmp:
            try:
                with self.assertRaises(VerificationException):
                    val = self.store.get_file(k, tmp.name)
            finally:
                os.unlink(tmp.name)

    def test_open_fails_on_manipulation(self):
        k = 'the_key!'
        v = 'somevalue'
        self.store.put(k, v)

        self.store.d[k] += 'a'
        with self.assertRaises(VerificationException):
            val = self.store.open(k).read()

        handle = self.store.open(k)

        # we read 1 extra byte now, because the value is actually l onger
        handle.read(len(v) + 1)
        with self.assertRaises(VerificationException):
            handle.read(1)

    def test_get_fails_on_replay_manipulation(self):
        k = 'somekey'
        evil = 'evilkey'
        self.store.put(k, 'myvalue')

        self.store.d[evil] = self.store.d[k]

        self.store.get(k)

        with self.assertRaises(VerificationException):
            self.store.get(evil)
Ejemplo n.º 5
0
 def hmacstore(self, secret_key, store):
     return HMACDecorator(secret_key, store)