From 15c5b2f28509cd556fdf361c530368fbe6688cd8 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 24 Aug 2017 16:45:27 +0200 Subject: Reject blank network name --- .../main/java/org/pacien/tincapp/commands/Tinc.kt | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/org') diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index 0bb1da4..6acd4f2 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt @@ -27,15 +27,21 @@ object Tinc { .thenApply { it.joinToString("\n") } fun init(netName: String, nodeName: String): CompletableFuture = - Executor.call(Command(AppPaths.tinc().absolutePath) - .withOption("config", AppPaths.confDir(netName).absolutePath) - .withArguments("init", nodeName)) - .thenApply { it.joinToString("\n") } + if (netName.isBlank()) + CompletableFuture.failedFuture(IllegalArgumentException("Network name cannot be blank.")) + else + Executor.call(Command(AppPaths.tinc().absolutePath) + .withOption("config", AppPaths.confDir(netName).absolutePath) + .withArguments("init", nodeName)) + .thenApply { it.joinToString("\n") } fun join(netName: String, invitationUrl: String): CompletableFuture = - Executor.call(Command(AppPaths.tinc().absolutePath) - .withOption("config", AppPaths.confDir(netName).absolutePath) - .withArguments("join", invitationUrl)) - .thenApply { it.joinToString("\n") } + if (netName.isBlank()) + CompletableFuture.failedFuture(IllegalArgumentException("Network name cannot be blank.")) + else + Executor.call(Command(AppPaths.tinc().absolutePath) + .withOption("config", AppPaths.confDir(netName).absolutePath) + .withArguments("join", invitationUrl)) + .thenApply { it.joinToString("\n") } } -- cgit v1.2.3