diff --git a/pom.xml b/pom.xml index 5f62380..9ecb082 100755 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.github.robertdeocampojr jspringbot-selenium-extension - 2.27 + 2.28 jar jspringbot-selenium-extension diff --git a/src/main/java/com/jspringbot/selenium/extension/SSHExtensionHelper.java b/src/main/java/com/jspringbot/selenium/extension/SSHExtensionHelper.java index a7c714b..653db28 100644 --- a/src/main/java/com/jspringbot/selenium/extension/SSHExtensionHelper.java +++ b/src/main/java/com/jspringbot/selenium/extension/SSHExtensionHelper.java @@ -72,9 +72,6 @@ public void setPort(int port) { this.port = port; } - - - public void sshConnectByPem(){ try{ config = new Properties(); @@ -115,7 +112,41 @@ public void sshConnect(){ } } - public void sshDisconnect(){ + public void sshConnectDatabaseByRsa(){ + try{ + jsch = new JSch(); + jsch.addIdentity(idrsaFilename, password); + + // Create a JSch session to connect to the server + Session session = jsch.getSession(username, hostname, port); + session.setPassword(password); + session.setConfig("StrictHostKeyChecking", strictHostKeyChecking); + session.setConfig("PreferredAuthentications", preferredAuthentications); + + + LOG.info("Establishing Connection..."); + session.connect(30000); + LOG.info(String.format("Connected to '%s' ", hostname)); + + session.setPortForwardingL(localPort, databaseHostname, remotePort); + LOG.info(String.format("Success Port Forwarding to '%s' ", databaseHostname)); + }catch(JSchException e){ + LOG.warn(String.format("Cannot connect to '%s' ", hostname)); + LOG.warn(String.format("Error Message '%s' ", e.getMessage())); + } + } + + public void sshChannelDisconnect(){ + try{ + channel.disconnect(); + LOG.info(String.format("Disconnected to Channel", hostname)); + }catch(Exception e){ + LOG.warn(String.format("Cannot disconnect to Channel ", hostname)); + LOG.warn(String.format("Error Message Channel: ", e.getMessage())); + } + } + + public void ssSessionDisconnect(){ try{ channel.disconnect(); session.disconnect(); @@ -128,5 +159,4 @@ public void sshDisconnect(){ - } diff --git a/src/main/java/com/jspringbot/selenium/extension/keyword/AbstractSeleniumExtensionKeyword.java b/src/main/java/com/jspringbot/selenium/extension/keyword/AbstractSeleniumExtensionKeyword.java index abdbf13..54d3add 100755 --- a/src/main/java/com/jspringbot/selenium/extension/keyword/AbstractSeleniumExtensionKeyword.java +++ b/src/main/java/com/jspringbot/selenium/extension/keyword/AbstractSeleniumExtensionKeyword.java @@ -18,6 +18,7 @@ package com.jspringbot.selenium.extension.keyword; +import com.jspringbot.selenium.extension.SSHExtensionHelper; import com.jspringbot.selenium.extension.SeleniumExtensionHelper; import com.jspringbot.selenium.extension.UtilityHelper; import org.jspringbot.Keyword; @@ -30,6 +31,8 @@ public abstract class AbstractSeleniumExtensionKeyword implements Keyword { protected SeleniumExtensionHelper helper; @Autowired protected UtilityHelper utilityHelper; + @Autowired + protected SSHExtensionHelper sshHelper; public AbstractSeleniumExtensionKeyword() { } diff --git a/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnect.java b/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnect.java new file mode 100755 index 0000000..db17ff7 --- /dev/null +++ b/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnect.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012. JSpringBot. All Rights Reserved. + * + * See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The JSpringBot licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.jspringbot.selenium.extension.keyword; + +import org.jspringbot.KeywordInfo; +import org.springframework.stereotype.Component; + +@Component +@KeywordInfo( + name = "SSH Connect", + description = "classpath:desc/sshConnect.txt" +) +public class sshConnect extends AbstractSeleniumExtensionKeyword { + + @Override + public Object execute(Object[] params) { + sshHelper.sshConnect(); + return null; + } +} diff --git a/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnectByPem.java b/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnectByPem.java new file mode 100755 index 0000000..23df97f --- /dev/null +++ b/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnectByPem.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012. JSpringBot. All Rights Reserved. + * + * See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The JSpringBot licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.jspringbot.selenium.extension.keyword; + +import org.jspringbot.KeywordInfo; +import org.springframework.stereotype.Component; + +@Component +@KeywordInfo( + name = "SSH Connect By PEM", + description = "classpath:desc/sshConnectByPem.txt" +) +public class sshConnectByPem extends AbstractSeleniumExtensionKeyword { + + @Override + public Object execute(Object[] params) { + sshHelper.sshConnectByPem(); + return null; + } +} diff --git a/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnectByRsa.java b/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnectByRsa.java new file mode 100755 index 0000000..11f4a3b --- /dev/null +++ b/src/main/java/com/jspringbot/selenium/extension/keyword/sshConnectByRsa.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012. JSpringBot. All Rights Reserved. + * + * See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The JSpringBot licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.jspringbot.selenium.extension.keyword; + +import org.jspringbot.KeywordInfo; +import org.springframework.stereotype.Component; + +@Component +@KeywordInfo( + name = "SSH Connect Database By RSA", + description = "classpath:desc/sshConnectByRsa.txt" +) +public class sshConnectByRsa extends AbstractSeleniumExtensionKeyword { + + @Override + public Object execute(Object[] params) { + sshHelper.sshConnectDatabaseByRsa(); + return null; + } +} diff --git a/src/main/java/com/jspringbot/selenium/extension/keyword/sshDisconnect.java b/src/main/java/com/jspringbot/selenium/extension/keyword/sshDisconnect.java new file mode 100755 index 0000000..4bac5a9 --- /dev/null +++ b/src/main/java/com/jspringbot/selenium/extension/keyword/sshDisconnect.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012. JSpringBot. All Rights Reserved. + * + * See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The JSpringBot licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.jspringbot.selenium.extension.keyword; + +import org.jspringbot.KeywordInfo; +import org.springframework.stereotype.Component; + +@Component +@KeywordInfo( + name = "SSH Session Disconnect", + description = "classpath:desc/sshDisconnect.txt" +) +public class sshDisconnect extends AbstractSeleniumExtensionKeyword { + + @Override + public Object execute(Object[] params) { + sshHelper.ssSessionDisconnect(); + return null; + } +} diff --git a/src/main/resources/spring/spring-extension-db.xml b/src/main/resources/spring/spring-extension-db.xml new file mode 100755 index 0000000..b9ef642 --- /dev/null +++ b/src/main/resources/spring/spring-extension-db.xml @@ -0,0 +1,65 @@ + + + + + + + + + classpath:jspringbot.properties + + + + + + + + + + + + + + + + + + + + + + + hibernate.dialect=${db.hibernate.dialect} + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/spring/spring-selenium-extension-chrome.xml b/src/main/resources/spring/spring-selenium-extension-chrome.xml index ce12b7a..eb412a9 100755 --- a/src/main/resources/spring/spring-selenium-extension-chrome.xml +++ b/src/main/resources/spring/spring-selenium-extension-chrome.xml @@ -83,18 +83,18 @@ - + - - - - - + + + + + diff --git a/src/test/java/com/jspringbot/selenium/extension/SeleniumHelperTest.java b/src/test/java/com/jspringbot/selenium/extension/SeleniumHelperTest.java index 9790357..6902bb2 100755 --- a/src/test/java/com/jspringbot/selenium/extension/SeleniumHelperTest.java +++ b/src/test/java/com/jspringbot/selenium/extension/SeleniumHelperTest.java @@ -50,13 +50,21 @@ public class SeleniumHelperTest { public UtilityHelper util; @Autowired public SeleniumHelper helper; - + @Autowired + public SSHExtensionHelper sshHelper; static int lport; static String rhost; static int rport; @Test + public void testSSHForwarding2() throws InterruptedException { + sshHelper.sshConnectDatabaseByRsa(); + Thread.sleep(60000); + sshHelper.ssSessionDisconnect(); + } + + public void testSSHForwarding(){ String user = "robert"; String password = "Rectawt6"; diff --git a/src/test/resources/jspringbot.properties b/src/test/resources/jspringbot.properties index 99fe4e8..b6bce1d 100755 --- a/src/test/resources/jspringbot.properties +++ b/src/test/resources/jspringbot.properties @@ -19,3 +19,16 @@ selenium.browserstack.os.version=Mavericks selenium.browserstack.debug=true selenium.browserstack.project=TEST.PROJECT selenium.browserstack.build=TEST.BUILD + + +ssh.connect.hostname=pharos.haveninc.com +ssh.connect.username=robert +ssh.connect.password=Rectawt6 +ssh.connect.port=22 +ssh.connect.pem.location=none +ssh.connect.strict.hostKey.checking=no +ssh.connect.remote.hostname=stage.db.hvn.io +ssh.connect.local.port=3309 +ssh.connect.remote.port=3306 +ssh.connect.idrsa.filename=~/.ssh/id_rsa +ssh.connect.pref.auth=publickey,keyboard-interactive,password \ No newline at end of file