Выпуск WDTT Plus v7
This commit is contained in:
1 parent
1b8aee591c
commit
b1418ff3d8
15 files changed
+1251
-252
No files matched your search
@@ -119,6 +119,38 @@ class TransferCodecTest {
|
||||
assertEquals("Работа", vpnProfileTransferName(2, listOf("", "", "Работа")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun vpnProfileNameInput_allowsSpacesBetweenWords() {
|
||||
assertEquals("Домашний ", sanitizeVpnProfileNameInput("Домашний "))
|
||||
assertEquals("Домашний сервер", sanitizeVpnProfileNameInput(" Домашний сервер"))
|
||||
assertEquals("Домашний сервер", normalizeVpnProfileName(" Домашний сервер "))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun adminProfilePatch_omitsEmptyAndDefaultTunnelFields() {
|
||||
val defaults = ServerAdminProfileInfo()
|
||||
assertEquals(listOf("update-admin-profile"), buildAdminProfilePatchArgs(defaults))
|
||||
assertFalse(hasMeaningfulAdminProfileFields(defaults))
|
||||
|
||||
val custom = defaults.copy(
|
||||
vkHashes = "hash-value",
|
||||
profileName = "Домашний сервер",
|
||||
workersPerHash = 24,
|
||||
noDns = true
|
||||
)
|
||||
assertEquals(
|
||||
listOf(
|
||||
"update-admin-profile",
|
||||
"--vk-hashes", "hash-value",
|
||||
"--profile-name", "Домашний сервер",
|
||||
"--workers", "24",
|
||||
"--no-dns"
|
||||
),
|
||||
buildAdminProfilePatchArgs(custom)
|
||||
)
|
||||
assertTrue(hasMeaningfulAdminProfileFields(custom))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun serverClientLink_carriesSourceVpnProfileName() {
|
||||
val link = buildServerConnectionLink(
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.wdtt.plus.ui
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ServerClientsAccessTest {
|
||||
@Test
|
||||
fun accessRequiresDeployHostSshAndAdminPassword() {
|
||||
assertEquals(
|
||||
"Укажите IP-адрес или домен сервера в верхнем блоке «Деплой».",
|
||||
serverClientsAccessIssue("", false, "", 22, "")
|
||||
)
|
||||
assertEquals(
|
||||
"Проверьте IP-адрес или домен сервера в верхнем блоке «Деплой».",
|
||||
serverClientsAccessIssue("https://bad host", false, "ssh", 22, "owner")
|
||||
)
|
||||
assertEquals(
|
||||
"Укажите SSH-пароль сервера в верхнем блоке «Деплой».",
|
||||
serverClientsAccessIssue("vpn.example.org", true, "", 22, "owner")
|
||||
)
|
||||
assertEquals(
|
||||
"Укажите корректный SSH-порт от 1 до 65535.",
|
||||
serverClientsAccessIssue("vpn.example.org", true, "ssh", 0, "owner")
|
||||
)
|
||||
assertEquals(
|
||||
"Откройте «Секреты» и укажите главный пароль администратора.",
|
||||
serverClientsAccessIssue("vpn.example.org", true, "ssh", 22, "")
|
||||
)
|
||||
assertNull(serverClientsAccessIssue("vpn.example.org", true, "ssh", 22, "owner"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clientAutoRefreshRunsOnlyOnceForReadyTarget() {
|
||||
assertTrue(shouldAutoRefreshServerClients(true, true, true, false, false, 0L))
|
||||
assertFalse(shouldAutoRefreshServerClients(false, true, true, false, false, 0L))
|
||||
assertFalse(shouldAutoRefreshServerClients(true, false, true, false, false, 0L))
|
||||
assertFalse(shouldAutoRefreshServerClients(true, true, true, true, false, 0L))
|
||||
assertFalse(shouldAutoRefreshServerClients(true, true, true, false, true, 0L))
|
||||
assertFalse(shouldAutoRefreshServerClients(true, true, true, false, false, 1L))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun outboundAutoRefreshRunsOncePerSshTarget() {
|
||||
assertTrue(shouldAutoRefreshOutboundState(true, false, false, true, true, "new", ""))
|
||||
assertFalse(shouldAutoRefreshOutboundState(true, false, false, true, true, "same", "same"))
|
||||
assertFalse(shouldAutoRefreshOutboundState(false, false, false, true, true, "new", ""))
|
||||
assertFalse(shouldAutoRefreshOutboundState(true, true, false, true, true, "new", ""))
|
||||
assertFalse(shouldAutoRefreshOutboundState(true, false, true, true, true, "new", ""))
|
||||
assertFalse(shouldAutoRefreshOutboundState(true, false, false, false, true, "new", ""))
|
||||
assertFalse(shouldAutoRefreshOutboundState(true, false, false, true, false, "new", ""))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.wdtt.plus.ui
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ServerMigrationTest {
|
||||
@Test
|
||||
fun backupValidation_acceptsCurrentOwnerAndClientFields() {
|
||||
validatePasswordsDbStructure(database("client-a", "Телефон"))
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun backupValidation_rejectsInvalidOwnerProfile() {
|
||||
val db = database("client-a", "Телефон")
|
||||
db.getJSONObject("admin_profile").put("workers_per_hash", 500)
|
||||
|
||||
validatePasswordsDbStructure(db)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun replaceImport_preservesClientDataAndHistory() {
|
||||
val source = database("client-a", "Телефон")
|
||||
val after = JSONObject(source.toString())
|
||||
after.getJSONObject("passwords").getJSONObject("client-a").put("ports", "56010,56011,9010")
|
||||
|
||||
validateImportedServerState(source.toString(), null, after.toString(), replace = true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mergeImport_preservesTargetAndAddsMissingClient() {
|
||||
val before = database("target-client", "Существующий")
|
||||
val source = database("source-client", "Перенесённый")
|
||||
val after = JSONObject(before.toString())
|
||||
after.getJSONObject("passwords").put(
|
||||
"source-client",
|
||||
JSONObject(source.getJSONObject("passwords").getJSONObject("source-client").toString())
|
||||
)
|
||||
|
||||
validateImportedServerState(source.toString(), before.toString(), after.toString(), replace = false)
|
||||
assertTrue(after.getJSONObject("passwords").has("target-client"))
|
||||
assertTrue(after.getJSONObject("passwords").has("source-client"))
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun importValidation_detectsMissingTransferredClient() {
|
||||
val source = database("client-a", "Телефон")
|
||||
val after = database("another-client", "Другой")
|
||||
|
||||
validateImportedServerState(source.toString(), null, after.toString(), replace = true)
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun mergeRejectsDeviceIdWithDifferentKeys() {
|
||||
val source = database("source-client", "Перенесённый")
|
||||
val target = database("target-client", "Существующий")
|
||||
bindDevice(source, "source-client", "same-device", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
|
||||
bindDevice(target, "target-client", "same-device", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=")
|
||||
|
||||
mergeServerDatabaseEntries(source, target, "56000,56001,9000")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mergeCopiesOnlyDeviceOfAddedClient() {
|
||||
val source = database("source-client", "Перенесённый")
|
||||
val target = database("target-client", "Существующий")
|
||||
bindDevice(source, "source-client", "used-device", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
|
||||
bindDevice(target, "target-client", "target-device", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=")
|
||||
source.getJSONObject("devices").put(
|
||||
"orphan-device",
|
||||
device("orphan-device", "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC=")
|
||||
)
|
||||
|
||||
mergeServerDatabaseEntries(source, target, "56000,56001,9000")
|
||||
|
||||
assertTrue(target.getJSONObject("devices").has("used-device"))
|
||||
assertTrue(!target.getJSONObject("devices").has("orphan-device"))
|
||||
assertTrue(target.getJSONObject("devices").getJSONObject("used-device").getString("ip") == "10.66.66.3")
|
||||
}
|
||||
|
||||
private fun database(password: String, label: String): JSONObject {
|
||||
val entry = JSONObject()
|
||||
.put("device_id", "")
|
||||
.put("expires_at", 0L)
|
||||
.put("down_bytes", 1024L)
|
||||
.put("up_bytes", 2048L)
|
||||
.put("label", label)
|
||||
.put("vk_hash", "1234567890abcdef")
|
||||
.put("ports", "56000,56001,9000")
|
||||
.put("traffic", JSONArray().put(
|
||||
JSONObject()
|
||||
.put("date", "2026-07-05")
|
||||
.put("down_bytes", 1024L)
|
||||
.put("up_bytes", 2048L)
|
||||
))
|
||||
.put("bind_history", JSONArray())
|
||||
return JSONObject()
|
||||
.put("main_password", "owner-password")
|
||||
.put("admin_id", "123456")
|
||||
.put("bot_token", "123456:token")
|
||||
.put("dns", "1.1.1.1,1.0.0.1")
|
||||
.put("public_ip", "vpn.example.org")
|
||||
.put("default_ports", "56000,56001,9000")
|
||||
.put("max_passwords", 50)
|
||||
.put("passwords", JSONObject().put(password, entry))
|
||||
.put("devices", JSONObject())
|
||||
.put("admin_profile", JSONObject()
|
||||
.put("workers_per_hash", 16)
|
||||
.put("protocol", "udp")
|
||||
.put("listen_port", 9000)
|
||||
.put("ports", "56000,56001,9000")
|
||||
)
|
||||
}
|
||||
|
||||
private fun bindDevice(db: JSONObject, password: String, deviceId: String, privateKey: String) {
|
||||
db.getJSONObject("passwords").getJSONObject(password).put("device_id", deviceId)
|
||||
db.getJSONObject("devices").put(deviceId, device(deviceId, privateKey))
|
||||
}
|
||||
|
||||
private fun device(deviceId: String, privateKey: String): JSONObject = JSONObject()
|
||||
.put("device_id", deviceId)
|
||||
.put("ip", "10.66.66.2")
|
||||
.put("priv_key", privateKey)
|
||||
.put("pub_key", "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD=")
|
||||
}
|
||||
Reference in new issue
Block a user