mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 10:22:58 +08:00
Init Commit
This commit is contained in:
25
src/test/kotlin/app/termora/AESTest.kt
Normal file
25
src/test/kotlin/app/termora/AESTest.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package app.termora
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
|
||||
|
||||
class AESTest {
|
||||
@Test
|
||||
fun test() {
|
||||
val data = "hello world. 中国 😄".toByteArray()
|
||||
val key = AES.randomBytes()
|
||||
val iv = AES.randomBytes(16)
|
||||
assertContentEquals(AES.CBC.decrypt(key, iv, AES.CBC.encrypt(key, iv, data)), data)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testECB() {
|
||||
val data = "hello world. 中国 😄".toByteArray()
|
||||
val key = AES.randomBytes()
|
||||
assertContentEquals(AES.ECB.decrypt(key, AES.ECB.encrypt(key, data)), data)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
50
src/test/kotlin/app/termora/BreakIteratorTest.kt
Normal file
50
src/test/kotlin/app/termora/BreakIteratorTest.kt
Normal file
@@ -0,0 +1,50 @@
|
||||
package app.termora
|
||||
|
||||
import java.text.BreakIterator
|
||||
import kotlin.test.Test
|
||||
|
||||
class BreakIteratorTest {
|
||||
@Test
|
||||
fun test() {
|
||||
val text = "Hello World"
|
||||
val breakIterator = BreakIterator.getCharacterInstance()
|
||||
breakIterator.setText(text)
|
||||
var start = breakIterator.first()
|
||||
var end = breakIterator.next()
|
||||
while (end != BreakIterator.DONE) {
|
||||
println(text.substring(start, end))
|
||||
start = end
|
||||
end = breakIterator.next()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testChinese() {
|
||||
val text = "你好中国 hello 123 @!。"
|
||||
val breakIterator = BreakIterator.getCharacterInstance()
|
||||
breakIterator.setText(text)
|
||||
var start = breakIterator.first()
|
||||
var end = breakIterator.next()
|
||||
while (end != BreakIterator.DONE) {
|
||||
println(text.substring(start, end))
|
||||
start = end
|
||||
end = breakIterator.next()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmoji() {
|
||||
val text = "⌚️哈哈😂123🀄️"
|
||||
val breakIterator = BreakIterator.getCharacterInstance()
|
||||
breakIterator.setText(text)
|
||||
var start = breakIterator.first()
|
||||
var end = breakIterator.next()
|
||||
while (end != BreakIterator.DONE) {
|
||||
println(text.substring(start, end))
|
||||
start = end
|
||||
end = breakIterator.next()
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/test/kotlin/app/termora/HostTest.kt
Normal file
22
src/test/kotlin/app/termora/HostTest.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package app.termora
|
||||
|
||||
import app.termora.Application.ohMyJson
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlin.test.Test
|
||||
|
||||
class HostTest {
|
||||
@Test
|
||||
fun test() {
|
||||
val host = ohMyJson.decodeFromString<Host>(
|
||||
"""
|
||||
{
|
||||
"name": "test",
|
||||
"protocol": "SSH",
|
||||
"test": ""
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
println(ohMyJson.encodeToString(host))
|
||||
}
|
||||
}
|
||||
26
src/test/kotlin/app/termora/I18nTest.kt
Normal file
26
src/test/kotlin/app/termora/I18nTest.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package app.termora
|
||||
|
||||
import org.apache.commons.lang3.LocaleUtils
|
||||
import java.io.BufferedOutputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class I18nTest {
|
||||
|
||||
|
||||
@Test
|
||||
fun test_zh_CN() {
|
||||
val bundle = ResourceBundle.getBundle("i18n/messages", LocaleUtils.toLocale("zh_CN"))
|
||||
assertEquals(bundle.getString("termora.confirm"), "确认")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun test_zh_TW() {
|
||||
val bundle = ResourceBundle.getBundle("i18n/messages", LocaleUtils.toLocale("zh_TW"))
|
||||
assertEquals(bundle.getString("termora.confirm"), "確定")
|
||||
}
|
||||
}
|
||||
13
src/test/kotlin/app/termora/KeyUtilsTest.kt
Normal file
13
src/test/kotlin/app/termora/KeyUtilsTest.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package app.termora
|
||||
|
||||
import org.apache.sshd.common.config.keys.KeyUtils
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class KeyUtilsTest {
|
||||
@Test
|
||||
fun test() {
|
||||
assertEquals(KeyUtils.getKeySize(KeyUtils.generateKeyPair("ssh-rsa", 1024).private), 1024)
|
||||
assertEquals(KeyUtils.getKeySize(KeyUtils.generateKeyPair("ssh-rsa", 1024).public), 1024)
|
||||
}
|
||||
}
|
||||
15
src/test/kotlin/app/termora/LocaleTest.kt
Normal file
15
src/test/kotlin/app/termora/LocaleTest.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package app.termora
|
||||
|
||||
import org.apache.commons.lang3.LocaleUtils
|
||||
import java.util.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class LocaleTest {
|
||||
@Test
|
||||
fun test() {
|
||||
assertEquals(Locale.of("zh_CN").toString(), "zh_cn")
|
||||
assertEquals(Locale.of("zh", "CN").toString(), "zh_CN")
|
||||
assertEquals(LocaleUtils.toLocale("zh_CN").toString(), "zh_CN")
|
||||
}
|
||||
}
|
||||
17
src/test/kotlin/app/termora/PBKDF2Test.kt
Normal file
17
src/test/kotlin/app/termora/PBKDF2Test.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package app.termora
|
||||
|
||||
import org.apache.commons.codec.binary.Hex
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class PBKDF2Test {
|
||||
@Test
|
||||
fun test() {
|
||||
val password = "password"
|
||||
assertEquals(
|
||||
"72629a41b076e588fba8c71ca37fadc9acdc8e7321b9cb4ea55fd0bf9fe8ed72", Hex.encodeHexString(
|
||||
PBKDF2.generateSecret(password.toCharArray(), "salt".toByteArray(), 10000, 256)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
23
src/test/kotlin/app/termora/RSA2048Test.kt
Normal file
23
src/test/kotlin/app/termora/RSA2048Test.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package app.termora
|
||||
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
|
||||
|
||||
class RSA2048Test {
|
||||
@Test
|
||||
fun test() {
|
||||
val data = "hello world. 中国 😄".toByteArray()
|
||||
|
||||
val pair = RSA.generateKeyPair()
|
||||
|
||||
println("publicKey: ${Base64.encodeBase64String(pair.public.encoded)}")
|
||||
println("privateKey: ${Base64.encodeBase64String(pair.private.encoded)}")
|
||||
|
||||
assertContentEquals(RSA.decrypt(pair.private, RSA.encrypt(pair.public, data)), data)
|
||||
assertContentEquals(RSA.decrypt(pair.public, RSA.encrypt(pair.private, data)), data)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
32
src/test/kotlin/app/termora/terminal/FindModelImplTest.kt
Normal file
32
src/test/kotlin/app/termora/terminal/FindModelImplTest.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package app.termora.terminal
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class FindModelImplTest {
|
||||
@Test
|
||||
fun test() {
|
||||
val terminal = VisualTerminal()
|
||||
terminal.write("hello world")
|
||||
assertEquals(terminal.getFindModel().find("o").size, 2)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testMultiline() {
|
||||
val terminal = VisualTerminal()
|
||||
terminal.write("hello world hello world hello world hello world hello world hello world world 123456789")
|
||||
val kind = terminal.getFindModel().find("123456789").first()
|
||||
assertEquals(kind.startPosition, Position(1, 79))
|
||||
assertEquals(kind.endPosition, Position(2, 7))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testChinese() {
|
||||
val terminal = VisualTerminal()
|
||||
terminal.write("aaaaa.txt")
|
||||
val kind = terminal.getFindModel().find("aa.txt").first()
|
||||
assertEquals(kind.startPosition, Position(1, 4))
|
||||
assertEquals(kind.endPosition, Position(1, 9))
|
||||
}
|
||||
}
|
||||
27
src/test/kotlin/app/termora/terminal/TextStyleTest.kt
Normal file
27
src/test/kotlin/app/termora/terminal/TextStyleTest.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package app.termora.terminal
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class TextStyleTest {
|
||||
@Test
|
||||
fun test() {
|
||||
var textStyle = TextStyle()
|
||||
assertFalse(textStyle.bold)
|
||||
assertTrue(textStyle.bold(true).bold)
|
||||
|
||||
|
||||
textStyle = textStyle.foreground(255 * 255 * 2)
|
||||
textStyle = textStyle.background(255 * 2)
|
||||
|
||||
assertEquals(textStyle.foreground, 255 * 255 * 2)
|
||||
assertEquals(textStyle.background, 255 * 2)
|
||||
assertFalse(textStyle.italic)
|
||||
|
||||
textStyle = textStyle.italic(true)
|
||||
assertTrue(textStyle.italic)
|
||||
|
||||
}
|
||||
}
|
||||
6
src/test/resources/sshd/Dockerfile
Normal file
6
src/test/resources/sshd/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM linuxserver/openssh-server
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
|
||||
&& apk update && apk add wget gcc g++ git make zsh htop && wget https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz \
|
||||
&& tar -xf lrzsz-0.12.20.tar.gz && cd lrzsz-0.12.20 && ./configure && make && make install \
|
||||
&& ln -s /usr/local/bin/lrz /usr/local/bin/rz && ln -s /usr/local/bin/lsz /usr/local/bin/sz
|
||||
|
||||
Reference in New Issue
Block a user