diff --git a/Tests/AntiFraudTests.cs b/Tests/AntiFraudTests.cs index 584419c..8ac6f2d 100644 --- a/Tests/AntiFraudTests.cs +++ b/Tests/AntiFraudTests.cs @@ -45,7 +45,7 @@ public void TestGetAntiFraudHeaders() { [Fact] public void TestGetPropertiesForMethod() { var props = AntiFraud.AntiFraud.GetPropertiesForMethod(ConnectionMethod.DESKTOP_APP_DIRECT); - Assert.Equal(12, props.Count()); + Assert.Equal(14, props.Count()); } } } diff --git a/Tests/TestBase.cs b/Tests/TestBase.cs index 826abcf..b1cd933 100644 --- a/Tests/TestBase.cs +++ b/Tests/TestBase.cs @@ -73,10 +73,13 @@ protected Client GetClient() { client.AntiFraud.PopulateLocalIPs(); client.AntiFraud.PopulateMACAddresses(); client.AntiFraud.PopulateUserAgent(); + client.AntiFraud.VendorForwarded = new Forwarded[] { + new Forwarded { By = System.Net.IPAddress.Parse("8.8.8.8"), For = System.Net.IPAddress.Parse("fe80::21a6:9255:4c0b:78e4%14")} + }; // Even though the documentation states that that these are optional, the API returns an error client.AntiFraud.UserAgent.DeviceManufacturer = "Dell"; - client.AntiFraud.UserAgent.DeviceModel = "XPS"; + client.AntiFraud.UserAgent.DeviceModel = "XPS Gaming PC"; client.AntiFraud.MultiFactor = new[] { new MultiFactor() { diff --git a/TipsTrade-HMRC/AntiFraud/AntiFraud.cs b/TipsTrade-HMRC/AntiFraud/AntiFraud.cs index a621fd7..2acdefe 100644 --- a/TipsTrade-HMRC/AntiFraud/AntiFraud.cs +++ b/TipsTrade-HMRC/AntiFraud/AntiFraud.cs @@ -230,7 +230,7 @@ private Dictionary GetAntiFraudHeaders(List errors) { string headerValue; if (value is string str) { - headerValue = str; // string are enumerable so catch them here + headerValue = HttpUtility.UrlEncode(str); // string are enumerable so catch them here } else if (value is IDictionary dict) { var sb = new StringBuilder(); diff --git a/TipsTrade-HMRC/AntiFraud/Forwarded.cs b/TipsTrade-HMRC/AntiFraud/Forwarded.cs index fd5562d..677a48b 100644 --- a/TipsTrade-HMRC/AntiFraud/Forwarded.cs +++ b/TipsTrade-HMRC/AntiFraud/Forwarded.cs @@ -1,5 +1,6 @@ using System; using System.Net; +using System.Web; namespace TipsTrade.HMRC.AntiFraud { /// Represents an object that contains information on hops over the internet that terminate TLS. @@ -15,7 +16,7 @@ public string GetHeaderValue() { if (By == null) throw new InvalidOperationException($"The {nameof(By)} property cannot be null."); if (For == null) throw new InvalidOperationException($"The {nameof(For)} property cannot be null."); - return $"by={By}&for={For}"; + return $"by={HttpUtility.UrlEncode(By.ToString())}&for={HttpUtility.UrlEncode(For.ToString())}"; } } } diff --git a/TipsTrade-HMRC/AntiFraud/UserAgent.cs b/TipsTrade-HMRC/AntiFraud/UserAgent.cs index c124421..f7c4ab6 100644 --- a/TipsTrade-HMRC/AntiFraud/UserAgent.cs +++ b/TipsTrade-HMRC/AntiFraud/UserAgent.cs @@ -10,7 +10,7 @@ public class UserAgent : IAntiFraudValue { /// Gets or sets the device model. public string DeviceModel { get; set; } - + /// Gets or sets the operating system family. public string OSFamily { get; set; } @@ -20,10 +20,10 @@ public class UserAgent : IAntiFraudValue { /// Retuns a string that contains the anti fraud header value. public string GetHeaderValue() { var dict = new Dictionary { - {"os-family", OSFamily }, - {"os-version", OSVersion }, - {"device-manufacturer", DeviceManufacturer }, - {"device-model", DeviceModel } + {"os-family", HttpUtility.UrlEncode(OSFamily) }, + {"os-version", HttpUtility.UrlEncode(OSVersion) }, + {"device-manufacturer", HttpUtility.UrlEncode(DeviceManufacturer) }, + {"device-model", HttpUtility.UrlEncode(DeviceModel) } }; return dict.GetHeaderValue();