Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To add scrubbing of email with random email values before @ #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CosmosClone/CosmosCloneCommon/Model/RandomNumberGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public static string GetRandomEntityType()
}
}

public static string RandomNumber()
{
Random random = new Random();
return random.Next().ToString();
}


//A simple implementation of Fisher yates algorithm for shuffling
public static List<T> Shuffle<T>(List<T> list)
{
Expand Down
2 changes: 1 addition & 1 deletion CosmosClone/CosmosCloneCommon/Model/ScrubRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ public ScrubRule(string filterCondition, string propertyName, RuleType type, str

}

public enum RuleType { SingleValue, NullValue, Shuffle, PartialMaskFromLeft, PartialMaskFromRight };//Can add random rule type later if required.
public enum RuleType { SingleValue, NullValue, Shuffle, PartialMaskFromLeft, PartialMaskFromRight, RandomEmailValue };//Can add random rule type later if required.
}
14 changes: 12 additions & 2 deletions CosmosClone/CosmosCloneCommon/Utility/ObjectScrubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public List<JToken> ScrubObjectList(List<string> srcList, ScrubRule scrubRule)
//var scrubbedObjects = new List<string>();
var scrubbedObjects = new List<JToken>();
var propNames = scrubRule.PropertyName.Split('.').ToList();
if(scrubRule.Type == RuleType.NullValue || scrubRule.Type == RuleType.SingleValue || scrubRule.Type == RuleType.PartialMaskFromLeft || scrubRule.Type == RuleType.PartialMaskFromRight)
if(scrubRule.Type == RuleType.NullValue || scrubRule.Type == RuleType.SingleValue || scrubRule.Type == RuleType.PartialMaskFromLeft || scrubRule.Type == RuleType.PartialMaskFromRight || scrubRule.Type == RuleType.RandomEmailValue)
{
foreach (var strObj in srcList)
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public List<JToken> ScrubObjectList(List<string> srcList, ScrubRule scrubRule)
throw ;
}
}
}
}
else
{
foreach (var strObj in srcList)
Expand Down Expand Up @@ -301,6 +301,14 @@ private JToken ScrubTokenValue(RuleType? ruleType, JToken tokenToBeScrubbed, str
tokenToBeScrubbed = string.Concat(oldValue.Remove(oldValue.Length - overwriteValue.Length, overwriteValue.Length), overwriteValue);
}
}
else if (ruleType == RuleType.RandomEmailValue)
{
var emailvalues = oldValue.Split('@');
var random = RandomNumberGenerator.RandomNumber();
var newvalue = oldValue.Replace(emailvalues.FirstOrDefault(), random);
tokenToBeScrubbed = newvalue;

}
else
{
tokenToBeScrubbed = overwriteValue;
Expand All @@ -309,5 +317,7 @@ private JToken ScrubTokenValue(RuleType? ruleType, JToken tokenToBeScrubbed, str

return tokenToBeScrubbed;
}

}
}