diff --git a/asyncssh/connection.py b/asyncssh/connection.py index cc4609c..df25aef 100644 --- a/asyncssh/connection.py +++ b/asyncssh/connection.py @@ -7911,9 +7911,17 @@ def prepare(self, # type: ignore rekey_seconds, connect_timeout, login_timeout, keepalive_interval, keepalive_count_max) - self.known_hosts = known_hosts if known_hosts != () else \ - (cast(List[str], config.get('UserKnownHostsFile', [])) + - cast(List[str], config.get('GlobalKnownHostsFile', []))) or () + if known_hosts != (): + self.known_hosts = known_hosts + else: + user_known_hosts = \ + cast(List[str], config.get('UserKnownHostsFile', ())) + + if user_known_hosts == []: + self.known_hosts = None + else: + self.known_hosts = list(user_known_hosts) + \ + cast(List[str], config.get('GlobalKnownHostsFile', [])) self.host_key_alias = \ cast(Optional[str], host_key_alias if host_key_alias != () else diff --git a/tests/test_connection.py b/tests/test_connection.py index 26f1ed5..1afc6bd 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -706,6 +706,16 @@ async def test_known_hosts_none(self): async with self.connect(known_hosts=None) as conn: self.assertEqual(conn.get_server_host_key_algs(), default_algs) + @asynctest + async def test_known_hosts_none_in_config(self): + """Test connecting with known hosts checking disabled in config file""" + + with open('config', 'w') as f: + f.write('UserKnownHostsFile none') + + async with self.connect(config='config'): + pass + @asynctest async def test_known_hosts_none_without_x509(self): """Test connecting with known hosts checking and X.509 disabled"""