Add unit tests for the userInfo parser and the getConfiguration method.
@@ -22,8 +22,11 @@ package org.apache.guacamole.auth.quickconnect.utility;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
/**
* Class to test methods in the QCParser utility class.
@@ -46,4 +49,63 @@ public class QCParserTest {
}
+ /**
+ * Verify that the parseUserInfo() method functions as designed.
+ */
+ @Test
+ public void testParseUserInfo() throws UnsupportedEncodingException {
+
+ Map<String, String> userInfoMap;
+
+ userInfoMap = QCParser.parseUserInfo("guacuser:secretpw");
+ assertEquals("guacuser", userInfoMap.get("username"));
+ assertEquals("secretpw", userInfoMap.get("password"));
+
+
+ userInfoMap = QCParser.parseUserInfo("guacuser");
+ assertEquals("guacuser", userInfoMap.get("username"));
+ assertFalse(userInfoMap.containsKey("password"));
+
+ userInfoMap = QCParser.parseUserInfo("guacuser:P%40ssw0rd%21");
+ assertEquals("guacuser", userInfoMap.get("username"));
+ assertEquals("P@ssw0rd!", userInfoMap.get("password"));
+
+ userInfoMap = QCParser.parseUserInfo("domain%5cguacuser:domain%2fpassword");
+ assertEquals("domain\\guacuser", userInfoMap.get("username"));
+ assertEquals("domain/password", userInfoMap.get("password"));
+
+ }
+
+ /**
+ * Verify that the getConfiguration() method returns the expected
+ * GuacamoleConfiguration object.
+ */
+ @Test
+ public void testGetConfiguration() throws GuacamoleException {
+
+ String uri1 = "ssh://guacuser:guacpassword@hostname1.domain.local/?param1=value1&param2=value2";
+ GuacamoleConfiguration config1 = QCParser.getConfiguration(uri1);
+ assertEquals("ssh", config1.getProtocol());
+ assertEquals("hostname1.domain.local", config1.getParameter("hostname"));
+ assertEquals("guacuser", config1.getParameter("username"));
+ assertEquals("guacpassword", config1.getParameter("password"));
+ assertEquals("value1", config1.getParameter("param1"));
+ assertEquals("value2", config1.getParameter("param2"));
+
+ String uri2 = "rdp://domain%5cguacuser:adPassword123@windows1.domain.tld/?enable-sftp=true";
+ GuacamoleConfiguration config2 = QCParser.getConfiguration(uri2);
+ assertEquals("rdp", config2.getProtocol());
+ assertEquals("windows1.domain.tld", config2.getParameter("hostname"));
+ assertEquals("domain\\guacuser", config2.getParameter("username"));
+ assertEquals("adPassword123", config2.getParameter("password"));
+ assertEquals("true", config2.getParameter("enable-sftp"));
+
+ String uri3 = "vnc://mirror1.example.com:5910/";
+ GuacamoleConfiguration config3 = QCParser.getConfiguration(uri3);
+ assertEquals("vnc", config3.getProtocol());
+ assertEquals("mirror1.example.com", config3.getParameter("hostname"));
+ assertEquals("5910", config3.getParameter("port"));
+
+ }
+
}
