Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError if None is passed as port to the constructor of gvm.connections.SSHConnection #320

Closed
Korkmatik opened this issue Oct 31, 2020 · 0 comments · Fixed by #321
Closed

Comments

@Korkmatik
Copy link
Contributor

Expected behavior

Passing None as Port in the constructor of gvm.connections.SSHConnection should not throw an TypeError. Because the type is Optional. So you should not worry about it if None is passed. https://docs.python.org/3/library/typing.html#typing.Optional. Also if you pass None as Port to gvm.connections.TLSConnection or gvm.connections.UnixSocketConnection then no errror is thrown.

Current behavior

If you pass None to gvm.connections.SSHConnection, TypeError is thrown. Because of converting it to int.

class SSHConnection(GvmConnection):
    def __init__(
        self,
        *,
        timeout: Optional[int] = DEFAULT_TIMEOUT,
        hostname: Optional[str] = DEFAULT_HOSTNAME,
        port: Optional[int] = DEFAULT_SSH_PORT,
        username: Optional[str] = "gmp",
        password: Optional[str] = ""
    ):
        super().__init__(timeout=timeout)

        self.hostname = hostname
        self.port = int(port)

Steps to reproduce

I've found this during writing tests for the parser in gvm-tools repository. This code will throw this error:
SSHConnection(port=None)

GVM versions

gsa: (gsad --version)
Not installed

gvm: (gvmd --version)
20.9.1

gvm-tools: (gvm-cli --version)
gvm-cli 20.10.2.dev1 (API version 20.9.1)

Environment

Operating system:
Linux Mint 20

Installation method / source: (packages, source installation)
Packages. I have cloned the gvm-tools repository and installed the dependencies.

Logfiles

Not the Logfile but the Traceback, after I have run my test:

Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/mock.py", line 1325, in patched
    return func(*newargs, **newkeywargs)
  File "/home/fox/Git/gvm-tools/tests/test_parser.py", line 478, in test_create_ssh_connection
    self.perform_create_connection_test('ssh', SSHConnection)
  File "/home/fox/Git/gvm-tools/tests/test_parser.py", line 481, in perform_create_connection_test
    connection = create_connection(connection_type)
  File "/home/fox/Git/gvm-tools/gvmtools/parser.py", line 336, in create_connection
    return SSHConnection(
  File "/home/fox/Git/gvm-tools/.venv/lib/python3.8/site-packages/gvm/connections.py", line 195, in __init__
    self.port = int(port)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant