Exemplo n.º 1
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="")
def test_getloginscountrequest_with_entries(mock_get_kpc, mock_authenticate,
                                            mock_search_entries,
                                            mock_set_verifier):
    mock_search_entries.return_value = [
        EntrySpec(uuid="1",
                  title="Login To Google",
                  login="******",
                  password="******",
                  url="http://www.google.de/login/form.html")
    ]
    kpc = TestKPC()
    kpc.decrypt.side_effect = [
        "url_encrypted",
    ]
    mock_get_kpc.return_value = kpc

    request = requests.GetLoginsCountRequest()

    test_dict = {
        "Key": "Some 64 encoded key",
        "Id": "some knwon client",
        'Nonce': "some nonce",
        "Verifier": "some verifier",
        "Url": "http://www.google.de/login"
    }

    assert request(test_dict) == {'Count': 1, 'Success': True}
def test_entry_spec_unicode():
    saved_key = "thT80v8XOBJaFZ85wmP05TdqSX/BB4lVTIvGuac/vgE="

    request_nonce = "I3AWYKKIgTtchOGCHwNi6A=="
    request_verifer = "eij8zQB61XVoh36SisyTDFbmh5J88oVzq/gVpOKQHQM="

    kpc = AESCipher(saved_key, request_nonce)

    entry = EntrySpec(uuid=u"1", title=u"ä", login=u"ü",
                      password=u"ö", url=u"http://www.fuß.de/login/form.html")

    assert entry.to_json_dict(kpc)
    def sync_entries(self):
        self.entries.purge()
        for entry in self.database.entries:

            if self._ignore_entry(entry):
                continue

            entry_spec = EntrySpec(title=entry.title,
                                   uuid=entry.uuid,
                                   login=entry.username,
                                   password=entry.password,
                                   url=entry.url)

            self.entries.push(entry_spec)
Exemplo n.º 5
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="")
Exemplo n.º 6
0
def test_getloginsrequest_with_entries(mock_authenticate, mock_response_kpc,
                                       mock_kpc, mock_search_entries,
                                       mock_set_verifier):
    kpc = TestKPC()
    mock_kpc.return_value = kpc
    mock_response_kpc.return_value = kpc
    mock_search_entries.return_value = [
        EntrySpec(uuid="1",
                  title="Login To Google",
                  login="******",
                  password="******",
                  url="http://www.google.de/login/form.html")
    ]

    test_dict = {"Id": "test_clientname", "Url": "http://www.google.de/login"}

    mock_response_kpc.encrypt.side_effect = [
        "name_encrypted", "login_encrypted", "uuid_encrypted",
        "password_encrypted"
    ]

    request = requests.GetLoginsRequest()

    assert request(test_dict) == {
        'Success':
        True,
        "Id":
        "test_clientname",
        'Entries': [{
            'Login': '******',
            'Password': '******',
            'Name': 'name_encrypted',
            'Uuid': 'uuid_encrypted'
        }]
    }

    assert mock_response_kpc.encrypt.call_args_list == [
        mock.call('Login To Google'),
        mock.call('*****@*****.**'),
        mock.call('1'),
        mock.call('1234')
    ]
    def sync_entries(self):
        self.entries.purge()

        db_entries = self.database.obj_root.xpath('//Group/Entry')
        for entry in db_entries:
            el_uuid = "00000000000000000000000000000000"
            if len(entry.xpath("UUID")) > 0:
                el_uuid = entry.find("UUID").text

            if self._ignore_entry(el_uuid):
                continue

            title = entry.find("String[Key='Title']/Value").text or ""
            login = entry.find("String[Key='UserName']/Value").text or ""
            password = entry.find("String[Key='Password']/Value").text or ""
            url = entry.find("String[Key='URL']/Value").text or ""

            entry_spec = EntrySpec(
                uuid=el_uuid,
                title=title,
                login=login,
                password=password,
                url=url)
            self.entries.push(entry_spec)
Exemplo n.º 8
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)