| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "ask-password-api.h" |
| 4 |
#include "strv.h" |
| 5 |
#include "tests.h" |
| 6 |
|
| 7 |
TEST(ask_password) { |
| 8 |
_cleanup_strv_free_ char **ret = NULL; |
| 9 |
int r; |
| 10 |
|
| 11 |
static const AskPasswordRequest req = { |
| 12 |
.tty_fd = -EBADF, |
| 13 |
.message = "hello?", |
| 14 |
.keyring = "da key", |
| 15 |
.until = USEC_INFINITY, |
| 16 |
.hup_fd = -EBADF, |
| 17 |
}; |
| 18 |
|
| 19 |
r = ask_password_tty(&req, /* flags= */ ASK_PASSWORD_CONSOLE_COLOR, &ret); |
| 20 |
if (r == -ECANCELED) |
| 21 |
ASSERT_NULL(ret); |
| 22 |
else { |
| 23 |
ASSERT_OK(r); |
| 24 |
assert_se(strv_length(ret) == 1); |
| 25 |
log_info("Got \"%s\"", *ret); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
DEFINE_TEST_MAIN(LOG_DEBUG); |