=htp make coding specs more robust
On my machine I got: GzipSpec: "invalid code lengths set" instead of "incomplete dynamic bit length tree" DeflateSpec: "unknown compression method" instead of "incorrect header check"
This commit is contained in:
parent
76cf157912
commit
cf8e59785a
4 changed files with 10 additions and 12 deletions
|
|
@ -28,7 +28,7 @@ abstract class CoderSpec extends WordSpec with CodecSpecSupport with Inspectors
|
|||
protected def newEncodedOutputStream(underlying: OutputStream): OutputStream
|
||||
|
||||
case object AllDataAllowed extends Exception with NoStackTrace
|
||||
protected def corruptInputMessage: Option[String]
|
||||
protected def corruptInputCheck: Boolean = true
|
||||
|
||||
def extraTests(): Unit = {}
|
||||
|
||||
|
|
@ -55,10 +55,11 @@ abstract class CoderSpec extends WordSpec with CodecSpecSupport with Inspectors
|
|||
val request = HttpRequest(POST, entity = HttpEntity(largeText))
|
||||
Coder.decode(Coder.encode(request)) should equal(request)
|
||||
}
|
||||
"throw an error on corrupt input" in {
|
||||
corruptInputMessage foreach { message ⇒
|
||||
val ex = the[DataFormatException] thrownBy ourDecode(corruptContent)
|
||||
ex.getMessage should equal(message)
|
||||
if (corruptInputCheck) {
|
||||
"throw an error on corrupt input" in {
|
||||
a[DataFormatException] should be thrownBy {
|
||||
ourDecode(corruptContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
"not throw an error if a subsequent block is corrupt" in {
|
||||
|
|
|
|||
|
|
@ -18,12 +18,11 @@ class DeflateSpec extends CoderSpec {
|
|||
protected def newEncodedOutputStream(underlying: OutputStream): OutputStream =
|
||||
new DeflaterOutputStream(underlying)
|
||||
|
||||
protected def corruptInputMessage: Option[String] = Some("invalid code -- missing end-of-block")
|
||||
|
||||
override def extraTests(): Unit = {
|
||||
"throw early if header is corrupt" in {
|
||||
val ex = the[DataFormatException] thrownBy ourDecode(ByteString(0, 1, 2, 3, 4))
|
||||
ex.getMessage should equal("incorrect header check")
|
||||
a[DataFormatException] should be thrownBy {
|
||||
ourDecode(ByteString(0, 1, 2, 3, 4))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ class GzipSpec extends CoderSpec {
|
|||
protected def newEncodedOutputStream(underlying: OutputStream): OutputStream =
|
||||
new GZIPOutputStream(underlying)
|
||||
|
||||
protected def corruptInputMessage: Option[String] = Some("invalid code lengths set")
|
||||
|
||||
override def extraTests(): Unit = {
|
||||
"decode concatenated compressions" in {
|
||||
ourDecode(Seq(encode("Hello, "), encode("dear "), encode("User!")).join) should readAs("Hello, dear User!")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.io.{ OutputStream, InputStream }
|
|||
class NoCodingSpec extends CoderSpec {
|
||||
protected def Coder: Coder with StreamDecoder = NoCoding
|
||||
|
||||
protected def corruptInputMessage: Option[String] = None // all input data is valid
|
||||
override protected def corruptInputCheck = false
|
||||
|
||||
protected def newEncodedOutputStream(underlying: OutputStream): OutputStream = underlying
|
||||
protected def newDecodedInputStream(underlying: InputStream): InputStream = underlying
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue