@@ -713,148 +713,53 @@ private static List<String> convertToHttps(List<String> urls) {
713713 }
714714
715715 // Tests for normalizeUrlForPortComparison method
716- @ Test
717- void normalizeUrlForPortComparison_withHttpStandardPort_removesPort () {
718- String urlWithPort = "http://example.com:80/path" ;
719- String expected = "http://example.com/path" ;
720-
721- String result = normalizeUrlForPortComparison (urlWithPort );
722-
723- assertThat (result ).isEqualTo (expected );
724- }
725-
726- @ Test
727- void normalizeUrlForPortComparison_withHttpsStandardPort_removesPort () {
728- String urlWithPort = "https://example.com:443/path" ;
729- String expected = "https://example.com/path" ;
730-
731- String result = normalizeUrlForPortComparison (urlWithPort );
732-
733- assertThat (result ).isEqualTo (expected );
734- }
735-
736- @ Test
737- void normalizeUrlForPortComparison_withHttpNonStandardPort_keepsPort () {
738- String urlWithPort = "http://example.com:8080/path" ;
739- String expected = "http://example.com:8080/path" ;
740-
741- String result = normalizeUrlForPortComparison (urlWithPort );
742-
743- assertThat (result ).isEqualTo (expected );
744- }
745-
746- @ Test
747- void normalizeUrlForPortComparison_withHttpsNonStandardPort_keepsPort () {
748- String urlWithPort = "https://example.com:8443/path" ;
749- String expected = "https://example.com:8443/path" ;
750-
751- String result = normalizeUrlForPortComparison (urlWithPort );
752-
753- assertThat (result ).isEqualTo (expected );
754- }
755-
756- @ Test
757- void normalizeUrlForPortComparison_withNoPort_remainsUnchanged () {
758- String urlWithoutPort = "http://example.com/path" ;
759- String expected = "http://example.com/path" ;
760-
761- String result = normalizeUrlForPortComparison (urlWithoutPort );
762-
763- assertThat (result ).isEqualTo (expected );
764- }
765-
766- @ Test
767- void normalizeUrlForPortComparison_withHttpsNoPort_remainsUnchanged () {
768- String urlWithoutPort = "https://example.com/path" ;
769- String expected = "https://example.com/path" ;
770-
771- String result = normalizeUrlForPortComparison (urlWithoutPort );
772-
773- assertThat (result ).isEqualTo (expected );
774- }
775-
776- @ Test
777- void normalizeUrlForPortComparison_withQueryParams_preservesQueryParams () {
778- String urlWithPort = "http://example.com:80/path?param1=value1¶m2=value2" ;
779- String expected = "http://example.com/path?param1=value1¶m2=value2" ;
780-
781- String result = normalizeUrlForPortComparison (urlWithPort );
782-
783- assertThat (result ).isEqualTo (expected );
784- }
785-
786- @ Test
787- void normalizeUrlForPortComparison_withFragment_preservesFragment () {
788- String urlWithPort = "https://example.com:443/path#section1" ;
789- String expected = "https://example.com/path#section1" ;
790-
791- String result = normalizeUrlForPortComparison (urlWithPort );
792-
793- assertThat (result ).isEqualTo (expected );
794- }
795-
796- @ Test
797- void normalizeUrlForPortComparison_withMalformedUrl_returnsOriginal () {
798- String malformedUrl = "not-a-valid-url" ;
799-
800- String result = normalizeUrlForPortComparison (malformedUrl );
801-
802- assertThat (result ).isEqualTo (malformedUrl );
716+ @ ParameterizedTest (name = "normalizeUrlForPortComparison: \" {0}\" should become \" {1}\" " )
717+ @ CsvSource ({
718+ // Standard port removal
719+ "'http://example.com:80/path', 'http://example.com/path'" ,
720+ "'https://example.com:443/path', 'https://example.com/path'" ,
721+
722+ // Non-standard ports preserved
723+ "'http://example.com:8080/path', 'http://example.com:8080/path'" ,
724+ "'https://example.com:8443/path', 'https://example.com:8443/path'" ,
725+
726+ // URLs without explicit ports remain unchanged
727+ "'http://example.com/path', 'http://example.com/path'" ,
728+ "'https://example.com/path', 'https://example.com/path'" ,
729+
730+ // Query parameters and fragments preserved
731+ "'http://example.com:80/path?param1=value1¶m2=value2', 'http://example.com/path?param1=value1¶m2=value2'" ,
732+ "'https://example.com:443/path#section1', 'https://example.com/path#section1'" ,
733+
734+ // Complex URLs with user info
735+ "'http://user:[email protected] :80/path/to/resource?query=value#fragment', 'http://user:[email protected] /path/to/resource?query=value#fragment'" ,
736+
737+ // Subdomains preserved
738+ "'https://subdomain.example.com:443/path', 'https://subdomain.example.com/path'" ,
739+
740+ // Different schemes keep non-standard ports
741+ "'ftp://example.com:80/path', 'ftp://example.com:80/path'" ,
742+
743+ // SAML-specific URL
744+ "'https://uaa.example.com:443/saml/SSO/alias/provider-name?RelayState=https://app.example.com¶m=value#section', 'https://uaa.example.com/saml/SSO/alias/provider-name?RelayState=https://app.example.com¶m=value#section'" ,
745+
746+ // Malformed URLs return unchanged
747+ "'not-a-valid-url', 'not-a-valid-url'" ,
748+ "'http://[invalid:url:with:colons:everywhere', 'http://[invalid:url:with:colons:everywhere'" ,
749+ "'http://example.com:80/path with spaces and special chars!@#$%^&*()', 'http://example.com:80/path with spaces and special chars!@#$%^&*()'" ,
750+
751+ // Empty string
752+ "'', ''"
753+ })
754+ void normalizeUrlForPortComparison_parameterizedTests (String inputUrl , String expectedUrl ) {
755+ String result = normalizeUrlForPortComparison (inputUrl );
756+ assertThat (result ).isEqualTo (expectedUrl );
757+ assertThat (result ).isNotNull (); // Ensure we never return null for non-null input
803758 }
804759
805760 @ Test
806761 void normalizeUrlForPortComparison_withNullUrl_returnsNull () {
807762 String result = normalizeUrlForPortComparison (null );
808-
809763 assertThat (result ).isNull ();
810764 }
811-
812- @ Test
813- void normalizeUrlForPortComparison_withEmptyUrl_returnsEmpty () {
814- String emptyUrl = "" ;
815-
816- String result = normalizeUrlForPortComparison (emptyUrl );
817-
818- assertThat (result ).isEqualTo (emptyUrl );
819- }
820-
821- @ Test
822- void normalizeUrlForPortComparison_withComplexUrl_handlesCorrectly () {
823- String complexUrl =
"http://user:[email protected] :80/path/to/resource?query=value#fragment" ;
824- String expected =
"http://user:[email protected] /path/to/resource?query=value#fragment" ;
825-
826- String result = normalizeUrlForPortComparison (complexUrl );
827-
828- assertThat (result ).isEqualTo (expected );
829- }
830-
831- @ Test
832- void normalizeUrlForPortComparison_withSubdomain_preservesSubdomain () {
833- String urlWithSubdomain = "https://subdomain.example.com:443/path" ;
834- String expected = "https://subdomain.example.com/path" ;
835-
836- String result = normalizeUrlForPortComparison (urlWithSubdomain );
837-
838- assertThat (result ).isEqualTo (expected );
839- }
840-
841- @ Test
842- void normalizeUrlForPortComparison_withDifferentScheme_keepsPort () {
843- String urlWithPort = "ftp://example.com:80/path" ;
844- String expected = "ftp://example.com:80/path" ;
845-
846- String result = normalizeUrlForPortComparison (urlWithPort );
847-
848- assertThat (result ).isEqualTo (expected );
849- }
850-
851- @ Test
852- void normalizeUrlForPortComparison_withSamlSpecificUrl_handlesCorrectly () {
853- String samlUrl = "https://uaa.example.com:443/saml/SSO/alias/provider-name?RelayState=https://app.example.com¶m=value#section" ;
854- String expected = "https://uaa.example.com/saml/SSO/alias/provider-name?RelayState=https://app.example.com¶m=value#section" ;
855-
856- String result = normalizeUrlForPortComparison (samlUrl );
857-
858- assertThat (result ).isEqualTo (expected );
859- }
860765}
0 commit comments