From 9bca503d0208267a12d4e3db5ef1a1c7a7a95694 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Tue, 18 Dec 2018 15:40:50 +0200 Subject: [PATCH 01/20] Add a specific exception to be thrown when trying to parse a parameter with an invalid value --- .../InvalidParameterValueException.cs | 47 +++++++++++++++++++ .../Gigya.ServiceContract.csproj | 1 + Gigya.ServiceContract/JsonHelper.cs | 23 +++++++-- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs diff --git a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs new file mode 100644 index 00000000..1cdcd57d --- /dev/null +++ b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs @@ -0,0 +1,47 @@ +using System; +using System.Runtime.Serialization; +using Gigya.Common.Contracts.Exceptions; + +namespace Gigya.ServiceContract.Exceptions +{ + /// + /// This excpetion is thrown if a parameter contains an invalid value + /// + public class InvalidParameterValueException: RequestException + { + ///ErrorCode of Invalid_parameter_value + public override int? ErrorCode => 400006; + + /// + /// Name of the parameter which has an invalid value + /// + public string ParameterName { get; } + + /// + /// Path to the parameter (e.g. on Json object) + /// + public string ParameterPath { get; } + + /// + /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// Optional. A collection of type that contains additional data about the exception, which must be encrypted when stored. + /// Optional. A collection of type that contains additional data about the exception, which needn't be encrypted when stored. + /// Optional. The exception that is the cause of the current exception. + public InvalidParameterValueException(string parameterName, string parameterPath, string message, Exception innerException = null, Tags encrypted = null, Tags unencrypted = null) : base(message, innerException, encrypted, unencrypted) + { + ParameterName = parameterName; + ParameterPath = parameterPath; + } + + /// Initializes a new instance of the class with serialized data. + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. + /// The parameter is null. + /// The class name is null or is zero (0). + protected InvalidParameterValueException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} diff --git a/Gigya.ServiceContract/Gigya.ServiceContract.csproj b/Gigya.ServiceContract/Gigya.ServiceContract.csproj index 32733aa8..9f0b6c74 100644 --- a/Gigya.ServiceContract/Gigya.ServiceContract.csproj +++ b/Gigya.ServiceContract/Gigya.ServiceContract.csproj @@ -46,6 +46,7 @@ + diff --git a/Gigya.ServiceContract/JsonHelper.cs b/Gigya.ServiceContract/JsonHelper.cs index 4cac363c..12e89dfc 100644 --- a/Gigya.ServiceContract/JsonHelper.cs +++ b/Gigya.ServiceContract/JsonHelper.cs @@ -21,6 +21,8 @@ #endregion using System; +using System.Linq; +using Gigya.ServiceContract.Exceptions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -61,10 +63,25 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) return dto.LocalDateTime; } - if (value is string && Type.GetTypeCode(paramType) == TypeCode.Object && paramType != typeof(DateTimeOffset) && paramType != typeof(TimeSpan) && paramType != typeof(Guid) && paramType != typeof(byte[])) - return JsonConvert.DeserializeObject((string)value, paramType); + try + { + if (value is string && Type.GetTypeCode(paramType) == TypeCode.Object && paramType != typeof(DateTimeOffset) && paramType != typeof(TimeSpan) && paramType != typeof(Guid) && paramType != typeof(byte[])) + return JsonConvert.DeserializeObject((string) value, paramType); + + return JToken.FromObject(value).ToObject(targetType, Serializer); + } + catch (JsonReaderException jsException) + { + var parameterPath = string.IsNullOrEmpty(jsException.Path) ? null : jsException.Path; + var parameterName = parameterPath?.Split('.').LastOrDefault(); + + var messageWithoutPath = jsException.Message; + if (messageWithoutPath.Contains(". Path '")) + messageWithoutPath = messageWithoutPath.Substring(0, messageWithoutPath.IndexOf(". Path '")); + + throw new InvalidParameterValueException(parameterName, parameterPath, messageWithoutPath, innerException: jsException); + } - return JToken.FromObject(value).ToObject(targetType, Serializer); } } } From b7aad8b5435d60e4c9653ed4790579ddf56768a0 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Tue, 18 Dec 2018 16:04:42 +0200 Subject: [PATCH 02/20] increase ServiceContract version number --- Gigya.ServiceContract/Properties/AssemblyInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gigya.ServiceContract/Properties/AssemblyInfo.cs b/Gigya.ServiceContract/Properties/AssemblyInfo.cs index d6f43d34..f21513ce 100644 --- a/Gigya.ServiceContract/Properties/AssemblyInfo.cs +++ b/Gigya.ServiceContract/Properties/AssemblyInfo.cs @@ -40,9 +40,9 @@ [assembly: AssemblyTrademark("")] -[assembly: AssemblyInformationalVersion("2.6.1")]// if pre-release should be in the format of "2.4.11-pre01". -[assembly: AssemblyVersion("2.6.1")] -[assembly: AssemblyFileVersion("2.6.1")] +[assembly: AssemblyInformationalVersion("2.6.2")]// if pre-release should be in the format of "2.4.11-pre01". +[assembly: AssemblyVersion("2.6.2")] +[assembly: AssemblyFileVersion("2.6.2")] From 795edc09b5c8d7af1fe8a8919da706fa992b25ad Mon Sep 17 00:00:00 2001 From: Daniel Lamberger Date: Wed, 19 Dec 2018 15:18:36 +0200 Subject: [PATCH 03/20] Removed unneeded console print --- Gigya.Microdot.Ninject/RegexTimeoutInitializer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Gigya.Microdot.Ninject/RegexTimeoutInitializer.cs b/Gigya.Microdot.Ninject/RegexTimeoutInitializer.cs index 475528c0..d27e0d36 100644 --- a/Gigya.Microdot.Ninject/RegexTimeoutInitializer.cs +++ b/Gigya.Microdot.Ninject/RegexTimeoutInitializer.cs @@ -24,7 +24,6 @@ public void Init() } AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT",TimeSpan.FromMilliseconds(regexDefaultMachTimeOutMs)); - Console.WriteLine($"REGEX_DEFAULT_MATCH_TIMEOUT is set to {regexDefaultMachTimeOutMs} ms"); } } } \ No newline at end of file From bac00fc9b05100414596f20406e85f7bae38aa10 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Tue, 18 Dec 2018 15:42:59 +0200 Subject: [PATCH 04/20] throw InvalidParameterValue exception in case Json cannot be converted properly --- .../HttpService/HttpServiceListener.cs | 18 ++++++++++++++++-- .../InvalidParameterValueException.cs | 8 +++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs b/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs index 3d4620b6..672c1c1d 100644 --- a/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs +++ b/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs @@ -49,6 +49,7 @@ using Gigya.Microdot.SharedLogic.HttpService; using Gigya.Microdot.SharedLogic.Measurement; using Gigya.Microdot.SharedLogic.Security; +using Gigya.ServiceContract.Exceptions; using Metrics; using Newtonsoft.Json; @@ -554,8 +555,21 @@ private static object[] GetParametersByName(ServiceMethod serviceMethod, IDictio { return serviceMethod.ServiceInterfaceMethod .GetParameters() - .Select(p => JsonHelper.ConvertWeaklyTypedValue(args[p.Name], p.ParameterType)) - .ToArray(); + .Select(p => + { + try + { + return JsonHelper.ConvertWeaklyTypedValue(args[p.Name], p.ParameterType); + } + catch (InvalidParameterValueException ex) + { + if (ex.ParameterName != null) + throw; + + throw new InvalidParameterValueException(p.Name, null, ex.Message, ex); + } + }). + ToArray(); } internal static HttpStatusCode GetExceptionStatusCode(Exception exception) diff --git a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs index 1cdcd57d..8af1c9cc 100644 --- a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs +++ b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs @@ -1,12 +1,14 @@ using System; using System.Runtime.Serialization; using Gigya.Common.Contracts.Exceptions; +using Newtonsoft.Json; namespace Gigya.ServiceContract.Exceptions { /// /// This excpetion is thrown if a parameter contains an invalid value /// + [Serializable] public class InvalidParameterValueException: RequestException { ///ErrorCode of Invalid_parameter_value @@ -15,12 +17,12 @@ public class InvalidParameterValueException: RequestException /// /// Name of the parameter which has an invalid value /// - public string ParameterName { get; } + public string ParameterName { get; set; } /// /// Path to the parameter (e.g. on Json object) /// - public string ParameterPath { get; } + public string ParameterPath { get; set; } /// /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. @@ -40,7 +42,7 @@ public InvalidParameterValueException(string parameterName, string parameterPath /// The that contains contextual information about the source or destination. /// The parameter is null. /// The class name is null or is zero (0). - protected InvalidParameterValueException(SerializationInfo info, StreamingContext context) : base(info, context) + public InvalidParameterValueException(SerializationInfo info, StreamingContext context) : base(info, context) { } } From a4f758a984e6e6234a084efbae11ffb919a4f66c Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Thu, 20 Dec 2018 16:01:21 +0200 Subject: [PATCH 05/20] Add exception if thrown JsonSerializationException --- Gigya.ServiceContract/JsonHelper.cs | 37 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Gigya.ServiceContract/JsonHelper.cs b/Gigya.ServiceContract/JsonHelper.cs index 12e89dfc..30318d65 100644 --- a/Gigya.ServiceContract/JsonHelper.cs +++ b/Gigya.ServiceContract/JsonHelper.cs @@ -22,6 +22,7 @@ using System; using System.Linq; +using System.Text.RegularExpressions; using Gigya.ServiceContract.Exceptions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -35,6 +36,9 @@ public static class JsonHelper { private static JsonSerializer Serializer { get; } = new JsonSerializer { DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind }; + private const string ParamCaptureName = "param"; + private static readonly Regex ParamRegex = new Regex(@"Path\s'(?<" + ParamCaptureName + ">.*)'.$", RegexOptions.Compiled | RegexOptions.CultureInvariant); + /// /// Converts values that were deserialized from JSON with weak typing (e.g. into ) back into @@ -65,7 +69,9 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) try { - if (value is string && Type.GetTypeCode(paramType) == TypeCode.Object && paramType != typeof(DateTimeOffset) && paramType != typeof(TimeSpan) && paramType != typeof(Guid) && paramType != typeof(byte[])) + if (value is string && Type.GetTypeCode(paramType) == TypeCode.Object && + paramType != typeof(DateTimeOffset) && paramType != typeof(TimeSpan) && paramType != typeof(Guid) && + paramType != typeof(byte[])) return JsonConvert.DeserializeObject((string) value, paramType); return JToken.FromObject(value).ToObject(targetType, Serializer); @@ -73,15 +79,32 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) catch (JsonReaderException jsException) { var parameterPath = string.IsNullOrEmpty(jsException.Path) ? null : jsException.Path; - var parameterName = parameterPath?.Split('.').LastOrDefault(); + throw InvalidParameterValueException(parameterPath, jsException); + } + catch (JsonSerializationException serException) + { + string parameterPath = null; + var match = ParamRegex.Match(serException.Message); + if (match.Success) + parameterPath = match.Groups[ParamCaptureName]?.Value; - var messageWithoutPath = jsException.Message; - if (messageWithoutPath.Contains(". Path '")) - messageWithoutPath = messageWithoutPath.Substring(0, messageWithoutPath.IndexOf(". Path '")); - - throw new InvalidParameterValueException(parameterName, parameterPath, messageWithoutPath, innerException: jsException); + throw InvalidParameterValueException(parameterPath, serException); } } + + private static InvalidParameterValueException InvalidParameterValueException(string parameterPath, JsonException jsException) + { + if (string.IsNullOrEmpty(parameterPath)) + parameterPath = null; + + var parameterName = parameterPath?.Split('.').LastOrDefault(); + + var messageWithoutPath = jsException.Message; + if (messageWithoutPath.Contains(". Path '")) + messageWithoutPath = messageWithoutPath.Substring(0, messageWithoutPath.IndexOf(". Path '")); + + throw new InvalidParameterValueException(parameterName, parameterPath, messageWithoutPath, innerException: jsException); + } } } From aca880d573816388240640401f1d6b5e31b86575 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Thu, 20 Dec 2018 16:02:41 +0200 Subject: [PATCH 06/20] increase version no --- Gigya.ServiceContract/Properties/AssemblyInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gigya.ServiceContract/Properties/AssemblyInfo.cs b/Gigya.ServiceContract/Properties/AssemblyInfo.cs index f21513ce..e9848298 100644 --- a/Gigya.ServiceContract/Properties/AssemblyInfo.cs +++ b/Gigya.ServiceContract/Properties/AssemblyInfo.cs @@ -40,9 +40,9 @@ [assembly: AssemblyTrademark("")] -[assembly: AssemblyInformationalVersion("2.6.2")]// if pre-release should be in the format of "2.4.11-pre01". -[assembly: AssemblyVersion("2.6.2")] -[assembly: AssemblyFileVersion("2.6.2")] +[assembly: AssemblyInformationalVersion("2.7.0")]// if pre-release should be in the format of "2.4.11-pre01". +[assembly: AssemblyVersion("2.7.0")] +[assembly: AssemblyFileVersion("2.7.0")] From d643471d6d4a5d9277f631a8f290fd8b784625c6 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Sun, 23 Dec 2018 15:58:08 +0200 Subject: [PATCH 07/20] ParameterPath as string array --- .../InvalidParameterValueException.cs | 4 ++-- Gigya.ServiceContract/JsonHelper.cs | 24 ++++--------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs index 1cdcd57d..2e568631 100644 --- a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs +++ b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs @@ -20,7 +20,7 @@ public class InvalidParameterValueException: RequestException /// /// Path to the parameter (e.g. on Json object) /// - public string ParameterPath { get; } + public string[] ParameterPath { get; } /// /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. @@ -29,7 +29,7 @@ public class InvalidParameterValueException: RequestException /// Optional. A collection of type that contains additional data about the exception, which must be encrypted when stored. /// Optional. A collection of type that contains additional data about the exception, which needn't be encrypted when stored. /// Optional. The exception that is the cause of the current exception. - public InvalidParameterValueException(string parameterName, string parameterPath, string message, Exception innerException = null, Tags encrypted = null, Tags unencrypted = null) : base(message, innerException, encrypted, unencrypted) + public InvalidParameterValueException(string parameterName, string[] parameterPath, string message, Exception innerException = null, Tags encrypted = null, Tags unencrypted = null) : base(message, innerException, encrypted, unencrypted) { ParameterName = parameterName; ParameterPath = parameterPath; diff --git a/Gigya.ServiceContract/JsonHelper.cs b/Gigya.ServiceContract/JsonHelper.cs index 30318d65..3bfaf473 100644 --- a/Gigya.ServiceContract/JsonHelper.cs +++ b/Gigya.ServiceContract/JsonHelper.cs @@ -78,33 +78,19 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) } catch (JsonReaderException jsException) { - var parameterPath = string.IsNullOrEmpty(jsException.Path) ? null : jsException.Path; - throw InvalidParameterValueException(parameterPath, jsException); + var parameterPath = string.IsNullOrEmpty(jsException.Path) ? new string[0] : jsException.Path.Split('.'); + throw new InvalidParameterValueException(null, parameterPath, jsException.Message, innerException: jsException); } catch (JsonSerializationException serException) { - string parameterPath = null; + string parameterPathStr = null; var match = ParamRegex.Match(serException.Message); if (match.Success) - parameterPath = match.Groups[ParamCaptureName]?.Value; + parameterPathStr = match.Groups[ParamCaptureName]?.Value; - throw InvalidParameterValueException(parameterPath, serException); + throw new InvalidParameterValueException(null, parameterPathStr?.Split(',') ?? new string[0], serException.Message, innerException: serException); } } - - private static InvalidParameterValueException InvalidParameterValueException(string parameterPath, JsonException jsException) - { - if (string.IsNullOrEmpty(parameterPath)) - parameterPath = null; - - var parameterName = parameterPath?.Split('.').LastOrDefault(); - - var messageWithoutPath = jsException.Message; - if (messageWithoutPath.Contains(". Path '")) - messageWithoutPath = messageWithoutPath.Substring(0, messageWithoutPath.IndexOf(". Path '")); - - throw new InvalidParameterValueException(parameterName, parameterPath, messageWithoutPath, innerException: jsException); - } } } From 45606d387ce2386314efa8a3faae98fac9880e52 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Sun, 23 Dec 2018 16:01:45 +0200 Subject: [PATCH 08/20] Make InvalidParameterValueException serializable --- .../Exceptions/InvalidParameterValueException.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs index 2e568631..36955acf 100644 --- a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs +++ b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs @@ -15,12 +15,12 @@ public class InvalidParameterValueException: RequestException /// /// Name of the parameter which has an invalid value /// - public string ParameterName { get; } + public string ParameterName { get; set; } /// /// Path to the parameter (e.g. on Json object) /// - public string[] ParameterPath { get; } + public string[] ParameterPath { get; set; } /// /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. @@ -40,7 +40,7 @@ public InvalidParameterValueException(string parameterName, string[] parameterPa /// The that contains contextual information about the source or destination. /// The parameter is null. /// The class name is null or is zero (0). - protected InvalidParameterValueException(SerializationInfo info, StreamingContext context) : base(info, context) + public InvalidParameterValueException(SerializationInfo info, StreamingContext context) : base(info, context) { } } From 8ba7d6cdd31e62e557673550a8beb4b47d81dec6 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Sun, 23 Dec 2018 16:02:55 +0200 Subject: [PATCH 09/20] Serialize breadcrumbs after adding them to the object --- .../Exceptions/StackTraceEnhancer.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Gigya.Microdot.SharedLogic/Exceptions/StackTraceEnhancer.cs b/Gigya.Microdot.SharedLogic/Exceptions/StackTraceEnhancer.cs index ff66dce4..9a186c15 100644 --- a/Gigya.Microdot.SharedLogic/Exceptions/StackTraceEnhancer.cs +++ b/Gigya.Microdot.SharedLogic/Exceptions/StackTraceEnhancer.cs @@ -33,6 +33,18 @@ public StackTraceEnhancer(Func getConfig, IEnvironme public JObject ToJObjectWithBreadcrumb(Exception exception) { + var breadcrumb = new Breadcrumb + { + ServiceName = CurrentApplicationInfo.Name, + ServiceVersion = CurrentApplicationInfo.Version.ToString(), + HostName = CurrentApplicationInfo.HostName, + DataCenter = Environment.Zone, + DeploymentEnvironment = Environment.DeploymentEnvironment + }; + + if (exception is SerializableException serEx) + serEx.AddBreadcrumb(breadcrumb); + var jobject = JObject.FromObject(exception, Serializer); if (GetConfig().Enabled == false) @@ -47,18 +59,6 @@ public JObject ToJObjectWithBreadcrumb(Exception exception) breadcrumbTarget = jobject.Property("StackTraceString"); } - var breadcrumb = new Breadcrumb - { - ServiceName = CurrentApplicationInfo.Name, - ServiceVersion = CurrentApplicationInfo.Version.ToString(), - HostName = CurrentApplicationInfo.HostName, - DataCenter = Environment.Zone, - DeploymentEnvironment = Environment.DeploymentEnvironment - }; - - if (exception is SerializableException serEx) - serEx.AddBreadcrumb(breadcrumb); - breadcrumbTarget.Value = $"\r\n--- End of stack trace from {breadcrumb} ---\r\n{breadcrumbTarget.Value}"; return jobject; From 2b137cca5c162b929d52bb25ea41ec416287cb38 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Sun, 23 Dec 2018 16:05:13 +0200 Subject: [PATCH 10/20] pass ParameterPath from original exception --- Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs b/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs index 672c1c1d..78faea39 100644 --- a/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs +++ b/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs @@ -566,7 +566,7 @@ private static object[] GetParametersByName(ServiceMethod serviceMethod, IDictio if (ex.ParameterName != null) throw; - throw new InvalidParameterValueException(p.Name, null, ex.Message, ex); + throw new InvalidParameterValueException(p.Name, ex.ParameterPath, ex.Message, ex); } }). ToArray(); From cef99f5a493deecef77a730965cc2e9375d35b48 Mon Sep 17 00:00:00 2001 From: Daniel Lamberger Date: Mon, 24 Dec 2018 12:53:40 +0200 Subject: [PATCH 11/20] review --- .../Exceptions/InvalidParameterValueException.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs index 36955acf..e13843b9 100644 --- a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs +++ b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs @@ -18,21 +18,25 @@ public class InvalidParameterValueException: RequestException public string ParameterName { get; set; } /// - /// Path to the parameter (e.g. on Json object) + /// For parameters that contain data structures, the path inside the data structure pointing to the field/property that + /// caused the deserialization or validation error. /// - public string[] ParameterPath { get; set; } + public string[] ErrorPath { get; } /// /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. /// + /// Name of the parameter which has an invalid value + /// For parameters that contain data structures, the path inside the data structure pointing to the field/property that + /// caused the deserialization or validation error. /// The error message that explains the reason for the exception. /// Optional. A collection of type that contains additional data about the exception, which must be encrypted when stored. /// Optional. A collection of type that contains additional data about the exception, which needn't be encrypted when stored. /// Optional. The exception that is the cause of the current exception. - public InvalidParameterValueException(string parameterName, string[] parameterPath, string message, Exception innerException = null, Tags encrypted = null, Tags unencrypted = null) : base(message, innerException, encrypted, unencrypted) + public InvalidParameterValueException(string parameterName, string[] errorPath, string message, Exception innerException = null, Tags encrypted = null, Tags unencrypted = null) : base(message, innerException, encrypted, unencrypted) { ParameterName = parameterName; - ParameterPath = parameterPath; + ErrorPath = errorPath; } /// Initializes a new instance of the class with serialized data. From 7dc31f8a1bbaae6839717b8e28a78bd14fc5083c Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Mon, 24 Dec 2018 16:04:20 +0200 Subject: [PATCH 12/20] InvalidParameterValueException - ErrorPath --- .../InvalidParameterValueException.cs | 13 ++-- Gigya.ServiceContract/JsonHelper.cs | 2 +- Gigya.ServiceContract/ServiceContract.sln | 11 +++ ....Microdot.ServiceContract.UnitTests.csproj | 16 ++-- .../JsonHelperTests.cs | 75 ++++++++++++++++++- 5 files changed, 98 insertions(+), 19 deletions(-) diff --git a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs index e13843b9..727f3848 100644 --- a/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs +++ b/Gigya.ServiceContract/Exceptions/InvalidParameterValueException.cs @@ -1,12 +1,14 @@ using System; using System.Runtime.Serialization; using Gigya.Common.Contracts.Exceptions; +using Newtonsoft.Json; namespace Gigya.ServiceContract.Exceptions { /// /// This excpetion is thrown if a parameter contains an invalid value /// + [Serializable] public class InvalidParameterValueException: RequestException { ///ErrorCode of Invalid_parameter_value @@ -15,27 +17,28 @@ public class InvalidParameterValueException: RequestException /// /// Name of the parameter which has an invalid value /// - public string ParameterName { get; set; } + [JsonProperty] + public string parameterName { get; set; } /// /// For parameters that contain data structures, the path inside the data structure pointing to the field/property that /// caused the deserialization or validation error. /// - public string[] ErrorPath { get; } + public string[] ErrorPath { get; set; } /// /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. /// - /// Name of the parameter which has an invalid value + /// Name of the parameter which has an invalid value /// For parameters that contain data structures, the path inside the data structure pointing to the field/property that /// caused the deserialization or validation error. /// The error message that explains the reason for the exception. /// Optional. A collection of type that contains additional data about the exception, which must be encrypted when stored. /// Optional. A collection of type that contains additional data about the exception, which needn't be encrypted when stored. /// Optional. The exception that is the cause of the current exception. - public InvalidParameterValueException(string parameterName, string[] errorPath, string message, Exception innerException = null, Tags encrypted = null, Tags unencrypted = null) : base(message, innerException, encrypted, unencrypted) + public InvalidParameterValueException(string paramName, string[] errorPath, string message, Exception innerException = null, Tags encrypted = null, Tags unencrypted = null) : base(message, innerException, encrypted, unencrypted) { - ParameterName = parameterName; + parameterName = paramName; ErrorPath = errorPath; } diff --git a/Gigya.ServiceContract/JsonHelper.cs b/Gigya.ServiceContract/JsonHelper.cs index 3bfaf473..d0991a9c 100644 --- a/Gigya.ServiceContract/JsonHelper.cs +++ b/Gigya.ServiceContract/JsonHelper.cs @@ -88,7 +88,7 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) if (match.Success) parameterPathStr = match.Groups[ParamCaptureName]?.Value; - throw new InvalidParameterValueException(null, parameterPathStr?.Split(',') ?? new string[0], serException.Message, innerException: serException); + throw new InvalidParameterValueException(null, parameterPathStr?.Split('.') ?? new string[0], serException.Message, innerException: serException); } } diff --git a/Gigya.ServiceContract/ServiceContract.sln b/Gigya.ServiceContract/ServiceContract.sln index e54b7ba0..47abaafb 100644 --- a/Gigya.ServiceContract/ServiceContract.sln +++ b/Gigya.ServiceContract/ServiceContract.sln @@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{E38B20 paket.lock = paket.lock EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gigya.Microdot.ServiceContract.UnitTests", "..\tests\Gigya.Microdot.ServiceContract.UnitTests\Gigya.Microdot.ServiceContract.UnitTests.csproj", "{C224F79A-EAB5-48B8-B587-65772B0966EF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{6D04C065-F8ED-408D-BE23-722DA84AD2F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,10 +25,17 @@ Global {DB6D3561-835E-40D5-B9D4-83951CF426DF}.Debug|Any CPU.Build.0 = Debug|Any CPU {DB6D3561-835E-40D5-B9D4-83951CF426DF}.Release|Any CPU.ActiveCfg = Release|Any CPU {DB6D3561-835E-40D5-B9D4-83951CF426DF}.Release|Any CPU.Build.0 = Release|Any CPU + {C224F79A-EAB5-48B8-B587-65772B0966EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C224F79A-EAB5-48B8-B587-65772B0966EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C224F79A-EAB5-48B8-B587-65772B0966EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C224F79A-EAB5-48B8-B587-65772B0966EF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C224F79A-EAB5-48B8-B587-65772B0966EF} = {6D04C065-F8ED-408D-BE23-722DA84AD2F5} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7F592F51-0A62-4EA9-8FA8-4544B4888416} EndGlobalSection diff --git a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj index 796cc69c..825f2ae9 100644 --- a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj +++ b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj @@ -57,6 +57,12 @@ + + + {db6d3561-835e-40d5-b9d4-83951cf426df} + Gigya.ServiceContract + + - - - - ..\..\packages\Gigya.ServiceContract\lib\net451\Gigya.ServiceContract.dll - True - True - - - + diff --git a/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs b/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs index 4d47a3ca..1bf37ce8 100644 --- a/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs +++ b/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs @@ -23,14 +23,16 @@ using System; using System.Linq; using System.Numerics; +using Gigya.ServiceContract.Exceptions; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using NUnit.Framework; using Shouldly; namespace Gigya.Common.Contracts.UnitTests { public enum MyEnum { Zero, One, Two } - public class SomeClass { public int A; public long B; public ushort? C; } + public class SomeClass { public int A; public long B; public ushort? C; [JsonProperty] SomeClass Inner; } public struct SomeStruct { public int A; public long B; public ushort? C; } [TestFixture] @@ -232,7 +234,7 @@ public void ConvertWeaklyTypedValue_TimeSpanAsString_ShouldConvert() [Test] public void ConvertWeaklyTypedValue_TimeSpanAsInvalidString_ShouldConvert() { - Should.Throw(() => JsonHelper.ConvertWeaklyTypedValue("INVALID", typeof(TimeSpan))); + Should.Throw(() => JsonHelper.ConvertWeaklyTypedValue("INVALID", typeof(TimeSpan))); } @@ -306,7 +308,7 @@ public void ConvertWeaklyTypedValue_NumericValue(object value, Type targetType) actual.ShouldBeOfType(Nullable.GetUnderlyingType(targetType) ?? targetType); actual.ShouldBe(value); } - catch (Exception ex) when (ex is OverflowException || ex.InnerException is OverflowException) { } + catch (InvalidParameterValueException ex) when (ex.InnerException is OverflowException) { } } @@ -326,7 +328,72 @@ public void ConvertWeaklyTypedValue_NullableNumericValue(object value, Type targ actual.ShouldBe(value); } - catch (Exception ex) when (ex is OverflowException || ex.InnerException is OverflowException) { } + catch (InvalidParameterValueException ex) when (ex.InnerException is OverflowException) { } } + + [Test] + public void ComplexObjectWithNullValue_ThrowException() + { + var json = JObject.Parse(@"{A:null}"); + try + { + JsonHelper.ConvertWeaklyTypedValue(json, typeof(SomeClass)); + Assert.Fail("Should throw exception because field 'A' is null"); + } + catch (InvalidParameterValueException ex) + { + ex.parameterName.ShouldBeNull(); + ex.ErrorPath.SequenceEqual(new[] {"A"}); + } + } + + [Test] + public void ComplexObjectWithWrongValue_ThrowException() + { + var json = JObject.Parse(@"{A:""abcd""}"); + try + { + JsonHelper.ConvertWeaklyTypedValue(json, typeof(SomeClass)); + Assert.Fail("Should throw exception because field 'A' has invalid value"); + } + catch (InvalidParameterValueException ex) + { + ex.parameterName.ShouldBeNull(); + ex.ErrorPath.SequenceEqual(new[] { "A" }); + } + } + + [Test] + public void ComplexObjectWithComplexObjectWithNullValue_ThrowException() + { + var json = JObject.Parse(@"{Inner: {A:null}}"); + try + { + JsonHelper.ConvertWeaklyTypedValue(json, typeof(SomeClass)); + Assert.Fail("Should throw exception because field 'Inner.A' is null"); + } + catch (InvalidParameterValueException ex) + { + ex.parameterName.ShouldBeNull(); + ex.ErrorPath.SequenceEqual(new[] { "Inner", "A" }); + } + } + + [Test] + public void ComplexObjectWithComplexObjectWithWrongValue_ThrowException() + { + var json = JObject.Parse(@"{Inner: {A:""abcd""}}"); + try + { + JsonHelper.ConvertWeaklyTypedValue(json, typeof(SomeClass)); + Assert.Fail("Should throw exception because field 'Inner.A' has invalid value"); + } + catch (InvalidParameterValueException ex) + { + ex.parameterName.ShouldBeNull(); + ex.ErrorPath.SequenceEqual(new[] { "Inner","A" }); + } + } + } } From 023f52863c4b28c6de51349958096d8e7b06b2d0 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Tue, 25 Dec 2018 10:08:49 +0200 Subject: [PATCH 13/20] upgrade Gigya.ServiceContract --- paket.lock | 2 +- .../Gigya.Microdot.ServiceContract.UnitTests.csproj | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/paket.lock b/paket.lock index 569d0130..70d448dc 100644 --- a/paket.lock +++ b/paket.lock @@ -8,7 +8,7 @@ NUGET DataAnnotationsValidator (2.1) FluentAssertions (5.5.3) System.ValueTuple (>= 4.4) - Gigya.ServiceContract (2.6) + Gigya.ServiceContract (2.7) Newtonsoft.Json (>= 9.0.1) Metrics.NET (0.5.5) Microsoft.Bcl (1.1.10) diff --git a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj index 825f2ae9..8f9d217f 100644 --- a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj +++ b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj @@ -72,7 +72,15 @@ --> - + + + + ..\..\packages\Gigya.ServiceContract\lib\net451\Gigya.ServiceContract.dll + True + True + + + From ebc27a6006b8af30d2d8eba0e5c6d7cd0ffc0c35 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Tue, 25 Dec 2018 12:43:45 +0200 Subject: [PATCH 14/20] Add tests for InvalidParameterValue --- .../HttpService/HttpServiceListener.cs | 4 +- .../HttpServiceListenerTests.cs | 66 +++++++++++++++++-- tests/Gigya.Microdot.UnitTests/TestingHost.cs | 14 +++- 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs b/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs index 78faea39..10cd8ed8 100644 --- a/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs +++ b/Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs @@ -563,10 +563,10 @@ private static object[] GetParametersByName(ServiceMethod serviceMethod, IDictio } catch (InvalidParameterValueException ex) { - if (ex.ParameterName != null) + if (ex.parameterName != null) throw; - throw new InvalidParameterValueException(p.Name, ex.ParameterPath, ex.Message, ex); + throw new InvalidParameterValueException(p.Name, ex.ErrorPath, ex.Message, ex); } }). ToArray(); diff --git a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs index 7ab2e7dd..f0f9dd3e 100644 --- a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs +++ b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs @@ -4,26 +4,29 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; - +using Castle.DynamicProxy.Generators.Emitters.SimpleAST; using FluentAssertions; using Gigya.Common.Application.HttpService.Client; using Gigya.Common.Contracts.Exceptions; +using Gigya.Common.Contracts.HttpService; using Gigya.Microdot.Fakes; +using Gigya.Microdot.Hosting.HttpService; using Gigya.Microdot.Hosting.Service; using Gigya.Microdot.SharedLogic; using Gigya.Microdot.SharedLogic.Events; using Gigya.Microdot.SharedLogic.Exceptions; +using Gigya.Microdot.SharedLogic.HttpService; using Gigya.Microdot.Testing; using Gigya.Microdot.Testing.Shared; using Gigya.Microdot.UnitTests.ServiceProxyTests; - +using Gigya.ServiceContract.Exceptions; using Metrics; using Ninject; using Ninject.Parameters; using NSubstitute; - +using NSubstitute.ExceptionExtensions; using NUnit.Framework; using RichardSzalay.MockHttp; @@ -42,6 +45,7 @@ public class HttpServiceListenerTests private Task _stopTask; private JsonExceptionSerializer _exceptionSerializer; private TestingKernel _kernel; + private Func _overrideServiceMethod; [OneTimeSetUp] public void OneTimeSetup() @@ -65,10 +69,29 @@ public virtual void SetUp() TracingContext.SetUpStorage(); TracingContext.SetRequestID("1"); - _testinghost = new TestingHost(); + _testinghost = new TestingHost(overrideBindings: kernel => + { + OverrideServiceEndpointDefinition(kernel); + } + ); _stopTask = _testinghost.RunAsync(new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive)); } + private void OverrideServiceEndpointDefinition(IKernel kernel) + { + _overrideServiceMethod = null; + + var orig = kernel.Get(); + var mock = Substitute.For(); + mock.Resolve(Arg.Any()).Returns(c => + { + var invocationTarget = c.Arg(); + return _overrideServiceMethod != null ? _overrideServiceMethod(invocationTarget) : orig.Resolve(invocationTarget); + }); + mock.HttpPort.Returns(orig.HttpPort); + kernel.Rebind().ToConstant(mock); + } + [TearDown] public virtual void TearDown() @@ -159,6 +182,33 @@ public async Task SendRequestWithNullParameter() await _testinghost.Instance.Received().ToUpper(null); } + [Test] + public async Task SendRequestWithInvalidParameterValue() + { + var methodName = nameof(IDemoService.ToUpper); + var expectedParamName = typeof(IDemoService).GetMethod(methodName).GetParameters().First().Name; + + _overrideServiceMethod = invocationTarget => + { + // Cause HttpServiceListener to think it is a weakly-typed request, + // and get the parameters list from the mocked ServiceMethod, and not from the original invocation target + invocationTarget.ParameterTypes = null; + + // return a ServiceMethod which expects only int values + return new ServiceMethod(typeof(IDemoServiceSupportOnlyIntValues), + typeof(IDemoServiceSupportOnlyIntValues).GetMethod(methodName)); + }; + + try + { + await _insecureClient.ToUpper("Non-Int value"); + Assert.Fail("Host was expected to throw an exception"); + } + catch (InvalidParameterValueException ex) + { + ex.parameterName.ShouldBe(expectedParamName); + } + } [Test] public async Task SendRequestWithNoParameters() @@ -204,6 +254,14 @@ private async Task< HttpRequestMessage> GetRequestFor(Func action) return new HttpRequestMessage(request.Method, request.RequestUri) { Content = contentClone }; } + /// + /// this class simulates a version of IDemoService, which defines an incorrect parameter type for ToUpper method + /// + [HttpService(5555)] + interface IDemoServiceSupportOnlyIntValues + { + Task ToUpper(int str); // the real IDemoService accepts any string value, not only int types + } } diff --git a/tests/Gigya.Microdot.UnitTests/TestingHost.cs b/tests/Gigya.Microdot.UnitTests/TestingHost.cs index ebb3cbcf..b1e95404 100644 --- a/tests/Gigya.Microdot.UnitTests/TestingHost.cs +++ b/tests/Gigya.Microdot.UnitTests/TestingHost.cs @@ -23,16 +23,21 @@ public class TestingHost : MicrodotServiceHost where T : class public T Instance { get; private set; } private readonly Action optionalConfigs; + private readonly Action overrideBindings; - public TestingHost(Action optionalConfigs = null) + private IKernel _kernel; + + public TestingHost(Action optionalConfigs = null, Action overrideBindings = null) { this.optionalConfigs = optionalConfigs; + this.overrideBindings = overrideBindings; } protected override ILoggingModule GetLoggingModule() { return new FakesLoggersModules(false); } protected override void Configure(IKernel kernel, BaseCommonConfig commonConfig) { + _kernel = kernel; kernel.Rebind().ToConstant(new ConsoleLog()); kernel.Rebind() @@ -50,7 +55,12 @@ protected override void Configure(IKernel kernel, BaseCommonConfig commonConfig) Instance = kernel.Get(); } - + + protected override void OnInitilize(IResolutionRoot resolutionRoot) + { + base.OnInitilize(resolutionRoot); + overrideBindings?.Invoke(_kernel); + } private class WaitingWorker : IWorker { From 7a0a0efb2e3eb36d2fcb3b415017614cf0dab90f Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Tue, 25 Dec 2018 12:44:06 +0200 Subject: [PATCH 15/20] Add tests for breadcrumbs serialization --- .../JsonExceptionSerializerTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Gigya.Microdot.UnitTests/ServiceProxyTests/JsonExceptionSerializerTests.cs b/tests/Gigya.Microdot.UnitTests/ServiceProxyTests/JsonExceptionSerializerTests.cs index 4e7fe173..98ec7c6c 100644 --- a/tests/Gigya.Microdot.UnitTests/ServiceProxyTests/JsonExceptionSerializerTests.cs +++ b/tests/Gigya.Microdot.UnitTests/ServiceProxyTests/JsonExceptionSerializerTests.cs @@ -57,6 +57,31 @@ public void RequestException_RoundTrip_IsIdentical() actual.StackTrace.ShouldNotBeNullOrEmpty(); } + [Test] + public void RequestException_Serialization_AddBreadcrumbs() + { + var json = ExceptionSerializer.Serialize(new RequestException("message").ThrowAndCatch()); + var actual = ExceptionSerializer.Deserialize(json); + + var breadcrumbs = ((RequestException)actual).Breadcrumbs; + breadcrumbs.ShouldNotBeEmpty(); + breadcrumbs.First().ServiceName.ShouldBe("InfraTests"); + } + + [Test] + public void RequestException_SerializedTwice_AddAnotherBreadcrumb() + { + var json1 = ExceptionSerializer.Serialize(new RequestException("message").ThrowAndCatch()); + var actual1 = ExceptionSerializer.Deserialize(json1); + var json2 = ExceptionSerializer.Serialize(actual1); + var actual2 = ExceptionSerializer.Deserialize(json2); + + var breadcrumbs = ((RequestException)actual2).Breadcrumbs; + breadcrumbs.Count.ShouldBe(2); + breadcrumbs[0].ServiceName.ShouldBe("InfraTests"); + breadcrumbs[1].ServiceName.ShouldBe("InfraTests"); + } + [Test] public void CustomerFacingException_RoundTrip_IsIdentical() { From ff70771c2cf58d1cf5db1c289b4adf33ee54b1bf Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Tue, 25 Dec 2018 13:46:56 +0200 Subject: [PATCH 16/20] InvalidParameterValue in case of overflow --- Gigya.ServiceContract/JsonHelper.cs | 4 ++++ Gigya.ServiceContract/Properties/AssemblyInfo.cs | 6 +++--- ...Gigya.Microdot.ServiceContract.UnitTests.csproj | 14 +++++--------- .../JsonHelperTests.cs | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Gigya.ServiceContract/JsonHelper.cs b/Gigya.ServiceContract/JsonHelper.cs index d0991a9c..b46cf21c 100644 --- a/Gigya.ServiceContract/JsonHelper.cs +++ b/Gigya.ServiceContract/JsonHelper.cs @@ -76,6 +76,10 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) return JToken.FromObject(value).ToObject(targetType, Serializer); } + catch (OverflowException overflowException) + { + throw new InvalidParameterValueException(null, null, overflowException.Message, innerException: overflowException); + } catch (JsonReaderException jsException) { var parameterPath = string.IsNullOrEmpty(jsException.Path) ? new string[0] : jsException.Path.Split('.'); diff --git a/Gigya.ServiceContract/Properties/AssemblyInfo.cs b/Gigya.ServiceContract/Properties/AssemblyInfo.cs index e9848298..3ad9469a 100644 --- a/Gigya.ServiceContract/Properties/AssemblyInfo.cs +++ b/Gigya.ServiceContract/Properties/AssemblyInfo.cs @@ -40,9 +40,9 @@ [assembly: AssemblyTrademark("")] -[assembly: AssemblyInformationalVersion("2.7.0")]// if pre-release should be in the format of "2.4.11-pre01". -[assembly: AssemblyVersion("2.7.0")] -[assembly: AssemblyFileVersion("2.7.0")] +[assembly: AssemblyInformationalVersion("2.7.1")]// if pre-release should be in the format of "2.4.11-pre01". +[assembly: AssemblyVersion("2.7.1")] +[assembly: AssemblyFileVersion("2.7.1")] diff --git a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj index 8f9d217f..d233c36d 100644 --- a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj +++ b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj @@ -62,6 +62,10 @@ {db6d3561-835e-40d5-b9d4-83951cf426df} Gigya.ServiceContract + + {db6d3561-835e-40d5-b9d4-83951cf426df} + Gigya.ServiceContract + - - - - ..\..\packages\Gigya.ServiceContract\lib\net451\Gigya.ServiceContract.dll - True - True - - - + diff --git a/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs b/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs index 1bf37ce8..3f5dc5b6 100644 --- a/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs +++ b/tests/Gigya.Microdot.ServiceContract.UnitTests/JsonHelperTests.cs @@ -308,7 +308,7 @@ public void ConvertWeaklyTypedValue_NumericValue(object value, Type targetType) actual.ShouldBeOfType(Nullable.GetUnderlyingType(targetType) ?? targetType); actual.ShouldBe(value); } - catch (InvalidParameterValueException ex) when (ex.InnerException is OverflowException) { } + catch (InvalidParameterValueException) { } } @@ -328,7 +328,7 @@ public void ConvertWeaklyTypedValue_NullableNumericValue(object value, Type targ actual.ShouldBe(value); } - catch (InvalidParameterValueException ex) when (ex.InnerException is OverflowException) { } + catch (InvalidParameterValueException) { } } [Test] From 6a139d6bed7299dc6ca2f13e0ea883078b1d53af Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Wed, 26 Dec 2018 15:32:52 +0200 Subject: [PATCH 17/20] Handle more types of exceptions (may throw OverflowException or ArgumentException) --- Gigya.ServiceContract/JsonHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gigya.ServiceContract/JsonHelper.cs b/Gigya.ServiceContract/JsonHelper.cs index b46cf21c..56626491 100644 --- a/Gigya.ServiceContract/JsonHelper.cs +++ b/Gigya.ServiceContract/JsonHelper.cs @@ -76,10 +76,6 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) return JToken.FromObject(value).ToObject(targetType, Serializer); } - catch (OverflowException overflowException) - { - throw new InvalidParameterValueException(null, null, overflowException.Message, innerException: overflowException); - } catch (JsonReaderException jsException) { var parameterPath = string.IsNullOrEmpty(jsException.Path) ? new string[0] : jsException.Path.Split('.'); @@ -94,6 +90,10 @@ public static object ConvertWeaklyTypedValue(object value, Type targetType) throw new InvalidParameterValueException(null, parameterPathStr?.Split('.') ?? new string[0], serException.Message, innerException: serException); } + catch (Exception ex) + { + throw new InvalidParameterValueException(null, null, ex.Message, innerException: ex); + } } } From ce0b084d0e76b372b1bd64145ae3c6b398f9476c Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Wed, 26 Dec 2018 15:33:08 +0200 Subject: [PATCH 18/20] fix arguments naming --- .../HttpServiceListenerTests.cs | 3 +-- tests/Gigya.Microdot.UnitTests/TestingHost.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs index f0f9dd3e..e3a424d4 100644 --- a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs +++ b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs @@ -26,7 +26,6 @@ using Ninject.Parameters; using NSubstitute; -using NSubstitute.ExceptionExtensions; using NUnit.Framework; using RichardSzalay.MockHttp; @@ -69,7 +68,7 @@ public virtual void SetUp() TracingContext.SetUpStorage(); TracingContext.SetRequestID("1"); - _testinghost = new TestingHost(overrideBindings: kernel => + _testinghost = new TestingHost(onInitialize: kernel => { OverrideServiceEndpointDefinition(kernel); } diff --git a/tests/Gigya.Microdot.UnitTests/TestingHost.cs b/tests/Gigya.Microdot.UnitTests/TestingHost.cs index b1e95404..74c08273 100644 --- a/tests/Gigya.Microdot.UnitTests/TestingHost.cs +++ b/tests/Gigya.Microdot.UnitTests/TestingHost.cs @@ -22,15 +22,15 @@ public class TestingHost : MicrodotServiceHost where T : class { public T Instance { get; private set; } - private readonly Action optionalConfigs; - private readonly Action overrideBindings; + private readonly Action _configure; + private readonly Action _onInitialize; private IKernel _kernel; - public TestingHost(Action optionalConfigs = null, Action overrideBindings = null) + public TestingHost(Action configure = null, Action onInitialize = null) { - this.optionalConfigs = optionalConfigs; - this.overrideBindings = overrideBindings; + this._configure = configure; + this._onInitialize = onInitialize; } protected override ILoggingModule GetLoggingModule() { return new FakesLoggersModules(false); } @@ -51,7 +51,7 @@ protected override void Configure(IKernel kernel, BaseCommonConfig commonConfig) kernel.Bind().ToConstant(Substitute.For()); - optionalConfigs?.Invoke(kernel); + _configure?.Invoke(kernel); Instance = kernel.Get(); } @@ -59,7 +59,7 @@ protected override void Configure(IKernel kernel, BaseCommonConfig commonConfig) protected override void OnInitilize(IResolutionRoot resolutionRoot) { base.OnInitilize(resolutionRoot); - overrideBindings?.Invoke(_kernel); + _onInitialize?.Invoke(_kernel); } private class WaitingWorker : IWorker From a4f5fd94b693a6a2e038037a9355e21dfe579024 Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Wed, 26 Dec 2018 16:00:54 +0200 Subject: [PATCH 19/20] upgrade Gigya.ServiceContract version --- paket.lock | 2 +- .../Gigya.Microdot.ServiceContract.UnitTests.csproj | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/paket.lock b/paket.lock index 70d448dc..3359bd8e 100644 --- a/paket.lock +++ b/paket.lock @@ -8,7 +8,7 @@ NUGET DataAnnotationsValidator (2.1) FluentAssertions (5.5.3) System.ValueTuple (>= 4.4) - Gigya.ServiceContract (2.7) + Gigya.ServiceContract (2.7.1) Newtonsoft.Json (>= 9.0.1) Metrics.NET (0.5.5) Microsoft.Bcl (1.1.10) diff --git a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj index d233c36d..d0f9e894 100644 --- a/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj +++ b/tests/Gigya.Microdot.ServiceContract.UnitTests/Gigya.Microdot.ServiceContract.UnitTests.csproj @@ -76,7 +76,15 @@ --> - + + + + ..\..\packages\Gigya.ServiceContract\lib\net451\Gigya.ServiceContract.dll + True + True + + + From d6454174cb03cf71edb2e327355b212088bd8dec Mon Sep 17 00:00:00 2001 From: David Bronshtein Date: Thu, 27 Dec 2018 10:05:10 +0200 Subject: [PATCH 20/20] increase version no --- SolutionVersion.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SolutionVersion.cs b/SolutionVersion.cs index a4e3452f..b199cc20 100644 --- a/SolutionVersion.cs +++ b/SolutionVersion.cs @@ -28,9 +28,9 @@ [assembly: AssemblyCopyright("© 2018 Gigya Inc.")] [assembly: AssemblyDescription("Microdot Framework")] -[assembly: AssemblyVersion("1.13.1.0")] -[assembly: AssemblyFileVersion("1.13.1.0")] -[assembly: AssemblyInformationalVersion("1.13.1.0")] +[assembly: AssemblyVersion("1.13.2.0")] +[assembly: AssemblyFileVersion("1.13.2.0")] +[assembly: AssemblyInformationalVersion("1.13.2.0")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from