diff mbox series

t5551-http-fetch-smart.sh: sort cookies before comparing

Message ID 20180907232205.31328-1-tmz@pobox.com (mailing list archive)
State New, archived
Headers show
Series t5551-http-fetch-smart.sh: sort cookies before comparing | expand

Commit Message

Todd Zullinger Sept. 7, 2018, 11:22 p.m. UTC
With curl-7.61.1 cookies are sorted by creation-time¹.  Sort the output
used in the 'cookies stored in http.cookiefile when http.savecookies
set' test before comparing it to the expected cookies.

¹ https://github.com/curl/curl/commit/e2ef8d6fa ("cookies: support
  creation-time attribute for cookies", 2018-08-28)

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
[Resending with the list in Cc; sorry for spamming you,
Junio, Jeff, and Gábor.]

The in-development version of Fedora updated to the recently
released curl-7.61.1 in the past few days.  This isn't
breakage from the 2.19.0 cycle, but if the fix looks good to
everyone it would be nice to include it.  That way other
distributions and users who update git and curl to the most
recent releases won't run into this test failure.

I tested this against Fedora 30 (curl-7.61.1) as well as
previous releases from RHEL/CentOS 6/7 (7.19.7/7.29.0) and
Fedora 27/28/29 (7.55.1/7.59.0/7.61.0).

The verbose output is:

expecting success:
	git config http.cookiefile cookies.txt &&
	git config http.savecookies true &&
	git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
	tail -3 cookies.txt >cookies_tail.txt &&
	test_cmp expect_cookies.txt cookies_tail.txt
++ git config http.cookiefile cookies.txt
++ git config http.savecookies true
++ git ls-remote http://127.0.0.1:5551/smart_cookies/repo.git master
7ae89caac6c721f16555e981eaeed64abc165c5d	refs/heads/master
263207bb5fbfbefbdf1c9c3fa4ae5d9663323217	refs/namespaces/ns/refs/heads/master
++ tail -3 cookies.txt
++ test_cmp expect_cookies.txt cookies_tail.txt
++ diff -u expect_cookies.txt cookies_tail.txt

Comments

Jeff King Sept. 7, 2018, 11:55 p.m. UTC | #1
On Fri, Sep 07, 2018 at 07:22:05PM -0400, Todd Zullinger wrote:

> With curl-7.61.1 cookies are sorted by creation-time¹.  Sort the output
> used in the 'cookies stored in http.cookiefile when http.savecookies
> set' test before comparing it to the expected cookies.
> 
> ¹ https://github.com/curl/curl/commit/e2ef8d6fa ("cookies: support
>   creation-time attribute for cookies", 2018-08-28)

According to that commit message, the creation-time sort is only for
cookies of the same length. But it's not clear to me if that just means
on-the-wire, and curl always stores by creation-time in the cookie file.

Either way, though, I guess it wouldn't matter for us as long as we
choose some arbitrary re-ordering for what curl produces (i.e., the
output of `sort`) and then make sure our "expect" output is in the same
order. Which is basically what your patch does. One question, though:

> diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
> index 771f36f9ff..538656bfef 100755
> --- a/t/t5551-http-fetch-smart.sh
> +++ b/t/t5551-http-fetch-smart.sh
> @@ -215,7 +215,7 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
>  	git config http.cookiefile cookies.txt &&
>  	git config http.savecookies true &&
>  	git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
> -	tail -3 cookies.txt >cookies_tail.txt &&
> +	tail -3 cookies.txt | sort >cookies_tail.txt &&
>  	test_cmp expect_cookies.txt cookies_tail.txt
>  '

We pick the bottom 3 before sorting. How do we know those are the three
we want to see?

...Ah, OK. The lines we are skipping are not actually cookies at all,
but just header cruft. I wonder if:

  grep "^[^#]" cookies.txt

would be a better way of doing that, but that is certainly not something
new.

So this fix looks fine. It might be worth a comment above the creation
of expect_cookies.txt to mention it must be in sorted order (of course
anybody modifying it would see a test failure).

> The in-development version of Fedora updated to the recently
> released curl-7.61.1 in the past few days.  This isn't
> breakage from the 2.19.0 cycle, but if the fix looks good to
> everyone it would be nice to include it.  That way other
> distributions and users who update git and curl to the most
> recent releases won't run into this test failure.
> 
> I tested this against Fedora 30 (curl-7.61.1) as well as
> previous releases from RHEL/CentOS 6/7 (7.19.7/7.29.0) and
> Fedora 27/28/29 (7.55.1/7.59.0/7.61.0).

You're pretty late in the 2.19 cycle, since the release is tentatively
scheduled for Sunday. Though since this is just touching the test
script, and since it looks Obviously Correct, I'm not opposed.

-Peff
Todd Zullinger Sept. 8, 2018, 3:28 a.m. UTC | #2
Jeff King wrote:
> On Fri, Sep 07, 2018 at 07:22:05PM -0400, Todd Zullinger wrote:
> 
>> With curl-7.61.1 cookies are sorted by creation-time¹.  Sort the output
>> used in the 'cookies stored in http.cookiefile when http.savecookies
>> set' test before comparing it to the expected cookies.
>> 
>> ¹ https://github.com/curl/curl/commit/e2ef8d6fa ("cookies: support
>>   creation-time attribute for cookies", 2018-08-28)
> 
> According to that commit message, the creation-time sort is only for
> cookies of the same length. But it's not clear to me if that just means
> on-the-wire, and curl always stores by creation-time in the cookie file.

Yeah, I didn't dig into the curl code deeply to try and
understand it.  I did test with the only the curl package
downgraded to 7.61.0 to confirm the test worked without
sorting.  And I saw that the curl commit updated existing
tests to sort the test data.

> Either way, though, I guess it wouldn't matter for us as long as we
> choose some arbitrary re-ordering for what curl produces (i.e., the
> output of `sort`) and then make sure our "expect" output is in the same
> order. Which is basically what your patch does. One question, though:
> 
>> diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
>> index 771f36f9ff..538656bfef 100755
>> --- a/t/t5551-http-fetch-smart.sh
>> +++ b/t/t5551-http-fetch-smart.sh
>> @@ -215,7 +215,7 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
>>  	git config http.cookiefile cookies.txt &&
>>  	git config http.savecookies true &&
>>  	git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
>> -	tail -3 cookies.txt >cookies_tail.txt &&
>> +	tail -3 cookies.txt | sort >cookies_tail.txt &&
>>  	test_cmp expect_cookies.txt cookies_tail.txt
>>  '
> 
> We pick the bottom 3 before sorting. How do we know those are the three
> we want to see?
> 
> ...Ah, OK. The lines we are skipping are not actually cookies at all,
> but just header cruft. I wonder if:
> 
>   grep "^[^#]" cookies.txt
> 
> would be a better way of doing that, but that is certainly not something
> new.
> 
> So this fix looks fine. It might be worth a comment above the creation
> of expect_cookies.txt to mention it must be in sorted order (of course
> anybody modifying it would see a test failure).

I thought about running the expect_cookies.txt file through
sort as well.  That would ensure that both files were using
the same sorting.  Whether that's needed on any platform
now, I don't know.  Maybe that would be a useful way to
protect against future edits to the expect_cookies.txt file
catching the editor?

I thought there might be a test function to sort the output,
but I was (incorrectly) thinking of check_access_log() which
Gábor added in e8b3b2e275 ("t/lib-httpd: avoid occasional
failures when checking access.log", 2018-07-12).

Perhaps it would be useful to have a test_cmp_sorted() to do
the simple dance of sorting the actual & expected.  I
haven't looked through the tests to see how often such a
function might be useful.

>> The in-development version of Fedora updated to the recently
>> released curl-7.61.1 in the past few days.  This isn't
>> breakage from the 2.19.0 cycle, but if the fix looks good to
>> everyone it would be nice to include it.  That way other
>> distributions and users who update git and curl to the most
>> recent releases won't run into this test failure.
>> 
>> I tested this against Fedora 30 (curl-7.61.1) as well as
>> previous releases from RHEL/CentOS 6/7 (7.19.7/7.29.0) and
>> Fedora 27/28/29 (7.55.1/7.59.0/7.61.0).
> 
> You're pretty late in the 2.19 cycle, since the release is tentatively
> scheduled for Sunday. Though since this is just touching the test
> script, and since it looks Obviously Correct, I'm not opposed.

Yep, I knew the final was coming very soon.  I would not
have been surprised to see it land tonight while I was
finishing my testing of this patch. :)

I'm certainly covered for the Fedora packages.  It's hard to
say whether there are many other users/packagers who might
upgrade both git and curl and run into this.  So it may not
be worth even a small risk of making the change at this
point.

On the other hand, the change only affects one test and may
be safe enough to apply.  I'll leave that choice in the
capable hands of our maintainer and the good folks here.

Thanks for a thoughtful review, as always.
Jeff King Sept. 8, 2018, 4:17 p.m. UTC | #3
On Fri, Sep 07, 2018 at 11:28:41PM -0400, Todd Zullinger wrote:

> > So this fix looks fine. It might be worth a comment above the creation
> > of expect_cookies.txt to mention it must be in sorted order (of course
> > anybody modifying it would see a test failure).
> 
> I thought about running the expect_cookies.txt file through
> sort as well.  That would ensure that both files were using
> the same sorting.  Whether that's needed on any platform
> now, I don't know.  Maybe that would be a useful way to
> protect against future edits to the expect_cookies.txt file
> catching the editor?

Yes, I think sorting the expect file would work fine. I'm OK with that,
or just leaving a comment. The comment has the bonus that it does not
cost an extra process at runtime. I'd probably use a sort if we expected
the list to be long and complicated, since it makes life easier on a
future developer. But since there are only 2 lines, I don't think it's a
big deal either way (or even just leaving it as-is without a comment is
probably OK).

> I thought there might be a test function to sort the output,
> but I was (incorrectly) thinking of check_access_log() which
> Gábor added in e8b3b2e275 ("t/lib-httpd: avoid occasional
> failures when checking access.log", 2018-07-12).
> 
> Perhaps it would be useful to have a test_cmp_sorted() to do
> the simple dance of sorting the actual & expected.  I
> haven't looked through the tests to see how often such a
> function might be useful.

I suspect it would occasionally be useful, but I don't recall it coming
up all that often.

-Peff
Junio C Hamano Sept. 11, 2018, 5:29 p.m. UTC | #4
Todd Zullinger <tmz@pobox.com> writes:

> With curl-7.61.1 cookies are sorted by creation-time¹.  Sort the output
> used in the 'cookies stored in http.cookiefile when http.savecookies
> set' test before comparing it to the expected cookies.
>
> ¹ https://github.com/curl/curl/commit/e2ef8d6fa ("cookies: support
>   creation-time attribute for cookies", 2018-08-28)
>
> Signed-off-by: Todd Zullinger <tmz@pobox.com>
> ---
> [Resending with the list in Cc; sorry for spamming you,
> Junio, Jeff, and Gábor.]
> ...
> 7ae89caac6c721f16555e981eaeed64abc165c5d	refs/heads/master
> 263207bb5fbfbefbdf1c9c3fa4ae5d9663323217	refs/namespaces/ns/refs/heads/master
> ++ tail -3 cookies.txt
> ++ test_cmp expect_cookies.txt cookies_tail.txt
> ++ diff -u expect_cookies.txt cookies_tail.txt
> --- expect_cookies.txt	2018-09-07 07:29:05.231532462 +0000
> +++ cookies_tail.txt	2018-09-07 07:29:05.306532366 +0000

Have you tried to apply this e-mail yourself before spamming the
list ;-)?

A good way to add supporting material that may be confusing to the
patch text itself is to indent them by one place with SP.

I'll manage anyway; thanks for a patch.

> @@ -1,3 +1,3 @@
>
> -127.0.0.1	FALSE	/smart_cookies/	FALSE	0	othername	othervalue
>  127.0.0.1	FALSE	/smart_cookies/repo.git/info/	FALSE	0	name	value
> +127.0.0.1	FALSE	/smart_cookies/	FALSE	0	othername	othervalue
> error: last command exited with $?=1
> not ok 22 - cookies stored in http.cookiefile when http.savecookies set
>
>  t/t5551-http-fetch-smart.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
> index 771f36f9ff..538656bfef 100755
> --- a/t/t5551-http-fetch-smart.sh
> +++ b/t/t5551-http-fetch-smart.sh
> @@ -215,7 +215,7 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
>  	git config http.cookiefile cookies.txt &&
>  	git config http.savecookies true &&
>  	git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
> -	tail -3 cookies.txt >cookies_tail.txt &&
> +	tail -3 cookies.txt | sort >cookies_tail.txt &&
>  	test_cmp expect_cookies.txt cookies_tail.txt
>  '
Junio C Hamano Sept. 17, 2018, 9:45 p.m. UTC | #5
Jeff King <peff@peff.net> writes:

> Yes, I think sorting the expect file would work fine. I'm OK with that,
> or just leaving a comment. The comment has the bonus that it does not
> cost an extra process at runtime. I'd probably use a sort if we expected
> the list to be long and complicated, since it makes life easier on a
> future developer. But since there are only 2 lines, I don't think it's a
> big deal either way (or even just leaving it as-is without a comment is
> probably OK).

Let's have "| sort" if only for its documentation value.  That way
we do not have to remember the list must be sorted.

Here is what I'll merge to 'next'.

-- >8 --
From: Todd Zullinger <tmz@pobox.com>
Date: Fri, 7 Sep 2018 19:22:05 -0400
Subject: [PATCH] t5551-http-fetch-smart.sh: sort cookies before comparing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With curl-7.61.1 cookies are sorted by creation-time¹.  Sort the output
used in the 'cookies stored in http.cookiefile when http.savecookies
set' test before comparing it to the expected cookies.

¹ https://github.com/curl/curl/commit/e2ef8d6fa ("cookies: support
  creation-time attribute for cookies", 2018-08-28)

[jc: Also use a part of the patch by Thomas Gummerer that sorts the
expected output, which makes it easier to maintain.]

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Helped-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t5551-http-fetch-smart.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
index 771f36f9ff..d13b993201 100755
--- a/t/t5551-http-fetch-smart.sh
+++ b/t/t5551-http-fetch-smart.sh
@@ -206,7 +206,7 @@ test_expect_success 'dumb clone via http-backend respects namespace' '
 cat >cookies.txt <<EOF
 127.0.0.1	FALSE	/smart_cookies/	FALSE	0	othername	othervalue
 EOF
-cat >expect_cookies.txt <<EOF
+cat <<EOF | sort >expect_cookies.txt
 
 127.0.0.1	FALSE	/smart_cookies/	FALSE	0	othername	othervalue
 127.0.0.1	FALSE	/smart_cookies/repo.git/info/	FALSE	0	name	value
@@ -215,7 +215,7 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
 	git config http.cookiefile cookies.txt &&
 	git config http.savecookies true &&
 	git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
-	tail -3 cookies.txt >cookies_tail.txt &&
+	tail -3 cookies.txt | sort >cookies_tail.txt &&
 	test_cmp expect_cookies.txt cookies_tail.txt
 '
Jeff King Sept. 17, 2018, 10:25 p.m. UTC | #6
On Mon, Sep 17, 2018 at 02:45:55PM -0700, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > Yes, I think sorting the expect file would work fine. I'm OK with that,
> > or just leaving a comment. The comment has the bonus that it does not
> > cost an extra process at runtime. I'd probably use a sort if we expected
> > the list to be long and complicated, since it makes life easier on a
> > future developer. But since there are only 2 lines, I don't think it's a
> > big deal either way (or even just leaving it as-is without a comment is
> > probably OK).
> 
> Let's have "| sort" if only for its documentation value.  That way
> we do not have to remember the list must be sorted.

OK, though...

> diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
> index 771f36f9ff..d13b993201 100755
> --- a/t/t5551-http-fetch-smart.sh
> +++ b/t/t5551-http-fetch-smart.sh
> @@ -206,7 +206,7 @@ test_expect_success 'dumb clone via http-backend respects namespace' '
>  cat >cookies.txt <<EOF
>  127.0.0.1	FALSE	/smart_cookies/	FALSE	0	othername	othervalue
>  EOF
> -cat >expect_cookies.txt <<EOF
> +cat <<EOF | sort >expect_cookies.txt

This can be spelled:

  sort >expect_cookies.txt <<EOF

can't it? Then we do not even incur the extra process. :)

-Peff
Junio C Hamano Sept. 18, 2018, 1:55 a.m. UTC | #7
Jeff King <peff@peff.net> writes:

>> -cat >expect_cookies.txt <<EOF
>> +cat <<EOF | sort >expect_cookies.txt
>
> This can be spelled:
>
>   sort >expect_cookies.txt <<EOF
>
> can't it? Then we do not even incur the extra process. :)

Yeah, true.  Running cat only to feed a pipe with contents of a
single file or the here-doc is an anti-pattern.
diff mbox series

Patch

--- expect_cookies.txt	2018-09-07 07:29:05.231532462 +0000
+++ cookies_tail.txt	2018-09-07 07:29:05.306532366 +0000
@@ -1,3 +1,3 @@ 

-127.0.0.1	FALSE	/smart_cookies/	FALSE	0	othername	othervalue
 127.0.0.1	FALSE	/smart_cookies/repo.git/info/	FALSE	0	name	value
+127.0.0.1	FALSE	/smart_cookies/	FALSE	0	othername	othervalue
error: last command exited with $?=1
not ok 22 - cookies stored in http.cookiefile when http.savecookies set

 t/t5551-http-fetch-smart.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
index 771f36f9ff..538656bfef 100755
--- a/t/t5551-http-fetch-smart.sh
+++ b/t/t5551-http-fetch-smart.sh
@@ -215,7 +215,7 @@  test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
 	git config http.cookiefile cookies.txt &&
 	git config http.savecookies true &&
 	git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
-	tail -3 cookies.txt >cookies_tail.txt &&
+	tail -3 cookies.txt | sort >cookies_tail.txt &&
 	test_cmp expect_cookies.txt cookies_tail.txt
 '