|
import pytest |
|
|
|
from keyring.backends import kwallet |
|
from keyring.testing.backend import BackendBasicTests |
|
|
|
|
|
@pytest.mark.skipif(not kwallet.DBusKeyring.viable, reason="KWallet5 unavailable") |
|
class TestDBusKWallet(BackendBasicTests): |
|
|
|
|
|
DIFFICULT_CHARS = BackendBasicTests.DIFFICULT_CHARS.replace('@', '') |
|
|
|
def init_keyring(self): |
|
return kwallet.DBusKeyring() |
|
|
|
def cleanup(self): |
|
for item in self.credentials_created: |
|
|
|
|
|
try: |
|
self.keyring.delete_password(*item) |
|
except BaseException: |
|
pass |
|
|
|
|
|
|
|
def set_password(self, service, username, password, old_format=False): |
|
|
|
|
|
self.credentials_created.add((service, username)) |
|
|
|
if old_format: |
|
username = username + '@' + service |
|
service = 'Python' |
|
|
|
super().set_password(service, username, password) |
|
|
|
def check_set_get(self, service, username, password): |
|
keyring = self.keyring |
|
|
|
|
|
assert keyring.get_password(service, username) is None |
|
|
|
|
|
self.set_password(service, username, password, True) |
|
|
|
self.keyring = keyring = self.init_keyring() |
|
ret_password = keyring.get_password(service, username) |
|
assert ret_password == password, ( |
|
f"Incorrect password for username: '{service}' " |
|
f"on service: '{username}'. '{ret_password}' != '{password}'", |
|
) |
|
|
|
|
|
self.set_password(service, username, "", True) |
|
|
|
self.keyring = keyring = self.init_keyring() |
|
ret_password = keyring.get_password(service, username) |
|
assert ret_password == "" |
|
ret_password = keyring.get_password('Python', username + '@' + service) |
|
assert ret_password is None |
|
|
|
|
|
@pytest.mark.skipif( |
|
not kwallet.DBusKeyringKWallet4.viable, reason="KWallet4 unavailable" |
|
) |
|
class TestDBusKWallet4(TestDBusKWallet): |
|
def init_keyring(self): |
|
return kwallet.DBusKeyringKWallet4() |
|
|