def upgrade():
    from inbox.ignition import main_engine
    from inbox.models.session import session_scope
    from inbox.security.blobstorage import encode_blob

    engine = main_engine(pool_size=1, max_overflow=0)
    Base = declarative_base()
    Base.metadata.reflect(engine)

    class Message(Base):
        __table__ = Base.metadata.tables["message"]

    with session_scope(versioned=False) as db_session:
        (max_id, ) = db_session.query(sa.func.max(Message.id)).one()
        if max_id is None:
            max_id = 0
        for i in range(0, max_id, CHUNK_SIZE):
            messages = (db_session.query(Message).filter(
                Message.id > i, Message.id <= i + CHUNK_SIZE).options(
                    load_only("_compacted_body", "sanitized_body")))
            for message in messages:
                if message._compacted_body is None:
                    message._compacted_body = encode_blob(
                        message.sanitized_body.encode("utf-8"))
            db_session.commit()
Esempio n. 2
0
def test_encoded_format(config, sample_input, encrypt):
    config["ENCRYPT_SECRETS"] = encrypt
    encoded = encode_blob(sample_input)
    assert encoded.startswith((b"\x01" if encrypt else b"\x00") + b"\x00\x00\x00\x00")
    data = encoded[5:]
    if encrypt:
        assert data != sample_input
        assert data != zlib.compress(sample_input)
    else:
        assert data == zlib.compress(sample_input)
Esempio n. 3
0
def test_encoded_format(config, sample_input, encrypt):
    config['ENCRYPT_SECRETS'] = encrypt
    encoded = encode_blob(sample_input)
    assert encoded.startswith(chr(encrypt) + '\x00\x00\x00\x00')
    data = encoded[5:]
    if encrypt:
        assert data != sample_input
        assert data != zlib.compress(sample_input)
    else:
        assert data == zlib.compress(sample_input)
def upgrade():
    from inbox.ignition import main_engine
    from inbox.models.session import session_scope
    from inbox.security.blobstorage import encode_blob
    engine = main_engine(pool_size=1, max_overflow=0)
    Base = declarative_base()
    Base.metadata.reflect(engine)

    class Message(Base):
        __table__ = Base.metadata.tables['message']

    with session_scope(versioned=False) as db_session:
        max_id, = db_session.query(sa.func.max(Message.id)).one()
        if max_id is None:
            max_id = 0
        for i in range(0, max_id, CHUNK_SIZE):
            messages = db_session.query(Message). \
                filter(Message.id > i, Message.id <= i + CHUNK_SIZE). \
                options(load_only('_compacted_body', 'sanitized_body'))
            for message in messages:
                if message._compacted_body is None:
                    message._compacted_body = encode_blob(
                        message.sanitized_body.encode('utf-8'))
            db_session.commit()
Esempio n. 5
0
 def body(self, value):
     if value is None:
         self._compacted_body = None
     else:
         self._compacted_body = encode_blob(value.encode('utf-8'))
Esempio n. 6
0
 def body(self, value):
     if value is None:
         self._compacted_body = None
     else:
         self._compacted_body = encode_blob(value.encode('utf-8'))
Esempio n. 7
0
def test_blobstorage(config, sample_input, encrypt):
    config["ENCRYPT_SECRETS"] = encrypt
    assert decode_blob(encode_blob(sample_input)) == sample_input
Esempio n. 8
0
def test_blobstorage(config, sample_input, encrypt):
    config['ENCRYPT_SECRETS'] = encrypt
    assert decode_blob(encode_blob(sample_input)) == sample_input