From b4edd33c7dfd64c4a95c0b6a2e85acfbaac35532 Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Wed, 3 Sep 2025 09:42:08 -0500 Subject: [PATCH 1/2] Extracted client command line parsing to tested class Signed-off-by: Mitch Gaffigan --- .../connect/client/ui/CommandLineOptions.java | 103 ++++++++++++++++++ .../com/mirth/connect/client/ui/Mirth.java | 67 ++---------- .../client/ui/CommandLineOptionsTest.java | 62 +++++++++++ 3 files changed, 175 insertions(+), 57 deletions(-) create mode 100644 client/src/com/mirth/connect/client/ui/CommandLineOptions.java create mode 100644 client/test/com/mirth/connect/client/ui/CommandLineOptionsTest.java diff --git a/client/src/com/mirth/connect/client/ui/CommandLineOptions.java b/client/src/com/mirth/connect/client/ui/CommandLineOptions.java new file mode 100644 index 0000000000..0fdabc3da8 --- /dev/null +++ b/client/src/com/mirth/connect/client/ui/CommandLineOptions.java @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: Mirth Corporation + +package com.mirth.connect.client.ui; + +import org.apache.commons.lang3.StringUtils; + +/** + * Immutable holder for command line options used by the Mirth client. + */ +public class CommandLineOptions { + private final String server; + private final String version; + private final String username; + private final String password; + private final String protocols; + private final String cipherSuites; + + /** + * Parse command line arguments for Mirth client. + */ + public CommandLineOptions(String[] args) { + String server = "https://localhost:8443"; + String version = ""; + String username = ""; + String password = ""; + String protocols = ""; + String cipherSuites = ""; + + if (args == null) { + args = new String[0]; + } + + if (args.length > 0) { + server = args[0]; + } + if (args.length > 1) { + version = args[1]; + } + if (args.length > 2) { + if (StringUtils.equalsIgnoreCase(args[2], "-ssl")) { + // -ssl [ [ [ []]]] + if (args.length > 3) { + protocols = args[3]; + } + if (args.length > 4) { + cipherSuites = args[4]; + } + if (args.length > 5) { + username = args[5]; + } + if (args.length > 6) { + password = args[6]; + } + } else { + // [ [-ssl [ []]]] + username = args[2]; + if (args.length > 3) { + password = args[3]; + } + if (args.length > 4 && StringUtils.equalsIgnoreCase(args[4], "-ssl")) { + if (args.length > 5) { + protocols = args[5]; + } + if (args.length > 6) { + cipherSuites = args[6]; + } + } + } + } + + this.server = server; + this.version = version; + this.username = username; + this.password = password; + this.protocols = protocols; + this.cipherSuites = cipherSuites; + } + + public String getServer() { + return server; + } + + public String getVersion() { + return version; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getProtocols() { + return protocols; + } + + public String getCipherSuites() { + return cipherSuites; + } +} diff --git a/client/src/com/mirth/connect/client/ui/Mirth.java b/client/src/com/mirth/connect/client/ui/Mirth.java index 4655e72af3..eacb683313 100644 --- a/client/src/com/mirth/connect/client/ui/Mirth.java +++ b/client/src/com/mirth/connect/client/ui/Mirth.java @@ -1,11 +1,5 @@ -/* - * Copyright (c) Mirth Corporation. All rights reserved. - * - * http://www.mirthcorp.com - * - * The software in this package is published under the terms of the MPL license a copy of which has - * been included with this distribution in the LICENSE.txt file. - */ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: Mirth Corporation package com.mirth.connect.client.ui; @@ -259,59 +253,18 @@ public static void initUIManager() { * String[] */ public static void main(String[] args) { - String server = "https://localhost:8443"; - String version = ""; - String username = ""; - String password = ""; - String protocols = ""; - String cipherSuites = ""; - - if (args.length > 0) { - server = args[0]; - } - if (args.length > 1) { - version = args[1]; - } - if (args.length > 2) { - if (StringUtils.equalsIgnoreCase(args[2], "-ssl")) { - // -ssl [ [ [ []]]] - if (args.length > 3) { - protocols = args[3]; - } - if (args.length > 4) { - cipherSuites = args[4]; - } - if (args.length > 5) { - username = args[5]; - } - if (args.length > 6) { - password = args[6]; - } - } else { - // [ [-ssl [ []]]] - username = args[2]; - if (args.length > 3) { - password = args[3]; - } - if (args.length > 4 && StringUtils.equalsIgnoreCase(args[4], "-ssl")) { - if (args.length > 5) { - protocols = args[5]; - } - if (args.length > 6) { - cipherSuites = args[6]; - } - } - } - } + CommandLineOptions opts = new CommandLineOptions(args); - if (StringUtils.isNotBlank(protocols)) { - PlatformUI.HTTPS_PROTOCOLS = StringUtils.split(protocols, ','); + if (StringUtils.isNotBlank(opts.getProtocols())) { + PlatformUI.HTTPS_PROTOCOLS = StringUtils.split(opts.getProtocols(), ','); } - if (StringUtils.isNotBlank(cipherSuites)) { - PlatformUI.HTTPS_CIPHER_SUITES = StringUtils.split(cipherSuites, ','); + if (StringUtils.isNotBlank(opts.getCipherSuites())) { + PlatformUI.HTTPS_CIPHER_SUITES = StringUtils.split(opts.getCipherSuites(), ','); } + PlatformUI.SERVER_URL = opts.getServer(); + PlatformUI.CLIENT_VERSION = opts.getVersion(); - start(server, version, username, password); + start(opts.getServer(), opts.getVersion(), opts.getUsername(), opts.getPassword()); } private static void start(final String server, final String version, final String username, final String password) { diff --git a/client/test/com/mirth/connect/client/ui/CommandLineOptionsTest.java b/client/test/com/mirth/connect/client/ui/CommandLineOptionsTest.java new file mode 100644 index 0000000000..3c0080ddd7 --- /dev/null +++ b/client/test/com/mirth/connect/client/ui/CommandLineOptionsTest.java @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: 2025 Mitch Gaffigan + +package com.mirth.connect.client.ui; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class CommandLineOptionsTest { + + @Test + public void testParseSslForm() { + String[] args = new String[] { "https://example:8443", "1.0", "-ssl", "TLSv1.2,TLSv1.3", "TLS_RSA_WITH_AES_128_GCM_SHA256", "alice", "secret" }; + CommandLineOptions opts = new CommandLineOptions(args); + + assertEquals("https://example:8443", opts.getServer()); + assertEquals("1.0", opts.getVersion()); + assertEquals("alice", opts.getUsername()); + assertEquals("secret", opts.getPassword()); + assertEquals("TLSv1.2,TLSv1.3", opts.getProtocols()); + assertEquals("TLS_RSA_WITH_AES_128_GCM_SHA256", opts.getCipherSuites()); + } + + @Test + public void testParseUsernameFormWithSsl() { + String[] args = new String[] { "https://example:8443", "1.0", "bob", "pw", "-ssl", "TLSv1.2", "CIPHER" }; + CommandLineOptions opts = new CommandLineOptions(args); + + assertEquals("https://example:8443", opts.getServer()); + assertEquals("1.0", opts.getVersion()); + assertEquals("bob", opts.getUsername()); + assertEquals("pw", opts.getPassword()); + assertEquals("TLSv1.2", opts.getProtocols()); + assertEquals("CIPHER", opts.getCipherSuites()); + } + + @Test + public void testNullArgsUsesDefaults() { + CommandLineOptions opts = new CommandLineOptions((String[]) null); + + assertEquals("https://localhost:8443", opts.getServer()); + assertEquals("", opts.getVersion()); + assertEquals("", opts.getUsername()); + assertEquals("", opts.getPassword()); + assertEquals("", opts.getProtocols()); + assertEquals("", opts.getCipherSuites()); + } + + @Test + public void testNormal() { + String[] args = new String[] { "https://example:8443", "1.0" }; + CommandLineOptions opts = new CommandLineOptions(args); + + assertEquals("https://example:8443", opts.getServer()); + assertEquals("1.0", opts.getVersion()); + assertEquals("", opts.getUsername()); + assertEquals("", opts.getPassword()); + assertEquals("", opts.getProtocols()); + assertEquals("", opts.getCipherSuites()); + } +} From d2682523c9868838fac7fb68faaa2a630669ad7d Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Wed, 3 Sep 2025 09:43:36 -0500 Subject: [PATCH 2/2] Simplified checks for login status isSuccess LoginPanel.java copyright change is based on 3954bc56c55c99bbaf56bc7fa2f81b18fac35a6b Signed-off-by: Mitch Gaffigan --- .../com/mirth/connect/client/ui/LoginPanel.java | 15 +++++---------- .../src/com/mirth/connect/model/LoginStatus.java | 14 ++++++-------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/client/src/com/mirth/connect/client/ui/LoginPanel.java b/client/src/com/mirth/connect/client/ui/LoginPanel.java index 5a78f8614a..0414b7accd 100644 --- a/client/src/com/mirth/connect/client/ui/LoginPanel.java +++ b/client/src/com/mirth/connect/client/ui/LoginPanel.java @@ -1,11 +1,6 @@ -/* - * Copyright (c) Mirth Corporation. All rights reserved. - * - * http://www.mirthcorp.com - * - * The software in this package is published under the terms of the MPL license a copy of which has - * been included with this distribution in the LICENSE.txt file. - */ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: Mirth Corporation +// SPDX-FileCopyrightText: 2025 Mitch Gaffigan and Tony Germano package com.mirth.connect.client.ui; @@ -451,7 +446,7 @@ public Void doInBackground() { } // If SUCCESS or SUCCESS_GRACE_PERIOD - if ((loginStatus != null) && ((loginStatus.getStatus() == LoginStatus.Status.SUCCESS) || (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD))) { + if (loginStatus != null && loginStatus.isSuccess()) { if (!handleSuccess(loginStatus)) { LoginPanel.getInstance().setVisible(false); LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); @@ -469,7 +464,7 @@ public Void doInBackground() { loginStatus = plugin.authenticate(LoginPanel.this, client, updatedUsername, loginStatus); - if ((loginStatus != null) && ((loginStatus.getStatus() == LoginStatus.Status.SUCCESS) || (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD))) { + if (loginStatus != null && loginStatus.isSuccess()) { errorOccurred = false; if (!handleSuccess(loginStatus)) { LoginPanel.getInstance().setVisible(false); diff --git a/server/src/com/mirth/connect/model/LoginStatus.java b/server/src/com/mirth/connect/model/LoginStatus.java index 5af8333a4f..1b8c89829b 100644 --- a/server/src/com/mirth/connect/model/LoginStatus.java +++ b/server/src/com/mirth/connect/model/LoginStatus.java @@ -1,11 +1,5 @@ -/* - * Copyright (c) Mirth Corporation. All rights reserved. - * - * http://www.mirthcorp.com - * - * The software in this package is published under the terms of the MPL license a copy of which has - * been included with this distribution in the LICENSE.txt file. - */ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: Mirth Corporation package com.mirth.connect.model; @@ -43,4 +37,8 @@ public String getMessage() { public String getUpdatedUsername() { return updatedUsername; } + + public boolean isSuccess() { + return status == Status.SUCCESS || status == Status.SUCCESS_GRACE_PERIOD; + } }