mirror of
https://github.com/apache/superset.git
synced 2026-04-16 14:45:21 +00:00
fix: SSH Tunnel configuration settings (#27186)
This commit is contained in:
@@ -19,7 +19,10 @@
|
||||
import pytest
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
from superset.commands.database.ssh_tunnel.exceptions import SSHTunnelInvalidError
|
||||
from superset.commands.database.ssh_tunnel.exceptions import (
|
||||
SSHTunnelDatabasePortError,
|
||||
SSHTunnelInvalidError,
|
||||
)
|
||||
|
||||
|
||||
def test_create_ssh_tunnel_command() -> None:
|
||||
@@ -27,7 +30,11 @@ def test_create_ssh_tunnel_command() -> None:
|
||||
from superset.databases.ssh_tunnel.models import SSHTunnel
|
||||
from superset.models.core import Database
|
||||
|
||||
database = Database(id=1, database_name="my_database", sqlalchemy_uri="sqlite://")
|
||||
database = Database(
|
||||
id=1,
|
||||
database_name="my_database",
|
||||
sqlalchemy_uri="postgresql://u:p@localhost:5432/db",
|
||||
)
|
||||
|
||||
properties = {
|
||||
"database_id": database.id,
|
||||
@@ -48,7 +55,11 @@ def test_create_ssh_tunnel_command_invalid_params() -> None:
|
||||
from superset.databases.ssh_tunnel.models import SSHTunnel
|
||||
from superset.models.core import Database
|
||||
|
||||
database = Database(id=1, database_name="my_database", sqlalchemy_uri="sqlite://")
|
||||
database = Database(
|
||||
id=1,
|
||||
database_name="my_database",
|
||||
sqlalchemy_uri="postgresql://u:p@localhost:5432/db",
|
||||
)
|
||||
|
||||
# If we are trying to create a tunnel with a private_key_password
|
||||
# then a private_key is mandatory
|
||||
@@ -65,3 +76,31 @@ def test_create_ssh_tunnel_command_invalid_params() -> None:
|
||||
with pytest.raises(SSHTunnelInvalidError) as excinfo:
|
||||
command.run()
|
||||
assert str(excinfo.value) == ("SSH Tunnel parameters are invalid.")
|
||||
|
||||
|
||||
def test_create_ssh_tunnel_command_no_port() -> None:
|
||||
from superset.commands.database.ssh_tunnel.create import CreateSSHTunnelCommand
|
||||
from superset.databases.ssh_tunnel.models import SSHTunnel
|
||||
from superset.models.core import Database
|
||||
|
||||
database = Database(
|
||||
id=1,
|
||||
database_name="my_database",
|
||||
sqlalchemy_uri="postgresql://u:p@localhost/db",
|
||||
)
|
||||
|
||||
properties = {
|
||||
"database": database,
|
||||
"server_address": "123.132.123.1",
|
||||
"server_port": "3005",
|
||||
"username": "foo",
|
||||
"password": "bar",
|
||||
}
|
||||
|
||||
command = CreateSSHTunnelCommand(database, properties)
|
||||
|
||||
with pytest.raises(SSHTunnelDatabasePortError) as excinfo:
|
||||
command.run()
|
||||
assert str(excinfo.value) == (
|
||||
"A database port is required when connecting via SSH Tunnel."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user