-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core (fix): Fix MessageUnpacker.unpackValue to check the custom strin…
…gSizeLimit (#753) * core (fix): Fix MessageUnpacker.unpackValue to check the custom stringSizeLimit * Cover unpackVariable(var)
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
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
37 changes: 37 additions & 0 deletions
37
msgpack-core/src/test/scala/org/msgpack/core/StringLimitTest.scala
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.msgpack.core | ||
|
||
import org.msgpack.core.MessagePack.UnpackerConfig | ||
import org.msgpack.value.Variable | ||
import wvlet.airspec.AirSpec | ||
|
||
class StringLimitTest extends AirSpec { | ||
|
||
test("throws an exception when the string size exceeds a limit") { | ||
val customLimit = 100 | ||
val packer = MessagePack.newDefaultBufferPacker() | ||
packer.packString("a" * (customLimit + 1)) | ||
val msgpack = packer.toByteArray | ||
|
||
test("unpackString") { | ||
val unpacker = new UnpackerConfig().withStringSizeLimit(customLimit).newUnpacker(msgpack) | ||
intercept[MessageSizeException] { | ||
unpacker.unpackString() | ||
} | ||
} | ||
|
||
test("unpackValue") { | ||
val unpacker = new UnpackerConfig().withStringSizeLimit(customLimit).newUnpacker(msgpack) | ||
intercept[MessageSizeException] { | ||
unpacker.unpackValue() | ||
} | ||
} | ||
|
||
test("unpackValue(var)") { | ||
val unpacker = new UnpackerConfig().withStringSizeLimit(customLimit).newUnpacker(msgpack) | ||
intercept[MessageSizeException] { | ||
val v = new Variable() | ||
unpacker.unpackValue(v) | ||
} | ||
} | ||
} | ||
} |