@@ -675,24 +675,28 @@ def test_preserves_percent_encoded_unassigned_or_newly_assigned_format_character
675675 ("unicode_host" , "ascii_host" ),
676676 [
677677 ("münchen.example" , "xn--mnchen-3ya.example" ),
678+ ("mu\u0308 nchen.example" , "xn--mnchen-3ya.example" ),
678679 ("例え.テスト" , "xn--r8jz45g.xn--zckzah" ),
679680 ("bücher.example" , "xn--bcher-kva.example" ),
680681 ],
681682)
682683@pytest .mark .parametrize ("host_form" , ["unicode" , "punycode" ])
684+ @pytest .mark .parametrize ("host_case" , ["lower" , "upper" ])
683685@pytest .mark .parametrize ("trailing_dot" , ["" , "." ])
684686def test_accepts_idn_hosts_and_preserves_the_supplied_representation (
685- unicode_host : str , ascii_host : str , host_form : str , trailing_dot : str
687+ unicode_host : str , ascii_host : str , host_form : str , host_case : str , trailing_dot : str
686688) -> None :
687689 host = (unicode_host if host_form == "unicode" else ascii_host ) + trailing_dot
690+ if host_case == "upper" :
691+ host = host .upper ()
688692 options = parse_connection_string (f"chronicle://id:secret@{ host } " )
689693
690694 assert options .host == host
691- assert options .host .encode ("idna" ).decode ("ascii" ) == ascii_host + trailing_dot
695+ assert options .host .encode ("idna" ).decode ("ascii" ). lower () == ascii_host + trailing_dot
692696 assert str (options ) == f"chronicle://id:****@{ host } :35000"
693697
694698
695- @pytest .mark .parametrize ("host" , ["PRIVATE_HOST\ud800 .example" , "é" * 58 + ".example" ])
699+ @pytest .mark .parametrize ("host" , ["PRIVATE_HOST\ud800 .example" , "é" * 58 + ".example" , "münchen.xn--" ])
696700def test_idna_conversion_failures_raise_a_chain_free_host_error (host : str ) -> None :
697701 connection_string = f"chronicle://PRIVATE_CLIENT:PRIVATE_SECRET@{ host } "
698702 with pytest .raises (InvalidHostError ) as caught :
@@ -707,6 +711,24 @@ def test_idna_conversion_failures_raise_a_chain_free_host_error(host: str) -> No
707711 assert caught .value .__context__ is None
708712
709713
714+ @pytest .mark .parametrize (
715+ "host" , ["example.com" , "127.0.0.1" , "ex\u034f ample.com" , "x\u2024 y.é" , "faß.de" ]
716+ )
717+ @pytest .mark .parametrize ("trailing_dot" , ["" , "." ])
718+ def test_rejects_idna_mappings_that_change_the_supplied_host (host : str , trailing_dot : str ) -> None :
719+ connection_string = f"chronicle://PRIVATE_CLIENT:PRIVATE_SECRET@{ host } { trailing_dot } "
720+ with pytest .raises (InvalidHostError ) as caught :
721+ parse_connection_string (connection_string )
722+
723+ assert str (caught .value ) == "The host is not a valid internationalised host name"
724+ for rendering in (str (caught .value ), repr (caught .value ), "" .join (traceback .format_exception (caught .value ))):
725+ assert "PRIVATE_CLIENT" not in rendering
726+ assert "PRIVATE_SECRET" not in rendering
727+ assert host not in rendering
728+ assert caught .value .__cause__ is None
729+ assert caught .value .__context__ is None
730+
731+
710732@pytest .mark .parametrize ("trailing_dot" , ["" , "." ])
711733def test_accepts_unicode_hosts_at_the_encoded_dns_length_limits (trailing_dot : str ) -> None :
712734 host = "." .join (["é" * 57 ] * 3 + ["a" * 61 ]) + trailing_dot
0 commit comments