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
Add validity checks for HTTP datagrams #85
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f6b5b7f
Check validity of HTTP requests
FlorianHockmann a78426d
Check validity of HTTP responses
FlorianHockmann 6bf2a9e
Add test for missing request method
FlorianHockmann d7ece16
HTTP validity checks don't override CalculateIsValid()
FlorianHockmann ebab5ed
Move common behavior up to HttpDatagram
FlorianHockmann 45dd226
Add IsValidStart check to RandomHttpTest
FlorianHockmann cf6c718
Fix spelling: "A HTTP" -> "An HTTP"
FlorianHockmann e9071e5
Rename HTTP IsValidStart tests to be more descriptive
FlorianHockmann File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -108,6 +108,7 @@ public void RandomHttpTest() | |
if (httpLayer.Header != null) | ||
{ | ||
Assert.AreEqual(httpLayer.Header.GetHashCode(), httpDatagram.Header.GetHashCode()); | ||
Assert.IsTrue(httpDatagram.IsValidStart, "IsValidStart"); | ||
|
||
foreach (var field in httpLayer.Header) | ||
Assert.IsFalse(field.Equals("abc")); | ||
|
@@ -470,6 +471,86 @@ public void HttpRequestMethodBadKnownTest() | |
Assert.IsNotNull(new HttpRequestMethod(HttpRequestKnownMethod.Unknown)); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartRequestValidTest() | ||
{ | ||
var packet = BuildPacket("UnknownMethod / HTTP/1.0\r\n\r\n"); | ||
|
||
Assert.IsTrue(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartRequestWithMissingUriNotAllowedTest() | ||
{ | ||
var packet = BuildPacket("GET HTTP/1.1\r\n\r\n"); | ||
|
||
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartRequestWithMissingVersionNumberNotAllowedTest() | ||
{ | ||
var packet = BuildPacket("GET / HTTP/\r\n\r\n"); | ||
|
||
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartRequestWithMissingVersionNotAllowedTest() | ||
{ | ||
var packet = BuildPacket("GET /\r\n\r\n"); | ||
|
||
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartRequestWithMissingMethodNotAllowedTest() | ||
{ | ||
var packet = BuildPacket(" / HTTP/1.0\r\n\r\n"); | ||
|
||
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartResponseValidTest() | ||
{ | ||
var packet = BuildPacket("HTTP/1.0 200 OK\r\n\r\n"); | ||
|
||
Assert.IsTrue(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartResponseMinimalValidTest() | ||
{ | ||
var packet = BuildPacket("HTTP/1.0 200 \r\n\r\n"); | ||
|
||
Assert.IsTrue(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartResponseWithMissingVersionNumberNotAllowedTest() | ||
{ | ||
var packet = BuildPacket("HTTP/ 200 OK\r\n\r\n"); | ||
|
||
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartResponseWithMissingVersionNotAllowed() | ||
{ | ||
var packet = BuildPacket(" 200 OK\r\n\r\n"); | ||
|
||
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
[TestMethod] | ||
public void HttpIsValidStartResponseWithMissingStatusCodeNotAllowedTest() | ||
{ | ||
var packet = BuildPacket("HTTP/1.0 OK \r\n\r\n"); | ||
|
||
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Http.IsValidStart); | ||
} | ||
|
||
private static void TestHttpRequest(string httpString, string expectedMethodString = null, string expectedUri = null, HttpVersion expectedVersion = null, HttpHeader expectedHeader = null, string expectedBodyString = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test the new method also in RandomHttpTest |
||
{ | ||
Datagram expectedBody = expectedBodyString == null ? null : new Datagram(Encoding.ASCII.GetBytes(expectedBodyString)); | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you only care about IsValidStart in these tests, you could put "IsValidStart" as part of the test names.
Otherwise you could test other properties for these use cases.