This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
IriEncodingDecodingTests.cs
158 lines (146 loc) · 6.94 KB
/
IriEncodingDecodingTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// 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
{
public class IriEncodingDecodingTest
{
// This array contains potentially problematic URI data strings and their canonical encoding.
private static string[,] RFC3986CompliantDecoding =
{
{ "%3B%2F%3F%3A%40%26%3D%2B%24%2C", "%3B%2F%3F%3A%40%26%3D%2B%24%2C" }, // Encoded RFC 2396 Reserved Marks.
{ @"-_.~", @"-_.~" }, // RFC3986 Unreserved Marks.
{ "%2D%5F%2E%7E", @"-_.~" }, // Encoded RFC 3986 Unreserved Marks.
{ "%2F%3F%3A%40%23%5B%5D", "%2F%3F%3A%40%23%5B%5D" }, // Encoded RFC 3986 Gen Delims.
{ @";&=+$,!'()*", @";&=+$,!'()*" }, // RFC 3986 Sub Delims.
{ "%3B%26%3D%2B%24%2C%21%27%28%29%2A", "%3B%26%3D%2B%24%2C%21%27%28%29%2A" }, // Encoded RFC3986 Sub Delims.
{ "%E2%80%8F%E2%80%8E%E2%80%AA%E2%80%AB%E2%80%AC%E2%80%AD%E2%80%AE",
"%E2%80%8F%E2%80%8E%E2%80%AA%E2%80%AB%E2%80%AC%E2%80%AD%E2%80%AE" }, // Encoded Unicode Bidi Control Characters.
{ "\u200E\u200F\u202A\u202B\u202C\u202D\u202E",
"%E2%80%8E%E2%80%8F%E2%80%AA%E2%80%AB%E2%80%AC%E2%80%AD%E2%80%AE" }, // Unencoded Unicode Bidi Control Characters
};
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void AbsoluteUri_DangerousPathSymbols_RFC3986CompliantAbsoluteUri()
{
Uri uri;
string baseUri = "http://a/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
string sourceStr = baseUri + RFC3986CompliantDecoding[i, 0];
uri = new Uri(sourceStr);
Assert.Equal(baseUri + RFC3986CompliantDecoding[i, 1], uri.AbsoluteUri);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void AbsolutePath_DangerousPathSymbols_RFC3986CompliantAbsolutePath()
{
Uri uri;
string host = "http://a";
string path = "/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
string sourceStr = host + path + RFC3986CompliantDecoding[i, 0];
uri = new Uri(sourceStr);
Assert.Equal(path + RFC3986CompliantDecoding[i, 1], uri.AbsolutePath);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void Segments_DangerousPathSymbols_RFC3986CompliantPathSegments()
{
Uri uri;
string host = "http://a";
string path = "/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
string sourceStr = host + path + RFC3986CompliantDecoding[i, 0];
uri = new Uri(sourceStr);
Assert.Equal(path + RFC3986CompliantDecoding[i, 1], String.Join(String.Empty, uri.Segments));
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void Equality_DangerousPathSymbols_RFC3986CompliantEquality()
{
string baseUri = "http://a/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
Uri uri1 = new Uri(baseUri + RFC3986CompliantDecoding[i, 0]);
Uri uri2 = new Uri(baseUri + RFC3986CompliantDecoding[i, 1]);
Assert.Equal(uri1, uri2);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void PathAndQuery_DangerousQuerySymbols_RFC3986CompliantPathAndQuery()
{
Uri uri;
string host = "http://a";
string path = "/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
string sourceStr = host + path + "?" + RFC3986CompliantDecoding[i, 0];
uri = new Uri(sourceStr);
Assert.Equal(path + "?" + RFC3986CompliantDecoding[i, 1], uri.PathAndQuery);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void Query_DangerousQuerySymbols_RFC3986CompliantQuery()
{
Uri uri;
string baseUri = "http://a/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
string sourceStr = baseUri + "?" + RFC3986CompliantDecoding[i, 0];
uri = new Uri(sourceStr);
Assert.Equal("?" + RFC3986CompliantDecoding[i, 1], uri.Query);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void Equality_DangerousQuerySymbols_RFC3986CompliantEquality()
{
string baseUri = "http://a/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
Uri uriTest = new Uri(baseUri + "?" + RFC3986CompliantDecoding[i, 0]);
Uri uriTest1 = new Uri(baseUri + "?" + RFC3986CompliantDecoding[i, 1]);
Assert.Equal(uriTest, uriTest1);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void Fragment_DangerousFragmentSymbols_RFC3986CompliantFragment()
{
Uri uri;
string baseUri = "http://a/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
string sourceStr = baseUri + "#" + RFC3986CompliantDecoding[i, 0];
uri = new Uri(sourceStr);
Assert.Equal("#" + RFC3986CompliantDecoding[i, 1], uri.Fragment);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void UserInfo_DangerousUserInfoSymbols_RFC3986CompliantUserInfo()
{
Uri uri;
string baseUri = "http://";
string host = "a";
string path = "/%C3%88/";
for (int i = 0; i < RFC3986CompliantDecoding.GetLength(0); i++)
{
string sourceStr = baseUri + RFC3986CompliantDecoding[i, 0] + "@" + host + path;
uri = new Uri(sourceStr);
Assert.Equal(RFC3986CompliantDecoding[i, 1], uri.UserInfo);
}
}
}
}