Skip to content

Commit

Permalink
Merge pull request 8343 from hotfix/v4.4.21 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Project Collection Build Service (51degrees) authored and Project Collection Build Service (51degrees) committed Mar 15, 2023
2 parents eeb632e + 68a7295 commit 779a04c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 37 deletions.
4 changes: 3 additions & 1 deletion Examples/Cloud/Framework-Web/App_Data/51Degrees.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
}
}
],
"ClientSideEnabled": true
"BuildParameters": {
"ClientSideEnabled": true
}
}
}
4 changes: 3 additions & 1 deletion Examples/OnPremise/Framework-Web/App_Data/51Degrees.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
}
}
],
"ClientSideEnabled": true
"BuildParameters": {
"ClientSideEnabled": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,39 +99,39 @@ protected override void ProcessInternal(IFlowData data)
var brandsString = SerializeBrands(uachData.Brands);
if (brandsString != null)
{
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_QUERY_KEY, brandsString);
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_HEADER_KEY, brandsString);
evidenceAdded = true;
}
var brandsFullVersionString = SerializeBrands(uachData.FullVersionList);
if (brandsFullVersionString != null)
{
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_QUERY_KEY,
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_HEADER_KEY,
brandsFullVersionString);
evidenceAdded = true;
}

if (uachData.Mobile.HasValue)
{
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MOBILE_QUERY_KEY,
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MOBILE_HEADER_KEY,
uachData.Mobile.Value ? "?1" : "?0");
evidenceAdded = true;
}

if (uachData.Model != null)
{
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MODEL_QUERY_KEY,
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MODEL_HEADER_KEY,
ConvertText(uachData.Model));
evidenceAdded = true;
}
if (uachData.Platform != null)
{
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY,
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY,
ConvertText(uachData.Platform));
evidenceAdded = true;
}
if (uachData.PlatformVersion != null)
{
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_QUERY_KEY,
data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_HEADER_KEY,
ConvertText(uachData.PlatformVersion));
evidenceAdded = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public class DeviceDetectionTests
private static UserAgentGenerator USER_AGENTS = new UserAgentGenerator(
TestHelpers.Utils.GetFilePath(Constants.UA_FILE_NAME));

private static readonly List<Dictionary<string, string>> UachTestValues = new List<Dictionary<string, string>>()
{
new Dictionary<string, string>()
{
{ Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY, @"""Windows""" },
{ Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_HEADER_KEY, @"""14.0.0""" }
}
};

[DataTestMethod]
// ******** Hash with a single thread *********
[DataRow(Constants.LITE_HASH_DATA_FILE_NAME, PerformanceProfiles.MaxPerformance, false, false, DisplayName = "Hash-MaxPerformance-NoLazyLoad-SingleThread")]
Expand Down Expand Up @@ -73,17 +82,46 @@ public void Hash_AllConfigurations_100_UserAgents(
bool useLazyLoading,
bool multiThreaded)
{
TestOnPremise_AllConfigurations_100_UserAgents(datafileName,
TestWithEvidence(datafileName,
performanceProfile,
useLazyLoading,
multiThreaded,
GetEvidenceFromUas(),
// Just access the IsMobile property to ensure we can get data out.
// This will throw an exception if the value was not populated
(dd) => { var result = dd.IsMobile; });
}

public void Hash_Uach(
string datafileName,
PerformanceProfiles performanceProfile,
bool useLazyLoading,
bool multiThreaded)
{
TestWithEvidence(datafileName,
performanceProfile,
useLazyLoading,
multiThreaded);
multiThreaded,
UachTestValues,
(dd) => { Assert.AreEqual("11", dd.PlatformVersion.Value); });
}

/// <summary>
/// This test will create a device detection pipeline based on the
/// supplied parameters, process 1000 user agents.
/// The various parameters allow the test to be run for many
/// different configurations.
/// Use the 'USER_AGENTS' field to construct a collection of evidence values.
/// </summary>
/// <returns></returns>
private IEnumerable<IEnumerable<KeyValuePair<string,string>>> GetEvidenceFromUas()
{
foreach (var ua in USER_AGENTS.GetRandomUserAgents(100))
{
var key = Pipeline.Core.Constants.EVIDENCE_HTTPHEADER_PREFIX +
Pipeline.Core.Constants.EVIDENCE_SEPERATOR + "User-Agent";
yield return new KeyValuePair<string, string>[1] { new KeyValuePair<string, string>(key, ua) };
}
}

/// <summary>
/// Test the supplied evidence using the specified device detection settings.
/// </summary>
/// <param name="datafileName">
/// The filename of the data file to use for device detection.
Expand All @@ -98,11 +136,20 @@ public void Hash_AllConfigurations_100_UserAgents(
/// Whether to use a single thread or multiple threads when
/// passing user agents to the pipeline for processing.
/// </param>
public void TestOnPremise_AllConfigurations_100_UserAgents(
/// <param name="evidence">
/// The evidence values to test with.
/// </param>
/// <param name="verifyAction">
/// An action to execute to verify that the result includes the expected values.
/// The action should throw an exception describing the problem if verification fails.
/// </param>
public void TestWithEvidence(
string datafileName,
PerformanceProfiles performanceProfile,
bool useLazyLoading,
bool multiThreaded)
bool multiThreaded,
IEnumerable<IEnumerable<KeyValuePair<string, string>>> evidence,
Action<IDeviceData> verifyAction)
{
var datafile = TestHelpers.Utils.GetFilePath(datafileName);
var updateService = new Mock<IDataUpdateService>();
Expand Down Expand Up @@ -138,19 +185,19 @@ public void TestOnPremise_AllConfigurations_100_UserAgents(


// Create a parallel loop to actually process the user agents.
Parallel.ForEach(USER_AGENTS.GetRandomUserAgents(100), options,
(useragent) =>
Parallel.ForEach(evidence, options,
(evidenceEntry) =>
{
// Create the flow data instance
using (var flowData = pipeline.CreateFlowData())
{

// Add the user agent to the flow data
// and process it
flowData.AddEvidence(
Pipeline.Core.Constants.EVIDENCE_HTTPHEADER_PREFIX +
Pipeline.Core.Constants.EVIDENCE_SEPERATOR + "User-Agent", useragent)
.Process();
// Add the evidence to the flow data and process it
foreach (var subEntry in evidenceEntry)
{
flowData.AddEvidence(subEntry.Key, subEntry.Value);
}
flowData.Process();

// Make sure no errors occurred. If any did then
// cancel the parallel process.
Expand All @@ -162,16 +209,15 @@ public void TestOnPremise_AllConfigurations_100_UserAgents(
cancellationSource.Cancel();
}

// Get the device data instance and access the
// IsMobile property to ensure we can get
// data out.
// Get the device data instance and pass it to the verifyAction.
var deviceData = flowData.Get<IDeviceData>();
var result = deviceData.IsMobile;
verifyAction(deviceData);
}
});
}
}


/// <summary>
/// Private method to present the given list of FlowError
/// instances as a single string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public void VerifyErrorHandling_KeysAlreadyPresent()
// Supply evidence
flowData.AddEvidence(Constants.EVIDENCE_HIGH_ENTROPY_VALUES_KEY_COOKIE, evidenceValue);
// Add an existing evidence value for query.sec-ch-ua-platform.
flowData.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY,
flowData.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY,
@"""Existing Platform""");
flowData.Process();

// Make sure the pre-existing value has been overwritten.
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY,
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY,
@"""Windows""");
}
}
Expand Down Expand Up @@ -171,17 +171,17 @@ public void VerifyRealWorldValues(
flowData.Process();

// Check that the evidence has been updated as expected.
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_QUERY_KEY,
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_HEADER_KEY,
expectedSecChUa);
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_QUERY_KEY,
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_HEADER_KEY,
expectedSecChUaFullVersionList);
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MOBILE_QUERY_KEY,
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MOBILE_HEADER_KEY,
expectedSecChUaMobile);
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MODEL_QUERY_KEY,
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MODEL_HEADER_KEY,
expectedSecChUaModel);
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY,
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY,
expectedSecChUaPlatform);
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_QUERY_KEY,
CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_HEADER_KEY,
expectedSecChUaPlatformVersion);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ci/common-ci
Submodule common-ci updated 1 files
+3 −58 release-config.json

0 comments on commit 779a04c

Please sign in to comment.