Esempio n. 1
0
    def test_get_into_stream(self, store, key, value):
        store.put(key, value)

        output = BytesIO()

        store.get_file(key, output)
        assert output.getvalue() == value
Esempio n. 2
0
    def test_get_into_stream(self, store, key, value):
        store.put(key, value)

        output = BytesIO()

        store.get_file(key, output)
        assert output.getvalue() == value
Esempio n. 3
0
    def test_put_file_set_default(self, store, key, value, small_ttl):
        store.default_ttl_secs = small_ttl

        store.put_file(key, BytesIO(value))

        time.sleep(small_ttl + TTL_MARGIN)
        with pytest.raises(KeyError):
            store.get(key)
Esempio n. 4
0
    def test_manipulated_input_full_read(self, secret_key, value, bad_datas,
                                         hashfunc):
        for bad_data in bad_datas:
            reader = _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                                     BytesIO(bad_data))

            with pytest.raises(VerificationException):
                reader.read()
Esempio n. 5
0
    def test_storage_class_putfile(self, store, prefix, key, value,
                                   storage_class, bucket):
        store.put_file(key, BytesIO(value))

        keyname = prefix + key

        if storage_class != 'STANDARD':
            pytest.xfail('boto does not support checking the storage class?')
        assert bucket.lookup(keyname).storage_class == storage_class
Esempio n. 6
0
    def test_manipulated_input_incremental_read(self, secret_key, bad_datas,
                                                hashfunc):
        for bad_data in bad_datas:
            reader = _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                                     BytesIO(bad_data))

            with pytest.raises(VerificationException):
                bitesize = 100
                while True:
                    if len(reader.read(bitesize)) != bitesize:
                        break
Esempio n. 7
0
    def test_file_permission_on_new_file_have_correct_value(
            self, store, perms, value):
        src = BytesIO(value)

        key = store.put_file(u'test123', src)

        parts = urlparse(store.url_for(key))
        path = parts.path

        mode = os.stat(path).st_mode
        mask = (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

        assert mode & mask == perms
Esempio n. 8
0
    def test_put_file_sets_prefix(self, store, prefix, key, value):
        full_key = prefix + key
        key == store.put_file(key, BytesIO(value))

        assert store._dstore.get(full_key) == value
Esempio n. 9
0
 def test_put_file_return_value(self, store, key, value):
     assert key == store.put_file(key, BytesIO(value))
Esempio n. 10
0
 def test_open_incremental_read(self, store, key, long_value):
     store.put_file(key, BytesIO(long_value))
     ok = store.open(key)
     assert long_value[:3] == ok.read(3)
     assert long_value[3:5] == ok.read(2)
     assert long_value[5:8] == ok.read(3)
Esempio n. 11
0
 def test_key_error_on_nonexistant_get_file(self, store, key):
     with pytest.raises(KeyError):
         store.get_file(key, BytesIO())
Esempio n. 12
0
 def test_put_file_obj(self, key, value, hmacstore):
     hmacstore.put_file(key, BytesIO(value))
     assert hmacstore.get(key) == value
Esempio n. 13
0
 def test_store_and_open(self, store, key, value):
     store.put_file(key, BytesIO(value))
     assert store.open(key).read() == value
Esempio n. 14
0
    def test_store_and_retrieve_overwrite(self, store, key, value, value2):
        store.put_file(key, BytesIO(value))
        assert store.get(key) == value

        store.put(key, value2)
        assert store.get(key) == value2
Esempio n. 15
0
    def test_put_file_with_ttl_argument(self, store, key, value, small_ttl):
        store.put_file(key, BytesIO(value), small_ttl)

        time.sleep(small_ttl + TTL_MARGIN)
        with pytest.raises(KeyError):
            store.get(key)
Esempio n. 16
0
 def test_store_and_retrieve_filelike(self, store, key, value):
     store.put_file(key, BytesIO(value))
     assert store.get(key) == value
Esempio n. 17
0
 def test_put_file_returns_correct_key(self, store, prefix, key, value):
     assert key == store.put_file(key, BytesIO(value))
Esempio n. 18
0
 def test_get_file_obj(self, key, value, hmacstore):
     hmacstore.put(key, value)
     b = BytesIO()
     hmacstore.get_file(key, b)
     assert b.getvalue() == value
Esempio n. 19
0
 def test_input_too_short(self, secret_key, hashfunc):
     with pytest.raises(VerificationException):
         _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                         BytesIO(b('a')))
Esempio n. 20
0
 def create_reader(self, stored_blob, secret_key, hashfunc):
     return lambda: _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                                    BytesIO(stored_blob))