Skip to content

Commit

Permalink
jon-UID2-3680-test-coverage-v4-base64-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
jon8787 committed Jul 26, 2024
1 parent 6ac53b1 commit d1248e6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/UID2.Client.Test/BidstreamClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ 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;
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);
var advertisingTokenBase64 = Convert.ToBase64String(tokenAsBinary);
Assert.True(advertisingTokenBase64.Contains("="));
Assert.True(advertisingTokenBase64.Contains("/"));
Assert.True(advertisingTokenBase64.Contains("+"));

DecryptAndAssertSuccess(advertisingTokenBase64, TokenVersion.V4);
}


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

0 comments on commit d1248e6

Please sign in to comment.