yuvipanda / jupyterhub-ssh

SSH Access to JupyterHubs
BSD 3-Clause "New" or "Revised" License
93 stars 29 forks source link

Write terminado tests #13

Open yuvipanda opened 3 years ago

yuvipanda commented 3 years ago

Jupyter uses the terminado package to provide terminal access in the GUI. We use its JSON API to provide terminal access via ssh - this way, we can provide terminal access to any JupyterHub, without depending on implementation details

jupyterhub_ssh/terminado.py is a class that's a client for terminado. This should be able to talk to any terminado server, running in a plain Jupyter Notebook. We should write simple tests that:

  1. Start a jupyter notebook
  2. Talk to the terminado endpoint there
  3. Verify that things work as they should!

Things we should test:

  1. Authorization works via token, fails without
  2. Sending stdin works fine. We can do this by sending something like touch <random-generated-id>\n to the shell, and verifying that the file was created.
  3. Fetching stdout works fine. We could do this by sending a commend via stdin like echo <random-generated-id>\n and testing that we see that in stdout.
  4. Setting size on the terminal (via set_size) is reflected fine in the backend. This reflects the row and column size used by TUI applications - like emacs, vim, top, etc. Once set_size is sent, you can validate the new size by running tput cols and tput lines.
  5. Terminal servers are started when needed, and whenever disconnects / issues happen, they are cleaned up properly. We shouldn't leave random terminado servers running. We can test this by hitting the notebook API ourselves and testing.

Would be nice to document the protocol too - I don't think there's public documentation of this JSON protocol.