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

feat(dotnet): masking #1074

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ cleanup-failure:
test-metrics-dotnet: ## Run Metrics tests against the .NET SDK
docker compose up --build --detach integration_dotnet_metrics_v6.0
sleep 5
npm run test:integration-metrics || make cleanup-failure
SUPPORTS_HASHING=true npm run test:integration-metrics || make cleanup-failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this flag and expect hashing across all of our integration suites, or are we still blocked by php?

@make cleanup

test-webhooks-dotnet: ## Run webhooks tests against the .NET SDK
docker compose up --build --detach integration_dotnet_webhooks_v6.0
npm run test:integration-webhooks || make cleanup-failure
SUPPORTS_HASHING=true npm run test:integration-webhooks || make cleanup-failure
@make cleanup

##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<string> BuildHar()
private Group BuildGroup()
{
Group group = new Group();
group.id = this.configValues.group.id;
group.id = MaskHelper.Mask(this.configValues.group.id);
group.label = this.configValues.group.label;
group.email = this.configValues.group.email;
return group;
Expand Down
17 changes: 17 additions & 0 deletions packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Security.Cryptography;
using System.Text;

public static class MaskHelper
{
public static string Mask(string data)
{
using (SHA512 sha512 = SHA512.Create())
{
byte[] hashBytes = sha512.ComputeHash(Encoding.UTF8.GetBytes(data));
string base64Hash = Convert.ToBase64String(hashBytes);
string opts = data.Length >= 4 ? data.Substring(data.Length - 4) : data;
return $"sha512-{base64Hash}?{opts}";
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndriiAndreiev looks like you're missing a couple end-of-file new lines. May want to update your IDE config!

Original file line number Diff line number Diff line change
Expand Up @@ -145,31 +145,25 @@ private List<Headers> GetHeaders()
{
foreach (var reqHeader in this.request.Headers)
{
Headers header = new Headers();
header.name = reqHeader.Key;
header.value = reqHeader.Key == "Authorization" ? MaskHelper.Mask(reqHeader.Value) : reqHeader.Value.ToString();
if (!this.configValues.options.isAllowListEmpty)
{
if (this.CheckAllowList(reqHeader.Key))
{
Headers header = new Headers();
header.name = reqHeader.Key;
header.value = reqHeader.Value;
headers.Add(header);
}
}
else if (!this.configValues.options.isDenyListEmpty)
{
if (!this.CheckDenyList(reqHeader.Key))
{
Headers header = new Headers();
header.name = reqHeader.Key;
header.value = reqHeader.Value;
headers.Add(header);
}
}
else
{
Headers header = new Headers();
header.name = reqHeader.Key;
header.value = reqHeader.Value;
headers.Add(header);
}
}
Expand Down Expand Up @@ -227,4 +221,4 @@ private List<Cookies> GetCookies()
return cookies;
}
}
}
}