mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 19:24:53 +08:00
complete some encrypt test and InputCommand test
This commit is contained in:
parent
12a49b71d1
commit
9ec10a6674
@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur
|
|||||||
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
|
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
|
||||||
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
|
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
|
||||||
|
|
||||||
VERSION = 1.1.1-alpha4
|
VERSION = 1.1.1-alpha5
|
||||||
|
|
||||||
USE_DELTA = false
|
USE_DELTA = false
|
||||||
VERSION_DELTA =
|
VERSION_DELTA =
|
||||||
|
@ -7,26 +7,84 @@ class CommonEncryptTest extends MornyTests with TableDrivenPropertyChecks {
|
|||||||
|
|
||||||
"while doing hash :" - {
|
"while doing hash :" - {
|
||||||
|
|
||||||
|
import cc.sukazyo.cono.morny.util.CommonEncrypt.{MD5, SHA1, SHA256, SHA512}
|
||||||
|
import cc.sukazyo.cono.morny.util.ConvertByteHex.toHex
|
||||||
|
|
||||||
val examples = Table(
|
val examples = Table(
|
||||||
("md5" , "text"),
|
(
|
||||||
("28be57d368b75051da76c068a6733284", "莲子"),
|
"text",
|
||||||
("9644c5cbae223013228cd528817ba4f5", "莲子\n"),
|
"md5",
|
||||||
("d41d8cd98f00b204e9800998ecf8427e", "")
|
"sha1",
|
||||||
|
"sha256",
|
||||||
|
"sha512"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"莲子",
|
||||||
|
"28be57d368b75051da76c068a6733284",
|
||||||
|
"556f7cadfcbffdcbf41b4aa1843528b4406e62e6",
|
||||||
|
"f7d6f172cb4a8d1a8f7513ee94c7b6bbf1cf5c8c643182ebbb1b9ab472704e9b",
|
||||||
|
"4be6cf5dc44582d913d4d716ef4528f04e08d94a45eee0f27395003d3c83be535d5b9a40f510625bc6fee3481f6a1de600057ceff6488c5953f6172641f4768d"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"莲子\n",
|
||||||
|
"9644c5cbae223013228cd528817ba4f5",
|
||||||
|
"86329fc40e4bab2c410e35ddbec7ab8a7b6574d6",
|
||||||
|
"3372ca6821832bebd681c705862c01d137cba9cf288f95465ee7876affc90ba0",
|
||||||
|
"bedf1c61330c0f945fa4f84aaccf2778b5c77926916689e8b8e4c3d1d567dc8b9d91643ff3451365e4fd04f789ca229e0b2ca61dd4976ad6f866f5600617430c"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"",
|
||||||
|
"d41d8cd98f00b204e9800998ecf8427e",
|
||||||
|
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
||||||
|
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||||
|
"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.util.CommonEncrypt.MD5
|
forAll (examples) { (text, md5, sha1, sha256, sha512) =>
|
||||||
import cc.sukazyo.cono.morny.util.ConvertByteHex.toHex
|
|
||||||
forAll (examples) { (md5, text) =>
|
|
||||||
s"while hashing text \"$text\" :" - {
|
s"while hashing text \"$text\" :" - {
|
||||||
|
|
||||||
s"the MD5 value should be $md5" in { MD5(text).toHex shouldEqual md5 }
|
s"the MD5 value should be $md5" in { MD5(text).toHex shouldEqual md5 }
|
||||||
|
s"the SHA1 should be $sha1" in { SHA1(text).toHex shouldEqual sha1 }
|
||||||
"other algorithms" in pending
|
s"the SHA256 should be $sha256" in { SHA256(text).toHex shouldEqual sha256 }
|
||||||
|
s"the SHA512 should be $sha512" in { SHA512(text).toHex shouldEqual sha512 }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s"while hashing binary file $pending_val" in pending
|
// todo: binary file source
|
||||||
|
case class ExampleHashValue (
|
||||||
|
md5: String,
|
||||||
|
sha1: String,
|
||||||
|
sha256: String,
|
||||||
|
sha512: String
|
||||||
|
)
|
||||||
|
val examples_binary = Table[String|Null, ExampleHashValue](
|
||||||
|
("file", "hashes"),
|
||||||
|
(
|
||||||
|
null, ExampleHashValue(
|
||||||
|
"d41d8cd98f00b204e9800998ecf8427e",
|
||||||
|
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
||||||
|
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||||
|
"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
forAll(examples_binary) { (file, hashes) =>
|
||||||
|
val _name = if file == null then "empty file" else s"file $file"
|
||||||
|
val _data = if file == null then Array.empty[Byte] else throw NotImplementedError("does not applied file get yet")
|
||||||
|
|
||||||
|
s"while hashing binary $_name :" - {
|
||||||
|
|
||||||
|
s"the MD5 value should be ${hashes.md5}" in { MD5(_data).toHex shouldEqual hashes.md5 }
|
||||||
|
s"the SHA1 should be $hashes.sha1" in { SHA1(_data).toHex shouldEqual hashes.sha1 }
|
||||||
|
s"the SHA256 should be $hashes.sha256" in { SHA256(_data).toHex shouldEqual hashes.sha256 }
|
||||||
|
s"the SHA512 should be $hashes.sha512" in { SHA512(_data).toHex shouldEqual hashes.sha512 }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,70 @@
|
|||||||
package cc.sukazyo.cono.morny.test.utils.tgapi
|
package cc.sukazyo.cono.morny.test.utils.tgapi
|
||||||
|
|
||||||
import cc.sukazyo.cono.morny.test.MornyTests
|
import cc.sukazyo.cono.morny.test.MornyTests
|
||||||
|
import cc.sukazyo.cono.morny.util.tgapi.InputCommand
|
||||||
|
import org.scalatest.prop.TableDrivenPropertyChecks
|
||||||
|
|
||||||
class InputCommandTest extends MornyTests {
|
class InputCommandTest extends MornyTests with TableDrivenPropertyChecks {
|
||||||
|
|
||||||
"while create new InputCommand :" - {
|
"while create new InputCommand :" - {
|
||||||
|
|
||||||
s"while input is $pending_val:" - {
|
val examples = Table[String|Array[String], String, String|Null, Array[String]](
|
||||||
|
(
|
||||||
|
"source",
|
||||||
|
"command",
|
||||||
|
"target",
|
||||||
|
"args"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"/exit@sukazyo_deving_bot",
|
||||||
|
"/exit",
|
||||||
|
"sukazyo_deving_bot",
|
||||||
|
Array.empty[String]
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"/test@a@b",
|
||||||
|
"/test",
|
||||||
|
"a@b",
|
||||||
|
Array.empty[String]
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"/test-data@random#user",
|
||||||
|
"/test-data",
|
||||||
|
"random#user",
|
||||||
|
Array.empty[String]
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"/info@sukazyo_deving_bot stickers.ID_403",
|
||||||
|
"/info",
|
||||||
|
"sukazyo_deving_bot",
|
||||||
|
Array("stickers.ID_403")
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"/info some extra info",
|
||||||
|
"/info",
|
||||||
|
null,
|
||||||
|
Array("some", "extra", "info")
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
examples forEvery { (source, command, target, args) =>
|
||||||
|
|
||||||
s"command should be $pending_val" in pending
|
val _source_describe = source match
|
||||||
s"target should be $pending_val" in pending
|
case s: String => s
|
||||||
|
case r: Array[String] => r.mkString
|
||||||
"args array should always exists" in pending
|
s"while input is $_source_describe:" - {
|
||||||
|
|
||||||
s"args should parsed to array $pending_val" in pending
|
val _ic: InputCommand = source match
|
||||||
|
case s: String => InputCommand(s)
|
||||||
|
case r: Array[String] => InputCommand(r)
|
||||||
|
|
||||||
|
s"command should be '$command'" in { _ic.command shouldEqual command }
|
||||||
|
s"target should be '$target'" in {_ic.target shouldEqual target}
|
||||||
|
|
||||||
|
"args array should always exists" in { _ic.args shouldNot equal (null) }
|
||||||
|
s"args should parsed to array ${args.mkString}" in { _ic.args shouldEqual args }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user