git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality
  2017-03-16  5:18 ` [GSoC][PATCH v4 0/4] Moving credential-cache socket to xdg path Devin Lehmacher
@ 2017-03-16  5:18   ` Devin Lehmacher
  2017-03-16 16:29     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Devin Lehmacher @ 2017-03-16  5:18 UTC (permalink / raw)
  To: lehmacdj; +Cc: git, gitster

Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>
---
 t/t0301-credential-cache.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/t/t0301-credential-cache.sh b/t/t0301-credential-cache.sh
index 82c841121..664c6dda1 100755
--- a/t/t0301-credential-cache.sh
+++ b/t/t0301-credential-cache.sh
@@ -12,6 +12,7 @@ test -z "$NO_UNIX_SOCKETS" || {
 # don't leave a stale daemon running
 trap 'code=$?; git credential-cache exit; (exit $code); die' EXIT
 
+# test that the daemon works with no special setup
 helper_test cache
 helper_test_timeout cache --timeout=1
 
@@ -20,4 +21,67 @@ helper_test_timeout cache --timeout=1
 # our socket, leaving us with no way to access the daemon.
 git credential-cache exit
 
+# we need to use rm -rf here since sometimes the daemon hasn't finished
+# cleaning up after itself and rmdir fails
+test_expect_success 'credential-cache --socket option overrides default location' '
+	test_when_finished "rm -rf \"$HOME\"/dir/" &&
+	check approve "cache --socket \"$HOME/dir/socket\"" <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test -S "$HOME/dir/socket" &&
+	git credential-cache exit
+'
+
+XDG_CACHE_HOME="$HOME/xdg"
+export XDG_CACHE_HOME
+# test behavior when XDG_CACHE_HOME is set
+helper_test cache
+
+test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
+	test -S "$XDG_CACHE_HOME/git/credential/socket" &&
+	test_path_is_missing "$HOME/.git-credential-cache/socket" &&
+	test_path_is_missing "$HOME/.cache/git/credential/socket" &&
+	git credential-cache exit
+'
+unset XDG_CACHE_HOME
+
+test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
+	check approve cache <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test -S "$HOME/.cache/git/credential/socket" &&
+	XDG_CACHE_HOME="$HOME/xdg" &&
+	export XDG_CACHE_HOME &&
+	check approve cache <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test -S "$HOME/xdg/git/credential/socket" &&
+	git credential-cache exit &&
+	unset XDG_CACHE_HOME
+'
+
+# we need to use rm -rf here since sometimes the daemon hasn't finished
+# cleaning up after itself and rmdir fails
+test_expect_success 'use user socket if user directory exists' '
+	test_when_finished "rm -rf \"$HOME/.git-credential-cache/\"" &&
+	mkdir -p -m 700 "$HOME/.git-credential-cache/" &&
+	check approve cache <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test -S "$HOME/.git-credential-cache/socket" &&
+	git credential-cache exit
+'
+
 test_done
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality
  2017-03-16  5:18   ` [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality Devin Lehmacher
@ 2017-03-16 16:29     ` Junio C Hamano
  2017-03-16 17:58       ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2017-03-16 16:29 UTC (permalink / raw)
  To: Devin Lehmacher, Jeff King; +Cc: git

Devin Lehmacher <lehmacdj@gmail.com> writes:

> @@ -20,4 +21,67 @@ helper_test_timeout cache --timeout=1
>  # our socket, leaving us with no way to access the daemon.
>  git credential-cache exit
>  
> +# we need to use rm -rf here since sometimes the daemon hasn't finished
> +# cleaning up after itself and rmdir fails

Hmmmm.  Peff, do you have ideas on better ways to do this (or
explanation why this is the best we could do)?

> +test_expect_success 'credential-cache --socket option overrides default location' '
> +	test_when_finished "rm -rf \"$HOME\"/dir/" &&
> +	check approve "cache --socket \"$HOME/dir/socket\"" <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	test -S "$HOME/dir/socket" &&
> +	git credential-cache exit
> +'
> +
> +XDG_CACHE_HOME="$HOME/xdg"
> +export XDG_CACHE_HOME
> +# test behavior when XDG_CACHE_HOME is set
> +helper_test cache
> +
> +test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
> +	test -S "$XDG_CACHE_HOME/git/credential/socket" &&
> +	test_path_is_missing "$HOME/.git-credential-cache/socket" &&
> +	test_path_is_missing "$HOME/.cache/git/credential/socket" &&
> +	git credential-cache exit
> +'
> +unset XDG_CACHE_HOME
> +
> +test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
> +	check approve cache <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	test -S "$HOME/.cache/git/credential/socket" &&
> +	XDG_CACHE_HOME="$HOME/xdg" &&
> +	export XDG_CACHE_HOME &&
> +	check approve cache <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	test -S "$HOME/xdg/git/credential/socket" &&
> +	git credential-cache exit &&
> +	unset XDG_CACHE_HOME

This unset will not run if any of the above steps since it was set
and exported fails.  It probably should be in test_when_finished and
should use safe_unset shell function instead.

> +'
> +
> +# we need to use rm -rf here since sometimes the daemon hasn't finished
> +# cleaning up after itself and rmdir fails
> +test_expect_success 'use user socket if user directory exists' '
> +	test_when_finished "rm -rf \"$HOME/.git-credential-cache/\"" &&
> +	mkdir -p -m 700 "$HOME/.git-credential-cache/" &&
> +	check approve cache <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	test -S "$HOME/.git-credential-cache/socket" &&

We should also test that the XDG location is not touched at the same
time that the traditional directory was used for the socket.

> +	git credential-cache exit
> +'

This last test should be replicated to also check the case where we
have a symbolic link at ~/.git-credential-cache that points at a
directory.

>  test_done

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality
  2017-03-16 16:29     ` Junio C Hamano
@ 2017-03-16 17:58       ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2017-03-16 17:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Devin Lehmacher, git

On Thu, Mar 16, 2017 at 09:29:58AM -0700, Junio C Hamano wrote:

> Devin Lehmacher <lehmacdj@gmail.com> writes:
> 
> > @@ -20,4 +21,67 @@ helper_test_timeout cache --timeout=1
> >  # our socket, leaving us with no way to access the daemon.
> >  git credential-cache exit
> >  
> > +# we need to use rm -rf here since sometimes the daemon hasn't finished
> > +# cleaning up after itself and rmdir fails
> 
> Hmmmm.  Peff, do you have ideas on better ways to do this (or
> explanation why this is the best we could do)?

If you call "git credential-cache exit", that should be deterministic.
The client program won't exit until the other side closes the
descriptor, which it won't do until it has cleaned up the socket. See
the comment at line 130 of credential-cache--daemon.c.

So here:

> > +test_expect_success 'credential-cache --socket option overrides default location' '
> > +	test_when_finished "rm -rf \"$HOME\"/dir/" &&
> > +	check approve "cache --socket \"$HOME/dir/socket\"" <<-\EOF &&
> > +	protocol=https
> > +	host=example.com
> > +	username=store-user
> > +	password=store-pass
> > +	EOF
> > +	test -S "$HOME/dir/socket" &&
> > +	git credential-cache exit
> > +'

This is almost right, except:

  - the "exit" needs to be told which socket to use

  - we should do the "exit" even when the test fails early (so in
    test_when_finished)

  - the test_when_finished block will interpolate $HOME when setting up
    the block, which will break if it contains double-quotes or other
    special characters. It should use \$HOME.

    I suspect the "check" invocation needs to do so as well, though it
    is even trickier (we shove it into a single-quoted "-c" argument).

    I think you could get by in both cases with relative paths.

So all together, probably:

  test_when_finished "
	git credential-cache --socket dir/socket &&
	rmdir dir
  " &&
  check approve "cache --socket dir/socket" <<-\EOF &&
  ...
  EOF
  test -S dir/socket

The final "test -S" should be OK in practice. We're assuming that the
cache-daemon is still running, but it has a 900 second timeout by
default (and besides, all the other tests have exact same race).

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality
@ 2017-03-16 21:03 Devin Lehmacher
  0 siblings, 0 replies; 4+ messages in thread
From: Devin Lehmacher @ 2017-03-16 21:03 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Junio C Hamano, Devin Lehmacher

> > > +test_expect_success 'credential-cache --socket option overrides default location' '
> > > + test_when_finished "rm -rf \"$HOME\"/dir/" &&
> > > + check approve "cache --socket \"$HOME/dir/socket\"" <<-\EOF &&
> > > + protocol=https
> > > + host=example.com
> > > + username=store-user
> > > + password=store-pass
> > > + EOF
> > > + test -S "$HOME/dir/socket" &&
> > > + git credential-cache exit
> > > +'
>
> This is almost right, except:
>
>   - the "exit" needs to be told which socket to use
>
>   - we should do the "exit" even when the test fails early (so in
>     test_when_finished)
>
>   - the test_when_finished block will interpolate $HOME when setting up
>     the block, which will break if it contains double-quotes or other
>     special characters. It should use \$HOME.
>
>     I suspect the "check" invocation needs to do so as well, though it
>     is even trickier (we shove it into a single-quoted "-c" argument).
>
>     I think you could get by in both cases with relative paths.

Using a relative path won't work since `git credential-cache --socket`
only accepts absolute paths. It shouldn't be too hard to escape the
string though.

-Devin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-16 21:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16 21:03 [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality Devin Lehmacher
  -- strict thread matches above, loose matches on Subject: below --
2017-03-14  0:32 [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket Devin Lehmacher
2017-03-16  5:18 ` [GSoC][PATCH v4 0/4] Moving credential-cache socket to xdg path Devin Lehmacher
2017-03-16  5:18   ` [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality Devin Lehmacher
2017-03-16 16:29     ` Junio C Hamano
2017-03-16 17:58       ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).