def device_gen(chain, urls): """Device object generator.""" itr = iter(urls) last = next(itr) for url in itr: yield Device(chain, make_hop_info_from_url(last), driver_name='jumphost', is_target=False) last = url yield Device(chain, make_hop_info_from_url(last), driver_name='generic', is_target=True)
def test_url_ssh_no_password(self): url = "ssh://[email protected]:2048" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'ssh' assert hop_info.username == 'user' assert hop_info.password is None assert hop_info.hostname == '1.1.1.1' assert hop_info.port == 2048
def test_url_ssh(self): url = "ssh://*****:*****@1.1.1.1" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'ssh' assert hop_info.username == 'user' assert hop_info.password == 'pass' assert hop_info.hostname == '1.1.1.1' assert hop_info.port == 22
def test_url_telnet_empty_password(self): url = "telnet://user:@1.1.1.1:2048" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'telnet' assert hop_info.username == 'user' assert hop_info.password == '' assert hop_info.hostname == '1.1.1.1' assert hop_info.port == 2048
def test_url_telnet_no_user_password(self): url = "telnet://1.1.1.1:2048" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'telnet' assert hop_info.username is None assert hop_info.password is None assert hop_info.hostname == '1.1.1.1' assert hop_info.port == 2048
def test_url_ssh_empty_user_password(self): url = "ssh://:@1.1.1.1:2048" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'ssh' assert hop_info.username == '' assert hop_info.password == '' assert hop_info.hostname == '1.1.1.1' assert hop_info.port == 2048
def test_url_telnet(self): url = "telnet://*****:*****@1.1.1.1" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'telnet' assert hop_info.username == 'user' assert hop_info.password == 'pass' assert hop_info.hostname == '1.1.1.1' assert hop_info.port == 23
def test_url_ssh_empty_password(self): url = "ssh://user:@1.1.1.1:2048" hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "ssh") self.assertEqual(hop_info.username, "user") self.assertEqual(hop_info.password, "") self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 2048)
def test_url_telnet_two_ip(self): url = "telnet://1.1.1.1,2.2.2.2:23,34/!@#$%^&*()1/2345678asdfgh" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'telnet' assert hop_info.username is None assert hop_info.password is None assert hop_info.hostname == '1.1.1.1,2.2.2.2' assert hop_info.port == 23, 24 assert hop_info.enable_password == "!@#$%^&*()1/2345678asdfgh"
def test_url_telnet_no_user_password_and_enable_no_port(self): url = "telnet://1.1.1.1/!@#$%^&*()1/2345678asdfgh" hop_info = make_hop_info_from_url(url) assert hop_info.protocol == 'telnet' assert hop_info.username is None assert hop_info.password is None assert hop_info.hostname == '1.1.1.1' assert hop_info.port == 23 assert hop_info.enable_password == "!@#$%^&*()1/2345678asdfgh"
def test_url_telnet_empty_user_password(self): url = "telnet://:@1.1.1.1:2048" hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "telnet") self.assertEqual(hop_info.username, "") self.assertEqual(hop_info.password, "") self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 2048)
def test_url_ssh_no_user_password(self): url = "ssh://1.1.1.1:2048" hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "ssh") self.assertEqual(hop_info.username, None) self.assertEqual(hop_info.password, None) self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 2048)
def test_url_telnet_no_password(self): url = "telnet://[email protected]:2048" hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "telnet") self.assertEqual(hop_info.username, "user") self.assertEqual(hop_info.password, None) self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 2048)
def test_url_telnet(self): url = "telnet://*****:*****@1.1.1.1" hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "telnet") self.assertEqual(hop_info.username, "user") self.assertEqual(hop_info.password, "pass") self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 23)
def test_url_telnet_no_user_password_and_enable_no_port_not_quoted(self): url = "telnet://1.1.1.1/?enable_password=!@#$%^&*()1/2345678asdfgh" hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "telnet") self.assertEqual(hop_info.username, None) self.assertEqual(hop_info.password, None) self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 23) self.assertNotEqual(hop_info.enable_password, "!@#$%^&*()1/2345678asdfgh")
def test_url_telnet_no_user_password_and_enable_no_port_quoted(self): password = """\|;':"!@#$%^&*()+{}:"<>?`,<>~./1234567890zxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP""" password_q = quote(password, safe="") url = "telnet://1.1.1.1/?enable_password={password}".format( password=password_q) hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "telnet") self.assertEqual(hop_info.username, None) self.assertEqual(hop_info.password, None) self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 23) self.assertEqual(hop_info.enable_password, password)
def test_url_telnet_complex_user_pass(self): username = """\|;':"!@#$%^&*()+{}:"<>?`,<>~./1234567890zxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP""" password = """\|;':"!@#$%^&*()+{}:"<>?`,<>~./1234567890zxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP""" username_q = quote(username, safe="") password_q = quote(password, safe="") url = "telnet://{username}:{password}@1.1.1.1".format( username=username_q, password=password_q) hop_info = make_hop_info_from_url(url) self.assertEqual(hop_info.protocol, "telnet") self.assertEqual(hop_info.username, username) self.assertEqual(hop_info.password, password) self.assertEqual(hop_info.hostname, "1.1.1.1") self.assertEqual(hop_info.port, 23)