]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
4368277c | 2 | |
8a0c1913 ZJS |
3 | #include "sd-bus.h" |
4 | ||
69a283c5 | 5 | #include "argv-util.h" |
8a0c1913 ZJS |
6 | #include "bus-internal.h" |
7 | #include "log.h" | |
8 | #include "string-util.h" | |
9 | #include "strv.h" | |
f68a2622 | 10 | #include "tests.h" |
8a0c1913 ZJS |
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)); | |
817d1940 ZJS |
19 | assert_se(r == result); |
20 | if (r >= 0) | |
21 | assert_se(streq_ptr(b->address, expected)); | |
8a0c1913 ZJS |
22 | } |
23 | ||
68da8adf | 24 | TEST(bus_set_address_system_remote) { |
8a0c1913 ZJS |
25 | _cleanup_(sd_bus_unrefp) sd_bus *b = NULL; |
26 | ||
27 | assert_se(sd_bus_new(&b) >= 0); | |
68da8adf | 28 | if (!strv_isempty(saved_argv + 1)) { |
68da8adf | 29 | STRV_FOREACH(a, saved_argv + 1) |
8a0c1913 ZJS |
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); | |
817d1940 ZJS |
40 | test_one_address(b, "host:", |
41 | -EINVAL, NULL); | |
8a0c1913 ZJS |
42 | test_one_address(b, "user@host", |
43 | 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=user%40host,argv4=systemd-stdio-bridge"); | |
8f37636d LP |
44 | test_one_address(b, "user@host@host", |
45 | -EINVAL, NULL); | |
8a0c1913 ZJS |
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"); | |
6a555849 SL |
52 | test_one_address(b, "user@[::1]:", |
53 | -EINVAL, NULL); | |
8a0c1913 ZJS |
54 | test_one_address(b, "user@[::1:", |
55 | -EINVAL, NULL); | |
6a555849 SL |
56 | test_one_address(b, "user@", |
57 | -EINVAL, NULL); | |
58 | test_one_address(b, "user@@", | |
59 | -EINVAL, NULL); | |
8a0c1913 ZJS |
60 | } |
61 | ||
68da8adf | 62 | DEFINE_TEST_MAIN(LOG_INFO); |