MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_ssh_tunnels

Function test_ssh_tunnels

test/cloudtest/test_ssh_tunnels.py:16–127  ·  view source on GitHub ↗
(mz: MaterializeApplication)

Source from the content-addressed store, hash-verified

14
15
16def test_ssh_tunnels(mz: MaterializeApplication) -> None:
17 mz.testdrive.run(input=dedent("""
18 > CREATE CONNECTION IF NOT EXISTS ssh_conn TO SSH TUNNEL (
19 HOST 'ssh-bastion-host',
20 USER 'mz',
21 PORT 22
22 );
23 """))
24
25 id, public_key = mz.environmentd.sql_query(
26 "SELECT id, public_key_1 FROM mz_ssh_tunnel_connections"
27 )[0]
28 assert id is not None
29
30 secret = f"user-managed-{id}"
31
32 # If the secret didn't exist, this would throw an exception
33 mz.kubectl("describe", "secret", secret)
34
35 # Add public key to SSH bastion host
36 mz.kubectl(
37 "exec",
38 "svc/ssh-bastion-host",
39 "--",
40 "bash",
41 "-c",
42 f"echo '{public_key}' > /etc/authorized_keys/mz",
43 )
44
45 mz.testdrive.run(
46 input=dedent("""
47 > CREATE SECRET pgpass AS 'postgres'
48 > CREATE CONNECTION pg TO POSTGRES (
49 HOST 'postgres',
50 DATABASE postgres,
51 USER postgres,
52 PASSWORD SECRET pgpass,
53 SSL MODE require,
54 SSH TUNNEL ssh_conn
55 );
56
57 $ postgres-execute connection=postgres://postgres:postgres@postgres
58 ALTER USER postgres WITH replication;
59 DROP SCHEMA IF EXISTS public CASCADE;
60 DROP PUBLICATION IF EXISTS mz_source;
61 CREATE SCHEMA public;
62
63 CREATE TABLE t1 (f1 INTEGER);
64 ALTER TABLE t1 REPLICA IDENTITY FULL;
65 INSERT INTO t1 VALUES (1);
66
67 CREATE PUBLICATION mz_source FOR TABLE t1;
68
69 > CREATE SOURCE mz_source
70 FROM POSTGRES CONNECTION pg
71 (PUBLICATION 'mz_source');
72
73 > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);

Callers

nothing calls this directly

Calls 5

waitFunction · 0.90
runMethod · 0.45
sql_queryMethod · 0.45
kubectlMethod · 0.45
sqlMethod · 0.45

Tested by

no test coverage detected