Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression which made libsecret backend unusable in v23.8.0 #587

Merged
merged 2 commits into from Aug 7, 2022

Conversation

mitya57
Copy link
Collaborator

@mitya57 mitya57 commented Aug 7, 2022

libsecret/secret-schema.h has this enum:

typedef enum {
    SECRET_SCHEMA_ATTRIBUTE_STRING = 0,
    SECRET_SCHEMA_ATTRIBUTE_INTEGER = 1,
    SECRET_SCHEMA_ATTRIBUTE_BOOLEAN = 2,
} SecretSchemaAttributeType;

Because of this, bool(Secret.SchemaAttributeType.STRING) evaluates to False. So when we do this, _query code ignores the second argument:

self._query(
Secret.SchemaAttributeType.STRING,
Secret.SchemaAttributeType.STRING,
application=Secret.SchemaAttributeType.STRING,
),

And it causes any use of libsecret backend to fail with this error:

>>> import keyring.backends.libsecret
>>> k = keyring.backends.libsecret.Keyring()
>>> k.set_password('foo', 'bar', 'baz')

(process:26311): libsecret-CRITICAL **: 19:22:53.299: secret_password_storev_sync: invalid username attribute for org.freedesktop.Secret.Generic schema
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dmitry/upstream/keyring/keyring/backends/libsecret.py", line 98, in set_password
    raise PasswordSetError("Failed to store password!")
keyring.errors.PasswordSetError: Failed to store password!

libsecret/secret-schema.h has this enum:

    typedef enum {
        SECRET_SCHEMA_ATTRIBUTE_STRING = 0,
        SECRET_SCHEMA_ATTRIBUTE_INTEGER = 1,
        SECRET_SCHEMA_ATTRIBUTE_BOOLEAN = 2,
    } SecretSchemaAttributeType;

Because of this, bool(Secret.SchemaAttributeType.STRING) evaluates to
False. So when we do this in schema property, _query code ignores the
second argument:

    self._query(
        Secret.SchemaAttributeType.STRING,
        Secret.SchemaAttributeType.STRING,
        application=Secret.SchemaAttributeType.STRING,
    )

And it causes any use of libsecret backend to fail with this error:

    >>> import keyring.backends.libsecret
    >>> k = keyring.backends.libsecret.Keyring()
    >>> k.set_password('foo', 'bar', 'baz')

    (process:26311): libsecret-CRITICAL **: 19:22:53.299: secret_password_storev_sync: invalid username attribute for org.freedesktop.Secret.Generic schema
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/dmitry/upstream/keyring/keyring/backends/libsecret.py", line 98, in set_password
        raise PasswordSetError("Failed to store password!")
    keyring.errors.PasswordSetError: Failed to store password!
@@ -250,7 +250,7 @@ def _query(self, service, username=None, **base):
scheme['username']: username,
scheme['service']: service,
}
if username
if username is not None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible some users are relying on username = '' as a non-value for username. We can address that separately if needed.

@jaraco jaraco self-assigned this Aug 7, 2022
@jaraco
Copy link
Owner

jaraco commented Aug 7, 2022

Thanks for the patch. I'd like to develop a regression test for the missed expectation. I'll do that and then merge it.

@jaraco
Copy link
Owner

jaraco commented Aug 7, 2022

I realize now we don't have libsecret tested anywhere, so I'm going to pull the test.

@jaraco jaraco merged commit f20bdd9 into main Aug 7, 2022
@jaraco jaraco deleted the fix-regression branch August 7, 2022 20:16
@jaraco
Copy link
Owner

jaraco commented Aug 7, 2022

Released as v23.8.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants