|
22 | 22 | namespace WebEid.Security.Tests.Validator |
23 | 23 | { |
24 | 24 | using NUnit.Framework; |
25 | | - using WebEid.Security.Exceptions; |
26 | | - using WebEid.Security.Tests.TestUtils; |
| 25 | + using Exceptions; |
| 26 | + using TestUtils; |
27 | 27 |
|
28 | 28 | public class AuthTokenAlgorithmTest : AbstractTestWithValidator |
29 | 29 | { |
30 | 30 | [Test] |
31 | 31 | public void WhenAlgorithmNoneThenValidationFailsAsync() |
32 | 32 | { |
33 | | - var authToken = this.ReplaceTokenField(ValidAuthTokenStr, "ES384", "NONE"); |
34 | | - Assert.ThrowsAsync<AuthTokenParseException>(() => this.Validator.Validate(authToken, ValidChallengeNonce)) |
| 33 | + var authToken = ReplaceTokenField(ValidAuthTokenStr, "ES384", "NONE"); |
| 34 | + Assert.ThrowsAsync<AuthTokenParseException>(() => Validator.Validate(authToken, ValidChallengeNonce)) |
35 | 35 | .WithMessage("Unsupported signature algorithm"); |
36 | 36 | } |
37 | 37 |
|
38 | 38 | [Test] |
39 | 39 | public void WhenAlgorithmEmptyThenParsingFailsAsync() |
40 | 40 | { |
41 | | - var authToken = this.ReplaceTokenField(ValidAuthTokenStr, "ES384", ""); |
42 | | - Assert.ThrowsAsync<AuthTokenParseException>(() => this.Validator.Validate(authToken, ValidChallengeNonce)) |
| 41 | + var authToken = ReplaceTokenField(ValidAuthTokenStr, "ES384", ""); |
| 42 | + Assert.ThrowsAsync<AuthTokenParseException>(() => Validator.Validate(authToken, ValidChallengeNonce)) |
43 | 43 | .WithMessage("'algorithm' is null or empty"); |
44 | 44 | } |
45 | 45 |
|
46 | 46 | [Test] |
47 | 47 | public void WhenAlgorithmInvalidThenParsingFailsAsync() |
48 | 48 | { |
49 | | - var authToken = this.ReplaceTokenField(ValidAuthTokenStr, "ES384", "\u0000\t\ninvalid"); |
50 | | - Assert.ThrowsAsync<AuthTokenParseException>(() => this.Validator.Validate(authToken, ValidChallengeNonce)) |
| 49 | + var authToken = ReplaceTokenField(ValidAuthTokenStr, "ES384", "\u0000\t\ninvalid"); |
| 50 | + Assert.ThrowsAsync<AuthTokenParseException>(() => Validator.Validate(authToken, ValidChallengeNonce)) |
51 | 51 | .WithMessage("Unsupported signature algorithm"); |
52 | 52 | } |
| 53 | + |
| 54 | + [Test] |
| 55 | + public void WhenV11TokenMissingSupportedAlgorithmsThenValidationFailsAsync() |
| 56 | + { |
| 57 | + var tokenJson = RemoveJsonField(ValidV11AuthTokenStr, "supportedSignatureAlgorithms"); |
| 58 | + var token = Validator.Parse(tokenJson); |
| 59 | + |
| 60 | + var ex = Assert.ThrowsAsync<AuthTokenParseException>(() => |
| 61 | + Validator.Validate(token, ValidChallengeNonce)); |
| 62 | + |
| 63 | + Assert.That(ex.Message, Does.Contain("'supportedSignatureAlgorithms' field is missing")); |
| 64 | + } |
| 65 | + |
| 66 | + [Test] |
| 67 | + public void WhenV11TokenHasInvalidCryptoAlgorithmThenValidationFailsAsync() |
| 68 | + { |
| 69 | + var token = ReplaceTokenField(ValidV11AuthTokenStr, "\"cryptoAlgorithm\":\"RSA\"", "\"cryptoAlgorithm\":\"INVALID\""); |
| 70 | + Assert.ThrowsAsync<AuthTokenParseException>(() => Validator.Validate(token, ValidChallengeNonce)) |
| 71 | + .WithMessage("Unsupported signature algorithm"); |
| 72 | + } |
| 73 | + |
| 74 | + [Test] |
| 75 | + public void WhenV11TokenHasInvalidHashFunctionThenValidationFailsAsync() |
| 76 | + { |
| 77 | + var token = ReplaceTokenField( ValidV11AuthTokenStr, "\"hashFunction\":\"SHA-256\"", "\"hashFunction\":\"NOT_A_HASH\""); |
| 78 | + Assert.ThrowsAsync<AuthTokenParseException>(() => Validator.Validate(token, ValidChallengeNonce)) |
| 79 | + .WithMessage("Unsupported signature algorithm"); |
| 80 | + } |
| 81 | + |
| 82 | + [Test] |
| 83 | + public void WhenV11TokenHasInvalidPaddingSchemeThenValidationFailsAsync() |
| 84 | + { |
| 85 | + var token = ReplaceTokenField( ValidV11AuthTokenStr, "\"paddingScheme\":\"PKCS1.5\"", "\"paddingScheme\":\"BAD_PADDING\""); |
| 86 | + Assert.ThrowsAsync<AuthTokenParseException>(() => Validator.Validate(token, ValidChallengeNonce)) |
| 87 | + .WithMessage("Unsupported signature algorithm"); |
| 88 | + } |
| 89 | + |
| 90 | + [Test] |
| 91 | + public void WhenV11TokenHasEmptySupportedAlgorithmsThenValidationFailsAsync() |
| 92 | + { |
| 93 | + var token = ReplaceTokenField( ValidV11AuthTokenStr, "\"supportedSignatureAlgorithms\":[{\"cryptoAlgorithm\":\"RSA\",\"hashFunction\":\"SHA-256\",\"paddingScheme\":\"PKCS1.5\"}]", "\"supportedSignatureAlgorithms\":[]"); |
| 94 | + Assert.ThrowsAsync<AuthTokenParseException>(() => Validator.Validate(token, ValidChallengeNonce)) |
| 95 | + .WithMessage("'supportedSignatureAlgorithms' field is missing"); |
| 96 | + } |
53 | 97 | } |
54 | 98 | } |
0 commit comments