Skip to content

urlmatch: allow wildcard-based matches

Patrick Steinhardt git 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest5 patches 3 repliesIn review
  2. v34 patches 5 repliesSuperseded
  3. v24 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches2 repliesSuperseded

Changes to the previous version from the cover letter

- applied Junio's proposed patch to replace strtok_r with a memchr-based loop
- applied Junio's proposed rewrite of the commit message of patch 5
- I realized that with my patches, "ranking" of URLs was broken. Previously, we've always taken the longest matching URL. As previously, only the user and path could actually differ, only these two components were used for the comparison. I've changed this now to also include the host part so that URLs with a longer host will take precedence. This resulted in a the patch 4.
- New tests are included which examine if the precedence-rules are actually honored correctly. The tests are part of patches 4 and 5.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5mailmap: add Patrick Steinhardt's work address.mailmap+1 -00 replies
2/5urlmatch: enable normalization of URLs with globsurlmatch.c+12 -20 replies
3/5urlmatch: split host and port fields in `struct url_info`urlmatch.c urlmatch.h+17 -80 replies
4/5urlmatch: include host and port in urlmatch lengtht/t1300-repo-config.sh urlmatch.c urlmatch.h+69 -260 replies
5/5urlmatch: allow globbing for the URL host partDocumentation/config.txt t/t1300-repo-config.sh urlmatch.c+121 -50 replies

Reviews trailers per patch

None of the 5 patches has a Reviewed-by or Acked-by.

PatchJunio C Hamano
1/5
2/5
3/5
4/5
5/5Helped-by

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/5] urlmatch: allow wildcard-based matches

Hi,

so this is part four of my patch series. The previous version can be found at [1]. The use case is to be able to configure an HTTP proxy for all subdomains of a domain where there are hundreds of subdomains.

Changes to the previous version:

- applied Junio's proposed patch to replace strtok_r with a memchr-based loop
- applied Junio's proposed rewrite of the commit message of patch 5
- I realized that with my patches, "ranking" of URLs was broken. Previously, we've always taken the longest matching URL. As previously, only the user and path could actually differ, only these two components were used for the comparison. I've changed this now to also include the host part so that URLs with a longer host will take precedence. This resulted in a the patch 4.
- New tests are included which examine if the precedence-rules are actually honored correctly. The tests are part of patches 4 and 5.

You can find the interdiff below.

Regards
Patrick

[1]: http://public-inbox.org/git/[email protected]/T/#t

Patrick Steinhardt (5):
mailmap: add Patrick Steinhardt's work address
urlmatch: enable normalization of URLs with globs
urlmatch: split host and port fields in struct url_info
urlmatch: include host and port in urlmatch length
urlmatch: allow globbing for the URL host part

 .mailmap                 |   1 +
 Documentation/config.txt |   5 +-
 t/t1300-repo-config.sh   | 105 ++++++++++++++++++++++++++++++++++++
 urlmatch.c               | 138 +++++++++++++++++++++++++++++++++++------------
 urlmatch.h               |  12 +++--
 5 files changed, 220 insertions(+), 41 deletions(-)
Signature · 1 line
2.11.0
t/t1300-repo-config.sh +70 -1
index ec545e092..052f12021 100755
@@ -1177,7 +1177,72 @@ test_expect_success 'urlmatch' '
 	test_cmp expect actual
 '
 
-test_expect_success 'glob-based urlmatch' '
+test_expect_success 'urlmatch favors more specific URLs' '
+	cat >.git/config <<-\EOF &&
+	[http "https://example.com/"]
+		cookieFile = /tmp/root.txt
+	[http "https://example.com/subdirectory"]
+		cookieFile = /tmp/subdirectory.txt
+	[http "https://[email protected]/"]
+		cookieFile = /tmp/user.txt
+	[http "https://[email protected]/"]
+		cookieFile = /tmp/averylonguser.txt
+	[http "https://preceding.example.com"]
+		cookieFile = /tmp/preceding.txt
+	[http "https://*.example.com"]
+		cookieFile = /tmp/wildcard.txt
+	[http "https://*.example.com/wildcardwithsubdomain"]
+		cookieFile = /tmp/wildcardwithsubdomain.txt
+	[http "https://trailing.example.com"]
+		cookieFile = /tmp/trailing.txt
+	[http "https://user@*.example.com/"]
+		cookieFile = /tmp/wildcardwithuser.txt
+	[http "https://sub.example.com/"]
+		cookieFile = /tmp/sub.txt
+	EOF
+
+	echo http.cookiefile /tmp/root.txt >expect &&
+	git config --get-urlmatch HTTP https://example.com >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/subdirectory.txt >expect &&
+	git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/subdirectory.txt >expect &&
+	git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/user.txt >expect &&
+	git config --get-urlmatch HTTP https://[email protected]/ >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/subdirectory.txt >expect &&
+	git config --get-urlmatch HTTP https://[email protected]/subdirectory >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/preceding.txt >expect &&
+	git config --get-urlmatch HTTP https://preceding.example.com >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/wildcard.txt >expect &&
+	git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/sub.txt >expect &&
+	git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/trailing.txt >expect &&
+	git config --get-urlmatch HTTP https://trailing.example.com >actual &&
+	test_cmp expect actual &&
+
+	echo http.cookiefile /tmp/sub.txt >expect &&
+	git config --get-urlmatch HTTP https://[email protected] >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'urlmatch with wildcard' '
 	cat >.git/config <<-\EOF &&
 	[http]
 		sslVerify
@@ -1210,6 +1275,10 @@ test_expect_success 'glob-based urlmatch' '
 		echo http.sslverify false
 	} >expect &&
 	git config --get-urlmatch HTTP https://good.example.com >actual &&
+	test_cmp expect actual &&
+
+	echo http.sslverify >expect &&
+	git config --get-urlmatch HTTP https://more.example.com.au >actual &&
 	test_cmp expect actual
 '
 
urlmatch.c +67 -47

173 lines not on this page · raw message

urlmatch.h +2 -1
index 0ea812b03..37ee5da85 100644
@@ -34,7 +34,8 @@ struct url_info {
 extern char *url_normalize(const char *, struct url_info *);
 
 struct urlmatch_item {
-	size_t matched_len;
+	size_t hostmatch_len;
+	size_t pathmatch_len;
 	char user_matched;
 };