From 6cba30ab33b8fa27b52ef9e74a19ecb93ddf597c Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Mon, 9 Sep 2024 20:43:48 +0700 Subject: [PATCH] test(filter): more tests for `SchemeDomainPort` (#4015) Adding more tests for the `SchemeDomainPort` ### Legal Boilerplate Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. --------- Co-authored-by: Joris Bayer --- relay-filter/src/csp.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/relay-filter/src/csp.rs b/relay-filter/src/csp.rs index 57b2712db3..c7cbe49b1f 100644 --- a/relay-filter/src/csp.rs +++ b/relay-filter/src/csp.rs @@ -232,6 +232,12 @@ mod tests { ("abc.com/something]:", None, Some("abc.com"), None), ("abc.co]m/[something:", None, Some("abc.co]m"), None), ("]abc.com:9000", None, Some("]abc.com"), Some("9000")), + ( + "https://api.example.com/foo/00000000-0000-0000-0000-000000000000?includes[]=user&includes[]=image&includes[]=author&includes[]=tag", + Some("https"), + Some("api.example.com"), + None, + ) ]; for (url, scheme, domain, port) in examples { @@ -265,6 +271,40 @@ mod tests { Some("[1fff:0:a88:85a3::ac1f]"), Some("8001"), ), + // invalid IPv6 for localhost since it's not inside brackets + ("::1", None, Some(":"), Some("1")), + ("[::1]", None, Some("[::1]"), None), + ( + "http://[fe80::862a:fdff:fe78:a2bf%13]", + Some("http"), + Some("[fe80::862a:fdff:fe78:a2bf%13]"), + None, + ), + // invalid addresses. although these results don't represent correct results, + // they are here to make sure the application won't crash. + ("192.168.1.1.1", None, Some("192.168.1.1.1"), None), + ("192.168.1.300", None, Some("192.168.1.300"), None), + ( + "[2001:0db8:85a3:::8a2e:0370:7334]", + None, + Some("[2001:0db8:85a3:::8a2e:0370:7334]"), + None, + ), + ("[fe80::1::]", None, Some("[fe80::1::]"), None), + ("fe80::1::", None, Some("fe80::1:"), Some("")), + ( + "[2001:0db8:85a3:xyz::8a2e:0370:7334]", + None, + Some("[2001:0db8:85a3:xyz::8a2e:0370:7334]"), + None, + ), + ( + "2001:0db8:85a3:xyz::8a2e:0370:7334", + None, + Some("2001:0db8:85a3:xyz::8a2e:0370"), + Some("7334"), + ), + ("192.168.0.1/24", None, Some("192.168.0.1"), None), ]; for (url, scheme, domain, port) in examples {