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