-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix EnableRelaxedDecoding implementation and add test coverage
- Loading branch information
Showing
2 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Text.Json; | ||
|
||
namespace Fido2NetLib.Tests; | ||
|
||
public class Base64UrlConverterTests | ||
{ | ||
[Fact] | ||
public void RelaxedDecodingWorks() | ||
{ | ||
string jsonText = | ||
""" | ||
{ | ||
"name": "anders", | ||
"id": "7w80qsdaWWm5R+KK2O64MO/WSitunFbxH1H8mE9IVORxzbXdxXDY1VRQlayoK/Lmh3MI/p0M59Rh98D8r4EoJw==", | ||
"displayName": "anders" | ||
} | ||
"""; | ||
|
||
Base64UrlConverter.EnableRelaxedDecoding = false; | ||
|
||
try | ||
{ | ||
_ = JsonSerializer.Deserialize<Fido2User>(jsonText); | ||
} | ||
catch (JsonException ex) | ||
{ | ||
Assert.Equal("Expected data to be in Base64Url format, but received Base64 encoding instead.", ex.Message); | ||
} | ||
|
||
Base64UrlConverter.EnableRelaxedDecoding = true; | ||
|
||
var user = JsonSerializer.Deserialize<Fido2User>(jsonText); | ||
|
||
Assert.Equal("7w80qsdaWWm5R+KK2O64MO/WSitunFbxH1H8mE9IVORxzbXdxXDY1VRQlayoK/Lmh3MI/p0M59Rh98D8r4EoJw==", Convert.ToBase64String(user.Id)); | ||
} | ||
} |