blob: efc5f09e8c311925f0752c1d002cdf98a1ed8bb7 [file] [log] [blame]
koder aka kdanilov39e449e2016-12-17 15:15:26 +02001import getpass
2
3from oktest import ok
4
5from wally import ssh_utils, ssh
6
7
8creds = "root@osd-0"
9
10
11def test_ssh_url_parser():
12 curr_user = getpass.getuser()
13 creds = {
14 "test": ssh_utils.ConnCreds("test", curr_user, port=23),
15 "test:13": ssh_utils.ConnCreds("test", curr_user, port=13),
16 "test::xxx.key": ssh_utils.ConnCreds("test", curr_user, port=23, key_file="xxx.key"),
17 "test:123:xxx.key": ssh_utils.ConnCreds("test", curr_user, port=123, key_file="xxx.key"),
18 "user@test": ssh_utils.ConnCreds("test", "user", port=23),
19 "user@test:13": ssh_utils.ConnCreds("test", "user", port=13),
20 "user@test::xxx.key": ssh_utils.ConnCreds("test", "user", port=23, key_file="xxx.key"),
21 "user@test:123:xxx.key": ssh_utils.ConnCreds("test", "user", port=123, key_file="xxx.key"),
22 "user:passwd:@test": ssh_utils.ConnCreds("test", curr_user, port=23, passwd="passwd:"),
23 "user:passwd:@test:123": ssh_utils.ConnCreds("test", curr_user, port=123, passwd="passwd:"),
24 }
25
26 for uri, expected in creds.items():
27 parsed = ssh_utils.parse_ssh_uri(uri)
28 ok(parsed.user) == expected.user
29 ok(parsed.addr.port) == expected.addr.port
30 ok(parsed.addr.host) == expected.addr.host
31 ok(parsed.key_file) == expected.key_file
32 ok(parsed.passwd) == expected.passwd
33