feat(proxy): allow proxy to connect to separate compute compared to mock cplane

This commit is contained in:
Conrad Ludgate
2024-12-17 18:46:38 +00:00
parent b5833ef259
commit a93639af6b
3 changed files with 85 additions and 72 deletions

View File

@@ -3274,7 +3274,7 @@ class NeonProxy(PgProtocol):
metric_collection_interval: str | None = None,
):
host = "127.0.0.1"
domain = "proxy.localtest.me" # resolves to 127.0.0.1
domain = "ep-test-endpoint.localtest.me" # resolves to 127.0.0.1
super().__init__(dsn=auth_backend.default_conn_url, host=domain, port=proxy_port)
self.domain = domain
@@ -3639,7 +3639,19 @@ def static_proxy(
vanilla_pg.safe_psql("create user proxy with login superuser password 'password'")
vanilla_pg.safe_psql("CREATE SCHEMA IF NOT EXISTS neon_control_plane")
vanilla_pg.safe_psql(
"CREATE TABLE neon_control_plane.endpoints (endpoint_id VARCHAR(255) PRIMARY KEY, allowed_ips VARCHAR(255))"
f"""
CREATE TABLE neon_control_plane.endpoints (
endpoint_id text PRIMARY KEY,
allowed_ips text,
host text not null default '{host}',
port integer not null default {port}
)
"""
)
vanilla_pg.safe_psql(
"""
insert into neon_control_plane.endpoints (endpoint_id) VALUES ('ep-test-endpoint');
"""
)
proxy_port = port_distributor.get_port()

View File

@@ -43,11 +43,16 @@ async def test_http_pool_begin_1(static_proxy: NeonProxy):
print(results)
def test_proxy_select_1(static_proxy: NeonProxy):
def test_proxy_select_1(static_proxy: NeonProxy, vanilla_pg: VanillaPostgres):
"""
A simplest smoke test: check proxy against a local postgres instance.
"""
# Establish the default compute for this endpoint
vanilla_pg.safe_psql(
"INSERT INTO neon_control_plane.endpoints (endpoint_id) VALUES ('generic-project-name')"
)
# no SNI, deprecated `options=project` syntax (before we had several endpoint in project)
out = static_proxy.safe_psql("select 1", sslsni=0, options="project=generic-project-name")
assert out[0][0] == 1
@@ -61,12 +66,17 @@ def test_proxy_select_1(static_proxy: NeonProxy):
assert out[0][0] == 42
def test_password_hack(static_proxy: NeonProxy):
def test_password_hack(static_proxy: NeonProxy, vanilla_pg: VanillaPostgres):
"""
Check the PasswordHack auth flow: an alternative to SCRAM auth for
clients which can't provide the project/endpoint name via SNI or `options`.
"""
# Establish the default compute for this endpoint
vanilla_pg.safe_psql(
"INSERT INTO neon_control_plane.endpoints (endpoint_id) VALUES ('irrelevant')"
)
user = "borat"
password = "password"
static_proxy.safe_psql(f"create role {user} with login password '{password}'")
@@ -107,7 +117,7 @@ async def test_link_auth(vanilla_pg: VanillaPostgres, link_proxy: NeonProxy):
@pytest.mark.parametrize("option_name", ["project", "endpoint"])
def test_proxy_options(static_proxy: NeonProxy, option_name: str):
def test_proxy_options(static_proxy: NeonProxy, vanilla_pg: VanillaPostgres, option_name: str):
"""
Check that we pass extra `options` to the PostgreSQL server:
* `project=...` and `endpoint=...` shouldn't be passed at all
@@ -115,6 +125,11 @@ def test_proxy_options(static_proxy: NeonProxy, option_name: str):
* everything else should be passed as-is.
"""
# Establish the default compute for this endpoint
vanilla_pg.safe_psql(
"INSERT INTO neon_control_plane.endpoints (endpoint_id) VALUES ('irrelevant')"
)
options = f"{option_name}=irrelevant -cproxytest.option=value"
out = static_proxy.safe_psql("show proxytest.option", options=options, sslsni=0)
assert out[0][0] == "value"