-Added IgnoreSerializableInterface to DefaultContractResolver
-Changed serializing ISerializable types under partial trust to error to fix security issue -Fixed LinqBridge collision error in .NET 2.0 by moving types to a different namespace -Fixed JObject.Keys error when object has no items
This commit is contained in:
@@ -25,8 +25,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
#if !NETFX_CORE
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -23,10 +23,6 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
#if !NETFX_CORE
|
||||
using NUnit.Framework;
|
||||
#else
|
||||
|
||||
@@ -52,11 +52,11 @@ using System.Xml.Serialization;
|
||||
using System.Collections.ObjectModel;
|
||||
using Newtonsoft.Json.Bson;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Converters;
|
||||
#if !PocketPC && !NET20 && !WINDOWS_PHONE
|
||||
using System.Runtime.Serialization.Json;
|
||||
#endif
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Globalization;
|
||||
@@ -72,6 +72,11 @@ using System.Linq.Expressions;
|
||||
using System.Dynamic;
|
||||
using System.ComponentModel;
|
||||
#endif
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
@@ -2789,6 +2794,86 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Test]
|
||||
public void SerializeISerializableInPartialTrustWithIgnoreInterface()
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(false);
|
||||
ISerializableTestObject value = new ISerializableTestObject("string!", 0, default(DateTimeOffset), null);
|
||||
|
||||
string json = JsonConvert.SerializeObject(value, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new DefaultContractResolver(false)
|
||||
{
|
||||
IgnoreSerializableInterface = true
|
||||
}
|
||||
});
|
||||
|
||||
Assert.AreEqual("{}", json);
|
||||
|
||||
value = JsonConvert.DeserializeObject<ISerializableTestObject>("{booleanValue:true}", new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new DefaultContractResolver(false)
|
||||
{
|
||||
IgnoreSerializableInterface = true
|
||||
}
|
||||
});
|
||||
|
||||
Assert.IsNotNull(value);
|
||||
Assert.AreEqual(false, value._booleanValue);
|
||||
}
|
||||
finally
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeISerializableInPartialTrust()
|
||||
{
|
||||
try
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSerializationException>(
|
||||
@"Type 'Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+ISerializableTestObject' implements ISerializable but cannot be deserialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
|
||||
To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add to JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.",
|
||||
() =>
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(false);
|
||||
|
||||
JsonConvert.DeserializeObject<ISerializableTestObject>("{booleanValue:true}");
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeISerializableInPartialTrust()
|
||||
{
|
||||
try
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSerializationException>(
|
||||
@"Type 'Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+ISerializableTestObject' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
|
||||
To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add to JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.",
|
||||
() =>
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(false);
|
||||
ISerializableTestObject value = new ISerializableTestObject("string!", 0, default(DateTimeOffset), null);
|
||||
|
||||
JsonConvert.SerializeObject(value);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void SerializeISerializableTestObject_IsoDate()
|
||||
{
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
#if !NETFX_CORE
|
||||
using NUnit.Framework;
|
||||
@@ -36,7 +34,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
|
||||
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
|
||||
#endif
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
#if !NETFX_CORE
|
||||
@@ -36,7 +34,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
|
||||
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
|
||||
#endif
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.IO;
|
||||
using ErrorEventArgs=Newtonsoft.Json.Serialization.ErrorEventArgs;
|
||||
|
||||
|
||||
@@ -27,12 +27,9 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
#if !NETFX_CORE
|
||||
using NUnit.Framework;
|
||||
@@ -42,8 +39,6 @@ using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttrib
|
||||
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
|
||||
#endif
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
|
||||
@@ -26,9 +26,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
#if !NETFX_CORE
|
||||
|
||||
Reference in New Issue
Block a user