def test_build_ssh_config(self): contents = """ [aaa] hostname = 1.2.3.4 user = toto [bbb] inherits = aaa port = 23 """ set_config(contents) advssh = AdvancedSshConfig(hostname='test', configfiles=[DEFAULT_CONFIG]) config = advssh.prepare_sshconfig() arr = advssh.build_sshconfig() string = '\n'.join(arr) self.assertEquals(len(arr), 9) dest = """ Host aaa user toto # hostname 1.2.3.4 Host bbb port 23 user toto # inherits aaa """ self.assertEquals(string.strip(), dest.strip())
def test_build_ssh_config_with_multiline_localforward(self): contents = """ [localhost] user = toto localforward = 1 2.3.4.5 6 7 8.9.10.11 12 port = 22 """ set_config(contents) advssh = AdvancedSshConfig(hostname='localhost', configfiles=[DEFAULT_CONFIG]) config = advssh.prepare_sshconfig() arr = advssh.build_sshconfig() string = '\n'.join(arr) self.assertEquals(len(arr), 11) dest = """ # assh version: {} Host localhost localforward 1 2.3.4.5 6 localforward 7 8.9.10.11 12 port 22 user toto Host * proxycommand assh connect %h --port=%p """.format(__version__) self.assertEquals(string.strip(), dest.strip())
def test_build_ssh_config(self): contents = """ [aaa] hostname = 1.2.3.4 user = toto [bbb] inherits = aaa port = 23 """ set_config(contents) advssh = AdvancedSshConfig(hostname='test', configfiles=[DEFAULT_CONFIG]) config = advssh.prepare_sshconfig() arr = advssh.build_sshconfig() string = '\n'.join(arr) self.assertEquals(len(arr), 14) dest = """ # assh version: {} Host aaa user toto # hostname 1.2.3.4 Host bbb port 23 user toto # inherits aaa Host * proxycommand assh connect %h --port=%p """.format(__version__) self.assertEquals(string.strip(), dest.strip())
def test_build_ssh_config_sorted(self): contents = """ [ddd] inherits = aaa port = 23 user = titi [bbb] user = titi inherits = aaa port = 23 hostname = 1.1.1.1 [ccc] hostname = 5.4.3.2 inherits = aaa port = 23 [aaa] hostname = 1.2.3.4 user = toto """ set_config(contents) advssh = AdvancedSshConfig(hostname='test', configfiles=[DEFAULT_CONFIG]) config = advssh.prepare_sshconfig() arr = advssh.build_sshconfig() string = '\n'.join(arr) dest = """ # assh version: {} Host aaa user toto # hostname 1.2.3.4 Host bbb port 23 user titi # hostname 1.1.1.1 # inherits aaa Host ccc port 23 user toto # hostname 5.4.3.2 # inherits aaa Host ddd port 23 user titi # inherits aaa Host * proxycommand assh connect %h --port=%p """.format(__version__) self.assertEquals(string.strip(), dest.strip())
def test_build_ssh_config_with_multiline_comment(self): contents = """ [localhost] port = 22 comment = . . O . _______O_ . / O \\ . / _ _ O _ _ \\ . | _ | . | o | | o | . |___|_|___| . user = toto """ set_config(contents) advssh = AdvancedSshConfig(hostname='localhost', configfiles=[DEFAULT_CONFIG]) config = advssh.prepare_sshconfig() arr = advssh.build_sshconfig() string = '\n'.join(arr) dest = """ # assh version: {} Host localhost port 22 user toto # comment . # comment . O # comment . _______O_ # comment . / O \\ # comment . / _ _ O _ _ \\ # comment . | _ | # comment . | o | | o | # comment . |___|_|___| # comment . Host * proxycommand assh connect %h --port=%p """.format(__version__) self.assertEquals(string.strip(), dest.strip())
def test_build_ssh_config_with_multiline_localforward_onliner(self): contents = """ [localhost] user = toto localforward = 1 2.3.4.5 6 \n 7 8.9.10.11 12 port = 22 """ set_config(contents) advssh = AdvancedSshConfig(hostname='localhost', configfiles=[DEFAULT_CONFIG]) config = advssh.prepare_sshconfig() arr = advssh.build_sshconfig() string = '\n'.join(arr) self.assertEquals(len(arr), 6) dest = """ Host localhost localforward 1 2.3.4.5 6 localforward 7 8.9.10.11 12 port 22 user toto """ self.assertEquals(string.strip(), dest.strip())