summaryrefslogtreecommitdiff
path: root/src/test/test-ask-password-api.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-02-06 09:32:16 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-02-06 10:51:13 +0100
commit72c08a471c9ccb65209b72ea539acefe17c33245 (patch)
treebd11c6f85deaa725c1c0e73dbbfdd1626692b830 /src/test/test-ask-password-api.c
parent39e96f844a467400cda1dd24401b2c8fbe480eeb (diff)
downloadsystemd-72c08a471c9ccb65209b72ea539acefe17c33245.tar.gz
shared/ask-password-api: return "error" when dialogue is cancelled
test-ask-password-api would crash if ^D was pressed. If think the callers generally expect a non-empty strv as reply. Let's return an error if we have nothing to return. Also modernize test-ask-password-api a bit.
Diffstat (limited to 'src/test/test-ask-password-api.c')
-rw-r--r--src/test/test-ask-password-api.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/test/test-ask-password-api.c b/src/test/test-ask-password-api.c
index fa91869cf5..13a1064b45 100644
--- a/src/test/test-ask-password-api.c
+++ b/src/test/test-ask-password-api.c
@@ -1,24 +1,26 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
-#include "alloc-util.h"
#include "ask-password-api.h"
-#include "log.h"
#include "strv.h"
+#include "tests.h"
-static void ask_password(void) {
+static void test_ask_password(void) {
int r;
_cleanup_strv_free_ char **ret = NULL;
r = ask_password_tty(-1, "hello?", "da key", 0, 0, NULL, &ret);
- assert(r >= 0);
- assert(strv_length(ret) == 1);
-
- log_info("Got %s", *ret);
+ if (r == -ECANCELED)
+ assert_se(ret == NULL);
+ else {
+ assert_se(r >= 0);
+ assert_se(strv_length(ret) == 1);
+ log_info("Got \"%s\"", *ret);
+ }
}
int main(int argc, char **argv) {
- log_parse_environment();
+ test_setup_logging(LOG_DEBUG);
- ask_password();
+ test_ask_password();
return EXIT_SUCCESS;
}