# testing instructions
# Author: Pascal Meunier
#
# Overview
The execution host receives commands via an SSH key in /root/.ssh/authorized_keys, 
which should have a forced command "/usr/bin/dispatch" specified.  
/usr/bin/vssh_exec_proxy enters the container via docker exec
/usr/bin/maxwell_service is used to start and stop tool containers, via /usr/bin/maxwell on the web server.

# Do these in order, because
# each testing step builds on the previous one.

1. Start a tool session.

2. Find out which container was used, e.g., 76.tools

3. Test starting the SSH server in the container with:
/usr/bin/vsshd_start display_number username
e.g., "/usr/bin/vsshd_start 76 pmeunier"

Edit /usr/bin/vsshd_start and set DEBUG=1 for more information.

4. Find the IP address of the container with docker inspect
There should be a line like "IPv4Address": "172.16.8.76" in the output

5. Test SSH into the container
ssh -i /etc/mw-virtualssh/ssh_guest_key -p 2200 username@IPaddress
e.g.,
ssh -i /etc/mw-virtualssh/ssh_guest_key -p 2200 pmeunier@172.16.8.76

A more correct and informative test is:
ssh -F /etc/mw-virtualssh/exec_ssh_config -i /etc/mw-virtualssh/ssh_guest_key -t -p 2200 username@IPaddress -v -v -v

6. Test /usr/bin/vssh_exec_proxy (previously named /usr/bin/virtualssh_client) locally on the execution host
Edit /usr/bin/vssh_exec_proxy and set DEBUG = True for more information.
/usr/bin/vssh_exec_proxy display_number username
e.g., 
/usr/bin/vssh_exec_proxy 76 pmeunier

Example debugging output:
using a container of class: ContainerDocker
input validation successful
requested command to run in container is ''
trying docker exec -it method
pmeunier@docker76:~$ 

7. Test /usr/bin/virtualssh_client called from the web server through SSH to root@exechost
# ssh -t -i /etc/mw-client/maxwell.key exec01.help.hubzero.org "/usr/bin/vssh_exec_proxy 76 pmeunier"
using a container of class: ContainerDocker
input validation successful
requested command to run in container is ''
trying docker exec -it method
pmeunier@docker76:~$ 

8. Test running a command in the tool container
# ssh -t -i /etc/mw-client/maxwell.key exec01.help.hubzero.org "/usr/bin/vssh_exec_proxy 76 pmeunier ls"
using a container of class: ContainerDocker
input validation successful
requested command to run in container is 'ls'
trying docker exec -it method
data  data_transfer
Connection to exec01.help.hubzero.org closed.

Note:  without the -t option you'll get "the input device is not a TTY"

9. Test X11 forwarding with a DISPLAY environment variable

# DISPLAY=192.168.8.76:0 /usr/bin/vssh_exec_proxy 76 pmeunier
using a container of class: ContainerDocker
input validation successful
requested command to run in container is ''
Docker container but there is a DISPLAY environment variable 192.168.8.76:0, skipped docker exec and using instead an SSH server inside container
starting SSH server inside container
SSH server started
ssh-client command is ''
flags are  ['-X', '-Y']
/usr/bin/ssh ssh -F /etc/mw-virtualssh/exec_ssh_config -i /etc/mw-virtualssh/ssh_guest_key ['-X', '-Y'] -p 2200 pmeunier@172.16.8.76 
All activity on this system is subject to HUBzero and HUBzero
policies and procedures. 
pmeunier@docker76:~$ 

10. Proceed to installing the front-virtualssh package on the web server, and testing through it
