Frank Kobzik has uploaded a new change for review. Change subject: tools: Validate WebSocketProxy config value ......................................................................
tools: Validate WebSocketProxy config value Change-Id: I84b02d25a15762ba24544bd678328e6532d360ac Bug-Url: https://bugzilla.redhat.com/1184164 Signed-off-by: Frantisek Kobzik <fkob...@redhat.com> --- A backend/manager/tools/src/main/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelper.java A backend/manager/tools/src/test/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelperTest.java M packaging/etc/engine-config/engine-config.properties 3 files changed, 65 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/98/37498/1 diff --git a/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelper.java b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelper.java new file mode 100644 index 0000000..6fa479c --- /dev/null +++ b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelper.java @@ -0,0 +1,29 @@ +package org.ovirt.engine.core.config.entity.helper; + +import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.core.config.entity.ConfigKey; + +public class WebSocketProxyLocationValueHelper extends StringValueHelper { + + @Override + public ValidationResult validate(ConfigKey key, String value) { + if (StringUtils.isBlank(value)) { + return new ValidationResult(false, "The WebSocketProxy can't be empty."); + } + + if ("Off".equals(value) || matchesHostColonPort(value)) { + return new ValidationResult(true); + } else { + return new ValidationResult(false, "Correct values are: Off (proxy is not deployed), " + + "Engine:<port> (Engine is reserved keyword meaning proxy is deployed on the same machine as " + + "the engine (on given port)), Host:<port> (Host is reserved keyword meaning proxy is deployed " + + "on each host on given port (if the deployment has more hosts, proxy must be deployed on each " + + "of them)), <hostname>:<port> (proxy is deployed on a machine identified by given hostname or ip " + + "and port)."); + } + } + + private boolean matchesHostColonPort(String s) { + return (s == null ? false : s.matches("\\S+:\\d+")); //$NON-NLS-1$ + } +} diff --git a/backend/manager/tools/src/test/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelperTest.java b/backend/manager/tools/src/test/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelperTest.java new file mode 100644 index 0000000..0301abe --- /dev/null +++ b/backend/manager/tools/src/test/java/org/ovirt/engine/core/config/entity/helper/WebSocketProxyLocationValueHelperTest.java @@ -0,0 +1,35 @@ +package org.ovirt.engine.core.config.entity.helper; + +import org.junit.Test; +import org.omg.CORBA.WStringValueHelper; + + +import static org.junit.Assert.*; + +public class WebSocketProxyLocationValueHelperTest { + + @Test + public void testValidateNull() throws Exception { + WebSocketProxyLocationValueHelper helper = new WebSocketProxyLocationValueHelper(); + assertFalse(helper.validate(null, null).isOk()); + } + + @Test + public void testValidateEmpty() throws Exception { + WebSocketProxyLocationValueHelper helper = new WebSocketProxyLocationValueHelper(); + assertFalse(helper.validate(null, "").isOk()); + } + + @Test + public void testValidateIncomplete() throws Exception { + WebSocketProxyLocationValueHelper helper = new WebSocketProxyLocationValueHelper(); + assertFalse(helper.validate(null, "myengine:").isOk()); + } + + @Test + public void testValidateHostPort() throws Exception { + WebSocketProxyLocationValueHelper helper = new WebSocketProxyLocationValueHelper(); + assertTrue(helper.validate(null, "myengine.com:6100").isOk()); + } + +} \ No newline at end of file diff --git a/packaging/etc/engine-config/engine-config.properties b/packaging/etc/engine-config/engine-config.properties index a71fbf6..47b30d7 100644 --- a/packaging/etc/engine-config/engine-config.properties +++ b/packaging/etc/engine-config/engine-config.properties @@ -286,7 +286,7 @@ ClientModeRdpDefault.validValues=Auto,Plugin,Native ClientModeRdpDefault.type=String WebSocketProxy.description="Location of Websocket proxy, values are: Off (proxy is not deployed), Engine:<port> (Engine is reserved keyword meaning proxy is deployed on the same machine as the engine (on given port)), Host:<port> (Host is reserved keyword meaning proxy is deployed on each host on given port (if the deployment has more hosts, proxy must be deployed on each of them)), <hostname>:<port> (proxy is deployed on a machine identified by given hostname or ip and port)." -WebSocketProxy.type=String +WebSocketProxy.type=WebSocketProxyLocation WebSocketProxyTicketValiditySeconds.description="Validity (in seconds) of tickets issued for websocket proxy." WebSocketProxyTicketValiditySeconds.type=Integer CustomDeviceProperties.description="Definition of custom properties per each device type" -- To view, visit http://gerrit.ovirt.org/37498 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I84b02d25a15762ba24544bd678328e6532d360ac Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Frank Kobzik <fkob...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches