Exemple #1
0
def test_main(mock_getpass, mock_input):
    """Test adding a note."""
    password = '******'
    mock_getpass.side_effect = [
        password,
        Exception('called too many times'),
    ]
    mock_input.side_effect = [
        'note',
        'This is a test note',
        Exception('called too many times'),
    ]

    with tempfile.NamedTemporaryFile() as file_:
        entry = {
            "category": "note",
            "timestamp": "2014-12-01T02:43:04.384669",
            "message": "This is a test.",
            "installation": "b8f2e978-f638-492a-022f-abce33fc8203",
            "id": "97c6683d-ff1f-4791-a313-6d4588fa5aaa",
        }
        length = file_.tell()
        opts = AttrDict()
        encrypt_json(get_secret_key(opts, password=password), entry, file_)
        assert length < file_.tell()
        length = file_.tell()
        main(argv=['--log={}'.format(file_.name)])
        file_.seek(0, 2)
        assert length < file_.tell()
Exemple #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)
Exemple #3
0
def _do_encrpyt_all(opts):
    """Do encrpyt all."""
    get_secret_key(opts)
    new_secret_key = get_secret_key(AttrDict(),
                                    prompt='Enter a new password: '******'Repeat your new password: '******'\r\n')
    out.seek(0)

    with open(opts.logit_filename, 'w') as f:
        f.write(out.read())
Exemple #4
0
def logit(opts, entry, timestamp):
    try:
        entry['timestamp'] = timestamp.isoformat()
        entry['id'] = str(uuid.uuid4())
        entry['installation'] = get_install_id()

        assert 'category' in entry
        entry['message'] = entry.get('message') or get_console_input('Notes: ')

        if entry.get('message'):
            with open(opts.logit_filename, 'a') as f:
                secret_key = get_secret_key(opts)
                encrypt_json(secret_key, entry, f)
                f.write('\r\n')
        else:
            print 'No logit entry entered.'
    finally:
        gc.collect()
Exemple #5
0
def test_get_secret_key():
    """Test get secret key."""
    opts = AttrDict()
    get_secret_key(opts, password='******')
    assert opts.secret_key is not None