MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / BaseTestSSLConnection

Class BaseTestSSLConnection

tests/test_connect.py:1796–1848  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1794
1795
1796class BaseTestSSLConnection(tb.ConnectedTestCase):
1797 @classmethod
1798 def get_server_settings(cls):
1799 conf = super().get_server_settings()
1800 conf.update({
1801 'ssl': 'on',
1802 'ssl_cert_file': SSL_CERT_FILE,
1803 'ssl_key_file': SSL_KEY_FILE,
1804 'ssl_ca_file': CLIENT_CA_CERT_FILE,
1805 })
1806 if cls.cluster.get_pg_version() >= (12, 0):
1807 conf['ssl_min_protocol_version'] = 'TLSv1.2'
1808 conf['ssl_max_protocol_version'] = 'TLSv1.2'
1809
1810 return conf
1811
1812 @classmethod
1813 def setup_cluster(cls):
1814 cls.cluster = cls.new_cluster(pg_cluster.TempCluster)
1815 cls.start_cluster(
1816 cls.cluster, server_settings=cls.get_server_settings())
1817
1818 def setUp(self):
1819 super().setUp()
1820
1821 self.cluster.reset_hba()
1822
1823 create_script = []
1824 create_script.append('CREATE ROLE ssl_user WITH LOGIN;')
1825 create_script.append('GRANT ALL ON SCHEMA public TO ssl_user;')
1826
1827 self._add_hba_entry()
1828
1829 # Put hba changes into effect
1830 self.cluster.reload()
1831
1832 create_script = '\n'.join(create_script)
1833 self.loop.run_until_complete(self.con.execute(create_script))
1834
1835 def tearDown(self):
1836 # Reset cluster's pg_hba.conf since we've meddled with it
1837 self.cluster.trust_local_connections()
1838
1839 drop_script = []
1840 drop_script.append('REVOKE ALL ON SCHEMA public FROM ssl_user;')
1841 drop_script.append('DROP ROLE ssl_user;')
1842 drop_script = '\n'.join(drop_script)
1843 self.loop.run_until_complete(self.con.execute(drop_script))
1844
1845 super().tearDown()
1846
1847 def _add_hba_entry(self):
1848 raise NotImplementedError()
1849
1850
1851@unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…