Skip to content

Commit

Permalink
update for 2.28
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdeocampojr committed Aug 16, 2019
1 parent 475e479 commit 373a99a
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.github.robertdeocampojr</groupId>
<artifactId>jspringbot-selenium-extension</artifactId>
<version>2.27</version>
<version>2.28</version>
<packaging>jar</packaging>

<name>jspringbot-selenium-extension</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public void setPort(int port) {
this.port = port;
}




public void sshConnectByPem(){
try{
config = new Properties();
Expand Down Expand Up @@ -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();
Expand All @@ -128,5 +159,4 @@ public void sshDisconnect(){




}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,8 @@ public abstract class AbstractSeleniumExtensionKeyword implements Keyword {
protected SeleniumExtensionHelper helper;
@Autowired
protected UtilityHelper utilityHelper;
@Autowired
protected SSHExtensionHelper sshHelper;

public AbstractSeleniumExtensionKeyword() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
65 changes: 65 additions & 0 deletions src/main/resources/spring/spring-extension-db.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:jspringbot.properties</value>
</list>
</property>
</bean>

<!--bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.jdbc.driverClassName}"/>
<property name="url" value="${db.jdbc.url}"/>
<property name="username" value="${db.jdbc.username}"/>
<property name="password" value="${db.jdbc.password}"/>
<property name="maxActive" value="5"/>
<property name="maxWait" value="1000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
</bean-->

<bean id="basicDataSourceManager" class="org.jspringbot.keyword.db.BasicDataSourceManagerImpl">
<property name="maxActive" value="5"/>
<property name="maxWait" value="1000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
<property name="propertiesResource" value="classpath:jspringbot.properties"/>
</bean>

<bean id="dataSource" class="org.jspringbot.keyword.db.MultipleDataSourceFactory">
<property name="manager" ref="basicDataSourceManager"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<value>
hibernate.dialect=${db.hibernate.dialect}
</value>
</property>
</bean>

<bean name="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean name="dbHelper" class="org.jspringbot.keyword.db.DbHelper">
<constructor-arg ref="sessionFactory"/>
<constructor-arg ref="basicDataSourceManager"/>
<property name="useSchemaSyntax" value="${db.switch.schema.statement:use %s}"/>
</bean>

<!-- Scan components -->
<ctx:component-scan base-package="org.jspringbot.keyword.db"/>
<ctx:annotation-config/>
</beans>
12 changes: 6 additions & 6 deletions src/main/resources/spring/spring-selenium-extension-chrome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@

<bean id="utilityHelper" class="com.jspringbot.selenium.extension.UtilityHelper" />

<bean class="com.jspringbot.selenium.extension.SSHExtensionHelper">
<bean id="sshHelper" class="com.jspringbot.selenium.extension.SSHExtensionHelper">
<property name="hostname" value="${ssh.connect.hostname:localhost}"/>
<property name="username" value="${ssh.connect.username:user}"/>
<property name="password" value="${ssh.connect.password:user}"/>
<property name="port" value="${ssh.connect.port:22}"/>
<property name="keyPemFile" value="${ssh.connect.pem.location:none}"/>
<property name="strictHostKeyChecking" value="${ssh.connect.strict.hostKey.checking:no}"/>
<property name="hostname" value="${ssh.connect.remote.hostname:localhost}"/>
<property name="hostname" value="${ssh.connect.local.port :localhost}"/>
<property name="hostname" value="${ssh.connect.hostname:localhost}"/>
<property name="hostname" value="${ssh.connect.hostname:localhost}"/>
<property name="hostname" value="${ssh.connect.hostname:localhost}"/>
<property name="databaseHostname" value="${ssh.connect.remote.hostname:localhost}"/>
<property name="localPort" value="${ssh.connect.local.port:3309}"/>
<property name="remotePort" value="${ssh.connect.remote.port:3306}"/>
<property name="idrsaFilename" value="${ssh.connect.idrsa.filename:~/.ssh/id_rsa}"/>
<property name="preferredAuthentications" value="${ssh.connect.pref.auth:publickey,keyboard-interactive,password}"/>
</bean>

<!-- Scan components -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 13 additions & 0 deletions src/test/resources/jspringbot.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 373a99a

Please sign in to comment.