-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from dvsekhvalnov/issue_237-more-checks
minor fixes and security guards
- Loading branch information
Showing
5 changed files
with
71 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4725,6 +4725,19 @@ public void DecodeObject() | |
Assert.Equal("[email protected]", test.sub); | ||
} | ||
|
||
[Fact] | ||
public void DecodeMalformedToken() | ||
{ | ||
// 1 parts | ||
Assert.Throws<JoseException>(() => Jose.JWT.Decode("eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0", testSuiteUtils.PubKey())); | ||
|
||
// 2 parts | ||
Assert.Throws<JoseException>(() => Jose.JWT.Decode("eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9", testSuiteUtils.PubKey())); | ||
|
||
// 4 parts | ||
Assert.Throws<JoseException>(() => Jose.JWT.Decode("eyJhbGciOiJBMTI4R0NNS1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiaXYiOiJ1SDVxVThlN2JVZXhGYWh3IiwidGFnIjoiamdxc2czdHoyUGo0QmhEWU1xTnBrdyJ9.peAzKiVO3_w2tAlSzRZdqqQpnUSpgPDHi_xgTd6VzP4.o8bhvYO_UTkrsxQmm__nIg.MSmgetpjXHWMs0TyuGgmWd-msfbQ7oVWC4WuCJcfAsbhLU9kLDLrd0naL5f_UkWBaM04bfcc31K4FRN20IiUxcHzLnMR-lY-HkvRFWYdur-kLWw1UXjIlPOb0nqCuyd2FRpxMdSfFnYr5Us9T45cF7DdK8p4iA7KqPToMHWBsvAcET_ycMIoERqJrBuiJzh-j7UtDzH6KtUfgD4tzZAm3iM6HWT2lq25Pqsu4qf19LYXxZaMIiFwFKboeexkJ5E0hc7P-wIeknzFJaZhkb5P4g", aes128Key)); | ||
} | ||
|
||
private static ECDiffieHellman Ecdh256Private(CngKeyUsages usage = CngKeyUsages.Signing) | ||
{ | ||
byte[] x = { 4, 114, 29, 223, 58, 3, 191, 170, 67, 128, 229, 33, 242, 178, 157, 150, 133, 25, 209, 139, 166, 69, 55, 26, 84, 48, 169, 165, 67, 232, 98, 9 }; | ||
|
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 |
---|---|---|
|
@@ -3031,6 +3031,30 @@ public void DecodeObject() | |
Assert.That(test.sub, Is.EqualTo("[email protected]")); | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof(JoseException))] | ||
|
||
public void DecodeMalformedTokenOnePart() | ||
{ | ||
Jose.JWT.Decode("eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0", PubKey()); | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof(JoseException))] | ||
|
||
public void DecodeMalformedTokenTwoPart() | ||
{ | ||
Jose.JWT.Decode("eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9", PubKey()); | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof(JoseException))] | ||
|
||
public void DecodeMalformedTokenFourPart() | ||
{ | ||
Jose.JWT.Decode("eyJhbGciOiJBMTI4R0NNS1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiaXYiOiJ1SDVxVThlN2JVZXhGYWh3IiwidGFnIjoiamdxc2czdHoyUGo0QmhEWU1xTnBrdyJ9.peAzKiVO3_w2tAlSzRZdqqQpnUSpgPDHi_xgTd6VzP4.o8bhvYO_UTkrsxQmm__nIg.MSmgetpjXHWMs0TyuGgmWd-msfbQ7oVWC4WuCJcfAsbhLU9kLDLrd0naL5f_UkWBaM04bfcc31K4FRN20IiUxcHzLnMR-lY-HkvRFWYdur-kLWw1UXjIlPOb0nqCuyd2FRpxMdSfFnYr5Us9T45cF7DdK8p4iA7KqPToMHWBsvAcET_ycMIoERqJrBuiJzh-j7UtDzH6KtUfgD4tzZAm3iM6HWT2lq25Pqsu4qf19LYXxZaMIiFwFKboeexkJ5E0hc7P-wIeknzFJaZhkb5P4g", PubKey()); | ||
} | ||
|
||
#region test utils | ||
|
||
private RSACryptoServiceProvider PrivKey() | ||
|
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 |
---|---|---|
|
@@ -5188,6 +5188,19 @@ public void DecodeObject() | |
Assert.Equal("[email protected]", test.sub); | ||
} | ||
|
||
[Fact] | ||
public void DecodeMalformedToken() | ||
{ | ||
// 1 parts | ||
Assert.Throws<JoseException>(() => Jose.JWT.Decode("eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0", PubKey())); | ||
|
||
// 2 parts | ||
Assert.Throws<JoseException>(() => Jose.JWT.Decode("eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9", PubKey())); | ||
|
||
// 4 parts | ||
Assert.Throws<JoseException>(() => Jose.JWT.Decode("eyJhbGciOiJBMTI4R0NNS1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiaXYiOiJ1SDVxVThlN2JVZXhGYWh3IiwidGFnIjoiamdxc2czdHoyUGo0QmhEWU1xTnBrdyJ9.peAzKiVO3_w2tAlSzRZdqqQpnUSpgPDHi_xgTd6VzP4.o8bhvYO_UTkrsxQmm__nIg.MSmgetpjXHWMs0TyuGgmWd-msfbQ7oVWC4WuCJcfAsbhLU9kLDLrd0naL5f_UkWBaM04bfcc31K4FRN20IiUxcHzLnMR-lY-HkvRFWYdur-kLWw1UXjIlPOb0nqCuyd2FRpxMdSfFnYr5Us9T45cF7DdK8p4iA7KqPToMHWBsvAcET_ycMIoERqJrBuiJzh-j7UtDzH6KtUfgD4tzZAm3iM6HWT2lq25Pqsu4qf19LYXxZaMIiFwFKboeexkJ5E0hc7P-wIeknzFJaZhkb5P4g", aes128Key)); | ||
} | ||
|
||
#region Test Utils | ||
|
||
private static RSACryptoServiceProvider PrivKey() | ||
|
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