コード例 #1
0
ファイル: test_logit.py プロジェクト: wbbradley/logit
def test_encrypt_decrypt_json_failure():
    """Test encrypt decrypt json."""
    stream = cStringIO.StringIO()
    secret_key = b'\xd3\x81by(!]\xbdU0\xd0\xe2\xa0\xd6j\xcc\xca\x92\x0e\x8c\xd7\xb5~D/1\xdc4\xbd\xb2w\x06'  # noqa
    blob_data = {'test': 'data', '1': 2}
    encrypt_json(secret_key, blob_data, stream)
    stream.seek(0)
    encrypted = stream.read()
    assert len(encrypted) > 0
    bad_secret_key = b'\xe3\x81by(!]\xbdU0\xd0\xe2\xa0\xd6j\xcc\xca\x92\x0e\x8c\xd7\xb5~D/1\xdc4\xbd\xb2w\x06'  # noqa

    try:
        decrypt_json(bad_secret_key, encrypted)
    except ValueError:
        pass
    else:
        assert False
コード例 #2
0
def _generate_entries_from_file(opts, file_, filename):
    """Generate all the entries from the local logit file"""
    for line, entry in enumerate(file_, start=1):
        if entry[0] != '{':
            yield decrypt_json(get_secret_key(opts), entry)
        else:
            try:
                yield json.loads(entry)
            except ValueError:
                logger.exception('error on line %d of %s', line, filename)
コード例 #3
0
ファイル: test_logit.py プロジェクト: wbbradley/logit
def test_encrypt_decrypt_json():
    """Test encrypt decrypt json."""
    stream = cStringIO.StringIO()
    secret_key = b'\xd3\x81by(!]\xbdU0\xd0\xe2\xa0\xd6j\xcc\xca\x92\x0e\x8c\xd7\xb5~D/1\xdc4\xbd\xb2w\x06'  # noqa
    blob_data = {'test': 'data', '1': 2}
    encrypt_json(secret_key, blob_data, stream)
    stream.seek(0)
    encrypted = stream.read()
    assert len(encrypted) > 0

    decrypted_blob = decrypt_json(secret_key, encrypted)
    assert decrypted_blob == blob_data