Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@@ -2,7 +2,8 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyKey>MSFT</AssemblyKey>
<IsNETCoreApp>true</IsNETCoreApp>
<IsUAP>true</IsUAP>
</PropertyGroup>

View File

@@ -64,6 +64,9 @@
<data name="net_headers_rsp" xml:space="preserve">
<value>This collection holds request headers and cannot contain the specified response header.</value>
</data>
<data name="net_emptyStringCall" xml:space="preserve">
<value>The parameter '{0}' cannot be an empty string.</value>
</data>
<data name="net_WebHeaderInvalidControlChars" xml:space="preserve">
<value>Specified value has invalid Control characters.</value>
</data>

View File

@@ -6,7 +6,6 @@
<AssemblyName>System.Net.WebHeaderCollection</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Debug|AnyCPU'" />

View File

@@ -39,14 +39,7 @@ namespace System.Net
protected WebHeaderCollection(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
int count = serializationInfo.GetInt32("Count");
for (int i = 0; i < count; i++)
{
string headerName = serializationInfo.GetString(i.ToString(NumberFormatInfo.InvariantInfo));
string headerValue = serializationInfo.GetString((i + count).ToString(NumberFormatInfo.InvariantInfo));
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"calling InnerCollection.Add() key:[{headerName}], value:[{headerValue}]");
InnerCollection.Add(headerName, headerValue);
}
throw new PlatformNotSupportedException();
}
private bool AllowHttpRequestHeader
@@ -188,20 +181,12 @@ namespace System.Net
public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
//
// for now disregard streamingContext.
//
serializationInfo.AddValue("Count", Count);
for (int i = 0; i < Count; i++)
{
serializationInfo.AddValue(i.ToString(NumberFormatInfo.InvariantInfo), GetKey(i));
serializationInfo.AddValue((i + Count).ToString(NumberFormatInfo.InvariantInfo), Get(i));
}
throw new PlatformNotSupportedException();
}
void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
GetObjectData(serializationInfo, streamingContext);
throw new PlatformNotSupportedException();
}
public void Remove(HttpRequestHeader header)
@@ -307,7 +292,7 @@ namespace System.Net
public void Add(string header)
{
if (string.IsNullOrWhiteSpace(header))
if (string.IsNullOrEmpty(header))
{
throw new ArgumentNullException(nameof(header));
}
@@ -336,6 +321,15 @@ namespace System.Net
public override void Add(string name, string value)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (name.Length == 0)
{
throw new ArgumentException(SR.Format(SR.net_emptyStringCall, nameof(name)), nameof(name));
}
name = HttpValidationHelpers.CheckBadHeaderNameChars(name);
ThrowOnRestrictedHeader(name);
value = HttpValidationHelpers.CheckBadHeaderValueChars(value);
@@ -400,7 +394,7 @@ namespace System.Net
/// </devdoc>
public override void Remove(string name)
{
if (string.IsNullOrWhiteSpace(name))
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException(nameof(name));
}

View File

@@ -7,8 +7,9 @@ using Xunit;
namespace System.Net.Tests
{
public class LoggingTest
public class WebHeaderCollectionLoggingTest
{
[ActiveIssue(20470, TargetFrameworkMonikers.UapAot)]
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NetEventSource is only part of .NET Core")]
public void EventSource_ExistsWithCorrectId()

View File

@@ -4,16 +4,20 @@
<PropertyGroup>
<ProjectGuid>{F8C21EE8-B271-4014-B9D9-B2C31520AF3F}</ProjectGuid>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="WebHeaderCollectionTest.cs" />
<Compile Include="LoggingTest.cs" />
<Compile Include="WebHeaderCollectionTest.netstandard.cs" />
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
<Link>Common\System\AssertExtensions.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>CommonTest\System\PlatformDetection.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
<Link>Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

View File

@@ -2,11 +2,14 @@
// 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 System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Tests;
using Xunit;
namespace System.Net.WebHeaderCollectionTests
namespace System.Net.Tests
{
public partial class WebHeaderCollectionTest
{
@@ -138,7 +141,7 @@ namespace System.Net.WebHeaderCollectionTests
public void Setter_NullOrEmptyName_Throws(string name)
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentNullException>("name", () => w[name] = "test");
AssertExtensions.Throws<ArgumentNullException>("name", () => w[name] = "test");
}
public static object[][] InvalidNames = {
@@ -151,7 +154,7 @@ namespace System.Net.WebHeaderCollectionTests
public void Setter_InvalidName_Throws(string name)
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentException>("name", () => w[name] = "test");
AssertExtensions.Throws<ArgumentException>("name", () => w[name] = "test");
}
public static object[][] InvalidValues = {
@@ -166,7 +169,7 @@ namespace System.Net.WebHeaderCollectionTests
public void Setter_InvalidValue_Throws(string value)
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentException>("value", () => w["custom"] = value);
AssertExtensions.Throws<ArgumentException>("value", () => w["custom"] = value);
}
public static object[][] ValidValues = {
@@ -202,20 +205,48 @@ namespace System.Net.WebHeaderCollectionTests
Assert.Equal("second", w[secondName]);
}
[Theory]
[InlineData("name")]
[InlineData("nAMe")]
public void Remove_HeaderExists_RemovesFromCollection(string name)
{
var headers = new WebHeaderCollection()
{
{ "name", "value" }
};
headers.Remove(name);
Assert.Empty(headers);
headers.Remove(name);
Assert.Empty(headers);
}
[ActiveIssue(20465, TargetFrameworkMonikers.UapAot)]
[Theory]
[InlineData(null)]
[InlineData("")]
public void Remove_NullOrEmptyName_Throws(string name)
public void Remove_NullOrEmptyHeader_ThrowsArgumentNullException(string name)
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentNullException>("name", () => w.Remove(name));
var headers = new WebHeaderCollection();
AssertExtensions.Throws<ArgumentNullException>("name", () => headers.Remove(name));
}
[ActiveIssue(20465, TargetFrameworkMonikers.UapAot)]
[Theory]
[InlineData(" \r \t \n")]
[InlineData(" name ")]
[MemberData(nameof(InvalidValues))]
public void Remove_InvalidHeader_ThrowsArgumentException(string name)
{
var headers = new WebHeaderCollection();
AssertExtensions.Throws<ArgumentException>("name", () => headers.Remove(name));
}
[Fact]
public void Remove_IllegalCharacter_Throws()
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentException>("name", () => w.Remove("{"));
AssertExtensions.Throws<ArgumentException>("name", () => w.Remove("{"));
}
[Fact]
@@ -387,5 +418,253 @@ namespace System.Net.WebHeaderCollectionTests
e.Reset();
}
}
public static IEnumerable<object[]> SerializeDeserialize_Roundtrip_MemberData()
{
for (int i = 0; i < 10; i++)
{
var wc = new WebHeaderCollection();
for (int j = 0; j < i; j++)
{
wc[$"header{j}"] = $"value{j}";
}
yield return new object[] { wc };
}
}
public static IEnumerable<object[]> Add_Value_TestData()
{
yield return new object[] { null, string.Empty };
yield return new object[] { string.Empty, string.Empty };
yield return new object[] { "VaLue", "VaLue" };
yield return new object[] { " value ", "value" };
// Documentation says this should fail but it does not.
string longString = new string('a', 65536);
yield return new object[] { longString, longString };
}
[Theory]
[MemberData(nameof(Add_Value_TestData))]
public void Add_ValidValue_Success(string value, string expectedValue)
{
var headers = new WebHeaderCollection
{
{ "name", value }
};
Assert.Equal(expectedValue, headers["name"]);
}
[Fact]
public void Add_HeaderAlreadyExists_AppendsValue()
{
var headers = new WebHeaderCollection
{
{ "name", "value1" },
{ "name", null },
{ "name", "value2" },
{ "NAME", "value3" },
{ "name", "" }
};
Assert.Equal("value1,,value2,value3,", headers["name"]);
}
[ActiveIssue(20465, TargetFrameworkMonikers.UapAot)]
[Fact]
public void Add_NullName_ThrowsArgumentNullException()
{
var headers = new WebHeaderCollection();
Assert.Throws<ArgumentNullException>("name", () => headers.Add(null, "value"));
}
[ActiveIssue(20465, TargetFrameworkMonikers.UapAot)]
[Theory]
[InlineData("")]
[InlineData("(")]
[InlineData("\r \t \n")]
[InlineData(" name ")]
[MemberData(nameof(InvalidValues))]
public void Add_InvalidName_ThrowsArgumentException(string name)
{
var headers = new WebHeaderCollection();
Assert.Throws<ArgumentException>("name", () => headers.Add(name, "value"));
}
[ActiveIssue(20465, TargetFrameworkMonikers.UapAot)]
[Theory]
[MemberData(nameof(InvalidValues))]
public void Add_InvalidValue_ThrowsArgumentException(string value)
{
var headers = new WebHeaderCollection();
Assert.Throws<ArgumentException>("value", () => headers.Add("name", value));
}
[Fact]
public void Add_ValidHeader_AddsToHeaders()
{
var headers = new WebHeaderCollection()
{
"name:value1",
"name:",
"NaMe:value2",
"name: ",
};
Assert.Equal("value1,,value2,", headers["name"]);
}
[ActiveIssue(20465, TargetFrameworkMonikers.UapAot)]
[Theory]
[InlineData(null)]
[InlineData("")]
public void Add_NullHeader_ThrowsArgumentNullException(string header)
{
var headers = new WebHeaderCollection();
Assert.Throws<ArgumentNullException>("header", () => headers.Add(header));
}
[ActiveIssue(20465, TargetFrameworkMonikers.UapAot)]
[Theory]
[InlineData(" \r \t \n", "header")]
[InlineData("nocolon", "header")]
[InlineData(" :value", "name")]
[InlineData("name :value", "name")]
[InlineData("name:va\rlue", "value")]
public void Add_InvalidHeader_ThrowsArgumentException(string header, string paramName)
{
var headers = new WebHeaderCollection();
Assert.Throws<ArgumentException>(paramName, () => headers.Add(header));
}
[Fact]
public void HttpRequestHeader_Add_Rmemove_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add(HttpRequestHeader.Warning, "Warning1");
Assert.Equal(1, w.Count);
Assert.Equal("Warning1", w[HttpRequestHeader.Warning]);
Assert.Equal("Warning", w.AllKeys[0]);
w.Remove(HttpRequestHeader.Warning);
Assert.Equal(0, w.Count);
}
[Fact]
public void HttpRequestHeader_Get_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
string[] values = w.GetValues(0);
Assert.Equal("value1", values[0]);
Assert.Equal("value2", values[1]);
}
[Fact]
public void HttpRequestHeader_ToByteArray_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
byte[] byteArr = w.ToByteArray();
Assert.NotEmpty(byteArr);
}
[Fact]
public void HttpRequestHeader_GetKey_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
Assert.NotEmpty(w.GetKey(0));
}
[Fact]
public void HttpRequestHeader_GetValues_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
Assert.Equal("value1", w.GetValues("header1")[0]);
}
[Fact]
public void HttpRequestHeader_Clear_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
w.Clear();
Assert.Equal(0, w.Count);
}
[Fact]
public void HttpRequestHeader_IsRestricted_Success()
{
Assert.True(WebHeaderCollection.IsRestricted("Accept"));
Assert.False(WebHeaderCollection.IsRestricted("Age"));
Assert.False(WebHeaderCollection.IsRestricted("Accept", true));
}
[Fact]
public void HttpRequestHeader_AddHeader_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add(HttpRequestHeader.ContentLength, "10");
w.Add(HttpRequestHeader.ContentType, "text/html");
Assert.Equal(2,w.Count);
}
[Fact]
public void WebHeaderCollection_Keys_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add(HttpRequestHeader.ContentLength, "10");
w.Add(HttpRequestHeader.ContentType, "text/html");
Assert.Equal(2, w.Keys.Count);
}
[Fact]
public void HttpRequestHeader_AddHeader_Failure()
{
WebHeaderCollection w = new WebHeaderCollection();
char[] arr = new char[ushort.MaxValue + 1];
string maxStr = new string(arr);
Assert.Throws<ArgumentException>(() => w.Add(HttpRequestHeader.ContentLength,maxStr));
Assert.Throws<ArgumentException>(() => w.Add("ContentLength", maxStr));
}
[Fact]
public void HttpResponseHeader_Set_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Set(HttpResponseHeader.ProxyAuthenticate, "value123");
Assert.Equal("value123", w[HttpResponseHeader.ProxyAuthenticate]);
}
[Fact]
public void HttpRequestHeader_Set_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Set(HttpRequestHeader.Connection, "keep-alive");
Assert.Equal(1, w.Count);
Assert.Equal("keep-alive", w[HttpRequestHeader.Connection]);
Assert.Equal("Connection", w.AllKeys[0]);
}
[Fact]
public void NameValue_Set_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Set("firstName", "first");
Assert.Equal(1, w.Count);
Assert.NotEmpty(w);
Assert.NotEmpty(w.AllKeys);
Assert.Equal(new[] { "firstName" }, w.AllKeys);
Assert.Equal("first", w["firstName"]);
}
}
}

View File

@@ -1,178 +0,0 @@
// 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 System.Runtime.Serialization.Formatters.Tests;
using Xunit;
namespace System.Net.WebHeaderCollectionTests
{
public partial class WebHeaderCollectionTest
{
public static IEnumerable<object[]> SerializeDeserialize_Roundtrip_MemberData()
{
for (int i = 0; i < 10; i++)
{
var wc = new WebHeaderCollection();
for (int j = 0; j < i; j++)
{
wc[$"header{j}"] = $"value{j}";
}
yield return new object[] { wc };
}
}
[Theory]
[MemberData(nameof(SerializeDeserialize_Roundtrip_MemberData))]
public void SerializeDeserialize_Roundtrip(WebHeaderCollection c)
{
Assert.Equal(c, BinaryFormatterHelpers.Clone(c));
}
[Fact]
public void HttpRequestHeader_Add_Remove_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add(HttpRequestHeader.Warning, "Warning1");
Assert.Equal(1, w.Count);
Assert.Equal("Warning1", w[HttpRequestHeader.Warning]);
Assert.Equal("Warning", w.AllKeys[0]);
w.Remove(HttpRequestHeader.Warning);
Assert.Equal(0, w.Count);
}
[Fact]
public void HttpRequestHeader_Get_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
string[] values = w.GetValues(0);
Assert.Equal("value1", values[0]);
Assert.Equal("value2", values[1]);
}
[Fact]
public void HttpRequestHeader_ToByteArray_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
byte[] byteArr = w.ToByteArray();
Assert.NotEmpty(byteArr);
}
[Fact]
public void HttpRequestHeader_GetKey_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
Assert.NotEmpty(w.GetKey(0));
}
[Fact]
public void HttpRequestHeader_GetValues_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
Assert.Equal("value1", w.GetValues("header1")[0]);
}
[Fact]
public void HttpRequestHeader_Clear_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
w.Clear();
Assert.Equal(0, w.Count);
}
[Fact]
public void HttpRequestHeader_IsRestricted_Success()
{
Assert.True(WebHeaderCollection.IsRestricted("Accept"));
Assert.False(WebHeaderCollection.IsRestricted("Age"));
Assert.False(WebHeaderCollection.IsRestricted("Accept", true));
}
[Fact]
public void HttpRequestHeader_AddHeader_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add(HttpRequestHeader.ContentLength, "10");
w.Add(HttpRequestHeader.ContentType, "text/html");
Assert.Equal(2,w.Count);
}
[Fact]
public void WebHeaderCollection_Keys_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add(HttpRequestHeader.ContentLength, "10");
w.Add(HttpRequestHeader.ContentType, "text/html");
Assert.Equal(2, w.Keys.Count);
}
[Fact]
public void HttpRequestHeader_AddHeader_Failure()
{
WebHeaderCollection w = new WebHeaderCollection();
char[] arr = new char[ushort.MaxValue + 1];
string maxStr = new string(arr);
Assert.Throws<ArgumentException>(() => w.Add(HttpRequestHeader.ContentLength,maxStr));
Assert.Throws<ArgumentException>(() => w.Add("ContentLength", maxStr));
}
[Fact]
public void HttpRequestHeader_AddMissingColon_Failure()
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentException>(() => w.Add("ContentType#text/html"));
}
[Fact]
public void HttpRequestHeader_Remove_Failure()
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentNullException>(() => w.Remove(null));
}
[Fact]
public void HttpResponseHeader_Set_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Set(HttpResponseHeader.ProxyAuthenticate, "value123");
Assert.Equal("value123", w[HttpResponseHeader.ProxyAuthenticate]);
}
[Fact]
public void HttpRequestHeader_Set_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Set(HttpRequestHeader.Connection, "keep-alive");
Assert.Equal(1, w.Count);
Assert.Equal("keep-alive", w[HttpRequestHeader.Connection]);
Assert.Equal("Connection", w.AllKeys[0]);
}
[Fact]
public void NameValue_Set_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Set("firstName", "first");
Assert.Equal(1, w.Count);
Assert.NotEmpty(w);
Assert.NotEmpty(w.AllKeys);
Assert.Equal(new[] { "firstName" }, w.AllKeys);
Assert.Equal("first", w["firstName"]);
}
}
}