Getting the output of a script run on a remote server over ssh by a C# test - ssh

I'm writing automation tests in .net core that will access a remote server running the application we're testing. I'm currently ssh-ing onto a remote server in the test to run a script that verifies certain data. I want to get the output from that script to my local machine, so my test can know whether that step passed or not.
I am using the Renci.SshNet tool to connect to the remote server.
Here is the code I run in my test to connect to the remote host, then send a command as a string.
string commandToRun = "/opt/scriptHome/scriptWithOutput";
using (var client = new SshClient(ipAddress, username, password))
{
client.Connect();
client.RunCommand(commandToRun);
client.Disconnect();
}

RunCommand returns an object of type SshCommand and you can use its properties to check the result of your command for example:
var command = client.RunCommand(commandToRun);
Console.WriteLine(command.Result);

Related

Forgot sonarqube password. Using it locally, No Database

I am using sonarqube from command line. I have a local server (sonarqube 64) on my windows 7 (x86-64). I successfully installed and I can open the web host http://localhost:9000/. but I cannot login the admin/admin login details are not working.
I know there is way of resetting the password but I need database that I don't have and i am the only user/admin.
Is there any way to recover the password or change it? should I uninstall the server and install it again?
It is not said how to properly unistall the server either
Thanks
I'm running 8.5 and this appears to be different, I used:
Change directory to /opt/sonarqube/lib/jdbc/h2
cd /opt/sonarqube/lib/jdbc/h2
Run the command line below to open h2 shell
java -cp h2-1.4.199.jar org.h2.tools.Shell
you will be prompted to fill the following:
URL jdbc:h2:tcp://localhost:9092/sonar
Driver org.h2.Driver
User [none]
Password [none]
You will be prompted now to sql command line (sql>), then type your query:
update users set crypted_password = '$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi', salt=null, hash_method='BCRYPT' where login = 'admin'
There is no real "installation" for SonarQube; you explode the zip and run one of the start scripts. So if you do decide to scrap your current instance, all you need to do is shut it down, delete the directory and re-explode the zip. However, once you do that, you should seriously consider connecting it to a production database. So far you're running with the embedded H2 database, and that's not appropriate for long-term use. Among other things, migration to new versions is not supported for the H2 database.
Once you've done that, you can reset the admin password by executing the following query:
update users set crypted_password = '88c991e39bb88b94178123a849606905ebf440f5', salt='6522f3c5007ae910ad690bb1bdbf264a34884c6d' where login = 'admin'
That sets it back to 'admin'
For the config below (openjdk-11, sonarqube-8), follow the steps:
Change directory to /opt/sq/lib/jdbc/h2
cd /opt/sq/lib/jdbc/h2
Run the command line below to open h2 shell
java -cp h2-1.3.176.jar org.h2.tools.Shell
you will be prompted to fill the following:
URL jdbc:h2:localhost:9000/data/sonar
Driver org.h2.Driver
User sonar
Password sonar
You will be prompted now to sql command line (sql>), then tap your query:
update users set crypted_password = '88c991e39bb88b94178123a849606905ebf440f5', salt='6522f3c5007ae910ad690bb1bdbf264a34884c6d' where login = 'admin'

How to Automate the application which is accesible through remote desktop

I have a requirement to automate one of my application which is accessible only through Remote desktop connection.
I normally connect to the application using following steps
1) Navigate to remote desktop connection and enter Ip address
2) Enter Server User id ,password
3) Then open application using browser.
Please help with the steps.
You can break your problems in 2steps :
1. Login to the box via java code (or any other preferable language, you are comfortable).
Remote Desktop Connection
JAVA
// creating credentials
Process p = Runtime.getRuntime().exec("cmdkey /generic:"+ip+" /user:"+userName+" /pass:"+password );
p.destroy();
Runtime.getRuntime().exec("mstsc /v: "+ip+" /f /console");
Thread.sleep(2*60*1000); // min sec millisec
// deleting credentials
Process p1 = Runtime.getRuntime().exec("cmdkey /delete:"+ip);
p1.destroy();
Once you able to login to the box, it is as simple as launching the browser, opening the application and running your scripts(these scripts should be present on your remote desktop where you want to run your scripts). This is pretty straight forward.

SSH.NET - send command

I'm making a program which uses SSH.NET but I don't know how to send a command to SSH server. Here is my current code and I need to add code which sends a command. SshClient raspberry = new SshClient(ip, 22, "pi", "raspberry");
raspberry.Connect();
MessageBox.Show("Connected");
ovladani oknoovladani = new ovladani();
oknoovladani.Show();
I think you would set up your command by cmd = sshclient.CreateCommand(...) and then execute via cmd.Execute().

block internet access with Test Complete

Are there any way, to prevent the internet access of the tester application under the test whit Test Complete? I'd like to test the application's reaction of the lost of the internet connection, but I have to perform this whith a CI tool, which means the Test Complete have to block and unblock to connection.
You can do this using WMI directly from a script (see Working With WMI Objects in Scripts) or by executing a PowerShell script (see Running PowerShell Scripts From TestComplete).
For example, see this question to get a sample PS script:
Command/Powershell script to reset a network adapter

Remotely control a graphical vb.net program through a command prompt

I have created a VB.NET program using windows forms. The program runs on a remote PC and displays information on a screen. The computer does not even have a mouse or keyboard connected to it. The program shows the information based on the file that is loaded.
I want to be able to change this file remotely to another file that is already on the remote PC. I can't use a graphical remote desktop client as we have very limited bandwidth.
So, my idea is to change the file using the command prompt (I think I'll need something like SSH). I'm not sure how to do this. Should I use something like this and load DosModule first:
Module DOSModule
Public Sub Main()
Console.Write("First, start with Command Prompt processing ...")
Dim myWinForm As New WinForm
Application.Run(myWinForm)
End Sub
End Module
How would I then read commands that is send to the program? I also only want one instance of the program running.
Thanks
You have 2 options. The first is a custom program that WILL require some network programming, like it or not. I would suggest creating either a Command-Line batch file or else a PowerShell script, then creating a program to transfer the script to the remote computer and execute the script.
The second option and the one better suited for you would be to download an SSH server. An SSH server will essentially open a command window and pipe the input and output over to a telnet client running on your machine. If you are running a version of Windows Server, an SSH server comes with Windows Server. Otherwise, you can download one for free here: http://www.freesshd.com/
Once you install the SSH server, you simply use telnet, from a command prompt, to link up with your remote SSH server