def test_fetch_entries_empty_database(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "empty.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    backend.sync_entries()
    assert len(backend.entries.items) == 0
def test_get_config(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "test_get_config.kdbx")
    backend = Backend(test_database, "abcd123")

    # existing associated client
    assert backend.get_config("test_name") == "test_key"

    # unknown client
    assert backend.get_config("test_unknown") is None
def test_root_node_has_a_different_name_than_root(tmpdir):
    """
    Ensure that we can handle the root node which has a different name than "Root"

    """
    test_database = _move_test_file_to_tmpdir(tmpdir, "root_has_a_different_name.kdbx")

    backend = Backend(test_database)
    backend.open_database("1234")

    backend.create_config_key("test_name", "test_key")
    assert len(backend.entries.items) == 1
def test_create_config(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "test_create_config.kdbx")

    backend = Backend(test_database, "abcd123")
    backend.sync_entries()
    assert len(backend.entries.items) == 0

    backend.create_config_key("test_name", "test_key")
    assert len(backend.entries.items) == 1
    assert backend.entries.items.pop() == EntrySpec(login="",
                                                    url='',
                                                    password='******',
                                                    title='test_name',
                                                    uuid="")
def test_unicode_characters_correctly_read(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "test_unicode_handling.kdbx")

    backend = Backend(test_database, "abcd123")
    backend.sync_entries()

    the_login = u'blaf\xf1oo'
    the_url = u'http://www.unicodeinurl\xf1.com'
    # keepassx currently doesn't support unicode in password field -
    # https://www.keepassx.org/dev/issues/158
    the_password = '******'
    the_title = u'Unicode fu\xf1'
    the_uuid = ''

    backend.entries.items[0].uuid = ''

    assert backend.entries.items[0] == EntrySpec(login=the_login,
                                                 url=the_url,
                                                 password=the_password,
                                                 title=the_title,
                                                 uuid=the_uuid)
Esempio n. 6
0
def test_fetch_entries_empty_database(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "empty.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    backend.sync_entries()
    assert len(backend.entries.items) == 0
Esempio n. 7
0
def test_create_config(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir,
                                              "test_create_config.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    backend.sync_entries()
    assert len(backend.entries.items) == 0

    backend.create_config_key("test_name", "test_key")
    assert len(backend.entries.items) == 1
    assert backend.entries.items.pop() == EntrySpec(login="",
                                                    url='',
                                                    password='******',
                                                    title='test_name',
                                                    uuid="")
Esempio n. 8
0
def test_get_config(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "test_get_config.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    # existing associated client
    assert backend.get_key_for_client("test_name") == "test_key"

    # unknown client
    assert backend.get_key_for_client("test_unknown") is None
Esempio n. 9
0
def test_get_search_entries(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir,
                                              "test_search_for_entries.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    backend.sync_entries()
    assert len(backend.entries.items) == 5

    # FIXME: remove config for client!
    # first one is the client config (key)
    del backend.entries.items[0]

    results = backend.search_entries("url", "https://www.google.com/login")
    assert len(results) == 1

    results = backend.search_entries("url", "https://gmx.net/login")
    assert len(results) == 2

    results = backend.search_entries("url", "http://web.de/login/form.php")
    assert len(results) == 1
Esempio n. 10
0
def test_root_node_has_a_different_name_than_root(tmpdir):
    """
    Ensure that we can handle the root node which has a different name than "Root"

    """
    test_database = _move_test_file_to_tmpdir(
        tmpdir, "root_has_a_different_name.kdbx")

    backend = Backend(test_database)
    backend.open_database("1234")

    backend.create_config_key("test_name", "test_key")
    assert len(backend.entries.items) == 1
def test_get_search_entries(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "test_search_for_entries.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    backend.sync_entries()
    assert len(backend.entries.items) == 5

    # FIXME: remove config for client!
    # first one is the client config (key)
    del backend.entries.items[0]

    results = backend.search_entries("url", "https://www.google.com/login")
    assert len(results) == 1

    results = backend.search_entries("url", "https://gmx.net/login")
    assert len(results) == 2

    results = backend.search_entries("url", "http://web.de/login/form.php")
    assert len(results) == 1
Esempio n. 12
0
def test_unicode_characters_correctly_read(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir,
                                              "test_unicode_handling.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    backend.sync_entries()

    the_login = u'blaf\xf1oo'
    the_url = u'http://www.unicodeinurl\xf1.com'
    # keepassx currently doesn't support unicode in password field -
    # https://www.keepassx.org/dev/issues/158
    the_password = '******'
    the_title = u'Unicode fu\xf1'
    the_uuid = ''

    backend.entries.items[0].uuid = ''

    assert backend.entries.items[0] == EntrySpec(login=the_login,
                                                 url=the_url,
                                                 password=the_password,
                                                 title=the_title,
                                                 uuid=the_uuid)
def test_create_login(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "test_create_login.kdbx")

    test_databse_passphrase = "abcd123"

    x = Backend(test_database, test_databse_passphrase)

    x.sync_entries()
    assert len(x.entries.items) == 1
    # valid logins
    x.create_login("test_name", "*****@*****.**", "geheim", u"https://www.google.com/login")
    # 2 accounts, same domain
    x.create_login("test_name", "*****@*****.**", "geheim2", u"https://gmx.net/login")
    x.create_login("test_name", "*****@*****.**", "geheim3", u"https://gmx.net/login")
    # another login
    x.create_login("test_name", "*****@*****.**", "geheim4", u"http://web.de/login/form.php")
    # x.get_entries(purge_cache=True)

    assert len(x.entries.items) == 5

    # FIXME: remove config for client!
    del x.entries.items[0]
    # first one is the client config (key)
    #
    assert x.entries.items[0] == EntrySpec(login="******",
                                           url='https://www.google.com/login',
                                           password='******',
                                           title=u"www.google.com",
                                           uuid="")
    assert x.entries.items[1] == EntrySpec(login="******",
                                           url='https://gmx.net/login',
                                           password='******',
                                           title=u"gmx.net",
                                           uuid="")
    assert x.entries.items[2] == EntrySpec(login="******",
                                           url='https://gmx.net/login',
                                           password='******',
                                           title=u"gmx.net",
                                           uuid="")
    assert x.entries.items[3] == EntrySpec(login="******",
                                           url='http://web.de/login/form.php',
                                           password='******',
                                           title=u"web.de",
                                           uuid="")
Esempio n. 14
0
def test_create_login(tmpdir):
    test_database = _move_test_file_to_tmpdir(tmpdir, "test_create_login.kdbx")

    backend = Backend(test_database)
    backend.open_database("abcd123")

    backend.sync_entries()
    assert len(backend.entries.items) == 1
    # valid logins
    backend.create_login("test_name", "*****@*****.**", "geheim",
                         u"https://www.google.com/login")
    # 2 accounts, same domain
    backend.create_login("test_name", "*****@*****.**", "geheim2",
                         u"https://gmx.net/login")
    backend.create_login("test_name", "*****@*****.**", "geheim3",
                         u"https://gmx.net/login")
    # another login
    backend.create_login("test_name", "*****@*****.**", "geheim4",
                         u"http://web.de/login/form.php")
    # x.get_entries(purge_cache=True)

    assert len(backend.entries.items) == 5

    # FIXME: remove config for client!
    del backend.entries.items[0]
    # first one is the client config (key)
    #
    assert backend.entries.items[0] == EntrySpec(
        login="******",
        url='https://www.google.com/login',
        password='******',
        title=u"www.google.com",
        uuid="")
    assert backend.entries.items[1] == EntrySpec(login="******",
                                                 url='https://gmx.net/login',
                                                 password='******',
                                                 title=u"gmx.net",
                                                 uuid="")
    assert backend.entries.items[2] == EntrySpec(login="******",
                                                 url='https://gmx.net/login',
                                                 password='******',
                                                 title=u"gmx.net",
                                                 uuid="")
    assert backend.entries.items[3] == EntrySpec(
        login="******",
        url='http://web.de/login/form.php',
        password='******',
        title=u"web.de",
        uuid="")