-
Notifications
You must be signed in to change notification settings - Fork 28
(#42) HtHead can be broken. #69
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,15 +23,20 @@ | |
| */ | ||
| package org.cactoos.http; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Random; | ||
| import org.cactoos.Text; | ||
| import org.cactoos.io.BytesOf; | ||
| import org.cactoos.io.InputOf; | ||
| import org.cactoos.text.JoinedText; | ||
| import org.cactoos.text.RepeatedText; | ||
| import org.cactoos.text.ReplacedText; | ||
| import org.cactoos.text.TextOf; | ||
| import org.hamcrest.MatcherAssert; | ||
| import org.hamcrest.Matchers; | ||
| import org.hamcrest.core.IsEqual; | ||
| import org.junit.Test; | ||
| import org.llorllale.cactoos.matchers.Assertion; | ||
| import org.llorllale.cactoos.matchers.EndsWith; | ||
| import org.llorllale.cactoos.matchers.StartsWith; | ||
| import org.llorllale.cactoos.matchers.TextHasString; | ||
|
|
||
| /** | ||
|
|
@@ -45,9 +50,10 @@ | |
| public final class HtHeadTest { | ||
|
|
||
| @Test | ||
| public void takesHeadOutOfHttpResponse() throws IOException { | ||
| MatcherAssert.assertThat( | ||
| new TextOf( | ||
| public void takesHeadOutOfHttpResponse() { | ||
| new Assertion<>( | ||
| "Header does not have 'text/plain'", | ||
| () -> new TextOf( | ||
| new HtHead( | ||
| new InputOf( | ||
| new JoinedText( | ||
|
|
@@ -59,15 +65,16 @@ public void takesHeadOutOfHttpResponse() throws IOException { | |
| ) | ||
| ) | ||
| ) | ||
| ).asString(), | ||
| Matchers.endsWith("text/plain") | ||
| ); | ||
| ), | ||
| new EndsWith("text/plain") | ||
| ).affirm(); | ||
| } | ||
|
|
||
| @Test | ||
| public void emptyHeadOfHttpResponse() throws IOException { | ||
| MatcherAssert.assertThat( | ||
| new TextOf( | ||
| public void emptyHeadOfHttpResponse() { | ||
| new Assertion<>( | ||
| "Text does not have an empty string", | ||
| () -> new TextOf( | ||
| new HtHead( | ||
| new InputOf( | ||
| new JoinedText( | ||
|
|
@@ -80,16 +87,17 @@ public void emptyHeadOfHttpResponse() throws IOException { | |
| ) | ||
| ), | ||
| new TextHasString("") | ||
| ); | ||
| ).affirm(); | ||
| } | ||
|
|
||
| @Test | ||
| public void largeText() throws IOException { | ||
| public void largeText() { | ||
| //@checkstyle MagicNumberCheck (1 lines) | ||
| final byte[] bytes = new byte[18000]; | ||
| new Random().nextBytes(bytes); | ||
| MatcherAssert.assertThat( | ||
| new TextOf( | ||
| new Assertion<>( | ||
| "Header does not have text/plain header", | ||
| () -> new TextOf( | ||
| new HtHead( | ||
| new InputOf( | ||
| new JoinedText( | ||
|
|
@@ -101,9 +109,55 @@ public void largeText() throws IOException { | |
| ) | ||
| ) | ||
| ) | ||
| ).asString(), | ||
| Matchers.endsWith("text/plain") | ||
| ); | ||
| ), | ||
| new EndsWith("text/plain") | ||
| ).affirm(); | ||
| } | ||
|
|
||
| @Test | ||
| public void edgeOfTheBlockTearing() throws Exception { | ||
| final int size = 16384; | ||
| final Text header = new JoinedText( | ||
| "\r\n", | ||
| "HTTP/1.1 200 OK", | ||
| "Referer: http://en.wikipedia.org/wiki/Main_Page#\0", | ||
| "Content-type: text/plain", | ||
| "" | ||
| ); | ||
| final Text block = new ReplacedText( | ||
| header, | ||
| "\0", | ||
| new RepeatedText( | ||
| "x", | ||
| size - header.asString().length() + 1 | ||
| ).asString() | ||
| ); | ||
| new Assertion<>( | ||
| "make sure the constructed block is exact size", | ||
| () -> block.asString().length(), | ||
| new IsEqual<>( | ||
|
Contributor
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. @ilyakharlamov please use cactoos-matchers'
Contributor
Author
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. Here I am constructing a block and making sure it has the exact length of the block.
Contributor
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. @ilyakharlamov you are right yes. I think this test is too complex to be easily understandable. Why are you checking the block length? You are not testing
Contributor
Author
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. @victornoel In order to reproduce the issue, I need to have a header of the exact size of the block (16384 bytes)
Contributor
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. @ilyakharlamov ok, it's good for me then, thank you for the explanation |
||
| size | ||
| ) | ||
| ).affirm(); | ||
| new Assertion<>( | ||
| String.format("Edge of the block tearing for size: %s", size), | ||
| () -> new TextOf( | ||
| new HtHead( | ||
| new InputOf( | ||
| new JoinedText( | ||
| "\r\n", | ||
| block.asString(), | ||
| "", | ||
| "body here" | ||
| ) | ||
| ) | ||
| ) | ||
| ), | ||
| Matchers.allOf( | ||
| new StartsWith("HTTP"), | ||
| new TextHasString("OK\r\nReferer"), | ||
| new EndsWith("text/plain") | ||
| ) | ||
| ).affirm(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.