-
-
Notifications
You must be signed in to change notification settings - Fork 27
Fix ArgumentOutOfRangeException when header value is empty
#488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+112
−1
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2aa56ad
Add bounds check for header substring operation
benyuz 85ec85e
Potential fix for pull request finding
benyuz f6dcce0
Add unit tests for WebHeaderCollection Authorization headers
benyuz 9c2263f
Add tests for Authorization header handling
benyuz fdc2c67
Remove obvious suffix from names
josesimoes c8ca5b7
Add new unit tests that are meant to throw
josesimoes f584fd9
WebHeaderCollectionTests are now in unit test project
josesimoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,101 @@ | ||
| // | ||
| // Copyright (c) .NET Foundation and Contributors | ||
| // See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| using nanoFramework.TestFramework; | ||
| using System; | ||
| using System.Net; | ||
|
|
||
| namespace HttpUnitTests | ||
| { | ||
| [TestClass] | ||
| public class WebHeaderCollectionTests | ||
| { | ||
| [TestMethod] | ||
| public void Add_Authorization_BearerWithSpaceAndNoValue() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| headers.Add("Authorization: Bearer "); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_Authorization_NoSpaceSingleChar() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| headers.Add("Authorization: 1"); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_Authorization_ValidBearer() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| headers.Add("Authorization: Bearer a11111"); | ||
| string value = headers["Authorization"]; | ||
| Assert.AreEqual("Bearer a11111", value); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_Authorization_ValidTestValue() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| headers.Add("Authorization: test 1"); | ||
| string value = headers["Authorization"]; | ||
| Assert.AreEqual("test 1", value); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_Authorization_ValidSingleLetterPair() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| headers.Add("Authorization: a b"); | ||
| string value = headers["Authorization"]; | ||
| Assert.AreEqual("a b", value); | ||
| } | ||
| [TestMethod] | ||
| public void Add_Authorization_EmptyValue() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| headers.Add("Authorization:"); | ||
| string value = headers["Authorization"]; | ||
| Assert.AreEqual(string.Empty, value); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_Authorization_ColonWithSpaceOnly() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| headers.Add("Authorization: "); | ||
| string value = headers["Authorization"]; | ||
| Assert.AreEqual(string.Empty, value); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_NullHeader_ThrowsArgumentNullException() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| Assert.ThrowsException(typeof(ArgumentNullException), () => headers.Add(null)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_EmptyHeader_ThrowsArgumentNullException() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| Assert.ThrowsException(typeof(ArgumentNullException), () => headers.Add(string.Empty)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_HeaderWithNoColon_ThrowsArgumentException() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| Assert.ThrowsException(typeof(ArgumentException), () => headers.Add("Authorization")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Add_HeaderNameWithSpace_ThrowsArgumentException() | ||
| { | ||
| var headers = new WebHeaderCollection(); | ||
| Assert.ThrowsException(typeof(ArgumentException), () => headers.Add("My Header: value")); | ||
| } | ||
|
josesimoes marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.