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

jon-UID2-3680-test-coverage-v4-base64-tokens #62

Merged
merged 2 commits into from
Jul 29, 2024
Merged
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
22 changes: 22 additions & 0 deletions test/UID2.Client.Test/BidstreamClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ private void SmokeTestForBidstream(IdentityScope identityScope, TokenVersion tok
DecryptAndAssertSuccess(advertisingToken, tokenVersion);
}

[Theory]
[InlineData(IdentityScope.UID2)]
[InlineData(IdentityScope.EUID)]
private void CanDecryptV4TokenEncodedAsBase64(IdentityScope identityScope)
{
Refresh(KeyBidstreamResponse(new[] { MASTER_KEY, SITE_KEY }, identityScope));

var now = DateTime.UtcNow;

string advertisingTokenBase64;
do
{
var advertisingTokenBase64Url = AdvertisingTokenBuilder.Builder().WithVersion(TokenVersion.V4).WithScope(identityScope).WithEstablished(now.AddMonths(-4)).WithGenerated(now.AddDays(-1)).WithExpiry(now.AddDays(2)).Build();
var tokenAsBinary = UID2Base64UrlCoder.Decode(advertisingTokenBase64Url);
advertisingTokenBase64 = Convert.ToBase64String(tokenAsBinary);

} while (!advertisingTokenBase64.Contains("=") || !advertisingTokenBase64.Contains("/") || !advertisingTokenBase64.Contains("+"));

DecryptAndAssertSuccess(advertisingTokenBase64, TokenVersion.V4);
}


private void DecryptAndAssertSuccess(string advertisingToken, TokenVersion tokenVersion)
{
var res = _client.DecryptTokenIntoRawUid(advertisingToken, null);
Expand Down