Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_non_existing_collection(self) -> None:
self.assertRaises(ItemNotFoundException,
secretstorage.get_collection_by_alias,
self.connection, 'non-existing-alias')
def test_deleting_item_prompt(self) -> None:
item_path = "/org/freedesktop/secrets/collection/lockone/confirm"
try:
item = Item(self.connection, item_path)
except ItemNotFoundException:
self.skipTest("This test should only be run with mock-service-lock.")
item.delete()
def test_double_deleting(self) -> None:
item = self.collection.create_item('MyItem',
{'application': 'secretstorage-test'}, b'pa$$word')
item.delete()
self.assertRaises(ItemNotFoundException, item.delete)
- The first collection in the collections list."""
try:
return Collection(connection)
except ItemNotFoundException:
pass
try:
# GNOME Keyring provides session collection where items
# are stored in process memory.
return Collection(connection, SESSION_COLLECTION)
except ItemNotFoundException:
pass
collections = list(get_all_collections(connection))
if collections:
return collections[0]
else:
raise ItemNotFoundException('No collections found.')
def send_and_get_reply(self, msg: Message) -> Any:
try:
return self._connection.send_and_get_reply(msg)
except DBusErrorResponse as resp:
if resp.name in (DBUS_UNKNOWN_METHOD, DBUS_NO_SUCH_OBJECT):
raise ItemNotFoundException('Item does not exist!') from resp
elif resp.name in (DBUS_SERVICE_UNKNOWN, DBUS_EXEC_FAILED,
DBUS_NO_REPLY):
data = resp.data
if isinstance(data, tuple):
data = data[0]
raise SecretServiceNotAvailableException(data) from resp
raise
- The first collection in the collections list."""
try:
return Collection(bus)
except ItemNotFoundException:
pass
try:
# GNOME Keyring provides session collection where items
# are stored in process memory.
return Collection(bus, SESSION_COLLECTION)
except ItemNotFoundException:
pass
collections = list(get_all_collections(bus))
if collections:
return collections[0]
else:
raise ItemNotFoundException('No collections found.')
def function_out(*args, **kwargs):
try:
return function_in(*args, **kwargs)
except dbus.exceptions.DBusException as e:
if e.get_dbus_name() == DBUS_UNKNOWN_METHOD:
raise ItemNotFoundException('Item does not exist!')
if e.get_dbus_name() == DBUS_NO_SUCH_OBJECT:
raise ItemNotFoundException(e.get_dbus_message())
if e.get_dbus_name() in (DBUS_NO_REPLY, DBUS_NOT_SUPPORTED):
raise SecretServiceNotAvailableException(
e.get_dbus_message())
raise
return function_out
def get_any_collection(bus):
"""Returns any collection, in the following order of preference:
- The default collection;
- The "session" collection (usually temporary);
- The first collection in the collections list."""
try:
return Collection(bus)
except ItemNotFoundException:
pass
try:
# GNOME Keyring provides session collection where items
# are stored in process memory.
return Collection(bus, SESSION_COLLECTION)
except ItemNotFoundException:
pass
collections = list(get_all_collections(bus))
if collections:
return collections[0]
else:
raise ItemNotFoundException('No collections found.')
def function_out(*args, **kwargs):
try:
return function_in(*args, **kwargs)
except dbus.exceptions.DBusException as e:
if e.get_dbus_name() == DBUS_UNKNOWN_METHOD:
raise ItemNotFoundException('Item does not exist!')
if e.get_dbus_name() == DBUS_NO_SUCH_OBJECT:
raise ItemNotFoundException(e.get_dbus_message())
if e.get_dbus_name() in (DBUS_NO_REPLY, DBUS_NOT_SUPPORTED):
raise SecretServiceNotAvailableException(
e.get_dbus_message())
raise
return function_out