You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{0febe054-68ac-446f-b999-9068736d3cec}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="UriRelativeResolutionTest.cs" />
|
||||
<Compile Include="UriTests.cs" />
|
||||
<!-- Test common -->
|
||||
<Compile Include="$(CommonTestPath)\System\ThreadCultureChange.cs">
|
||||
<Link>Common\System\ThreadCultureChange.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
491
external/corefx/src/System.Private.Uri/tests/ExtendedFunctionalTests/UriRelativeResolutionTest.cs
vendored
Normal file
491
external/corefx/src/System.Private.Uri/tests/ExtendedFunctionalTests/UriRelativeResolutionTest.cs
vendored
Normal file
@@ -0,0 +1,491 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UriRelativeResolution
|
||||
/// </summary>
|
||||
public class UriRelativeResolutionTest
|
||||
{
|
||||
// See RFC 3986 Section 5.2.2 and 5.4 http://www.ietf.org/rfc/rfc3986.txt
|
||||
|
||||
private readonly Uri _fullBaseUri = new Uri("http://user:psw@host:9090/path1/path2/path3/fileA?query#fragment");
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsAbsolute_ReturnsFullAbsolute()
|
||||
{
|
||||
string absolute = "http://username:password@hostname:8080/p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, absolute);
|
||||
|
||||
Assert.Equal(absolute, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsAuthority_ReturnsBaseSchemePlusAuthority()
|
||||
{
|
||||
string authority = "//username:password@hostname:8080/p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, authority);
|
||||
|
||||
String expectedResult = _fullBaseUri.Scheme + ":" + authority;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsFullPath_ReturnsBaseAuthorityPlusFullPath()
|
||||
{
|
||||
string fullPath = "/p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, fullPath);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + fullPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsQueryAndFragment_ReturnsBaseAuthorityAndPathPlusQueryAndFragment()
|
||||
{
|
||||
string queryAndFragment = "?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, queryAndFragment);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Path) + queryAndFragment;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsQuery_ReturnsBaseAuthorityAndPathPlusQuery()
|
||||
{
|
||||
string query = "?AQuery";
|
||||
Uri resolved = new Uri(_fullBaseUri, query);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Path) + query;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsFragment_ReturnsBasePlusFragment()
|
||||
{
|
||||
string fragment = "#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, fragment);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Query) + fragment;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
// Drop the 'filename' part of the path
|
||||
// IE: http://a/b/c/d;p?q + y = http://a/b/c/y
|
||||
public void Uri_Relative_BaseVsPartialPath_ReturnsMergedPaths()
|
||||
{
|
||||
string partialPath = "p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSimplePartialPath_ReturnsMergedPaths()
|
||||
{
|
||||
string partialPath = "p1";
|
||||
Uri resolved = new Uri(_fullBaseUri, partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSimplePartialPathTrailingSlash_ReturnsMergedPaths()
|
||||
{
|
||||
string partialPath = "p1/";
|
||||
Uri resolved = new Uri(_fullBaseUri, partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
/* RFC 3986 Section 5.4.2 - System.Uri is a strict parser, not backward compatible with RFC 1630
|
||||
"Some parsers allow the scheme name to be present in a relative
|
||||
reference if it is the same as the base URI scheme. This is
|
||||
considered to be a loophole in prior specifications of partial URI
|
||||
[RFC1630]. Its use should be avoided but is allowed for backward
|
||||
compatibility.
|
||||
|
||||
"http:g" = "http:g" ; for strict parsers
|
||||
/ "http://a/b/c/g" ; for backward compatibility "*/
|
||||
public void Uri_Relative_BaseVsSimplePartialPathWithScheme_ReturnsPartialPathWithScheme()
|
||||
{
|
||||
string partialPath = "scheme:p1";
|
||||
Uri resolved = new Uri(_fullBaseUri, partialPath);
|
||||
|
||||
String expectedResult = partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsDoubleCharColinChar_ReturnsCharColinChar()
|
||||
{
|
||||
string basicUri = "gd:a";
|
||||
Uri resolved = new Uri(_fullBaseUri, basicUri);
|
||||
|
||||
String expectedResult = basicUri;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsFileLikeUri_MissingRootSlash_ThrowsUriFormatException()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
string partialPath = "g:a";
|
||||
Uri resolved = new Uri(_fullBaseUri, partialPath);
|
||||
});
|
||||
}
|
||||
|
||||
#region PathCompression
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSingleDotSlashStartingCompressPath_ReturnsMergedPathsWithoutSingleDot()
|
||||
{
|
||||
string compressable = "./";
|
||||
string partialPath = "p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable + partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsDoubleDotSlashStartingCompressPath_ReturnsBasePathBacksteppedOncePlusRelativePath()
|
||||
{
|
||||
string compressable = "../";
|
||||
string partialPath = "p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable + partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
baseUri = baseUri.Substring(0, baseUri.LastIndexOf("/"));
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsDoubleDoubleDotSlashStartingCompressPath_ReturnsBasePathBacksteppedTwicePlusRelativePath()
|
||||
{
|
||||
string compressable = "../../";
|
||||
string partialPath = "p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable + partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
baseUri = baseUri.Substring(0, baseUri.LastIndexOf("/"));
|
||||
baseUri = baseUri.Substring(0, baseUri.LastIndexOf("/"));
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsTrippleDoubleDotSlashStartingCompressPath_ReturnsBaseWithoutPathPlusRelativePath()
|
||||
{
|
||||
string compressable = "../../../";
|
||||
string partialPath = "p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable + partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Authority);
|
||||
String expectedResult = baseUri + "/" + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsTooManyDoubleDotSlashStartingCompressPath_ReturnsBaseWithoutPathPlusRelativePath()
|
||||
{
|
||||
string compressable = "../../../../";
|
||||
string partialPath = "p1/p2/p3/p4/file1?AQuery#TheFragment";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable + partialPath);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Authority);
|
||||
String expectedResult = baseUri + "/" + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSingleDotSlashEndingCompressPath_ReturnsMergedPathsWithoutSingleDot()
|
||||
{
|
||||
string compressable = "./";
|
||||
string partialPath = "p1/p2/p3/p4/";
|
||||
Uri resolved = new Uri(_fullBaseUri, partialPath + compressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSingleDotEndingCompressPath_ReturnsMergedPathsWithoutSingleDot()
|
||||
{
|
||||
string compressable = ".";
|
||||
string partialPath = "p1/p2/p3/p4/";
|
||||
Uri resolved = new Uri(_fullBaseUri, partialPath + compressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + partialPath;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSingleDot_ReturnsBasePathMinusFileWithoutSingleDot()
|
||||
{
|
||||
string compressable = ".";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1);
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSlashDot_ReturnsBaseMinusPath()
|
||||
{
|
||||
string compressable = "/.";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + "/";
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSlashDotSlashFile_ReturnsBasePlusRelativeFile()
|
||||
{
|
||||
string compressable = "/./file";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + "/file";
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSlashDoubleDotSlashFile_ReturnsBasePlusRelativeFile()
|
||||
{
|
||||
string compressable = "/../file";
|
||||
Uri resolved = new Uri(_fullBaseUri, compressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + "/file";
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsCharDot_ReturnsBasePathPlusCharDot()
|
||||
{
|
||||
string nonCompressable = "f.";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsDotChar_ReturnsBasePathPlusDotChar()
|
||||
{
|
||||
string nonCompressable = ".f";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsCharDoubleDot_ReturnsBasePathPlusCharDoubleDot()
|
||||
{
|
||||
string nonCompressable = "f..";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsDoubleDotChar_ReturnsBasePathPlusDoubleDotChar()
|
||||
{
|
||||
string nonCompressable = "..f";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsTrippleDot_ReturnsBasePathPlusTrippleDot()
|
||||
{
|
||||
string nonCompressable = "...";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String baseUri = _fullBaseUri.GetLeftPart(UriPartial.Path);
|
||||
String expectedResult = baseUri.Substring(0, baseUri.LastIndexOf("/") + 1) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsCharDotSlash_ReturnsCharDotSlash()
|
||||
{
|
||||
string nonCompressable = "/f./";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSlashDotCharSlash_ReturnsSlashDotCharSlash()
|
||||
{
|
||||
string nonCompressable = "/.f/";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsCharDoubleDotSlash_ReturnsCharDoubleDotSlash()
|
||||
{
|
||||
string nonCompressable = "/f../";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSlashDoubleDotCharSlash_ReturnsSlashDoubleDotCharSlash()
|
||||
{
|
||||
string nonCompressable = "/..f/";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseVsSlashTrippleDotSlash_ReturnsSlashTrippleDotSlash()
|
||||
{
|
||||
string nonCompressable = "/.../";
|
||||
Uri resolved = new Uri(_fullBaseUri, nonCompressable);
|
||||
|
||||
String expectedResult = _fullBaseUri.GetLeftPart(UriPartial.Authority) + nonCompressable;
|
||||
Assert.Equal(expectedResult, resolved.ToString());
|
||||
}
|
||||
|
||||
#endregion PathCompression
|
||||
|
||||
#region MakeRelativeToUri
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseMadeRelativeToSamePath_ReturnsQueryAndFragment()
|
||||
{
|
||||
Uri compareUri = new Uri("http://user:psw@host:9090/path1/path2/path3/fileA?AQuery#AFragment");
|
||||
Uri relative = _fullBaseUri.MakeRelativeUri(compareUri);
|
||||
|
||||
String expectedResult = "?AQuery#AFragment"; // compareUri.GetParts(UriComponents.Query | UriComponents.Fragment,UriFormat.Unescaped);
|
||||
Assert.Equal(expectedResult, relative.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseMadeRelativeToLastSlash_ReturnsDotSlashPlusQueryAndFragment()
|
||||
{
|
||||
Uri compareUri = new Uri("http://user:psw@host:9090/path1/path2/path3/?AQuery#AFragment");
|
||||
Uri relative = _fullBaseUri.MakeRelativeUri(compareUri);
|
||||
Uri reassembled = new Uri(_fullBaseUri, relative); // Symetric
|
||||
|
||||
|
||||
String expectedResult = "./" + "?AQuery#AFragment"; // compareUri.GetParts(UriComponents.Query | UriComponents.Fragment, UriFormat.Unescaped);
|
||||
Assert.Equal(expectedResult, relative.ToString());
|
||||
Assert.Equal(compareUri, reassembled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseMadeRelativeToLastSlash_ReturnsDotSlash()
|
||||
{
|
||||
Uri compareUri = new Uri("http://user:psw@host:9090/path1/path2/path3/");
|
||||
Uri relative = _fullBaseUri.MakeRelativeUri(compareUri);
|
||||
Uri reassembled = new Uri(_fullBaseUri, relative); // Symetric
|
||||
|
||||
String expectedResult = "./";
|
||||
Assert.Equal(expectedResult, relative.ToString());
|
||||
Assert.Equal(compareUri, reassembled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseMadeRelativeToLastSlashWithExtra_ReturnsDotSlashPlusQueryAndFragment()
|
||||
{
|
||||
Uri compareUri = new Uri("http://user:psw@host:9090/path1/path2/path3/Path4/fileb?AQuery#AFragment");
|
||||
Uri relative = _fullBaseUri.MakeRelativeUri(compareUri);
|
||||
Uri reassembled = new Uri(_fullBaseUri, relative); // Symetric
|
||||
|
||||
String expectedResult = "Path4/fileb" + "?AQuery#AFragment"; // compareUri.GetParts(UriComponents.Query | UriComponents.Fragment, UriFormat.Unescaped);
|
||||
Assert.Equal(expectedResult, relative.ToString());
|
||||
Assert.Equal(compareUri, reassembled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseMadeRelativeToSecondToLastSlash_ReturnsDoubleDotSlashPlusQueryAndFragment()
|
||||
{
|
||||
Uri compareUri = new Uri("http://user:psw@host:9090/path1/path2/?AQuery#AFragment");
|
||||
Uri relative = _fullBaseUri.MakeRelativeUri(compareUri);
|
||||
Uri reassembled = new Uri(_fullBaseUri, relative); // Symetric
|
||||
|
||||
String expectedResult = "../" + "?AQuery#AFragment"; // compareUri.GetParts(UriComponents.Query | UriComponents.Fragment, UriFormat.Unescaped);
|
||||
Assert.Equal(expectedResult, relative.ToString());
|
||||
Assert.Equal(compareUri, reassembled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseMadeRelativeToThirdToLastSlash_ReturnsDoubleDoubleDotSlashPlusQueryAndFragment()
|
||||
{
|
||||
Uri compareUri = new Uri("http://user:psw@host:9090/path1/?AQuery#AFragment");
|
||||
Uri relative = _fullBaseUri.MakeRelativeUri(compareUri);
|
||||
Uri reassembled = new Uri(_fullBaseUri, relative); // Symetric
|
||||
|
||||
String expectedResult = "../../" + "?AQuery#AFragment"; // compareUri.GetParts(UriComponents.Query | UriComponents.Fragment, UriFormat.Unescaped);
|
||||
Assert.Equal(expectedResult, relative.ToString());
|
||||
Assert.Equal(compareUri, reassembled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_Relative_BaseMadeRelativeToEmptyPath_ReturnsTrippleDoubleDotSlashPlusQueryAndFragment()
|
||||
{
|
||||
Uri compareUri = new Uri("http://user:psw@host:9090/?AQuery#AFragment");
|
||||
Uri relative = _fullBaseUri.MakeRelativeUri(compareUri);
|
||||
Uri reassembled = new Uri(_fullBaseUri, relative); // Symetric
|
||||
|
||||
String expectedResult = "../../../" + "?AQuery#AFragment"; // compareUri.GetParts(UriComponents.Query | UriComponents.Fragment, UriFormat.Unescaped);
|
||||
Assert.Equal(expectedResult, relative.ToString());
|
||||
Assert.Equal(compareUri, reassembled);
|
||||
}
|
||||
|
||||
#endregion MakeRelativeToUri
|
||||
|
||||
[Fact]
|
||||
public void UriRelative_AbsoluteToAbsolute_CustomPortCarriedOver()
|
||||
{
|
||||
Uri baseUri = new Uri("http://nothing.com/");
|
||||
Uri testUri = new Uri("https://specialPort.com:00065535/path?query#fragment");
|
||||
|
||||
int throwAway = testUri.Port; // Trigger parsing.
|
||||
|
||||
Uri resultUri = new Uri(baseUri, testUri);
|
||||
|
||||
throwAway = resultUri.Port; // For Debugging.
|
||||
|
||||
Assert.Equal(testUri.Port, resultUri.Port);
|
||||
}
|
||||
}
|
||||
}
|
||||
248
external/corefx/src/System.Private.Uri/tests/ExtendedFunctionalTests/UriTests.cs
vendored
Normal file
248
external/corefx/src/System.Private.Uri/tests/ExtendedFunctionalTests/UriTests.cs
vendored
Normal file
@@ -0,0 +1,248 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public static class UriTests
|
||||
{
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
[Theory]
|
||||
public static void TestCtor_String_Boolean(bool dontEscape)
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
#pragma warning disable 0612
|
||||
Uri uri = new Uri(@"http://foo/bar/baz#frag", dontEscape);
|
||||
#pragma warning restore 0612
|
||||
#pragma warning restore 0618
|
||||
|
||||
int i;
|
||||
String s;
|
||||
bool b;
|
||||
UriHostNameType uriHostNameType;
|
||||
String[] ss;
|
||||
|
||||
s = uri.ToString();
|
||||
Assert.Equal(s, @"http://foo/bar/baz#frag");
|
||||
|
||||
s = uri.AbsolutePath;
|
||||
Assert.Equal<String>(s, @"/bar/baz");
|
||||
|
||||
s = uri.AbsoluteUri;
|
||||
Assert.Equal<String>(s, @"http://foo/bar/baz#frag");
|
||||
|
||||
s = uri.Authority;
|
||||
Assert.Equal<String>(s, @"foo");
|
||||
|
||||
s = uri.DnsSafeHost;
|
||||
Assert.Equal<String>(s, @"foo");
|
||||
|
||||
s = uri.Fragment;
|
||||
Assert.Equal<String>(s, @"#frag");
|
||||
|
||||
s = uri.Host;
|
||||
Assert.Equal<String>(s, @"foo");
|
||||
|
||||
uriHostNameType = uri.HostNameType;
|
||||
Assert.Equal<UriHostNameType>(uriHostNameType, UriHostNameType.Dns);
|
||||
|
||||
b = uri.IsAbsoluteUri;
|
||||
Assert.True(b);
|
||||
|
||||
b = uri.IsDefaultPort;
|
||||
Assert.True(b);
|
||||
|
||||
b = uri.IsFile;
|
||||
Assert.False(b);
|
||||
|
||||
b = uri.IsLoopback;
|
||||
Assert.False(b);
|
||||
|
||||
b = uri.IsUnc;
|
||||
Assert.False(b);
|
||||
|
||||
s = uri.LocalPath;
|
||||
Assert.Equal<String>(s, @"/bar/baz");
|
||||
|
||||
s = uri.OriginalString;
|
||||
Assert.Equal<String>(s, @"http://foo/bar/baz#frag");
|
||||
|
||||
s = uri.PathAndQuery;
|
||||
Assert.Equal<String>(s, @"/bar/baz");
|
||||
|
||||
i = uri.Port;
|
||||
Assert.Equal<int>(i, 80);
|
||||
|
||||
s = uri.Query;
|
||||
Assert.Equal<String>(s, @"");
|
||||
|
||||
s = uri.Scheme;
|
||||
Assert.Equal<String>(s, @"http");
|
||||
|
||||
ss = uri.Segments;
|
||||
Assert.Equal<int>(ss.Length, 3);
|
||||
Assert.Equal<String>(ss[0], @"/");
|
||||
Assert.Equal<String>(ss[1], @"bar/");
|
||||
Assert.Equal<String>(ss[2], @"baz");
|
||||
|
||||
b = uri.UserEscaped;
|
||||
Assert.Equal(b, dontEscape);
|
||||
|
||||
s = uri.UserInfo;
|
||||
Assert.Equal<String>(s, @"");
|
||||
}
|
||||
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
[Theory]
|
||||
public static void TestCtor_Uri_String_Boolean(bool dontEscape)
|
||||
{
|
||||
Uri uri;
|
||||
|
||||
uri = new Uri(@"http://www.contoso.com/");
|
||||
#pragma warning disable 0618
|
||||
uri = new Uri(uri, "catalog/shownew.htm?date=today", dontEscape);
|
||||
#pragma warning restore 0618
|
||||
|
||||
int i;
|
||||
String s;
|
||||
bool b;
|
||||
UriHostNameType uriHostNameType;
|
||||
String[] ss;
|
||||
|
||||
s = uri.ToString();
|
||||
Assert.Equal(s, @"http://www.contoso.com/catalog/shownew.htm?date=today");
|
||||
|
||||
s = uri.AbsolutePath;
|
||||
Assert.Equal<String>(s, @"/catalog/shownew.htm");
|
||||
|
||||
s = uri.AbsoluteUri;
|
||||
Assert.Equal<String>(s, @"http://www.contoso.com/catalog/shownew.htm?date=today");
|
||||
|
||||
s = uri.Authority;
|
||||
Assert.Equal<String>(s, @"www.contoso.com");
|
||||
|
||||
s = uri.DnsSafeHost;
|
||||
Assert.Equal<String>(s, @"www.contoso.com");
|
||||
|
||||
s = uri.Fragment;
|
||||
Assert.Equal<String>(s, @"");
|
||||
|
||||
s = uri.Host;
|
||||
Assert.Equal<String>(s, @"www.contoso.com");
|
||||
|
||||
uriHostNameType = uri.HostNameType;
|
||||
Assert.Equal<UriHostNameType>(uriHostNameType, UriHostNameType.Dns);
|
||||
|
||||
b = uri.IsAbsoluteUri;
|
||||
Assert.True(b);
|
||||
|
||||
b = uri.IsDefaultPort;
|
||||
Assert.True(b);
|
||||
|
||||
b = uri.IsFile;
|
||||
Assert.False(b);
|
||||
|
||||
b = uri.IsLoopback;
|
||||
Assert.False(b);
|
||||
|
||||
b = uri.IsUnc;
|
||||
Assert.False(b);
|
||||
|
||||
s = uri.LocalPath;
|
||||
Assert.Equal<String>(s, @"/catalog/shownew.htm");
|
||||
|
||||
s = uri.OriginalString;
|
||||
Assert.Equal<String>(s, @"http://www.contoso.com/catalog/shownew.htm?date=today");
|
||||
|
||||
s = uri.PathAndQuery;
|
||||
Assert.Equal<String>(s, @"/catalog/shownew.htm?date=today");
|
||||
|
||||
i = uri.Port;
|
||||
Assert.Equal<int>(i, 80);
|
||||
|
||||
s = uri.Query;
|
||||
Assert.Equal<String>(s, @"?date=today");
|
||||
|
||||
s = uri.Scheme;
|
||||
Assert.Equal<String>(s, @"http");
|
||||
|
||||
ss = uri.Segments;
|
||||
Assert.Equal<int>(ss.Length, 3);
|
||||
Assert.Equal<String>(ss[0], @"/");
|
||||
Assert.Equal<String>(ss[1], @"catalog/");
|
||||
Assert.Equal<String>(ss[2], @"shownew.htm");
|
||||
|
||||
b = uri.UserEscaped;
|
||||
Assert.Equal(b, dontEscape);
|
||||
|
||||
s = uri.UserInfo;
|
||||
Assert.Equal<String>(s, @"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestMakeRelative_Invalid()
|
||||
{
|
||||
var baseUri = new Uri("http://www.domain.com/");
|
||||
var relativeUri = new Uri("/path/", UriKind.Relative);
|
||||
#pragma warning disable 0618
|
||||
Assert.Throws<ArgumentNullException>("toUri", () => baseUri.MakeRelative(null)); // Uri is null
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => relativeUri.MakeRelative(baseUri)); // Base uri is relative
|
||||
Assert.Throws<InvalidOperationException>(() => baseUri.MakeRelative(relativeUri)); // Uri is relative
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestMakeRelative()
|
||||
{
|
||||
// Create a base Uri.
|
||||
Uri address1 = new Uri("http://www.contoso.com/");
|
||||
Uri address2 = new Uri("http://www.contoso.com:8000/");
|
||||
Uri address3 = new Uri("http://username@www.contoso.com/");
|
||||
|
||||
// Create a new Uri from a string.
|
||||
Uri address4 = new Uri("http://www.contoso.com/index.htm?date=today");
|
||||
#pragma warning disable 0618
|
||||
// Determine the relative Uri.
|
||||
string uriStr1 = address1.MakeRelative(address4);
|
||||
string uriStr2 = address2.MakeRelative(address4);
|
||||
string uriStr3 = address3.MakeRelative(address4);
|
||||
#pragma warning restore 0618
|
||||
|
||||
Assert.Equal(uriStr1, @"index.htm");
|
||||
Assert.Equal(uriStr2, @"http://www.contoso.com/index.htm?date=today");
|
||||
Assert.Equal(uriStr3, @"index.htm");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestHexMethods()
|
||||
{
|
||||
char testChar = 'e';
|
||||
Assert.True(Uri.IsHexDigit(testChar));
|
||||
Assert.Equal(14, Uri.FromHex(testChar));
|
||||
|
||||
string hexString = Uri.HexEscape(testChar);
|
||||
Assert.Equal(hexString, "%65");
|
||||
|
||||
int index = 0;
|
||||
Assert.True(Uri.IsHexEncoding(hexString, index));
|
||||
Assert.Equal(testChar, Uri.HexUnescape(hexString, ref index));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestHexMethods_Invalid()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => Uri.FromHex('?'));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Uri.HexEscape('\x100'));
|
||||
int index = -1;
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Uri.HexUnescape("%75", ref index));
|
||||
index = 0;
|
||||
Uri.HexUnescape("%75", ref index);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Uri.HexUnescape("%75", ref index));
|
||||
}
|
||||
}
|
||||
}
|
||||
18
external/corefx/src/System.Private.Uri/tests/FunctionalTests/AppxUriValue.cs
vendored
Normal file
18
external/corefx/src/System.Private.Uri/tests/FunctionalTests/AppxUriValue.cs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public class AppxUriValues
|
||||
{
|
||||
[Fact]
|
||||
public static void SupportStringsOfForm_MsApp()
|
||||
{
|
||||
var uri = new Uri("ms-app://s-1-15-2-123456789-1234567890-1234567890-098765432-123456789-0987765432-0987654321");
|
||||
Assert.NotNull(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IdnCheckHostNameTest.cs
vendored
Normal file
61
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IdnCheckHostNameTest.cs
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Net;
|
||||
using System.Common.Tests;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public class IdnCheckHostNameTest
|
||||
{
|
||||
[Fact]
|
||||
public void IdnCheckHostName_Empty_Unknown()
|
||||
{
|
||||
Assert.Equal(UriHostNameType.Unknown, Uri.CheckHostName(String.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnCheckHostName_FlatDns_Dns()
|
||||
{
|
||||
Assert.Equal(UriHostNameType.Dns, Uri.CheckHostName("Host"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnCheckHostName_FqdnDns_Dns()
|
||||
{
|
||||
Assert.Equal(UriHostNameType.Dns, Uri.CheckHostName("Host.corp.micorosoft.com"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnCheckHostName_IPv4_IPv4()
|
||||
{
|
||||
Assert.Equal(UriHostNameType.IPv4, Uri.CheckHostName(IPAddress.Loopback.ToString()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnCheckHostName_IPv6WithoutBrackets_IPv6()
|
||||
{
|
||||
Assert.Equal(UriHostNameType.IPv6, Uri.CheckHostName(IPAddress.IPv6Loopback.ToString()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnCheckHostName_IPv6WithBrackets_IPv6()
|
||||
{
|
||||
Assert.Equal(UriHostNameType.IPv6, Uri.CheckHostName("[" + IPAddress.IPv6Loopback.ToString() + "]"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnCheckHostName_UnicodeIdnOffIriOn_Dns()
|
||||
{
|
||||
using (var helper = new ThreadCultureChange())
|
||||
{
|
||||
Assert.Equal(UriHostNameType.Dns, Uri.CheckHostName("nZMot\u00E1\u00D3\u0063vKi\u00CD.contoso.com"));
|
||||
helper.ChangeCultureInfo("zh-cn");
|
||||
Assert.Equal(UriHostNameType.Dns, Uri.CheckHostName("nZMot\u00E1\u00D3\u0063vKi\u00CD.contoso.com"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
81
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IdnDnsSafeHostTest.cs
vendored
Normal file
81
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IdnDnsSafeHostTest.cs
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for IdnDnsSafeHostTest
|
||||
/// </summary>
|
||||
public class IdnDnsSafeHostTest
|
||||
{
|
||||
[Fact]
|
||||
public void IdnDnsSafeHost_IdnOffWithBuiltInScheme_Success()
|
||||
{
|
||||
Uri test = new Uri("http://www.\u30AF.com/");
|
||||
|
||||
string dns = test.DnsSafeHost;
|
||||
|
||||
Assert.True(dns.IndexOf('%') < 0, "% found");
|
||||
Assert.True(test.AbsoluteUri.IndexOf('%') < 0, "% found: " + test.AbsoluteUri);
|
||||
Assert.True(test.ToString().IndexOf('%') < 0, "% found: " + test.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnDnsSafeHost_IdnOffWithUnregisteredScheme_Success()
|
||||
{
|
||||
Uri test = new Uri("any://www.\u30AF.com/");
|
||||
|
||||
string dns = test.DnsSafeHost;
|
||||
|
||||
Assert.True(dns.IndexOf('%') < 0, "% found");
|
||||
Assert.True(test.AbsoluteUri.IndexOf('%') < 0, "% found: " + test.AbsoluteUri);
|
||||
Assert.True(test.ToString().IndexOf('%') < 0, "% found: " + test.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnDnsSafeHost_IPv6Host_ScopeIdButNoBrackets()
|
||||
{
|
||||
Uri test = new Uri("http://[::1%23]/");
|
||||
|
||||
Assert.Equal("::1%23", test.DnsSafeHost);
|
||||
Assert.Equal("::1%23", test.IdnHost);
|
||||
Assert.Equal("[::1]", test.Host);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnDnsSafeHost_MixedCase_ToLowerCase()
|
||||
{
|
||||
Uri test = new Uri("HTTPS://www.xn--pck.COM/");
|
||||
|
||||
Assert.Equal("www.xn--pck.com", test.Host);
|
||||
Assert.Equal("www.xn--pck.com", test.DnsSafeHost);
|
||||
Assert.Equal("www.xn--pck.com", test.IdnHost);
|
||||
Assert.Equal("https://www.xn--pck.com/", test.AbsoluteUri);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnDnsSafeHost_SingleLabelAllExceptIntranet_Unicode()
|
||||
{
|
||||
Uri test = new Uri("HTTPS://\u30AF/");
|
||||
|
||||
Assert.Equal("\u30AF", test.Host);
|
||||
Assert.Equal("\u30AF", test.DnsSafeHost);
|
||||
Assert.Equal("xn--pck", test.IdnHost);
|
||||
Assert.Equal("https://\u30AF/", test.AbsoluteUri);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnDnsSafeHost_MultiLabelAllExceptIntranet_Punycode()
|
||||
{
|
||||
Uri test = new Uri("HTTPS://\u30AF.com/");
|
||||
|
||||
Assert.Equal("\u30AF.com", test.Host);
|
||||
Assert.Equal("\u30AF.com", test.DnsSafeHost);
|
||||
Assert.Equal("xn--pck.com", test.IdnHost);
|
||||
Assert.Equal("https://\u30AF.com/", test.AbsoluteUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
137
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IdnHostNameValidationTest.cs
vendored
Normal file
137
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IdnHostNameValidationTest.cs
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public class IdnHostNameValidationTest
|
||||
{
|
||||
[Fact]
|
||||
public void IdnHost_Call()
|
||||
{
|
||||
Uri u = new Uri("http://someHost\u1234.com");
|
||||
Assert.Equal("xn--somehost-vk7a.com", u.IdnHost);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_Call_ThrowsException()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
Uri u = new Uri("/test/test2/file.tst", UriKind.Relative);
|
||||
string s = u.IdnHost;
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_UnknownFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("unknown");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_HttpFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("http");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_FtpUnicodeFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("ftp");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_FileFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("file");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_NetPipeFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("net.pipe");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_NetTcpFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("net.tcp");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_VSMacrosFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("vsmacros");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_GopherFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("gopher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_NntpFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("nntp");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_TelnetFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("telnet");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_LdapFqdn_Success()
|
||||
{
|
||||
CommonSchemesTest("ldap");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdnHost_Internal_Call_ThrowsException()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
Uri u = new Uri("/test/test2/file.tst", UriKind.Relative);
|
||||
string s = u.DnsSafeHost;
|
||||
});
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
public void CommonSchemesTest(string scheme)
|
||||
{
|
||||
string unicodeHost = "a\u00FChost.dom\u00FCin.n\u00FCet";
|
||||
string punycodeHost = "xn--ahost-kva.xn--domin-mva.xn--net-hoa";
|
||||
|
||||
// initial unicode host
|
||||
ValidateUri(scheme, unicodeHost, UriHostNameType.Dns, unicodeHost, unicodeHost, punycodeHost);
|
||||
|
||||
// initial punycode host
|
||||
ValidateUri(scheme, punycodeHost, UriHostNameType.Dns, punycodeHost, punycodeHost, punycodeHost);
|
||||
}
|
||||
|
||||
public void ValidateUri(
|
||||
string scheme,
|
||||
string host,
|
||||
UriHostNameType expectedHostType,
|
||||
string expectedHost,
|
||||
string expectedDnsSafeHost,
|
||||
string expectedIdnHost)
|
||||
{
|
||||
Uri uri;
|
||||
Assert.True(Uri.TryCreate(scheme + "://" + host, UriKind.Absolute, out uri));
|
||||
Assert.Equal(expectedHost, uri.Host);
|
||||
Assert.Equal(expectedDnsSafeHost, uri.DnsSafeHost);
|
||||
Assert.Equal(expectedHostType, uri.HostNameType);
|
||||
Assert.Equal(expectedHostType, Uri.CheckHostName(host));
|
||||
Assert.Equal(expectedIdnHost, uri.IdnHost);
|
||||
}
|
||||
|
||||
#endregion Helpers
|
||||
}
|
||||
}
|
||||
312
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IriRelativeFileResolutionTest.cs
vendored
Normal file
312
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IriRelativeFileResolutionTest.cs
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// These tests attempt to verify the transitivity of Uri.MakeRelativeUri with new Uri(base, rel).
|
||||
/// Specifically these tests address the use of Unicode and Iri with explicit and implicit file Uris.
|
||||
/// Note: Many of the test only partially pass with the currrent Uri implementation. Known discrepancies
|
||||
/// have been marked as expected so that we can still track changes.
|
||||
/// </summary>
|
||||
public class IriRelativeFileResolutionTest
|
||||
{
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndExplicitFileWithNoUnicode_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeImplicitTestFile = @"c:\path\path3\test.txt";
|
||||
string nonUnicodeImplicitFileBase = @"c:\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareImplicitVsExplicitFiles(nonUnicodeImplicitTestFile,
|
||||
nonUnicodeImplicitFileBase, out testResults);
|
||||
Assert.True((errorCount == 0), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndExplicitFileWithReservedChar_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeImplicitTestFile = @"c:\path\path3\test.txt%25%";
|
||||
string nonUnicodeImplicitFileBase = @"c:\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareImplicitVsExplicitFiles(nonUnicodeImplicitTestFile,
|
||||
nonUnicodeImplicitFileBase, out testResults);
|
||||
Assert.True((errorCount == 4), testResults);
|
||||
// AbsolutePath, AbsoluteUri, LocalPath, PathAndQuery
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndExplicitFileWithUnicodeIriOn_AllPropertiesTheSame()
|
||||
{
|
||||
string unicodeImplicitTestFile = @"c:\path\\u30AF\path3\\u30EB\u30DE.text";
|
||||
string nonUnicodeImplicitFileBase = @"c:\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareImplicitVsExplicitFiles(unicodeImplicitTestFile,
|
||||
nonUnicodeImplicitFileBase, out testResults);
|
||||
Assert.True((errorCount == 0), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndExplicitFileWithUnicodeAndReservedCharIriOn_AllPropertiesTheSame()
|
||||
{
|
||||
string unicodeImplicitTestFile = @"c:\path\\u30AF\path3\\u30EB\u30DE.text%25%";
|
||||
string nonUnicodeImplicitFileBase = @"c:\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareImplicitVsExplicitFiles(unicodeImplicitTestFile,
|
||||
nonUnicodeImplicitFileBase, out testResults);
|
||||
Assert.True((errorCount == 4), testResults);
|
||||
// AbsolutePath, AbsoluteUri, LocalPath, PathAndQuery
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndExplicitUncWithNoUnicode_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeImplicitTestUnc = @"\\c\path\path3\test.txt";
|
||||
string nonUnicodeImplicitUncBase = @"\\c\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareImplicitVsExplicitFiles(nonUnicodeImplicitTestUnc,
|
||||
nonUnicodeImplicitUncBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndExplicitUncForwardSlashesWithNoUnicode_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeImplicitTestUnc = @"//c/path/path3/test.txt";
|
||||
string nonUnicodeImplicitUncBase = @"//c/path/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareImplicitVsExplicitFiles(nonUnicodeImplicitTestUnc,
|
||||
nonUnicodeImplicitUncBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndExplicitUncWithUnicodeIriOn_AllPropertiesTheSame()
|
||||
{
|
||||
string unicodeImplicitTestUnc = @"\\c\path\\u30AF\path3\\u30EB\u30DE.text";
|
||||
string nonUnicodeImplicitUncBase = @"\\c\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareImplicitVsExplicitFiles(unicodeImplicitTestUnc,
|
||||
nonUnicodeImplicitUncBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
public static int RelatavizeRestoreCompareImplicitVsExplicitFiles(string original,
|
||||
string baseString, out string errors)
|
||||
{
|
||||
Uri implicitTestUri = new Uri(original);
|
||||
Uri implicitBaseUri = new Uri(baseString);
|
||||
Uri explicitBaseUri = new Uri("file:///" + baseString);
|
||||
|
||||
Uri rel = implicitBaseUri.MakeRelativeUri(implicitTestUri);
|
||||
Uri implicitResultUri = new Uri(implicitBaseUri, rel);
|
||||
Uri explicitResultUri = new Uri(explicitBaseUri, rel);
|
||||
|
||||
Type uriType = typeof(Uri);
|
||||
PropertyInfo[] infoList = uriType.GetProperties();
|
||||
StringBuilder testResults = new StringBuilder();
|
||||
int errorCount = 0;
|
||||
foreach (PropertyInfo info in infoList)
|
||||
{
|
||||
string implicitValue = info.GetValue(implicitResultUri, null).ToString();
|
||||
string explicitValue = info.GetValue(explicitResultUri, null).ToString();
|
||||
if (!(implicitValue.Equals(explicitValue) || ("file:///" + implicitValue).Equals(explicitValue)))
|
||||
{
|
||||
errorCount++;
|
||||
testResults.Append("Property mismatch: " + info.Name + ", implicit value: " + implicitValue
|
||||
+ ", explicit value: " + explicitValue + "; ");
|
||||
}
|
||||
}
|
||||
|
||||
string implicitString = implicitResultUri.ToString();
|
||||
string explicitString = explicitResultUri.ToString();
|
||||
if (!implicitString.Equals(explicitString))
|
||||
{
|
||||
errorCount++;
|
||||
testResults.Append("ToString mismatch; implicit value: " + implicitString
|
||||
+ ", explicit value: " + explicitString);
|
||||
}
|
||||
|
||||
errors = testResults.ToString();
|
||||
return errorCount;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareImplcitAndOriginalFileWithNoUnicode_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeImplicitTestFile = @"c:\path\path3\test.txt";
|
||||
string nonUnicodeImplicitFileBase = @"c:\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(nonUnicodeImplicitTestFile,
|
||||
nonUnicodeImplicitFileBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareUncAndOriginalFileWithNoUnicode_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeUncTestFile = @"\\c\path\path3\test.txt";
|
||||
string nonUnicodeUncFileBase = @"\\c\path\file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(nonUnicodeUncTestFile,
|
||||
nonUnicodeUncFileBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareUncForwardSlashesAndOriginalFileWithNoUnicode_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeUncTestFile = @"//c/path/path3/test.txt";
|
||||
string nonUnicodeUncFileBase = @"//c/path/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(nonUnicodeUncTestFile,
|
||||
nonUnicodeUncFileBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareRelativeAndOriginalHttpWithNoUnicode_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeTest = @"http://user:password@host.com:9090/path/path3/test.txt";
|
||||
string nonUnicodeBase = @"http://user:password@host.com:9090/path2/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(nonUnicodeTest,
|
||||
nonUnicodeBase, out testResults);
|
||||
Assert.True((errorCount == 0), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareRelativeAndOriginalHttpWithNoUnicodeAndReservedChar_AllPropertiesTheSame()
|
||||
{
|
||||
string nonUnicodeTest = @"http://user:password@host.com:9090/path/path3/test.txt%25%";
|
||||
string nonUnicodeBase = @"http://user:password@host.com:9090/path2/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(nonUnicodeTest,
|
||||
nonUnicodeBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareRelativeAndOriginalHttpWithUnicodeIriOff_AllPropertiesTheSame()
|
||||
{
|
||||
string unicodeTest = @"http://user:password@host.com:9090/path\u30AF/path3/ルtest.txt";
|
||||
string nonUnicodeBase = @"http://user:password@host.com:9090/path2/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(unicodeTest,
|
||||
nonUnicodeBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareRelativeAndOriginalHttpWithUnicodeAndReservedCharIriOff_AllPropertiesTheSame()
|
||||
{
|
||||
string unicodeTest = @"http://user:password@host.com:9090/path\u30AF/path3/ルtest.txt%25%";
|
||||
string nonUnicodeBase = @"http://user:password@host.com:9090/path2/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(unicodeTest,
|
||||
nonUnicodeBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareRelativeAndOriginalHttpWithUnicodeIriOn_AllPropertiesTheSame()
|
||||
{
|
||||
string unicodeTest = @"http://user:password@host.com:9090/path\u30AF/path3/ルtest.txt";
|
||||
string nonUnicodeBase = @"http://user:password@host.com:9090/path2/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(unicodeTest,
|
||||
nonUnicodeBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IriRelativeResolution_CompareRelativeAndOriginalHttpWithUnicodeAndReservedCharIriOn_AllPropertiesTheSame()
|
||||
{
|
||||
string unicodeTest = @"http://user:password@host.com:9090/path\u30AF/path3/ルtest.txt%25%";
|
||||
string nonUnicodeBase = @"http://user:password@host.com:9090/path2/file.txt";
|
||||
|
||||
string testResults;
|
||||
int errorCount = RelatavizeRestoreCompareVsOriginal(unicodeTest,
|
||||
nonUnicodeBase, out testResults);
|
||||
Assert.True((errorCount == 1), testResults);
|
||||
Assert.True(IsOriginalString(testResults), testResults);
|
||||
}
|
||||
|
||||
public static int RelatavizeRestoreCompareVsOriginal(string original, string baseString, out string errors)
|
||||
{
|
||||
Uri startUri = new Uri(original);
|
||||
string abs = startUri.AbsolutePath;
|
||||
Uri baseUri = new Uri(baseString);
|
||||
|
||||
Uri rel = baseUri.MakeRelativeUri(startUri);
|
||||
//string relString = rel.ToString(); // For debugging
|
||||
|
||||
Uri stage2Uri = new Uri(baseUri, rel); // Test for true transitivity with an extra cycle
|
||||
rel = baseUri.MakeRelativeUri(stage2Uri);
|
||||
Uri resultUri = new Uri(baseUri, rel);
|
||||
|
||||
Type uriType = typeof(Uri);
|
||||
PropertyInfo[] infoList = uriType.GetProperties();
|
||||
StringBuilder testResults = new StringBuilder();
|
||||
int errorCount = 0;
|
||||
foreach (PropertyInfo info in infoList)
|
||||
{
|
||||
string resultValue = info.GetValue(resultUri, null).ToString();
|
||||
string startValue = info.GetValue(startUri, null).ToString();
|
||||
if (!resultValue.Equals(startValue))
|
||||
{
|
||||
errorCount++;
|
||||
testResults.Append("Property mismatch: " + info.Name + ", result value: "
|
||||
+ resultValue + ", start value: " + startValue + "; ");
|
||||
}
|
||||
}
|
||||
|
||||
string resultString = resultUri.ToString();
|
||||
string startString = startUri.ToString();
|
||||
if (!resultString.Equals(startString))
|
||||
{
|
||||
errorCount++;
|
||||
testResults.Append("ToString mismatch; result value: " + resultString
|
||||
+ ", start value: " + startString);
|
||||
}
|
||||
|
||||
errors = testResults.ToString();
|
||||
return errorCount;
|
||||
}
|
||||
|
||||
private static bool IsOriginalString(string error)
|
||||
{
|
||||
return error.StartsWith("Property mismatch: OriginalString,");
|
||||
}
|
||||
}
|
||||
}
|
||||
525
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IriTest.cs
vendored
Normal file
525
external/corefx/src/System.Private.Uri/tests/FunctionalTests/IriTest.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{B0FFC4A8-BAC3-4A7F-8FD5-5B680209371C}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="AppxUriValue.cs" />
|
||||
<Compile Include="IdnCheckHostNameTest.cs" />
|
||||
<Compile Include="IdnDnsSafeHostTest.cs" />
|
||||
<Compile Include="IdnHostNameValidationTest.cs" />
|
||||
<Compile Include="IriRelativeFileResolutionTest.cs" />
|
||||
<Compile Include="IriTest.cs" />
|
||||
<Compile Include="UriBuilderParameterTest.cs" />
|
||||
<Compile Include="UriBuilderRefreshTest.cs" />
|
||||
<Compile Include="UriBuilderTests.cs" />
|
||||
<Compile Include="UriEscapingTest.cs" />
|
||||
<Compile Include="UriGetComponentsTest.cs" />
|
||||
<Compile Include="UriIpHostTest.cs" />
|
||||
<Compile Include="UriIsWellFormedUriStringTest.cs" />
|
||||
<Compile Include="UriMailToTest.cs" />
|
||||
<Compile Include="UriParameterValidationTest.cs" />
|
||||
<Compile Include="UriRelativeResolutionTest.cs" />
|
||||
<Compile Include="UriTests.cs" />
|
||||
<Compile Include="WebSocketsUriParserTest.cs" />
|
||||
<!-- Test common -->
|
||||
<Compile Include="$(CommonTestPath)\System\ThreadCultureChange.cs">
|
||||
<Link>Common\System\ThreadCultureChange.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)'=='netstandard'">
|
||||
<Compile Include="UriParserTest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
23
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriBuilderParameterTest.cs
vendored
Normal file
23
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriBuilderParameterTest.cs
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UriBuilderParamiterTest
|
||||
/// </summary>
|
||||
public class UriBuilderParameterTest
|
||||
{
|
||||
[Fact]
|
||||
public void UriBuilder_Ctor_NullParameter_ThrowsArgumentException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
UriBuilder builder = new UriBuilder((Uri)null);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
109
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriBuilderRefreshTest.cs
vendored
Normal file
109
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriBuilderRefreshTest.cs
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public class UriBuilderRefreshTest
|
||||
{
|
||||
private static Uri s_starterUri = new Uri("http://user:psw@host:9090/path/file.txt?query#fragment");
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangeScheme_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<String>(s_starterUri.Scheme, builder.Scheme);
|
||||
Assert.Equal<String>(s_starterUri.Scheme, builder.Uri.Scheme);
|
||||
String newValue = "newvalue";
|
||||
builder.Scheme = newValue;
|
||||
Assert.Equal<String>(newValue, builder.Scheme);
|
||||
Assert.Equal<String>(newValue, builder.Uri.Scheme);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangeUser_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<String>(s_starterUri.UserInfo, builder.UserName + ":" + builder.Password);
|
||||
Assert.Equal<String>(s_starterUri.UserInfo, builder.Uri.UserInfo);
|
||||
String newValue = "newvalue";
|
||||
builder.UserName = newValue;
|
||||
Assert.Equal<String>(newValue, builder.UserName);
|
||||
Assert.Equal<String>(newValue + ":" + builder.Password, builder.Uri.UserInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangePassword_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<String>(s_starterUri.UserInfo, builder.UserName + ":" + builder.Password);
|
||||
Assert.Equal<String>(s_starterUri.UserInfo, builder.Uri.UserInfo);
|
||||
String newValue = "newvalue";
|
||||
builder.Password = newValue;
|
||||
Assert.Equal<String>(newValue, builder.Password);
|
||||
Assert.Equal<String>(builder.UserName + ":" + newValue, builder.Uri.UserInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangeHost_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<String>(s_starterUri.Host, builder.Host);
|
||||
Assert.Equal<String>(s_starterUri.Host, builder.Uri.Host);
|
||||
String newValue = "newvalue";
|
||||
builder.Host = newValue;
|
||||
Assert.Equal<String>(newValue, builder.Host);
|
||||
Assert.Equal<String>(newValue, builder.Uri.Host);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangePort_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<int>(s_starterUri.Port, builder.Port);
|
||||
Assert.Equal<int>(s_starterUri.Port, builder.Uri.Port);
|
||||
int newValue = 1010;
|
||||
builder.Port = newValue;
|
||||
Assert.Equal<int>(newValue, builder.Port);
|
||||
Assert.Equal<int>(newValue, builder.Uri.Port);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangePath_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<String>(s_starterUri.AbsolutePath, builder.Path);
|
||||
Assert.Equal<String>(s_starterUri.AbsolutePath, builder.Uri.AbsolutePath);
|
||||
String newValue = "/newvalue";
|
||||
builder.Path = newValue;
|
||||
Assert.Equal<String>(newValue, builder.Path);
|
||||
Assert.Equal<String>(newValue, builder.Uri.AbsolutePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangeQuery_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<String>(s_starterUri.Query, builder.Query);
|
||||
Assert.Equal<String>(s_starterUri.Query, builder.Uri.Query);
|
||||
String newValue = "newvalue";
|
||||
builder.Query = newValue;
|
||||
Assert.Equal<String>("?" + newValue, builder.Query);
|
||||
Assert.Equal<String>("?" + newValue, builder.Uri.Query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriBuilder_ChangeFragment_Refreshed()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(s_starterUri);
|
||||
Assert.Equal<String>(s_starterUri.Fragment, builder.Fragment);
|
||||
Assert.Equal<String>(s_starterUri.Fragment, builder.Uri.Fragment);
|
||||
String newValue = "newvalue";
|
||||
builder.Fragment = newValue;
|
||||
Assert.Equal<String>("#" + newValue, builder.Fragment);
|
||||
Assert.Equal<String>("#" + newValue, builder.Uri.Fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
388
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriBuilderTests.cs
vendored
Normal file
388
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriBuilderTests.cs
vendored
Normal file
@@ -0,0 +1,388 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public class UriBuilderTests
|
||||
{
|
||||
//This test tests a case where the Core implementation of UriBuilder differs from Desktop Framework UriBuilder.
|
||||
//The Query property will not longer prepend a ? character if the string being assigned is already prepended.
|
||||
[Fact]
|
||||
public static void TestQuery()
|
||||
{
|
||||
var uriBuilder = new UriBuilder(@"http://foo/bar/baz?date=today");
|
||||
|
||||
Assert.Equal("?date=today", uriBuilder.Query);
|
||||
|
||||
uriBuilder.Query = "?date=yesterday";
|
||||
Assert.Equal(@"?date=yesterday", uriBuilder.Query);
|
||||
|
||||
uriBuilder.Query = "date=tomorrow";
|
||||
Assert.Equal("?date=tomorrow", uriBuilder.Query);
|
||||
|
||||
uriBuilder.Query += @"&place=redmond";
|
||||
Assert.Equal("?date=tomorrow&place=redmond", uriBuilder.Query);
|
||||
|
||||
uriBuilder.Query = null;
|
||||
Assert.Equal("", uriBuilder.Query);
|
||||
|
||||
uriBuilder.Query = "";
|
||||
Assert.Equal("", uriBuilder.Query);
|
||||
|
||||
uriBuilder.Query = "?";
|
||||
Assert.Equal("?", uriBuilder.Query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_Empty()
|
||||
{
|
||||
var uriBuilder = new UriBuilder();
|
||||
VerifyUriBuilder(uriBuilder, scheme: "http", userName: "", password: "", host: "localhost", port: -1, path: "/", query: "", fragment: "");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("http://host/", true, "http", "", "", "host", 80, "/", "", "")]
|
||||
[InlineData("http://username@host/", true, "http", "username", "", "host", 80, "/", "", "")]
|
||||
[InlineData("http://username:password@host/", true, "http", "username", "password", "host", 80, "/", "", "")]
|
||||
[InlineData("http://host:90/", true, "http", "", "", "host", 90, "/", "", "")]
|
||||
[InlineData("http://host/path", true, "http", "", "", "host", 80, "/path", "", "")]
|
||||
[InlineData("http://host/?query", true, "http", "", "", "host", 80, "/", "?query", "")]
|
||||
[InlineData("http://host/#fragment", true, "http", "", "", "host", 80, "/", "", "#fragment")]
|
||||
[InlineData("http://username:password@host:90/path1/path2?query#fragment", true, "http", "username", "password", "host", 90, "/path1/path2", "?query", "#fragment")]
|
||||
[InlineData("www.host.com", false, "http", "", "", "www.host.com", 80, "/", "", "")] // Relative
|
||||
[InlineData("unknownscheme:", true, "unknownscheme", "", "", "", -1, "", "", "")] // No authority
|
||||
public void Ctor_String(string uriString, bool createUri, string scheme, string username, string password, string host, int port, string path, string query, string fragment)
|
||||
{
|
||||
var uriBuilder = new UriBuilder(uriString);
|
||||
VerifyUriBuilder(uriBuilder, scheme, username, password, host, port, path, query, fragment);
|
||||
|
||||
if (createUri)
|
||||
{
|
||||
uriBuilder = new UriBuilder(new Uri(uriString, UriKind.RelativeOrAbsolute));
|
||||
VerifyUriBuilder(uriBuilder, scheme, username, password, host, port, path, query, fragment);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() => new UriBuilder(new Uri(uriString, UriKind.RelativeOrAbsolute)));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_String_Invalid()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("uriString", () => new UriBuilder((string)null)); // UriString is null
|
||||
Assert.Throws<UriFormatException>(() => new UriBuilder(@"http://host\")); // UriString is invalid
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_Uri_Null()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("uri", () => new UriBuilder((Uri)null)); // Uri is null
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("http", "host", "http", "host")]
|
||||
[InlineData("HTTP", "host", "http", "host")]
|
||||
[InlineData("http", "[::1]", "http", "[::1]")]
|
||||
[InlineData("https", "::1]", "https", "[::1]]")]
|
||||
[InlineData("http", "::1", "http", "[::1]")]
|
||||
[InlineData("http1:http2", "host", "http1", "host")]
|
||||
[InlineData("http", "", "http", "")]
|
||||
[InlineData("", "host", "", "host")]
|
||||
[InlineData("", "", "", "")]
|
||||
[InlineData("http", null, "http", "")]
|
||||
[InlineData(null, "", "", "")]
|
||||
[InlineData(null, null, "", "")]
|
||||
public void Ctor_String_String(string schemeName, string hostName, string expectedScheme, string expectedHost)
|
||||
{
|
||||
var uriBuilder = new UriBuilder(schemeName, hostName);
|
||||
VerifyUriBuilder(uriBuilder, expectedScheme, "", "", expectedHost, -1, "/", "", "");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("http", "host", 0, "http", "host")]
|
||||
[InlineData("HTTP", "host", 20, "http", "host")]
|
||||
[InlineData("http", "[::1]", 40, "http", "[::1]")]
|
||||
[InlineData("https", "::1]", 60, "https", "[::1]]")]
|
||||
[InlineData("http", "::1", 80, "http", "[::1]")]
|
||||
[InlineData("http1:http2", "host", 100, "http1", "host")]
|
||||
[InlineData("http", "", 120, "http", "")]
|
||||
[InlineData("", "host", 140, "", "host")]
|
||||
[InlineData("", "", 160, "", "")]
|
||||
[InlineData("http", null, 180, "http", "")]
|
||||
[InlineData(null, "", -1, "", "")]
|
||||
[InlineData(null, null, 65535, "", "")]
|
||||
public void Ctor_String_String_Int(string scheme, string host, int port, string expectedScheme, string expectedHost)
|
||||
{
|
||||
var uriBuilder = new UriBuilder(scheme, host, port);
|
||||
VerifyUriBuilder(uriBuilder, expectedScheme, "", "", expectedHost, port, "/", "", "");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("http", "host", 0, "/path", "http", "host", "/path")]
|
||||
[InlineData("HTTP", "host", 20, "/path1/path2", "http", "host", "/path1/path2")]
|
||||
[InlineData("http", "[::1]", 40, "/", "http", "[::1]", "/")]
|
||||
[InlineData("https", "::1]", 60, "/path1/", "https", "[::1]]", "/path1/")]
|
||||
[InlineData("http", "::1", 80, null, "http", "[::1]", "/")]
|
||||
[InlineData("http1:http2", "host", 100, "path1", "http1", "host", "path1")]
|
||||
[InlineData("http", "", 120, "path1/path2", "http", "", "path1/path2")]
|
||||
[InlineData("", "host", 140, "path1/path2/path3/", "", "host", "path1/path2/path3/")]
|
||||
[InlineData("", "", 160, @"\path1\path2\path3", "", "", "/path1/path2/path3")]
|
||||
[InlineData("http", null, 180, @"path1\path2\", "http", "", "path1/path2/")]
|
||||
[InlineData(null, "", -1, "\u1234", "", "", "%E1%88%B4")]
|
||||
[InlineData(null, null, 65535, "\u1234\u2345", "", "", "%E1%88%B4%E2%8D%85")]
|
||||
public void Ctor_String_String_Int_String(string schemeName, string hostName, int port, string pathValue, string expectedScheme, string expectedHost, string expectedPath)
|
||||
{
|
||||
var uriBuilder = new UriBuilder(schemeName, hostName, port, pathValue);
|
||||
VerifyUriBuilder(uriBuilder, expectedScheme, "", "", expectedHost, port, expectedPath, "", "");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("http", "host", 0, "/path", "?query#fragment", "http", "host", "/path", "?query", "#fragment")]
|
||||
[InlineData("HTTP", "host", 20, "/path1/path2", "?query&query2=value#fragment", "http", "host", "/path1/path2", "?query&query2=value", "#fragment")]
|
||||
[InlineData("http", "[::1]", 40, "/", "#fragment?query", "http", "[::1]", "/", "", "#fragment?query")]
|
||||
[InlineData("https", "::1]", 60, "/path1/", "?query", "https", "[::1]]", "/path1/", "?query", "")]
|
||||
[InlineData("http", "::1", 80, null, "#fragment", "http", "[::1]", "/", "", "#fragment")]
|
||||
[InlineData("http", "", 120, "path1/path2", "?#", "http", "", "path1/path2", "", "")]
|
||||
[InlineData("", "host", 140, "path1/path2/path3/", "?", "", "host", "path1/path2/path3/", "", "")]
|
||||
[InlineData("", "", 160, @"\path1\path2\path3", "#", "", "", "/path1/path2/path3", "", "")]
|
||||
[InlineData("http", null, 180, @"path1\path2\", "?\u1234#\u2345", "http", "", "path1/path2/", "?\u1234", "#\u2345")]
|
||||
[InlineData(null, "", -1, "\u1234", "", "", "", "%E1%88%B4", "", "")]
|
||||
[InlineData(null, null, 65535, "\u1234\u2345", null, "", "", "%E1%88%B4%E2%8D%85", "", "")]
|
||||
public void Ctor_String_String_Int_String_String(string schemeName, string hostName, int port, string pathValue, string extraValue, string expectedScheme, string expectedHost, string expectedPath, string expectedQuery, string expectedFragment)
|
||||
{
|
||||
var uriBuilder = new UriBuilder(schemeName, hostName, port, pathValue, extraValue);
|
||||
VerifyUriBuilder(uriBuilder, expectedScheme, "", "", expectedHost, port, expectedPath, expectedQuery, expectedFragment);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("query#fragment")]
|
||||
[InlineData("fragment?fragment")]
|
||||
public void Ctor_InvalidExtraValue_ThrowsArgumentException(string extraValue)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new UriBuilder("scheme", "host", 80, "path", extraValue));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("https", "https")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
public void Scheme_Get_Set(string value, string expected)
|
||||
{
|
||||
var uriBuilder = new UriBuilder("http://userinfo@domain/path?query#fragment");
|
||||
uriBuilder.Scheme = value;
|
||||
Assert.Equal(expected, uriBuilder.Scheme);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("\u1234http")]
|
||||
[InlineData(".")]
|
||||
[InlineData("-")]
|
||||
public void InvalidScheme_ThrowsArgumentException(string schemeName)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new UriBuilder(schemeName, "host"));
|
||||
Assert.Throws<ArgumentException>(() => new UriBuilder(schemeName, "host", 80));
|
||||
Assert.Throws<ArgumentException>(() => new UriBuilder(schemeName, "host", 80, "path"));
|
||||
Assert.Throws<ArgumentException>(() => new UriBuilder(schemeName, "host", 80, "?query#fragment"));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => new UriBuilder().Scheme = schemeName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("username", "username")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
public void UserName_Get_Set(string value, string expected)
|
||||
{
|
||||
var uriBuilder = new UriBuilder("http://userinfo@domain/path?query#fragment");
|
||||
uriBuilder.UserName = value;
|
||||
Assert.Equal(expected, uriBuilder.UserName);
|
||||
|
||||
Uri oldUri = uriBuilder.Uri;
|
||||
uriBuilder.UserName = value;
|
||||
Assert.NotSame(uriBuilder.Uri, oldUri); // Should generate new uri
|
||||
Assert.Equal(uriBuilder.UserName, uriBuilder.Uri.UserInfo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("password", "password")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
public void Password_Get_Set(string value, string expected)
|
||||
{
|
||||
var uriBuilder = new UriBuilder("http://userinfo1:userinfo2@domain/path?query#fragment");
|
||||
uriBuilder.Password = value;
|
||||
Assert.Equal(expected, uriBuilder.Password);
|
||||
|
||||
Uri oldUri = uriBuilder.Uri;
|
||||
uriBuilder.Password = value;
|
||||
Assert.NotSame(uriBuilder.Uri, oldUri);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("host", "host")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
public void Host_Get_Set(string value, string expected)
|
||||
{
|
||||
var uriBuilder = new UriBuilder("http://userinfo@domain/path?query#fragment");
|
||||
uriBuilder.Host = value;
|
||||
Assert.Equal(expected, uriBuilder.Host);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(0)]
|
||||
[InlineData(80)]
|
||||
[InlineData(180)]
|
||||
[InlineData(65535)]
|
||||
public void Port_Get_Set(int port)
|
||||
{
|
||||
var uriBuilder = new UriBuilder("http://userinfo@domain/path?query#fragment");
|
||||
uriBuilder.Port = port;
|
||||
Assert.Equal(port, uriBuilder.Port);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-2)]
|
||||
[InlineData(65536)]
|
||||
public void InvalidPort_ThrowsArgumentOutOfRangeException(int portNumber)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new UriBuilder("scheme", "host", portNumber));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new UriBuilder("scheme", "host", portNumber, "path"));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new UriBuilder("scheme", "host", portNumber, "path", "?query#fragment"));
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new UriBuilder().Port = portNumber);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/path1/path2", "/path1/path2")]
|
||||
[InlineData(@"\path1\path2", "/path1/path2")]
|
||||
[InlineData("", "/")]
|
||||
[InlineData(null, "/")]
|
||||
public void Path_Get_Set(string value, string expected)
|
||||
{
|
||||
var uriBuilder = new UriBuilder("http://userinfo@domain/path?query#fragment");
|
||||
uriBuilder.Path = value;
|
||||
Assert.Equal(expected, uriBuilder.Path);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("query", "?query")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
public void Query_Get_Set(string value, string expected)
|
||||
{
|
||||
var uriBuilder = new UriBuilder();
|
||||
uriBuilder.Query = value;
|
||||
Assert.Equal(expected, uriBuilder.Query);
|
||||
|
||||
Uri oldUri = uriBuilder.Uri;
|
||||
uriBuilder.Query = value;
|
||||
Assert.NotSame(uriBuilder.Uri, oldUri); // Should generate new uri
|
||||
Assert.Equal(uriBuilder.Query, uriBuilder.Uri.Query);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("fragment", "#fragment")]
|
||||
[InlineData("#fragment", "#fragment")]
|
||||
[InlineData("#", "#")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
public void Fragment_Get_Set(string value, string expected)
|
||||
{
|
||||
var uriBuilder = new UriBuilder();
|
||||
uriBuilder.Fragment = value;
|
||||
Assert.Equal(expected, uriBuilder.Fragment);
|
||||
|
||||
Uri oldUri = uriBuilder.Uri;
|
||||
uriBuilder.Fragment = value;
|
||||
Assert.NotSame(uriBuilder.Uri, oldUri); // Should generate new uri
|
||||
Assert.Equal(uriBuilder.Fragment, uriBuilder.Uri.Fragment);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { new UriBuilder(), new UriBuilder(), true };
|
||||
yield return new object[] { new UriBuilder(), null, false };
|
||||
|
||||
yield return new object[] { new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), true };
|
||||
yield return new object[] { new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), new UriBuilder("http://domain.com:80/path/file?query#fragment"), true }; // Ignores userinfo
|
||||
yield return new object[] { new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment2"), true }; // Ignores fragment
|
||||
yield return new object[] { new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), new UriBuilder("http://username:password@host.com:80/path/file?query#fragment"), false };
|
||||
yield return new object[] { new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), new UriBuilder("http://username:password@domain.com:90/path/file?query#fragment"), false };
|
||||
yield return new object[] { new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), new UriBuilder("http://username:password@domain.com:80/path2/file?query#fragment"), false };
|
||||
yield return new object[] { new UriBuilder("http://username:password@domain.com:80/path/file?query#fragment"), new UriBuilder("http://username:password@domain.com:80/path/file?query2#fragment"), false };
|
||||
|
||||
yield return new object[] { new UriBuilder("unknown:"), new UriBuilder("unknown:"), true };
|
||||
yield return new object[] { new UriBuilder("unknown:"), new UriBuilder("different:"), false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals(UriBuilder uriBuilder1, UriBuilder uriBuilder2, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, uriBuilder1.Equals(uriBuilder2));
|
||||
if (uriBuilder2 != null)
|
||||
{
|
||||
Assert.Equal(expected, uriBuilder1.GetHashCode().Equals(uriBuilder2.GetHashCode()));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
yield return new object[] { new UriBuilder(), "http://localhost/" };
|
||||
yield return new object[] { new UriBuilder() { Scheme = "" }, "localhost/" };
|
||||
yield return new object[] { new UriBuilder() { Scheme = "unknown" }, "unknown://localhost/" };
|
||||
yield return new object[] { new UriBuilder() { Scheme = "unknown", Host = "" }, "unknown:/" };
|
||||
yield return new object[] { new UriBuilder() { Scheme = "unknown", Host = "", Path = "path1/path2" }, "unknown:path1/path2" };
|
||||
yield return new object[] { new UriBuilder() { UserName = "username" }, "http://username@localhost/" };
|
||||
yield return new object[] { new UriBuilder() { UserName = "username", Password = "password" }, "http://username:password@localhost/" };
|
||||
yield return new object[] { new UriBuilder() { Port = 80 }, "http://localhost:80/" };
|
||||
yield return new object[] { new UriBuilder() { Port = 0 }, "http://localhost:0/" };
|
||||
yield return new object[] { new UriBuilder() { Host = "", Port = 80 }, "http:///" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Path = "" }, "http://host/" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Path = "/" }, "http://host/" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Path = @"\" }, "http://host/" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Path = "path" }, "http://host/path" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Path = "path", Query = "query" }, "http://host/path?query" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Path = "path", Fragment = "fragment" }, "http://host/path#fragment" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Path = "path", Query = "query", Fragment = "fragment" }, "http://host/path?query#fragment" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Query = "query" }, "http://host/?query" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Fragment = "fragment" }, "http://host/#fragment" };
|
||||
yield return new object[] { new UriBuilder() { Host = "host", Query = "query", Fragment = "fragment" }, "http://host/?query#fragment" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToString_TestData))]
|
||||
public void ToString(UriBuilder uriBuilder, string expected)
|
||||
{
|
||||
Assert.Equal(expected, uriBuilder.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_Invalid()
|
||||
{
|
||||
var uriBuilder = new UriBuilder();
|
||||
uriBuilder.Password = "password";
|
||||
Assert.Throws<UriFormatException>(() => uriBuilder.ToString()); // Uri has a password but no username
|
||||
}
|
||||
|
||||
public static void VerifyUriBuilder(UriBuilder uriBuilder, string scheme, string userName, string password, string host, int port, string path, string query, string fragment)
|
||||
{
|
||||
Assert.Equal(scheme, uriBuilder.Scheme);
|
||||
Assert.Equal(userName, uriBuilder.UserName);
|
||||
Assert.Equal(password, uriBuilder.Password);
|
||||
Assert.Equal(host, uriBuilder.Host);
|
||||
Assert.Equal(port, uriBuilder.Port);
|
||||
Assert.Equal(path, uriBuilder.Path);
|
||||
Assert.Equal(query, uriBuilder.Query);
|
||||
Assert.Equal(fragment, uriBuilder.Fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
713
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriEscapingTest.cs
vendored
Normal file
713
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriEscapingTest.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
87
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriGetComponentsTest.cs
vendored
Normal file
87
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriGetComponentsTest.cs
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public class UriGetComponentsTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetComponents_ASCIIHost_LowerCaseResult()
|
||||
{
|
||||
Uri testUri = new Uri("http://MixedCase.HostName");
|
||||
Assert.Equal("mixedcase.hostname", testUri.GetComponents(UriComponents.Host, UriFormat.UriEscaped));
|
||||
Assert.Equal("mixedcase.hostname", testUri.Host);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetComponents_PunycodeHostIriOnIdnOff_LowerCaseResult()
|
||||
{
|
||||
Uri testUri = new Uri("http://wWw.xn--pCk.Com");
|
||||
Assert.Equal("www.xn--pck.com", testUri.GetComponents(UriComponents.Host, UriFormat.UriEscaped));
|
||||
Assert.Equal("www.xn--pck.com", testUri.Host);
|
||||
Assert.Equal("www.xn--pck.com", testUri.DnsSafeHost);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetComponents_UnknownScheme_ComponentsUnaffected()
|
||||
{
|
||||
Uri testUri;
|
||||
|
||||
testUri = new Uri("eb://00000000000000000000000/dir1/dir2?query=expression#fragment");
|
||||
Assert.Equal("00000000000000000000000", testUri.Authority);
|
||||
Assert.Equal("eb", testUri.Scheme);
|
||||
Assert.Equal("/dir1/dir2", testUri.AbsolutePath);
|
||||
Assert.Equal("?query=expression", testUri.Query);
|
||||
Assert.Equal("#fragment", testUri.Fragment);
|
||||
Assert.Equal("eb://00000000000000000000000/dir1/dir2?query=expression#fragment", testUri.AbsoluteUri);
|
||||
|
||||
// Hex numbers should not be converted
|
||||
testUri = new Uri("eb://123.231.0x0f.1/dir");
|
||||
Assert.Equal("123.231.0x0f.1", testUri.Authority);
|
||||
|
||||
// Octal numbers should not be converted
|
||||
testUri = new Uri("eb://123.032.123.023/dir");
|
||||
Assert.Equal("123.032.123.023", testUri.Authority);
|
||||
testUri = new Uri("eb://123.002.123.023/dir");
|
||||
Assert.Equal("123.002.123.023", testUri.Authority);
|
||||
testUri = new Uri("eb://123.0032.123.023/dir");
|
||||
Assert.Equal("123.0032.123.023", testUri.Authority);
|
||||
|
||||
// IP Address containing 0, 00 and 000
|
||||
testUri = new Uri("abcd://123.0.10.100/dir");
|
||||
Assert.Equal("123.0.10.100", testUri.Authority);
|
||||
testUri = new Uri("efghi://123.00.10.100/dir");
|
||||
Assert.Equal("123.00.10.100", testUri.Authority);
|
||||
testUri = new Uri("ijklmn://123.000.10.100/dir");
|
||||
Assert.Equal("123.000.10.100", testUri.Authority);
|
||||
|
||||
// Known limitation: port will always be canonicalized since it is exposed as an int.
|
||||
testUri = new Uri("abc://127.00.000.001:01234");
|
||||
Assert.Equal("127.00.000.001:1234", testUri.Authority);
|
||||
|
||||
// Known limitation: port 0 is ignored.
|
||||
testUri = new Uri("cbd://127.00.1.2:0000");
|
||||
Assert.Equal("127.00.1.2", testUri.Authority);
|
||||
testUri = new Uri("cbd://127.00.1.2:0");
|
||||
Assert.Equal("127.00.1.2", testUri.Authority);
|
||||
|
||||
testUri = new Uri("eb://[0000::01:123.32.123.23]/dir");
|
||||
Assert.Equal("[::1:7b20:7b17]", testUri.Authority);
|
||||
|
||||
// TODO #8330 : Canonical IPv6 is still performed for unknown schemes.
|
||||
Assert.NotEqual("[0000::01:123.32.123.23]", testUri.Authority);
|
||||
}
|
||||
|
||||
// Visual Studio 12 has a dependency on this behavior.
|
||||
[Fact]
|
||||
public void GetComponents_UnknownScheme_LocalHostAndPort_Success()
|
||||
{
|
||||
Uri testUri = new Uri("tcp://127.0.0.1:23714");
|
||||
Assert.Equal("127.0.0.1", testUri.Host);
|
||||
Assert.Equal(23714, testUri.Port);
|
||||
}
|
||||
}
|
||||
}
|
||||
381
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriIpHostTest.cs
vendored
Normal file
381
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriIpHostTest.cs
vendored
Normal file
@@ -0,0 +1,381 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
public class UriIpHostTest
|
||||
{
|
||||
#region IPv4
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_CanonicalDotedDecimal_Success()
|
||||
{
|
||||
ParseIPv4Address(IPAddress.Loopback.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0.0.0.0", "0.0.0.0")]
|
||||
[InlineData("0", "0.0.0.0")]
|
||||
[InlineData("0x0", "0.0.0.0")]
|
||||
public void UriIPv4Host_Any_Success(string address, string expected)
|
||||
{
|
||||
ParseIPv4Address(address, expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
// 255.255.255.255
|
||||
[InlineData("255.255.255.255", "255.255.255.255")]
|
||||
[InlineData("0xFF.0xFF.0xFF.0xFF", "255.255.255.255")]
|
||||
[InlineData("0377.0377.0377.0377", "255.255.255.255")]
|
||||
// Biggest value 4.0 supported in this format
|
||||
[InlineData("4294967294", "255.255.255.254")]
|
||||
[InlineData("0xFFFFFFFE", "255.255.255.254")]
|
||||
[InlineData("037777777776", "255.255.255.254")] // Octal
|
||||
// IPAddress doesn't support these formats, except on XP / 2003?
|
||||
[InlineData("4294967295", "255.255.255.255")]
|
||||
[InlineData("0xFFFFFFFF", "255.255.255.255")]
|
||||
[InlineData("037777777777", "255.255.255.255")] // Octal
|
||||
public void UriIPv4Host_None_Success(string address, string expected)
|
||||
{
|
||||
ParseIPv4Address(address, expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_FullDec_Success()
|
||||
{
|
||||
ParseIPv4Address("2637895963", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("157.3873051", "157.59.25.27")]
|
||||
[InlineData("157.6427", "157.0.25.27")]
|
||||
public void UriIPv4Host_PartialDec_Success(string address, string expected)
|
||||
{
|
||||
ParseIPv4Address(address, expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_FullHex_Success()
|
||||
{
|
||||
ParseIPv4Address("0x9D3B191B", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_DottedHex_Success()
|
||||
{
|
||||
ParseIPv4Address("0X9D.0x3B.0X19.0x1B", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_DottedHexLowerCase_Success()
|
||||
{
|
||||
ParseIPv4Address("0x89.0xab.0xcd.0xef", expected: "137.171.205.239");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("157.59.25.0x1B", "157.59.25.27")]
|
||||
[InlineData("157.59.0x001B", "157.59.0.27")]
|
||||
[InlineData("157.0x00001B", "157.0.0.27")]
|
||||
public void UriIPv4Host_PartialHex_Success(string address, string expected)
|
||||
{
|
||||
ParseIPv4Address(address, expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_FullOctal_Success()
|
||||
{
|
||||
// 4.0 Uri truncates the leading zeros and reads these as decimal
|
||||
ParseIPv4Address("023516614433", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_FullOctalExtraLeadingZeros_Success()
|
||||
{
|
||||
// 4.0 Uri truncates the leading zeros and reads these as decimal
|
||||
ParseIPv4Address("00000023516614433", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_DottedOctal_Success()
|
||||
{
|
||||
// 4.0 Uri truncates the leading zeros and reads these as decimal
|
||||
ParseIPv4Address("0235.073.031.033", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_DottedOctalExtraLeadingZeros_Success()
|
||||
{
|
||||
// 4.0 Uri truncates the leading zeros and reads these as decimal
|
||||
ParseIPv4Address("000235.000073.0000031.00000033", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_PartialOctal_Success()
|
||||
{
|
||||
// 4.0 Uri truncates the leading zeros and reads these as decimal
|
||||
ParseIPv4Address("157.59.25.033", expected: "157.59.25.27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_PartDecHexOct_Success()
|
||||
{
|
||||
// 4.0 Uri truncates the leading zeros and reads these as decimal
|
||||
ParseIPv4Address("157.59.0x25.033", expected: "157.59.37.27");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("127.0.0.1 ")]
|
||||
[InlineData(" 127.0.0.1")]
|
||||
[InlineData("157.3B191B")] // Hex without 0x
|
||||
[InlineData("260.156")] // Left dotted segments can't be more than 255
|
||||
[InlineData("255.260.156")] // Left dotted segments can't be more than 255
|
||||
[InlineData("1.1.1.0x")] // Empty trailing hex segment
|
||||
[InlineData("0x.1.1.1")] // Empty leading hex segment
|
||||
[InlineData("...")] // Empty sections
|
||||
[InlineData("1.1.1.")] // Empty trailing section
|
||||
[InlineData("1..1.1")] // Empty internal section
|
||||
[InlineData(".1.1.1")] // Empty leading section
|
||||
[InlineData("..11.1")] // Empty sections
|
||||
[InlineData("0xFF.0xFFFFFF.0xFF")] // Middle segment too large
|
||||
[InlineData("0xFFFFFF.0xFF.0xFFFFFF")] // Leading segment too large
|
||||
[InlineData("1.1\u67081.1.1")] // Unicode, Crashes .NET 4.0 IPAddress.TryParse
|
||||
[InlineData("0000X9D.0x3B.0X19.0x1B")] // Leading zeros on hex
|
||||
[InlineData("01011101001110110001100100011011")] // Binary? Read as octal, overflows
|
||||
[InlineData("10011101001110110001100100011011")] // Binary? Read as decimal, overflows
|
||||
[InlineData("040000000000")] // Octal overflow by 1
|
||||
[InlineData("4294967296")] // Decimal overflow by 1
|
||||
[InlineData("0x100000000")] // Hex overflow by 1
|
||||
[InlineData("0.0.0.089")] // Octal (leading zero) but with 8 or 9
|
||||
public void UriIPv4Host_BadAddresses_AllFail(string address)
|
||||
{
|
||||
ParseBadIPv4Address(address);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_UriWithPort_Success()
|
||||
{
|
||||
Uri testUri;
|
||||
Assert.True(Uri.TryCreate("http://" + IPAddress.Loopback.ToString() + ":9090", UriKind.Absolute, out testUri));
|
||||
Assert.Equal(UriHostNameType.IPv4, testUri.HostNameType);
|
||||
Assert.Equal(IPAddress.Loopback.ToString(), testUri.Host);
|
||||
Assert.Equal(IPAddress.Loopback.ToString(), testUri.DnsSafeHost);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_UriWithQuery_Success()
|
||||
{
|
||||
Uri testUri;
|
||||
Assert.True(Uri.TryCreate("http://" + IPAddress.Loopback.ToString() + "?Query", UriKind.Absolute, out testUri));
|
||||
Assert.Equal(UriHostNameType.IPv4, testUri.HostNameType);
|
||||
Assert.Equal(IPAddress.Loopback.ToString(), testUri.Host);
|
||||
Assert.Equal(IPAddress.Loopback.ToString(), testUri.DnsSafeHost);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv4Host_UriWithFragment_Success()
|
||||
{
|
||||
Uri testUri;
|
||||
Assert.True(Uri.TryCreate("http://" + IPAddress.Loopback.ToString() + "#fragment", UriKind.Absolute, out testUri));
|
||||
Assert.Equal(UriHostNameType.IPv4, testUri.HostNameType);
|
||||
Assert.Equal(IPAddress.Loopback.ToString(), testUri.Host);
|
||||
Assert.Equal(IPAddress.Loopback.ToString(), testUri.DnsSafeHost);
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
private void ParseIPv4Address(string ipv4String)
|
||||
{
|
||||
ParseIPv4Address(ipv4String, expected: ipv4String);
|
||||
}
|
||||
|
||||
private void ParseIPv4Address(string ipv4String, string expected)
|
||||
{
|
||||
// TryCreate
|
||||
Uri testUri;
|
||||
Assert.True(Uri.TryCreate("http://" + ipv4String, UriKind.Absolute, out testUri), ipv4String);
|
||||
Assert.Equal(UriHostNameType.IPv4, testUri.HostNameType);
|
||||
Assert.Equal(expected, testUri.Host);
|
||||
Assert.Equal(expected, testUri.DnsSafeHost);
|
||||
|
||||
// Constructor
|
||||
testUri = new Uri("http://" + ipv4String);
|
||||
Assert.Equal(UriHostNameType.IPv4, testUri.HostNameType);
|
||||
Assert.Equal(expected, testUri.Host);
|
||||
Assert.Equal(expected, testUri.DnsSafeHost);
|
||||
|
||||
// CheckHostName
|
||||
Assert.Equal(UriHostNameType.IPv4, Uri.CheckHostName(ipv4String));
|
||||
}
|
||||
|
||||
private void ParseBadIPv4Address(string badIpv4String)
|
||||
{
|
||||
// CheckHostName
|
||||
Assert.NotEqual(UriHostNameType.IPv4, Uri.CheckHostName(badIpv4String));
|
||||
|
||||
// TryCreate
|
||||
Uri testUri;
|
||||
if (Uri.TryCreate("http://" + badIpv4String + "/", UriKind.Absolute, out testUri))
|
||||
{
|
||||
Assert.NotEqual(UriHostNameType.IPv4, testUri.HostNameType);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Helpers
|
||||
|
||||
#endregion IPv4
|
||||
|
||||
#region IPv6
|
||||
|
||||
[Fact]
|
||||
public void UriIPv6Host_CanonicalCollonHex_Success()
|
||||
{
|
||||
ParseIPv6Address(IPAddress.IPv6Loopback.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("::")]
|
||||
[InlineData("0000:0000:0000:0000:0000:0000:0000:0000")]
|
||||
public void UriIPv6Host_Any_Success(string address)
|
||||
{
|
||||
ParseIPv6Address(address, expected: "::");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv6Host_MaxValue_Success()
|
||||
{
|
||||
ParseIPv6Address("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", expected: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIPv6Host_LeadingValue_Success()
|
||||
{
|
||||
ParseIPv6Address("1::");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0:0:0:0:0:0:0:0", "::")]
|
||||
[InlineData("1:0:0:0:0:0:0:0", "1::")]
|
||||
[InlineData("0:1:0:0:0:0:0:0", "0:1::")]
|
||||
[InlineData("0:0:1:0:0:0:0:0", "0:0:1::")]
|
||||
[InlineData("0:0:0:1:0:0:0:0", "0:0:0:1::")]
|
||||
[InlineData("0:0:0:0:1:0:0:0", "::1:0:0:0")]
|
||||
[InlineData("0:0:0:0:0:1:0:0", "::1:0:0")]
|
||||
[InlineData("0:0:0:0:0:0:1:0", "::0.1.0.0")]
|
||||
[InlineData("0:0:0:0:0:0:0:1", "::1")]
|
||||
[InlineData("1:0:0:0:0:0:0:1", "1::1")]
|
||||
[InlineData("1:1:0:0:0:0:0:1", "1:1::1")]
|
||||
[InlineData("1:0:1:0:0:0:0:1", "1:0:1::1")]
|
||||
[InlineData("1:0:0:1:0:0:0:1", "1:0:0:1::1")]
|
||||
[InlineData("1:0:0:0:1:0:0:1", "1::1:0:0:1")]
|
||||
[InlineData("1:0:0:0:0:1:0:1", "1::1:0:1")]
|
||||
[InlineData("1:0:0:0:0:0:1:1", "1::1:1")]
|
||||
[InlineData("1:1:0:0:1:0:0:1", "1:1::1:0:0:1")]
|
||||
[InlineData("1:0:1:0:0:1:0:1", "1:0:1::1:0:1")]
|
||||
[InlineData("1:0:0:1:0:0:1:1", "1::1:0:0:1:1")]
|
||||
[InlineData("1:1:0:0:0:1:0:1", "1:1::1:0:1")]
|
||||
[InlineData("1:0:0:0:1:0:1:1", "1::1:0:1:1")]
|
||||
public void UriIPv6Host_CompressionRangeSelection_Success(string address, string expected)
|
||||
{
|
||||
ParseIPv6Address(address, expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1::%1")]
|
||||
[InlineData("::1%12")]
|
||||
[InlineData("::%123")]
|
||||
public void UriIPv6Host_ScopeId_Success(string address)
|
||||
{
|
||||
ParseIPv6Address(address);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("FE08::192.168.0.1", "fe08::c0a8:1")] // Output is not IPv4 mapped
|
||||
[InlineData("::192.168.0.1", "::192.168.0.1")]
|
||||
[InlineData("::FFFF:192.168.0.1", "::ffff:192.168.0.1")] // SIIT
|
||||
[InlineData("::FFFF:0:192.168.0.1", "::ffff:0:192.168.0.1")] // SIIT
|
||||
[InlineData("::5EFE:192.168.0.1", "::5efe:192.168.0.1")] // ISATAP
|
||||
[InlineData("1::5EFE:192.168.0.1", "1::5efe:192.168.0.1")] // ISATAP
|
||||
[InlineData("::192.168.0.010", "::192.168.0.10")] // Embedded IPv4 octal, read as decimal
|
||||
public void UriIPv6Host_EmbeddedIPv4_Success(string address, string expected)
|
||||
{
|
||||
ParseIPv6Address(address, expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("1")]
|
||||
[InlineData(":1")]
|
||||
[InlineData("1:")]
|
||||
[InlineData("::1 ")]
|
||||
[InlineData(" ::1")]
|
||||
[InlineData("1::1::1")] // Ambigious
|
||||
[InlineData("1:1\u67081:1:1")] // Unicoded. Crashes .NET 4.0 IPAddress.TryParse
|
||||
[InlineData("FE08::260.168.0.1")] // Embedded IPv4 out of range
|
||||
[InlineData("::192.168.0.0x0")] // Embedded IPv4 hex
|
||||
[InlineData("192.168.0.1")] // Raw IPv4
|
||||
[InlineData("G::")] // Hex out of range
|
||||
[InlineData("FFFFF::")] // Hex out of range
|
||||
[InlineData(":%12")] // Colon Scope
|
||||
[InlineData("%12")] // Just Scope
|
||||
// TODO # 8330 Discrepency: IPAddress doesn't accept bad scopes, Uri does.
|
||||
//[InlineData("::%1a")] // Alpha numeric Scope
|
||||
public void UriIPv6Host_BadAddress(string address)
|
||||
{
|
||||
ParseBadIPv6Address(address);
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
private void ParseIPv6Address(string ipv6String)
|
||||
{
|
||||
ParseIPv6Address(ipv6String, expected: ipv6String);
|
||||
}
|
||||
|
||||
private void ParseIPv6Address(string ipv6String, string expected)
|
||||
{
|
||||
// Host property returns bracketed address without the scope ID
|
||||
int scopeIndex = expected.IndexOf('%');
|
||||
string expectedResultWithBrackets = $"[{((scopeIndex == -1) ? expected : expected.Substring(0, scopeIndex))}]";
|
||||
|
||||
// TryCreate
|
||||
Uri testUri;
|
||||
Assert.True(Uri.TryCreate("http://[" + ipv6String + "]", UriKind.Absolute, out testUri), ipv6String);
|
||||
Assert.Equal(UriHostNameType.IPv6, testUri.HostNameType);
|
||||
Assert.Equal(expectedResultWithBrackets, testUri.Host);
|
||||
Assert.Equal(expected, testUri.DnsSafeHost);
|
||||
|
||||
// Constructor
|
||||
testUri = new Uri("http://[" + ipv6String + "]");
|
||||
Assert.Equal(UriHostNameType.IPv6, testUri.HostNameType);
|
||||
Assert.Equal(expectedResultWithBrackets, testUri.Host);
|
||||
Assert.Equal(expected, testUri.DnsSafeHost);
|
||||
|
||||
// CheckHostName
|
||||
Assert.Equal(UriHostNameType.IPv6, Uri.CheckHostName(ipv6String));
|
||||
}
|
||||
|
||||
private void ParseBadIPv6Address(string badIpv6String)
|
||||
{
|
||||
// CheckHostName
|
||||
Assert.NotEqual(UriHostNameType.IPv6, Uri.CheckHostName(badIpv6String));
|
||||
|
||||
// TryCreate
|
||||
Uri testUri;
|
||||
Assert.False(Uri.TryCreate("http://[" + badIpv6String + "]/", UriKind.Absolute, out testUri),
|
||||
badIpv6String);
|
||||
}
|
||||
|
||||
#endregion Helpers
|
||||
|
||||
#endregion IPv6
|
||||
}
|
||||
}
|
||||
294
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriIsWellFormedUriStringTest.cs
vendored
Normal file
294
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriIsWellFormedUriStringTest.cs
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UriIsWellFormedUriStringTest
|
||||
/// </summary>
|
||||
public class UriIsWellFormedUriStringTest
|
||||
{
|
||||
[Fact]
|
||||
public void UriIsWellFormed_AbsoluteWellFormed_Success()
|
||||
{
|
||||
Assert.True(Uri.IsWellFormedUriString("http://foo.com/bad:url", UriKind.Absolute));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_RelativeWellFormed_Success()
|
||||
{
|
||||
Assert.True(Uri.IsWellFormedUriString("/path/file?Query", UriKind.Relative));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_RelativeWithColon_Failure()
|
||||
{
|
||||
Assert.False(Uri.IsWellFormedUriString("http://foo", UriKind.Relative));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_RelativeWithPercentAndColon_Failure()
|
||||
{
|
||||
Assert.False(Uri.IsWellFormedUriString("bad%20http://foo", UriKind.Relative));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_NewRelativeRegisteredAbsolute_Throws()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri test = new Uri("http://foo", UriKind.Relative);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_NewAbsoluteUnregisteredAsRelative_Throws()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri test = new Uri("any://foo", UriKind.Relative);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_NewRelativeWithKnownSchemeAndQuery_SuccessButNotWellFormed()
|
||||
{
|
||||
Uri test = new Uri("http:?foo", UriKind.Relative);
|
||||
Assert.False(Uri.IsWellFormedUriString(test.ToString(), UriKind.Relative), "Not well formed");
|
||||
Assert.False(Uri.IsWellFormedUriString(test.ToString(), UriKind.Absolute), "Should not be well formed");
|
||||
Assert.True(Uri.TryCreate(test.ToString(), UriKind.Relative, out test), "TryCreate Mismatch");
|
||||
Uri result = new Uri(new Uri("http://host.com"), test);
|
||||
Assert.True(Uri.IsWellFormedUriString(result.ToString(), UriKind.Absolute), "Not well formed");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_NewRelativeWithUnknownSchemeAndQuery_Throws()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
// The generic parser allows this kind of absolute Uri, where the http parser does not
|
||||
Uri test;
|
||||
Assert.False(Uri.TryCreate("any:?foo", UriKind.Relative, out test), "TryCreate should have Failed");
|
||||
test = new Uri("any:?foo", UriKind.Relative);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_TryCreateNewRelativeWithColon_Failure()
|
||||
{
|
||||
Uri test;
|
||||
Assert.False(Uri.TryCreate("http://foo", UriKind.Relative, out test));
|
||||
}
|
||||
|
||||
// App-compat - A colon in the first segment of a relative Uri is invalid, but we cannot reject it.
|
||||
[Fact]
|
||||
public void UriIsWellFormed_TryCreateNewRelativeWithPercentAndColon_Success()
|
||||
{
|
||||
string input = "bad%20http://foo";
|
||||
Uri test;
|
||||
Assert.True(Uri.TryCreate(input, UriKind.Relative, out test));
|
||||
Assert.False(test.IsWellFormedOriginalString());
|
||||
Assert.False(Uri.IsWellFormedUriString(input, UriKind.Relative));
|
||||
Assert.False(Uri.IsWellFormedUriString(input, UriKind.RelativeOrAbsolute));
|
||||
Assert.False(Uri.IsWellFormedUriString(input, UriKind.Absolute));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_AbsoluteWithColonToRelative_AppendsDotSlash()
|
||||
{
|
||||
Uri baseUri = new Uri("https://base.com/path/stuff");
|
||||
Uri test = new Uri("https://base.com/path/hi:there/", UriKind.Absolute);
|
||||
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Assert.True(Uri.IsWellFormedUriString(rel.ToString(), UriKind.Relative), "Not well formed: " + rel);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<Uri>(test, result); //"Transitivity failure"
|
||||
|
||||
Assert.True(String.CompareOrdinal(rel.ToString(), 0, "./", 0, 2) == 0, "Cannot have colon in first segment, must append ./");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_AbsoluteWithPercentAndColonToRelative_AppendsDotSlash()
|
||||
{
|
||||
Uri baseUri = new Uri("https://base.com/path/stuff");
|
||||
Uri test = new Uri("https://base.com/path/h%20i:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Assert.True(Uri.IsWellFormedUriString(rel.ToString(), UriKind.Relative), "Not well formed: " + rel);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<Uri>(test, result); //"Transitivity failure"
|
||||
|
||||
Assert.True(String.CompareOrdinal(rel.ToString(), 0, "./", 0, 2) == 0, "Cannot have colon in first segment, must append ./");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ImplicitFileCommonBaseWithColon_AppendsDotSlash()
|
||||
{
|
||||
Uri baseUri = new Uri(@"c:/base/path/stuff");
|
||||
Uri test = new Uri(@"c:/base/path/hi:there/", UriKind.Absolute);
|
||||
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Assert.True(Uri.IsWellFormedUriString(rel.ToString(), UriKind.Relative), "Not well formed: " + rel);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<String>(test.LocalPath, result.LocalPath); // "Transitivity failure"
|
||||
|
||||
Assert.True(String.CompareOrdinal(rel.ToString(), 0, "./", 0, 2) == 0, "Cannot have colon in first segment, must append ./");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ImplicitFileDifferentBaseWithColon_ReturnsSecondUri()
|
||||
{
|
||||
Uri baseUri = new Uri(@"c:/base/path/stuff");
|
||||
Uri test = new Uri(@"d:/base/path/hi:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<String>(test.LocalPath, result.LocalPath); //"Transitivity failure"
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ExplicitFileDifferentBaseWithColon_ReturnsSecondUri()
|
||||
{
|
||||
Uri baseUri = new Uri(@"file://c:/stuff");
|
||||
Uri test = new Uri(@"file://d:/hi:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Assert.False(rel.IsAbsoluteUri, "Result should be relative");
|
||||
|
||||
Assert.Equal<String>("d:/hi:there/", rel.ToString());
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<String>(test.LocalPath, result.LocalPath); // "Transitivity failure"
|
||||
Assert.Equal<String>(test.ToString(), result.ToString()); // "Transitivity failure"
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ExplicitUncFileVsDosFile_ReturnsSecondPath()
|
||||
{
|
||||
Uri baseUri = new Uri(@"file:///u:/stuff");
|
||||
Uri test = new Uri(@"file:///unc/hi:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
// This is a known oddity when mix and matching Unc & dos paths in this order.
|
||||
// The other way works as expected.
|
||||
Assert.Equal<string>("file:///u:/unc/hi:there/", result.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ExplicitDosFileWithHost_ReturnsSecondPath()
|
||||
{
|
||||
Uri baseUri = new Uri(@"file://host/u:/stuff");
|
||||
Uri test = new Uri(@"file://host/unc/hi:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<String>(test.LocalPath, result.LocalPath); // "Transitivity failure"
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ExplicitDosFileSecondWithHost_ReturnsSecondPath()
|
||||
{
|
||||
Uri baseUri = new Uri(@"file://host/unc/stuff");
|
||||
Uri test = new Uri(@"file://host/u:/hi:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<String>(test.LocalPath, result.LocalPath); //"Transitivity failure"
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ExplicitDosFileVsUncFile_ReturnsSecondUri()
|
||||
{
|
||||
Uri baseUri = new Uri(@"file:///unc/stuff");
|
||||
Uri test = new Uri(@"file:///u:/hi:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<String>(test.LocalPath, result.LocalPath); //"Transitivity failure"
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_ExplicitDosFileContainingImplicitDosPath_AddsDotSlash()
|
||||
{
|
||||
Uri baseUri = new Uri(@"file:///u:/stuff/file");
|
||||
Uri test = new Uri(@"file:///u:/stuff/h:there/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<String>(test.LocalPath, result.LocalPath); //"Transitivity failure"
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_DifferentSchemes_ReturnsSecondUri()
|
||||
{
|
||||
Uri baseUri = new Uri(@"http://base/path/stuff");
|
||||
Uri test = new Uri(@"https://base/path/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Assert.Equal<Uri>(test, rel);
|
||||
|
||||
Assert.True(Uri.IsWellFormedUriString(rel.ToString(), UriKind.Absolute), "Not well formed: " + rel);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<Uri>(result, test);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_DifferentHost_ReturnsSecondUri()
|
||||
{
|
||||
Uri baseUri = new Uri(@"http://host1/path/stuff");
|
||||
Uri test = new Uri(@"http://host2/path/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Assert.Equal<Uri>(test, rel);
|
||||
|
||||
Assert.True(Uri.IsWellFormedUriString(rel.ToString(), UriKind.Absolute), "Not well formed: " + rel);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<Uri>(result, test);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMakeRelative_DifferentPort_ReturnsSecondUri()
|
||||
{
|
||||
Uri baseUri = new Uri(@"http://host:1/path/stuff");
|
||||
Uri test = new Uri(@"http://host:2/path/", UriKind.Absolute);
|
||||
Uri rel = baseUri.MakeRelativeUri(test);
|
||||
|
||||
Assert.Equal<Uri>(test, rel);
|
||||
|
||||
Assert.True(Uri.IsWellFormedUriString(rel.ToString(), UriKind.Absolute), "Not well formed: " + rel);
|
||||
|
||||
Uri result = new Uri(baseUri, rel);
|
||||
|
||||
Assert.Equal<Uri>(result, test);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriIsWellFormed_IPv6HostIriOn_True()
|
||||
{
|
||||
Assert.True(Uri.IsWellFormedUriString("http://[::1]/", UriKind.Absolute));
|
||||
}
|
||||
}
|
||||
}
|
||||
230
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriMailToTest.cs
vendored
Normal file
230
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriMailToTest.cs
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UriMailToParsing
|
||||
/// </summary>
|
||||
public class UriMailToTest
|
||||
{
|
||||
public UriMailToTest()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeOnly_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:", uri.ToString());
|
||||
Assert.Equal("", uri.Host);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeAndBackslash_Throws()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri uri = new Uri(@"mailto:\");
|
||||
ValidateNotCorrupt(uri);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeAndForwardSlash_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:/");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:/", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:/", uri.ToString());
|
||||
Assert.Equal("", uri.Host);
|
||||
Assert.Equal("/", uri.AbsolutePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeAndDoubleForwardSlash_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto://");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto://", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto://", uri.ToString());
|
||||
Assert.Equal("", uri.Host);
|
||||
Assert.Equal("//", uri.AbsolutePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeAndQuery_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:?to=User2@Host2.com;cc=User3@Host3com");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:?to=User2@Host2.com;cc=User3@Host3com", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:?to=User2@Host2.com;cc=User3@Host3com", uri.ToString());
|
||||
Assert.Equal("", uri.Host);
|
||||
Assert.Equal("", uri.UserInfo);
|
||||
Assert.Equal("", uri.AbsolutePath);
|
||||
Assert.Equal("?to=User2@Host2.com;cc=User3@Host3com", uri.Query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserAt_Throws()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@");
|
||||
ValidateNotCorrupt(uri);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserColonPasswordAt_Throws()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri uri = new Uri("mailto:User:Password@");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserAtQuery_Throws()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@?to=User2@Host2.com;cc=User3@Host3com");
|
||||
ValidateNotCorrupt(uri);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserAtHost_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@Host");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:User@host", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:User@host", uri.ToString());
|
||||
Assert.Equal("host", uri.Host);
|
||||
Assert.Equal("User", uri.UserInfo);
|
||||
Assert.Equal("", uri.AbsolutePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserColonPasswordAtHost_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:User:Password@Host");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:User:Password@host", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:User:Password@host", uri.ToString());
|
||||
Assert.Equal("host", uri.Host);
|
||||
Assert.Equal("User:Password", uri.UserInfo);
|
||||
Assert.Equal("", uri.AbsolutePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserAtHostPort_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@Host:3555");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:User@host:3555", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:User@host:3555", uri.ToString());
|
||||
Assert.Equal("host", uri.Host);
|
||||
Assert.Equal(3555, uri.Port);
|
||||
Assert.Equal("User", uri.UserInfo);
|
||||
Assert.Equal("", uri.AbsolutePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_TwoSemiColonSepratedAddresses_Success()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@Host;User@Host");
|
||||
ValidateNotCorrupt(uri);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_TwoCommaSepratedAddresses_Success()
|
||||
{
|
||||
Assert.ThrowsAny<FormatException>(() =>
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@Host,User@Host");
|
||||
ValidateNotCorrupt(uri);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserAtHostPath_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@Host/Path1/./Path2/../...");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:User@host/Path1/./Path2/../...", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:User@host/Path1/./Path2/../...", uri.ToString());
|
||||
Assert.Equal("host", uri.Host);
|
||||
Assert.Equal("User", uri.UserInfo);
|
||||
Assert.Equal("/Path1/./Path2/../...", uri.AbsolutePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserAtHostQuery_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@Host?to=User2@Host2.com;cc=User3@Host3com");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:User@host?to=User2@Host2.com;cc=User3@Host3com", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:User@host?to=User2@Host2.com;cc=User3@Host3com", uri.ToString());
|
||||
Assert.Equal("host", uri.Host);
|
||||
Assert.Equal("User", uri.UserInfo);
|
||||
Assert.Equal("", uri.AbsolutePath);
|
||||
Assert.Equal("?to=User2@Host2.com;cc=User3@Host3com", uri.Query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_SchemeUserAtHostPathQuery_Success()
|
||||
{
|
||||
Uri uri = new Uri("mailto:User@Host/Path1/./Path2/../...?to=User2@Host2.com;cc=User3@Host3com");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:User@host/Path1/./Path2/../...?to=User2@Host2.com;cc=User3@Host3com", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:User@host/Path1/./Path2/../...?to=User2@Host2.com;cc=User3@Host3com", uri.ToString());
|
||||
Assert.Equal("host", uri.Host);
|
||||
Assert.Equal("User", uri.UserInfo);
|
||||
Assert.Equal("/Path1/./Path2/../...", uri.AbsolutePath);
|
||||
Assert.Equal("?to=User2@Host2.com;cc=User3@Host3com", uri.Query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriMailTo_EAI_SomeEscaping()
|
||||
{
|
||||
Uri uri = new Uri("mailto:\u30AF@\u30AF");
|
||||
Assert.Equal("mailto", uri.Scheme);
|
||||
Assert.Equal("mailto:%E3%82%AF@\u30AF", uri.AbsoluteUri);
|
||||
Assert.Equal("mailto:\u30AF@\u30AF", uri.ToString());
|
||||
Assert.Equal("%E3%82%AF", uri.UserInfo);
|
||||
Assert.Equal("\u30AF", uri.Host);
|
||||
Assert.Equal("", uri.AbsolutePath);
|
||||
Assert.Equal("\u30AF@\u30AF", uri.GetComponents(UriComponents.UserInfo | UriComponents.Host, UriFormat.SafeUnescaped));
|
||||
}
|
||||
|
||||
|
||||
#region Helper methods
|
||||
|
||||
// private void ValidateResult(Uri result, string absoluteUri, string scheme, string host,
|
||||
|
||||
// Some MailTo Uri's succesfully parse in the contructor or TryParse, but then they throw when accessing properties.
|
||||
private void ValidateNotCorrupt(Uri uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
string result = uri.AbsoluteUri;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.False(true, "Exception thrown too late: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Helper methods
|
||||
}
|
||||
}
|
||||
45
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriParameterValidationTest.cs
vendored
Normal file
45
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriParameterValidationTest.cs
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.PrivateUri.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for WorkItemTest
|
||||
/// </summary>
|
||||
public class UriParameterValidationTest
|
||||
{
|
||||
[Fact]
|
||||
public void Uri_MakeRelativeUri_NullParameter_ThrowsArgumentException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
Uri baseUri = new Uri("http://localhost/");
|
||||
Uri rel = baseUri.MakeRelativeUri((Uri)null);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_TryCreate_NullParameter_ReturnsFalse()
|
||||
{
|
||||
Uri baseUri = new Uri("http://localhost/");
|
||||
Uri result;
|
||||
Assert.False(Uri.TryCreate(baseUri, (Uri)null, out result));
|
||||
Assert.False(Uri.TryCreate((Uri)null, baseUri, out result));
|
||||
Assert.False(Uri.TryCreate((Uri)null, (Uri)null, out result));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri_IsBaseOf_NullParameter_ThrowsArgumentException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
Uri baseUri = new Uri("http://localhost/");
|
||||
Uri relUri = null;
|
||||
bool success = baseUri.IsBaseOf(relUri);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
558
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriParserTest.cs
vendored
Normal file
558
external/corefx/src/System.Private.Uri/tests/FunctionalTests/UriParserTest.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user