|
| 1 | +using NUnit.Framework; |
| 2 | +using System; |
| 3 | +using Umbraco.Web.Routing; |
| 4 | + |
| 5 | +namespace Umbraco.Tests.Routing |
| 6 | +{ |
| 7 | + |
| 8 | + [TestFixture] |
| 9 | + public class WebPathTests |
| 10 | + { |
| 11 | + |
| 12 | + [Test] |
| 13 | + [TestCase("ftp://hello.com/", UriKind.Absolute, ExpectedResult = true)] |
| 14 | + [TestCase("file:///hello.com/", UriKind.Absolute, ExpectedResult = true)] |
| 15 | + [TestCase("ws://hello.com/", UriKind.Absolute, ExpectedResult = true)] |
| 16 | + [TestCase("wss://hello.com/", UriKind.Absolute, ExpectedResult = true)] |
| 17 | + [TestCase("https://hello.com:8080/", UriKind.Absolute, ExpectedResult = true)] |
| 18 | + [TestCase("http://hello.com:8080/", UriKind.Absolute, ExpectedResult = true)] |
| 19 | + [TestCase("https://hello.com/path", UriKind.Absolute, ExpectedResult = true)] |
| 20 | + [TestCase("http://hello.com/path", UriKind.Absolute, ExpectedResult = true)] |
| 21 | + [TestCase("https://hello.com/path?query=param", UriKind.Absolute, ExpectedResult = true)] |
| 22 | + [TestCase("http://hello.com/path?query=param", UriKind.Absolute, ExpectedResult = true)] |
| 23 | + [TestCase("https://hello.com/path#fragment", UriKind.Absolute, ExpectedResult = true)] |
| 24 | + [TestCase("http://hello.com/path#fragment", UriKind.Absolute, ExpectedResult = true)] |
| 25 | + [TestCase("https://hello.com/path?query=param#fragment", UriKind.Absolute, ExpectedResult = true)] |
| 26 | + [TestCase("http://hello.com/path?query=param#fragment", UriKind.Absolute, ExpectedResult = true)] |
| 27 | + [TestCase("https://hello.com:8080/path?query=param#fragment", UriKind.Absolute, ExpectedResult = true)] |
| 28 | + [TestCase("http://hello.com:8080/path?query=param#fragment", UriKind.Absolute, ExpectedResult = true)] |
| 29 | + [TestCase("//hello.com:8080/path?query=param#fragment", UriKind.Absolute, ExpectedResult = true)] |
| 30 | + [TestCase("//hello.com:8080/path", UriKind.Absolute, ExpectedResult = true)] |
| 31 | + [TestCase("//hello.com:8080", UriKind.Absolute, ExpectedResult = true)] |
| 32 | + [TestCase("//hello.com", UriKind.Absolute, ExpectedResult = true)] |
| 33 | + [TestCase("/test/test.jpg", UriKind.Absolute, ExpectedResult = false)] |
| 34 | + [TestCase("/test", UriKind.Absolute, ExpectedResult = false)] |
| 35 | + [TestCase("test", UriKind.Absolute, ExpectedResult = false)] |
| 36 | + [TestCase("", UriKind.Absolute, ExpectedResult = false)] |
| 37 | + [TestCase(null, UriKind.Absolute, ExpectedResult = false)] |
| 38 | + [TestCase("this is not welformed", UriKind.Absolute, ExpectedResult = false)] |
| 39 | + [TestCase("ftp://hello.com/", UriKind.Relative, ExpectedResult = false)] |
| 40 | + [TestCase("file:///hello.com/", UriKind.Relative, ExpectedResult = false)] |
| 41 | + [TestCase("ws://hello.com/", UriKind.Relative, ExpectedResult = false)] |
| 42 | + [TestCase("wss://hello.com/", UriKind.Relative, ExpectedResult = false)] |
| 43 | + [TestCase("https://hello.com:8080/", UriKind.Relative, ExpectedResult = false)] |
| 44 | + [TestCase("http://hello.com:8080/", UriKind.Relative, ExpectedResult = false)] |
| 45 | + [TestCase("https://hello.com/path", UriKind.Relative, ExpectedResult = false)] |
| 46 | + [TestCase("http://hello.com/path", UriKind.Relative, ExpectedResult = false)] |
| 47 | + [TestCase("https://hello.com/path?query=param", UriKind.Relative, ExpectedResult = false)] |
| 48 | + [TestCase("http://hello.com/path?query=param", UriKind.Relative, ExpectedResult = false)] |
| 49 | + [TestCase("https://hello.com/path#fragment", UriKind.Relative, ExpectedResult = false)] |
| 50 | + [TestCase("http://hello.com/path#fragment", UriKind.Relative, ExpectedResult = false)] |
| 51 | + [TestCase("https://hello.com/path?query=param#fragment", UriKind.Relative, ExpectedResult = false)] |
| 52 | + [TestCase("http://hello.com/path?query=param#fragment", UriKind.Relative, ExpectedResult = false)] |
| 53 | + [TestCase("https://hello.com:8080/path?query=param#fragment", UriKind.Relative, ExpectedResult = false)] |
| 54 | + [TestCase("http://hello.com:8080/path?query=param#fragment", UriKind.Relative, ExpectedResult = false)] |
| 55 | + [TestCase("//hello.com:8080/path?query=param#fragment", UriKind.Relative, ExpectedResult = false)] |
| 56 | + [TestCase("//hello.com:8080/path", UriKind.Relative, ExpectedResult = false)] |
| 57 | + [TestCase("//hello.com:8080", UriKind.Relative, ExpectedResult = false)] |
| 58 | + [TestCase("//hello.com", UriKind.Relative, ExpectedResult = false)] |
| 59 | + [TestCase("/test/test.jpg", UriKind.Relative, ExpectedResult = true)] |
| 60 | + [TestCase("/test", UriKind.Relative, ExpectedResult = true)] |
| 61 | + [TestCase("test", UriKind.Relative, ExpectedResult = true)] |
| 62 | + [TestCase("", UriKind.Relative, ExpectedResult = false)] |
| 63 | + [TestCase(null, UriKind.Relative, ExpectedResult = false)] |
| 64 | + [TestCase("this is not welformed", UriKind.Relative, ExpectedResult = false)] |
| 65 | + [TestCase("ftp://hello.com/", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 66 | + [TestCase("file:///hello.com/", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 67 | + [TestCase("ws://hello.com/", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 68 | + [TestCase("wss://hello.com/", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 69 | + [TestCase("https://hello.com:8080/", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 70 | + [TestCase("http://hello.com:8080/", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 71 | + [TestCase("https://hello.com/path", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 72 | + [TestCase("http://hello.com/path", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 73 | + [TestCase("https://hello.com/path?query=param", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 74 | + [TestCase("http://hello.com/path?query=param", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 75 | + [TestCase("https://hello.com/path#fragment", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 76 | + [TestCase("http://hello.com/path#fragment", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 77 | + [TestCase("https://hello.com/path?query=param#fragment", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 78 | + [TestCase("http://hello.com/path?query=param#fragment", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 79 | + [TestCase("https://hello.com:8080/path?query=param#fragment", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 80 | + [TestCase("http://hello.com:8080/path?query=param#fragment", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 81 | + [TestCase("//hello.com:8080/path?query=param#fragment", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 82 | + [TestCase("//hello.com:8080/path", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 83 | + [TestCase("//hello.com:8080", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 84 | + [TestCase("//hello.com", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 85 | + [TestCase("/test/test.jpg", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 86 | + [TestCase("/test", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 87 | + [TestCase("test", UriKind.RelativeOrAbsolute, ExpectedResult = true)] |
| 88 | + [TestCase("", UriKind.RelativeOrAbsolute, ExpectedResult = false)] |
| 89 | + [TestCase(null, UriKind.RelativeOrAbsolute, ExpectedResult = false)] |
| 90 | + [TestCase("this is not welformed", UriKind.RelativeOrAbsolute, ExpectedResult = false)] |
| 91 | + public bool IsWellFormedWebPath(string? webPath, UriKind uriKind) |
| 92 | + { |
| 93 | + return WebPath.IsWellFormedWebPath(webPath, uriKind); |
| 94 | + } |
| 95 | + |
| 96 | + } |
| 97 | +} |
0 commit comments