]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
4368277c | 2 | |
8a0c1913 ZJS |
3 | #include "sd-bus.h" |
4 | ||
5 | #include "bus-internal.h" | |
6 | #include "log.h" | |
7 | #include "string-util.h" | |
8 | #include "strv.h" | |
f68a2622 | 9 | #include "tests.h" |
8a0c1913 ZJS |
10 | |
11 | static void test_one_address(sd_bus *b, | |
12 | const char *host, | |
13 | int result, const char *expected) { | |
14 | int r; | |
15 | ||
16 | r = bus_set_address_system_remote(b, host); | |
17 | log_info("\"%s\" → %d, \"%s\"", host, r, strna(r >= 0 ? b->address : NULL)); | |
18 | if (result < 0 || expected) { | |
f21b863e | 19 | assert_se(r == result); |
8a0c1913 ZJS |
20 | if (r >= 0) |
21 | assert_se(streq(b->address, expected)); | |
22 | } | |
23 | } | |
24 | ||
68da8adf | 25 | TEST(bus_set_address_system_remote) { |
8a0c1913 ZJS |
26 | _cleanup_(sd_bus_unrefp) sd_bus *b = NULL; |
27 | ||
28 | assert_se(sd_bus_new(&b) >= 0); | |
68da8adf | 29 | if (!strv_isempty(saved_argv + 1)) { |
68da8adf | 30 | STRV_FOREACH(a, saved_argv + 1) |
8a0c1913 ZJS |
31 | test_one_address(b, *a, 0, NULL); |
32 | return; | |
33 | }; | |
34 | ||
35 | test_one_address(b, "host", | |
36 | 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=host,argv4=systemd-stdio-bridge"); | |
37 | test_one_address(b, "host:123", | |
38 | 0, "unixexec:path=ssh,argv1=-xT,argv2=-p,argv3=123,argv4=--,argv5=host,argv6=systemd-stdio-bridge"); | |
39 | test_one_address(b, "host:123:123", | |
40 | -EINVAL, NULL); | |
6a555849 SL |
41 | test_one_address(b, "host:", |
42 | -EINVAL, NULL); | |
8a0c1913 ZJS |
43 | test_one_address(b, "user@host", |
44 | 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=user%40host,argv4=systemd-stdio-bridge"); | |
8f37636d LP |
45 | test_one_address(b, "user@host@host", |
46 | -EINVAL, NULL); | |
8a0c1913 ZJS |
47 | test_one_address(b, "[::1]", |
48 | 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=%3a%3a1,argv4=systemd-stdio-bridge"); | |
49 | test_one_address(b, "user@[::1]", | |
50 | 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=user%40%3a%3a1,argv4=systemd-stdio-bridge"); | |
51 | test_one_address(b, "user@[::1]:99", | |
52 | 0, "unixexec:path=ssh,argv1=-xT,argv2=-p,argv3=99,argv4=--,argv5=user%40%3a%3a1,argv6=systemd-stdio-bridge"); | |
6a555849 SL |
53 | test_one_address(b, "user@[::1]:", |
54 | -EINVAL, NULL); | |
8a0c1913 ZJS |
55 | test_one_address(b, "user@[::1:", |
56 | -EINVAL, NULL); | |
6a555849 SL |
57 | test_one_address(b, "user@", |
58 | -EINVAL, NULL); | |
59 | test_one_address(b, "user@@", | |
60 | -EINVAL, NULL); | |
8a0c1913 ZJS |
61 | } |
62 | ||
68da8adf | 63 | DEFINE_TEST_MAIN(LOG_INFO); |