Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-51064] Lenient URL validator for Root URL (#3415)
* [JENKINS-51064] Lenient URL validator for Root URL - especially with the TLDs - more test cases * add blank line * Adjust comment * Correction typo
- Loading branch information
Showing
3 changed files
with
54 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,19 @@ | |
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@Issue("JENKINS-31661") | ||
public class UrlHelperTest { | ||
|
||
@Test | ||
@Issue("JENKINS-31661") | ||
public void isValid() { | ||
assertTrue(UrlHelper.isValidRootUrl("http://www.google.com")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://www.google.com/")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://www.google.com/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://www.google.com:8080")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://www.google.com:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("https://www.google.com:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://localhost:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://localhost:8080/jenkins/")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://my_server:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://MY_SERVER_IN_PRIVATE_NETWORK:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://jenkins")); | ||
|
@@ -40,5 +42,24 @@ public void isValid() { | |
// this url will be used as a root url and so will be concatenated with other part, fragments are not allowed | ||
assertFalse(UrlHelper.isValidRootUrl("http://jenkins#fragment")); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
@Issue("JENKINS-51064") | ||
public void isAlsoValid() { | ||
assertTrue(UrlHelper.isValidRootUrl("http://my-server:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://jenkins.internal/")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://jenkins.otherDomain/")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://my-server.domain:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://my-ser_ver.do_m-ain:8080/jenkins")); | ||
assertTrue(UrlHelper.isValidRootUrl("http://my-ser_ver.do_m-ain:8080/jenkins")); | ||
|
||
// forbidden to start or end domain with - or . | ||
assertFalse(UrlHelper.isValidRootUrl("http://-jenkins.com")); | ||
assertFalse(UrlHelper.isValidRootUrl("http://jenkins.com-")); | ||
assertFalse(UrlHelper.isValidRootUrl("http://.jenkins.com")); | ||
assertFalse(UrlHelper.isValidRootUrl("http://jenkins.com.")); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
oleg-nenashev
Member
|
||
|
||
// forbidden to have multiple dots in chain | ||
assertFalse(UrlHelper.isValidRootUrl("http://jen..kins.com")); | ||
} | ||
} |
FYI trailing dots at the end of domain names are valid (and technically canonical for full-qualified domain names). A good article on the topic can be found at http://www.dns-sd.org/trailingdotsindomainnames.html.