-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Base64 decoding when whitespaces occur (#571)
* Fix Base64 decoding when whitespaces occur * Fix JWK validation of the field 'x5c'. This field is b64-encoded and not b64-url encoded.
- Loading branch information
1 parent
b899a2f
commit 13ec96e
Showing
7 changed files
with
187 additions
and
79 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
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
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,44 @@ | ||
using System; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace JsonWebToken.Tests | ||
{ | ||
public class Base64Tests | ||
{ | ||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData("SGVsbG8=", "Hello")] | ||
[InlineData("SGVsbG8gV29ybGQ=", "Hello World")] | ||
[InlineData("SGVsbG8\tgV29ybGQ=", "Hello World")] | ||
[InlineData("SGVsbG8\rgV29ybGQ=", "Hello World")] | ||
[InlineData("SGVsbG8\ngV29ybGQ=", "Hello World")] | ||
[InlineData("SGVsbG8\vgV29ybGQ=", "Hello World")] | ||
[InlineData("SGVsbG8\fgV29ybGQ=", "Hello World")] | ||
[InlineData("SGVsbG8 gV29ybGQ=", "Hello World")] | ||
[InlineData(" SGVsbG8gV29ybGQ=", "Hello World")] | ||
[InlineData("SG Vsb G8gV29ybGQ=", "Hello World")] | ||
[InlineData("S G V s b G 8 g V 2 9 y b G Q =", "Hello World")] | ||
[InlineData("S G V s b G8gV29ybGQ=", "Hello World")] | ||
[InlineData(" S G V s b G8gV29ybGQ= ", "Hello World")] | ||
[InlineData("SGV+bG8=", "He~lo")] | ||
[InlineData("SGV/bG8=", "He\u007flo")] | ||
public void Decode_Valid(string value, string expected) | ||
{ | ||
var result = Base64.Decode(Encoding.UTF8.GetBytes(value)); | ||
Assert.NotNull(result); | ||
Assert.Equal(Encoding.UTF8.GetBytes(expected), result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("SGVsbG8")] | ||
[InlineData("SGVsbG8&")] | ||
[InlineData("SGVsbG=8")] | ||
[InlineData("S-/sbG8=")] | ||
[InlineData("S+_sbG8=")] | ||
public void Decode_Invalid(string value) | ||
{ | ||
Assert.Throws<FormatException>(() => Base64.Decode(Encoding.UTF8.GetBytes(value))); | ||
} | ||
} | ||
} |
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,38 @@ | ||
using System; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace JsonWebToken.Tests | ||
{ | ||
public class Base64UrlTests | ||
{ | ||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData("SGVsbG8", "Hello")] | ||
[InlineData("SGVsbG8gV29ybGQ", "Hello World")] | ||
[InlineData("SGV-bG8", "He~lo")] | ||
[InlineData("SGV_bG8", "He\u007flo")] | ||
public void Decode_Valid(string value, string expected) | ||
{ | ||
var result = Base64Url.Decode(Encoding.UTF8.GetBytes(value)); | ||
Assert.NotNull(result); | ||
Assert.Equal(Encoding.UTF8.GetBytes(expected), result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("SGVsbG8=")] | ||
[InlineData("SGVsbG8 ")] | ||
[InlineData(" SGVsbG8")] | ||
[InlineData("SGV sbG8")] | ||
public void Decode_Invalid(string value) | ||
{ | ||
Assert.Throws<FormatException>(() => Base64Url.Decode(Encoding.UTF8.GetBytes(value))); | ||
} | ||
|
||
[Fact] | ||
public void Decode_Null() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => Base64Url.Decode((string)null)); | ||
} | ||
} | ||
} |
Oops, something went wrong.