Re: [PATCH v2] credential/libsecret: support password_expiry_utc
- From
M Hickford <mirth.hickford@gmail.com>
- Date
- May 5, 2023, 07:00 UTC
- Message-ID
- <CAGJzqsmL6AK8BsxJJzRRddcdep-F2szUAvE-2ep5KBsmUVnghw@mail.gmail.com>
- In-Reply-To
- <xmqqjzxoj8mm.fsf@gitster.g>
On Thu, 4 May 2023 at 18:42, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
> > "M Hickford via GitGitGadget" <gitgitgadget@gmail.com> writes: > > We used to use the bog-standard "COMPAT_NETWORK" but now we are > adding an extra element, and that makes it necessary to define our > own? OK.
Exactly.
Show 26 quoted lines
>
> > static char *make_label(struct credential *c)
> > {
> > if (c->port)
> > @@ -78,6 +93,9 @@ static GHashTable *make_attr_list(struct credential *c)
> > g_hash_table_insert(al, "port", g_strdup_printf("%hu", c->port));
> > if (c->path)
> > g_hash_table_insert(al, "object", g_strdup(c->path));
> > + if (c->password_expiry_utc)
> > + g_hash_table_insert(al, "password_expiry_utc",
> > + g_strdup(c->password_expiry_utc));
> >
> > return al;
> > }
> > @@ -101,9 +119,11 @@ static int keyring_get(struct credential *c)
> >
> > attributes = make_attr_list(c);
> > items = secret_service_search_sync(service,
> > - SECRET_SCHEMA_COMPAT_NETWORK,
> > + &schema,
> > attributes,
> > - SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK,
> > + SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK |
> > + // for backwards compatibility
>
> No // comments please.I'll amend in v3.
Show 15 quoted lines
> > > + SECRET_SCHEMA_DONT_MATCH_NAME, > > SECRET_SCHEMA_DONT_MATCH_NAME does not seem to be listed as one of > the flags to be used with secret_service_search_sync(), > > https://www.manpagez.com/html/libsecret-1/libsecret-1-0.18.6/SecretService.php#secret-service-search-sync > > and the only reference to it I found was as a flag to be placed in > the schema. > > https://www.manpagez.com/html/libsecret-1/libsecret-1-0.18.6/migrating-schemas.php > https://www.manpagez.com/html/libsecret-1/libsecret-1-0.18.6/libsecret-SecretSchema.php > > But I'll take your word for it.
Good spot. I must have misread the docs. I shall fix in v3 and test backwards compatibility carefully.
[1] https://gnome.pages.gitlab.gnome.org/libsecret/migrating-libgnome-keyring.html#working-with-schemas
Show 5 quoted lines
> > I found nothing unexpected or surprising in the rest of the patch to > this file. They all looked just a fallout of having to store and > retrieve one extra item from the database together with many other > things we already store and retrieve. Cleanly written.
Thanks Junio for the review.
Show 53 quoted lines
>
> > diff --git a/t/lib-credential.sh b/t/lib-credential.sh
> > index 5ea8bc9f1dc..9ebf7eeae48 100644
> > --- a/t/lib-credential.sh
> > +++ b/t/lib-credential.sh
> > @@ -43,6 +43,7 @@ helper_test_clean() {
> > reject $1 https example.com store-user
> > reject $1 https example.com user1
> > reject $1 https example.com user2
> > + reject $1 https example.com user3
> > reject $1 http path.tld user
> > reject $1 https timeout.tld user
> > reject $1 https sso.tld
> > @@ -298,6 +299,35 @@ helper_test_timeout() {
> > '
> > }
> >
> > +helper_test_password_expiry_utc() {
> > + HELPER=$1
> > +
> > + test_expect_success "helper ($HELPER) stores password_expiry_utc" '
> > + check approve $HELPER <<-\EOF
> > + protocol=https
> > + host=example.com
> > + username=user3
> > + password=pass
> > + password_expiry_utc=9999999999
> > + EOF
> > + '
> >
> > + test_expect_success "helper ($HELPER) gets password_expiry_utc" '
> > + check fill $HELPER <<-\EOF
> > + protocol=https
> > + host=example.com
> > + username=user3
> > + --
> > + protocol=https
> > + host=example.com
> > + username=user3
> > + password=pass
> > + password_expiry_utc=9999999999
> > + --
> > + EOF
> > + '
> > +}
> > +
>
> Is any random number usable for this test, or is there some
> constraints (like, "it cannot be too small to be a timestamp in the
> past, because the entry will be expired immediately")? If there is
> some constraint like that, is it a good idea to also test that
> (like, "make sure an entry with expiry already happened is
> rejected")?The date has to be in the future otherwise the credential will be discarded by `credential approve` before it reaches the helper. That logic is already tested in t/t0300-credentials.sh. There isn't any expiry logic in the helper itself to test.
> > Thanks. >