Skip to content

Commit

Permalink
Merge pull request #1 from huashengdun/master
Browse files Browse the repository at this point in the history
upstream pull
  • Loading branch information
dogukanoksuz authored Apr 14, 2023
2 parents a6e37c1 + 47cfeed commit 6bb1a9e
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 19 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# https://beta.ruff.rs
name: python
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip install --user ruff
- run: ruff --format=github --ignore=F401 --target-version=py38 .
pytest:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install pytest pytest-cov -r requirements.txt
- run: pytest --cov=webssh
- run: mkdir -p coverage
- uses: tj-actions/coverage-badge-py@v2
with:
output: coverage/coverage.svg
- uses: JamesIves/github-pages-deploy-action@v4
with:
branch: coverage-badge
folder: coverage
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## WebSSH

[![Build Status](https://travis-ci.org/huashengdun/webssh.svg?branch=master)](https://travis-ci.org/huashengdun/webssh)
[![codecov](https://codecov.io/gh/huashengdun/webssh/branch/master/graph/badge.svg)](https://codecov.io/gh/huashengdun/webssh)
[![python](https://github.com/huashengdun/webssh/actions/workflows/python.yml/badge.svg)](https://github.com/huashengdun/webssh/actions/workflows/python.yml)
[![codecov](https://raw.githubusercontent.com/huashengdun/webssh/coverage-badge/coverage.svg)](https://raw.githubusercontent.com/huashengdun/webssh/coverage-badge/coverage.svg)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/webssh.svg)
![PyPI](https://img.shields.io/pypi/v/webssh.svg)

Expand Down Expand Up @@ -37,7 +37,7 @@ A simple web application to be used as an ssh client to connect to your ssh serv

### Requirements

* Python 2.7/3.4+
* Python 3.8+


### Quickstart
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ How it works
Requirements
~~~~~~~~~~~~

- Python 2.7/3.4+
- Python 3.8+

Quickstart
~~~~~~~~~~
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
paramiko==2.10.4
tornado==5.1.1; python_version < '3.5'
tornado==6.1.0; python_version >= '3.5'
paramiko==3.0.0
tornado==6.2.0
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
include_package_data=True,
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
install_requires=[
'tornado>=4.5.0',
Expand Down
8 changes: 4 additions & 4 deletions tests/sshserver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import random
import socket
# import sys
Expand All @@ -6,7 +7,6 @@
import paramiko

from binascii import hexlify
from paramiko.py3compat import u, decodebytes
from tests.utils import make_tests_data_path


Expand All @@ -16,7 +16,7 @@
host_key = paramiko.RSAKey(filename=make_tests_data_path('test_rsa.key'))
# host_key = paramiko.DSSKey(filename='test_dss.key')

print('Read key: ' + u(hexlify(host_key.get_fingerprint())))
print('Read key: ' + hexlify(host_key.get_fingerprint()).decode('utf-8'))

banner = u'\r\n\u6b22\u8fce\r\n'
event_timeout = 5
Expand All @@ -29,7 +29,7 @@ class Server(paramiko.ServerInterface):
b'fAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMC'
b'KDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iT'
b'UWT10hcuO4Ks8=')
good_pub_key = paramiko.RSAKey(data=decodebytes(data))
good_pub_key = paramiko.RSAKey(data=base64.decodebytes(data))

commands = [
b'$SHELL -ilc "locale charmap"',
Expand Down Expand Up @@ -62,7 +62,7 @@ def check_auth_password(self, username, password):
return paramiko.AUTH_FAILED

def check_auth_publickey(self, username, key):
print('Auth attempt with username: {!r} & key: {!r}'.format(username, u(hexlify(key.get_fingerprint())))) # noqa
print('Auth attempt with username: {!r} & key: {!r}'.format(username, hexlify(key.get_fingerprint()).decode('utf-8'))) # noqa
if (username in ['robey', 'keyonly']) and (key == self.good_pub_key):
return paramiko.AUTH_SUCCESSFUL
if username == 'pkey2fa' and key == self.good_pub_key:
Expand Down
25 changes: 24 additions & 1 deletion tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import unittest
import paramiko

Expand All @@ -7,7 +8,7 @@
from webssh import handler
from webssh import worker
from webssh.handler import (
MixinHandler, WsockHandler, PrivateKey, InvalidValueError
IndexHandler, MixinHandler, WsockHandler, PrivateKey, InvalidValueError, SSHClient
)

try:
Expand Down Expand Up @@ -315,3 +316,25 @@ def __call__(self):
obj.worker_ref = ref
WsockHandler.on_message(obj, b'{"data": "somestuff"}')
obj.close.assert_called_with(reason='Worker closed')

class TestIndexHandler(unittest.TestCase):
def test_null_in_encoding(self):
handler = Mock(spec=IndexHandler)

# This is a little nasty, but the index handler has a lot of
# dependencies to mock. Mocking out everything but the bits
# we want to test lets us test this case without needing to
# refactor the relevant code out of IndexHandler
def parse_encoding(data):
return IndexHandler.parse_encoding(handler, data)
handler.parse_encoding = parse_encoding

ssh = Mock(spec=SSHClient)
stdin = io.BytesIO()
stdout = io.BytesIO(initial_bytes=b"UTF-8\0")
stderr = io.BytesIO()
ssh.exec_command.return_value = (stdin, stdout, stderr)

encoding = IndexHandler.get_default_encoding(handler, ssh)
self.assertEquals("utf-8", encoding)

2 changes: 1 addition & 1 deletion webssh/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (1, 6, 1)
__version_info__ = (1, 6, 2)
__version__ = '.'.join(map(str, __version_info__))
2 changes: 2 additions & 0 deletions webssh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def is_valid_encoding(encoding):
u'test'.encode(encoding)
except LookupError:
return False
except ValueError:
return False
return True


Expand Down

0 comments on commit 6bb1a9e

Please sign in to comment.